Commit 59c8b933 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

Modified IOptionsPage interface for Apply button

The previous interface wasn't sufficient to properly support the Apply
button, since it didn't separate applying the changes from the cleanup
phase.

Designer settings pages still need some fixing.

Fixes Apply button causing problems for certain plugins, for example the
QuickOpen.
parent e6f7cb68
...@@ -54,7 +54,8 @@ public: ...@@ -54,7 +54,8 @@ public:
virtual QString trCategory() const = 0; virtual QString trCategory() const = 0;
virtual QWidget *createPage(QWidget *parent) = 0; virtual QWidget *createPage(QWidget *parent) = 0;
virtual void finished(bool accepted) = 0; virtual void apply() = 0;
virtual void finish() = 0;
}; };
} // namespace Core } // namespace Core
......
...@@ -126,20 +126,22 @@ void SettingsDialog::pageSelected(QTreeWidgetItem *) ...@@ -126,20 +126,22 @@ void SettingsDialog::pageSelected(QTreeWidgetItem *)
void SettingsDialog::accept() void SettingsDialog::accept()
{ {
foreach (IOptionsPage *page, m_pages) foreach (IOptionsPage *page, m_pages) {
page->finished(true); page->apply();
page->finish();
}
done(QDialog::Accepted); done(QDialog::Accepted);
} }
void SettingsDialog::reject() void SettingsDialog::reject()
{ {
foreach (IOptionsPage *page, m_pages) foreach (IOptionsPage *page, m_pages)
page->finished(false); page->finish();
done(QDialog::Rejected); done(QDialog::Rejected);
} }
void SettingsDialog::apply() void SettingsDialog::apply()
{ {
foreach (IOptionsPage *page, m_pages) foreach (IOptionsPage *page, m_pages)
page->finished(true); page->apply();
} }
...@@ -120,14 +120,14 @@ QWidget *ShortcutSettings::createPage(QWidget *parent) ...@@ -120,14 +120,14 @@ QWidget *ShortcutSettings::createPage(QWidget *parent)
return w; return w;
} }
void ShortcutSettings::finished(bool accepted) void ShortcutSettings::apply()
{ {
if (accepted) { foreach (ShortcutItem *item, m_scitems)
foreach (ShortcutItem *item, m_scitems) { item->m_cmd->setKeySequence(item->m_key);
item->m_cmd->setKeySequence(item->m_key); }
}
}
void ShortcutSettings::finish()
{
qDeleteAll(m_scitems); qDeleteAll(m_scitems);
m_scitems.clear(); m_scitems.clear();
} }
......
...@@ -77,7 +77,8 @@ public: ...@@ -77,7 +77,8 @@ public:
QString trCategory() const; QString trCategory() const;
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void finished(bool accepted); void apply();
void finish();
protected: protected:
bool eventFilter(QObject *o, QEvent *e); bool eventFilter(QObject *o, QEvent *e);
......
...@@ -81,11 +81,8 @@ QWidget *GeneralSettings::createPage(QWidget *parent) ...@@ -81,11 +81,8 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
return w; return w;
} }
void GeneralSettings::finished(bool accepted) void GeneralSettings::apply()
{ {
if (!accepted)
return;
// Apply the new base color if accepted // Apply the new base color if accepted
StyleHelper::setBaseColor(m_page->colorButton->color()); StyleHelper::setBaseColor(m_page->colorButton->color());
EditorManager::instance()->setExternalEditor(m_page->externalEditorEdit->text()); EditorManager::instance()->setExternalEditor(m_page->externalEditorEdit->text());
......
...@@ -55,7 +55,8 @@ public: ...@@ -55,7 +55,8 @@ public:
QString category() const; QString category() const;
QString trCategory() const; QString trCategory() const;
QWidget* createPage(QWidget *parent); QWidget* createPage(QWidget *parent);
void finished(bool accepted); void apply();
void finish() { }
private slots: private slots:
void resetInterfaceColor(); void resetInterfaceColor();
......
...@@ -86,11 +86,8 @@ QWidget *SettingsPage::createPage(QWidget *parent) ...@@ -86,11 +86,8 @@ QWidget *SettingsPage::createPage(QWidget *parent)
return w; return w;
} }
void SettingsPage::finished(bool accepted) void SettingsPage::apply()
{ {
if (!accepted)
return;
m_username = m_ui.userEdit->text(); m_username = m_ui.userEdit->text();
m_server = QUrl(m_ui.serverEdit->text()); m_server = QUrl(m_ui.serverEdit->text());
m_copy = m_ui.clipboardBox->isChecked(); m_copy = m_ui.clipboardBox->isChecked();
......
...@@ -59,7 +59,8 @@ public: ...@@ -59,7 +59,8 @@ public:
QString trCategory() const; QString trCategory() const;
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void finished(bool accepted); void apply();
void finish() { }
QString username() const; QString username() const;
QUrl serverUrl() const; QUrl serverUrl() const;
......
...@@ -78,11 +78,8 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent) ...@@ -78,11 +78,8 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent)
return w; return w;
} }
void CompletionSettingsPage::finished(bool accepted) void CompletionSettingsPage::apply()
{ {
if (!accepted)
return;
m_completion->setCaseSensitivity( m_completion->setCaseSensitivity(
m_page->caseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive); m_page->caseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive);
m_completion->setAutoInsertBraces(m_page->autoInsertBraces->isChecked()); m_completion->setAutoInsertBraces(m_page->autoInsertBraces->isChecked());
......
...@@ -56,7 +56,8 @@ public: ...@@ -56,7 +56,8 @@ public:
QString trCategory() const; QString trCategory() const;
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void finished(bool accepted); void apply();
void finish() { }
private: private:
CppCodeCompletion *m_completion; CppCodeCompletion *m_completion;
......
...@@ -122,11 +122,8 @@ void GdbOptionPage::onScriptFileChanged() ...@@ -122,11 +122,8 @@ void GdbOptionPage::onScriptFileChanged()
m_settings->m_scriptFile = m_ui.scriptFileChooser->path(); m_settings->m_scriptFile = m_ui.scriptFileChooser->path();
} }
void GdbOptionPage::finished(bool accepted) void GdbOptionPage::apply()
{ {
if (!accepted)
return;
m_settings->m_gdbCmd = m_ui.gdbLocationChooser->path(); m_settings->m_gdbCmd = m_ui.gdbLocationChooser->path();
m_settings->m_gdbEnv = m_ui.environmentEdit->text(); m_settings->m_gdbEnv = m_ui.environmentEdit->text();
m_settings->m_autoRun = m_ui.autoStartBox->isChecked(); m_settings->m_autoRun = m_ui.autoStartBox->isChecked();
......
...@@ -59,7 +59,8 @@ public: ...@@ -59,7 +59,8 @@ public:
QString trCategory() const; QString trCategory() const;
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void finished(bool accepted); void apply();
void finish() { }
public slots: public slots:
void onGdbLocationChanged(); void onGdbLocationChanged();
......
...@@ -39,7 +39,8 @@ ...@@ -39,7 +39,8 @@
using namespace Designer::Internal; using namespace Designer::Internal;
SettingsPage::SettingsPage(QDesignerOptionsPageInterface *designerPage) : SettingsPage::SettingsPage(QDesignerOptionsPageInterface *designerPage) :
m_designerPage(designerPage) m_designerPage(designerPage),
m_applyOnFinish(false)
{ {
} }
...@@ -64,10 +65,17 @@ QString SettingsPage::trCategory() const ...@@ -64,10 +65,17 @@ QString SettingsPage::trCategory() const
QWidget *SettingsPage::createPage(QWidget *parent) QWidget *SettingsPage::createPage(QWidget *parent)
{ {
m_applyOnFinish = false;
return m_designerPage->createPage(parent); return m_designerPage->createPage(parent);
} }
void SettingsPage::finished(bool accepted) void SettingsPage::apply()
{ {
m_designerPage->finish(accepted); // FIXME: Since no cleanup should be done here, we can't call finish(true)
m_applyOnFinish = true;
}
void SettingsPage::finish()
{
m_designerPage->finish(m_applyOnFinish);
} }
...@@ -59,10 +59,12 @@ public: ...@@ -59,10 +59,12 @@ public:
QString trCategory() const; QString trCategory() const;
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void finished(bool accepted); void apply();
void finish();
private: private:
QDesignerOptionsPageInterface *m_designerPage; QDesignerOptionsPageInterface *m_designerPage;
bool m_applyOnFinish;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -95,11 +95,10 @@ QWidget *SettingsPage::createPage(QWidget *parent) ...@@ -95,11 +95,10 @@ QWidget *SettingsPage::createPage(QWidget *parent)
return m_widget; return m_widget;
} }
void SettingsPage::finished(bool accepted) void SettingsPage::apply()
{ {
if (!accepted || !m_widget) if (!m_widget)
return; return;
GitPlugin::instance()->setSettings(m_widget->settings()); GitPlugin::instance()->setSettings(m_widget->settings());
} }
...@@ -77,7 +77,8 @@ public: ...@@ -77,7 +77,8 @@ public:
QString trCategory() const; QString trCategory() const;
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void finished(bool accepted); void apply();
void finish() { }
private: private:
QPointer<SettingsPageWidget> m_widget; QPointer<SettingsPageWidget> m_widget;
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include <QtHelp/QHelpEngine> #include <QtHelp/QHelpEngine>
using namespace Help::Internal; using namespace Help::Internal;
DocSettingsPage::DocSettingsPage(QHelpEngine *helpEngine) DocSettingsPage::DocSettingsPage(QHelpEngine *helpEngine)
: m_helpEngine(helpEngine), : m_helpEngine(helpEngine),
m_registeredDocs(false) m_registeredDocs(false)
...@@ -64,16 +64,16 @@ QWidget *DocSettingsPage::createPage(QWidget *parent) ...@@ -64,16 +64,16 @@ QWidget *DocSettingsPage::createPage(QWidget *parent)
{ {
QWidget *w = new QWidget(parent); QWidget *w = new QWidget(parent);
m_ui.setupUi(w); m_ui.setupUi(w);
connect(m_ui.addButton, SIGNAL(clicked()), connect(m_ui.addButton, SIGNAL(clicked()),
this, SLOT(addDocumentation())); this, SLOT(addDocumentation()));
connect(m_ui.removeButton, SIGNAL(clicked()), connect(m_ui.removeButton, SIGNAL(clicked()),
this, SLOT(removeDocumentation())); this, SLOT(removeDocumentation()));
m_ui.docsListWidget->addItems(m_helpEngine->registeredDocumentations()); m_ui.docsListWidget->addItems(m_helpEngine->registeredDocumentations());
m_registeredDocs = false; m_registeredDocs = false;
m_removeDocs.clear(); m_removeDocs.clear();
return w; return w;
} }
...@@ -82,7 +82,7 @@ void DocSettingsPage::addDocumentation() ...@@ -82,7 +82,7 @@ void DocSettingsPage::addDocumentation()
QStringList files = QFileDialog::getOpenFileNames(m_ui.addButton->parentWidget(), QStringList files = QFileDialog::getOpenFileNames(m_ui.addButton->parentWidget(),
tr("Add Documentation"), tr("Add Documentation"),
QString(), tr("Qt Help Files (*.qch)")); QString(), tr("Qt Help Files (*.qch)"));
if (files.isEmpty()) if (files.isEmpty())
return; return;
...@@ -107,23 +107,20 @@ void DocSettingsPage::removeDocumentation() ...@@ -107,23 +107,20 @@ void DocSettingsPage::removeDocumentation()
QListWidgetItem *item = m_ui.docsListWidget->currentItem(); QListWidgetItem *item = m_ui.docsListWidget->currentItem();
if (!item) if (!item)
return; return;
m_removeDocs.append(item->text()); m_removeDocs.append(item->text());
int row = m_ui.docsListWidget->currentRow(); int row = m_ui.docsListWidget->currentRow();
m_ui.docsListWidget->takeItem(row); m_ui.docsListWidget->takeItem(row);
if (row > 0) if (row > 0)
--row; --row;
if (m_ui.docsListWidget->count()) if (m_ui.docsListWidget->count())
m_ui.docsListWidget->setCurrentRow(row); m_ui.docsListWidget->setCurrentRow(row);
delete item; delete item;
} }
void DocSettingsPage::finished(bool accepted) void DocSettingsPage::apply()
{ {
if (!accepted)
return;
emit dialogAccepted(); emit dialogAccepted();
} }
......
...@@ -57,7 +57,8 @@ public: ...@@ -57,7 +57,8 @@ public:
QString trCategory() const; QString trCategory() const;
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void finished(bool accepted); void apply();
void finish() { }
bool applyChanges(); bool applyChanges();
......
...@@ -173,8 +173,10 @@ void FilterSettingsPage::removeFilter() ...@@ -173,8 +173,10 @@ void FilterSettingsPage::removeFilter()
m_ui.filterWidget->setCurrentRow(0); m_ui.filterWidget->setCurrentRow(0);
} }
void FilterSettingsPage::finished(bool) void FilterSettingsPage::apply()
{ {
// This is handled via HelpPlugin::checkForHelpChanges, which is connected
// to DocSettingsPage::apply.
} }
bool FilterSettingsPage::applyChanges() bool FilterSettingsPage::applyChanges()
......
...@@ -56,7 +56,8 @@ public: ...@@ -56,7 +56,8 @@ public:
QString trCategory() const; QString trCategory() const;
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void finished(bool accepted); void apply();
void finish() { }
bool applyChanges(); bool applyChanges();
......
...@@ -96,9 +96,9 @@ QWidget *SettingsPage::createPage(QWidget *parent) ...@@ -96,9 +96,9 @@ QWidget *SettingsPage::createPage(QWidget *parent)
return m_widget; return m_widget;
} }
void SettingsPage::finished(bool accepted) void SettingsPage::apply()
{ {
if (!accepted || !m_widget) if (!m_widget)
return; return;
PerforcePlugin::perforcePluginInstance()->setSettings(m_widget->settings()); PerforcePlugin::perforcePluginInstance()->setSettings(m_widget->settings());
......
...@@ -70,7 +70,8 @@ public: ...@@ -70,7 +70,8 @@ public:
QString trCategory() const; QString trCategory() const;
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void finished(bool accepted); void apply();
void finish() { }
private: private:
QPointer<SettingsPageWidget> m_widget; QPointer<SettingsPageWidget> m_widget;
......
...@@ -162,11 +162,8 @@ void QtVersionManager::updateUniqueIdToIndexMap() ...@@ -162,11 +162,8 @@ void QtVersionManager::updateUniqueIdToIndexMap()
m_uniqueIdToIndex.insert(m_versions.at(i)->uniqueId(), i); m_uniqueIdToIndex.insert(m_versions.at(i)->uniqueId(), i);
} }
void QtVersionManager::finished(bool accepted) void QtVersionManager::apply()
{ {
if (!accepted)
return;
m_widget->finish(); m_widget->finish();
QList<QtVersion*> newVersions = m_widget->versions(); QList<QtVersion*> newVersions = m_widget->versions();
bool versionPathsChanged = m_versions.size() != newVersions.size(); bool versionPathsChanged = m_versions.size() != newVersions.size();
......
...@@ -172,7 +172,8 @@ public: ...@@ -172,7 +172,8 @@ public:
QString trCategory() const; QString trCategory() const;
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void finished(bool accepted); void apply();
void finish() { }
void writeVersionsIntoSettings(); void writeVersionsIntoSettings();
......
...@@ -71,7 +71,7 @@ QList<FilterEntry> QuickOpenFiltersFilter::matchesFor(const QString &entry) ...@@ -71,7 +71,7 @@ QList<FilterEntry> QuickOpenFiltersFilter::matchesFor(const QString &entry)
{ {
QList<FilterEntry> entries; QList<FilterEntry> entries;
if (entry.isEmpty()) { if (entry.isEmpty()) {
foreach (IQuickOpenFilter *filter, m_plugin->filter()) { foreach (IQuickOpenFilter *filter, m_plugin->filters()) {
if (!filter->shortcutString().isEmpty() && !filter->isHidden()) { if (!filter->shortcutString().isEmpty() && !filter->isHidden()) {
FilterEntry entry(this, FilterEntry entry(this,
filter->shortcutString(), filter->shortcutString(),
......
...@@ -76,8 +76,7 @@ QuickOpenPlugin::~QuickOpenPlugin() ...@@ -76,8 +76,7 @@ QuickOpenPlugin::~QuickOpenPlugin()
delete m_openDocumentsFilter; delete m_openDocumentsFilter;
delete m_fileSystemFilter; delete m_fileSystemFilter;
delete m_settingsPage; delete m_settingsPage;
foreach (IQuickOpenFilter *filter, m_customFilter) qDeleteAll(m_customFilters);
delete filter;
} }
bool QuickOpenPlugin::initialize(const QStringList &, QString *) bool QuickOpenPlugin::initialize(const QStringList &, QString *)
...@@ -125,8 +124,8 @@ void QuickOpenPlugin::openQuickOpen() ...@@ -125,8 +124,8 @@ void QuickOpenPlugin::openQuickOpen()
void QuickOpenPlugin::extensionsInitialized() void QuickOpenPlugin::extensionsInitialized()
{ {
m_filter = ExtensionSystem::PluginManager::instance()->getObjects<IQuickOpenFilter>(); m_filters = ExtensionSystem::PluginManager::instance()->getObjects<IQuickOpenFilter>();