# HG changeset patch # User Torsten # Date 1422212597 -3600 # Node ID 101ce4eaa56c84f5dda2ad075068341417751342 # Parent 4e85ca0b48878e185fc49664d878c44147b68d33 prevent opening the settings dialog multiple times * main-window.h: settings dialog is now a guarded pointer and class member * main-window.cc (constructor): initialize settings dialog pointer to 0; (destructor): delete pointer if necessary; (process_settings_dialog_request): only switch to desired tab if settings dialog already exists; * settings-dialog.h: new function show_tab, write_changed_setting provate now * settings-dialog.cc (constructor) do not set desired tab here; (show_tab): but here so it can be called independently (button_clicked): close the dialog when ok or cancel was clicked * settings-dialog.ui: removed accepted/rejected signals from the button box since closing the dialog is now done in settings_dialog::button_clicked diff -r 4e85ca0b4887 -r 101ce4eaa56c libgui/src/main-window.cc --- a/libgui/src/main-window.cc Sun Jan 25 12:22:48 2015 +0100 +++ b/libgui/src/main-window.cc Sun Jan 25 20:03:17 2015 +0100 @@ -85,6 +85,7 @@ doc_browser_window (new documentation_dock_widget (this)), editor_window (create_default_editor (this)), workspace_window (new workspace_view (this)), + _settings_dlg (0), find_files_dlg (0), release_notes_window (0), community_news_window (0), @@ -150,6 +151,11 @@ delete release_notes_window; release_notes_window = 0; } + if (_settings_dlg) + { + delete _settings_dlg; + _settings_dlg = 0; + } if (community_news_window) { delete community_news_window; @@ -668,14 +674,21 @@ void main_window::process_settings_dialog_request (const QString& desired_tab) { - settings_dialog *settingsDialog = new settings_dialog (this, desired_tab); - - connect (settingsDialog, SIGNAL (apply_new_settings ()), + if (_settings_dlg) // _settings_dlg is a guarded pointer! + { // here the dialog is still open and called once again + if (! desired_tab.isEmpty ()) + _settings_dlg->show_tab (desired_tab); + return; + } + + _settings_dlg = new settings_dialog (this, desired_tab); + + connect (_settings_dlg, SIGNAL (apply_new_settings ()), this, SLOT (request_reload_settings ())); - settingsDialog->setModal (false); - settingsDialog->setAttribute (Qt::WA_DeleteOnClose); - settingsDialog->show (); + _settings_dlg->setModal (false); + _settings_dlg->setAttribute (Qt::WA_DeleteOnClose); + _settings_dlg->show (); } void diff -r 4e85ca0b4887 -r 101ce4eaa56c libgui/src/main-window.h --- a/libgui/src/main-window.h Sun Jan 25 12:22:48 2015 +0100 +++ b/libgui/src/main-window.h Sun Jan 25 20:03:17 2015 +0100 @@ -37,6 +37,7 @@ #include #include #include +#include // Editor includes #include "file-editor-interface.h" @@ -57,6 +58,8 @@ #include "octave-dock-widget.h" #include "find-files-dialog.h" +class settings_dialog; + /** * \class MainWindow * @@ -105,7 +108,6 @@ void focus_changed (QWidget *w_old, QWidget *w_new); void request_reload_settings (); - void report_status_message (const QString& statusMessage); void handle_save_workspace_request (void); void handle_load_workspace_request (const QString& file = QString ()); @@ -379,6 +381,9 @@ static const int current_directory_max_count = 16; QLineEdit *_current_directory_line_edit; + // settings dialog as guarded pointer (set to 0 when deleted) + QPointer _settings_dlg; + // Find files dialog find_files_dialog * find_files_dlg; diff -r 4e85ca0b4887 -r 101ce4eaa56c libgui/src/settings-dialog.cc --- a/libgui/src/settings-dialog.cc Sun Jan 25 12:22:48 2015 +0100 +++ b/libgui/src/settings-dialog.cc Sun Jan 25 20:03:17 2015 +0100 @@ -388,18 +388,9 @@ #endif // which tab is the desired one? - if (desired_tab.isEmpty ()) - ui->tabWidget->setCurrentIndex (settings->value ("settings/last_tab", - 0).toInt ()); - else - { - QHash tab_hash; - tab_hash["editor"] = ui->tab_editor; - tab_hash["editor_styles"] = ui->tab_editor_styles; - ui->tabWidget->setCurrentIndex ( - ui->tabWidget->indexOf (tab_hash.value (desired_tab))); - } + show_tab (desired_tab); + // connect button box signal connect (ui->button_box, SIGNAL (clicked (QAbstractButton *)), this, SLOT (button_clicked (QAbstractButton *))); } @@ -409,6 +400,24 @@ delete ui; } +void +settings_dialog::show_tab (const QString& tab) +{ + if (tab.isEmpty ()) + { + QSettings *settings = resource_manager::get_settings (); + ui->tabWidget->setCurrentIndex (settings->value ("settings/last_tab", + 0).toInt ()); + } + else + { + QHash tab_hash; + tab_hash["editor"] = ui->tab_editor; + tab_hash["editor_styles"] = ui->tab_editor_styles; + ui->tabWidget->setCurrentIndex ( + ui->tabWidget->indexOf (tab_hash.value (tab))); + } +} #ifdef HAVE_QSCINTILLA int @@ -957,6 +966,10 @@ write_changed_settings (); emit apply_new_settings (); } + + if (button_role == QDialogButtonBox::RejectRole || + button_role == QDialogButtonBox::AcceptRole) + close (); } void diff -r 4e85ca0b4887 -r 101ce4eaa56c libgui/src/settings-dialog.h --- a/libgui/src/settings-dialog.h Sun Jan 25 12:22:48 2015 +0100 +++ b/libgui/src/settings-dialog.h Sun Jan 25 20:03:17 2015 +0100 @@ -44,7 +44,7 @@ explicit settings_dialog (QWidget * parent, const QString& desired_tab = QString ()); ~settings_dialog (); - void write_changed_settings (); + void show_tab (const QString&); signals: void apply_new_settings (); @@ -74,6 +74,8 @@ MaxStyleNumber = 128 }; #endif + void write_changed_settings (); + void read_workspace_colors (QSettings *settings); void write_workspace_colors (QSettings *settings); diff -r 4e85ca0b4887 -r 101ce4eaa56c libgui/src/settings-dialog.ui --- a/libgui/src/settings-dialog.ui Sun Jan 25 12:22:48 2015 +0100 +++ b/libgui/src/settings-dialog.ui Sun Jan 25 20:03:17 2015 +0100 @@ -2460,38 +2460,6 @@ - button_box - accepted() - settings_dialog - accept() - - - 299 - 366 - - - 299 - 199 - - - - - button_box - rejected() - settings_dialog - reject() - - - 299 - 366 - - - 299 - 199 - - - - useCustomFileEditor toggled(bool) customEditorLabel