changeset 19632:101ce4eaa56c gui-release

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
author Torsten <ttl@justmail.de>
date Sun, 25 Jan 2015 20:03:17 +0100
parents 4e85ca0b4887
children 5d1c7e967742
files libgui/src/main-window.cc libgui/src/main-window.h libgui/src/settings-dialog.cc libgui/src/settings-dialog.h libgui/src/settings-dialog.ui
diffstat 5 files changed, 52 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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 <QToolButton>
 #include <QComboBox>
 #include <QSemaphore>
+#include <QPointer>
 
 // 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_dialog> _settings_dlg;
+
   // Find files dialog
   find_files_dialog * find_files_dlg;
 
--- 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 <QString, QWidget*> 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 <QString, QWidget*> 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
--- 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);
 
--- 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 @@
    </hints>
   </connection>
   <connection>
-   <sender>button_box</sender>
-   <signal>accepted()</signal>
-   <receiver>settings_dialog</receiver>
-   <slot>accept()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>299</x>
-     <y>366</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>299</x>
-     <y>199</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>button_box</sender>
-   <signal>rejected()</signal>
-   <receiver>settings_dialog</receiver>
-   <slot>reject()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>299</x>
-     <y>366</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>299</x>
-     <y>199</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
    <sender>useCustomFileEditor</sender>
    <signal>toggled(bool)</signal>
    <receiver>customEditorLabel</receiver>