changeset 19463:be53bf420464 gui-release

fix access to already removed editor window at exit * file-editor.h: enable_menu_shortcuts is a slot, no ordinary function * main-window.cc (focus_changed): emit new signal editor_focus_changed when editor gets or loses focus; (set_global_edit_shortcuts): boolean parameter is true when editor has focus, do not enable editor menus here; (construct): connect new signal editor_focus_changed to slot for setting global shortcuts and for dis- or enabling the editor menu * main-window.h: new signal editor_focus_changed
author Torsten <ttl@justmail.de>
date Thu, 25 Dec 2014 15:48:43 +0100
parents 3c038da18218
children 472a5572849c
files libgui/src/m-editor/file-editor.h libgui/src/main-window.cc libgui/src/main-window.h
diffstat 3 files changed, 23 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.h	Thu Dec 25 08:31:31 2014 +0100
+++ b/libgui/src/m-editor/file-editor.h	Thu Dec 25 15:48:43 2014 +0100
@@ -63,7 +63,6 @@
 
   void check_actions (void);
   void empty_script (bool startup, bool visible);
-  void enable_menu_shortcuts (bool enable);
 
 signals:
 
@@ -114,7 +113,9 @@
   void file_loaded_signal ();
 
 public slots:
+
   void focus (void);
+  void enable_menu_shortcuts (bool);
   bool check_closing (int closing_state);
 
   void request_new_file (const QString& commands);
--- a/libgui/src/main-window.cc	Thu Dec 25 08:31:31 2014 +0100
+++ b/libgui/src/main-window.cc	Thu Dec 25 15:48:43 2014 +0100
@@ -191,9 +191,9 @@
       octave_dock_widget *edit_dock_widget =
                         static_cast <octave_dock_widget *> (editor_window);
       if (edit_dock_widget == dock)
-        set_global_edit_shortcuts (false);
+        emit editor_focus_changed (true);
       else if (edit_dock_widget == _active_dock)
-        set_global_edit_shortcuts (true);
+        emit editor_focus_changed (false);
 
       _active_dock = dock;
     }
@@ -1278,6 +1278,12 @@
   connect (this, SIGNAL (settings_changed (const QSettings *)),
            this, SLOT (notice_settings (const QSettings *)));
 
+  connect (this, SIGNAL (editor_focus_changed (bool)),
+           this, SLOT (set_global_edit_shortcuts (bool)));
+
+  connect (this, SIGNAL (editor_focus_changed (bool)),
+           editor_window, SLOT (enable_menu_shortcuts (bool)));
+
   connect (file_browser_window, SIGNAL (load_file_signal (const QString&)),
            this, SLOT (handle_load_workspace_request (const QString&)));
 
@@ -2312,30 +2318,27 @@
 }
 
 void
-main_window::set_global_edit_shortcuts (bool enable)
+main_window::set_global_edit_shortcuts (bool editor_has_focus)
 {
   // this slot is called when editor gets/loses focus
-  if (enable)
-    { // editor loses focus, set the global shortcuts
-      // and disable the editor's menu
-      shortcut_manager::set_shortcut (_copy_action, "main_edit:copy");
-      shortcut_manager::set_shortcut (_paste_action, "main_edit:paste");
-      shortcut_manager::set_shortcut (_undo_action, "main_edit:undo");
-      shortcut_manager::set_shortcut (_select_all_action, "main_edit:select_all");
-    }
-  else
+  if (editor_has_focus)
     { // disable shortcuts that are also provided by the editor itself
-      // and enable editor's menu
       QKeySequence no_key = QKeySequence ();
       _copy_action->setShortcut (no_key);
       _paste_action->setShortcut (no_key);
       _undo_action->setShortcut (no_key);
       _select_all_action->setShortcut (no_key);
     }
-
-  // enable/disable the main and the editor's menu shortcuts (alt-key)
-  editor_window->enable_menu_shortcuts (! enable);
-  enable_menu_shortcuts (enable);
+  else
+    { // editor loses focus, set the global shortcuts
+      shortcut_manager::set_shortcut (_copy_action, "main_edit:copy");
+      shortcut_manager::set_shortcut (_paste_action, "main_edit:paste");
+      shortcut_manager::set_shortcut (_undo_action, "main_edit:undo");
+      shortcut_manager::set_shortcut (_select_all_action, "main_edit:select_all");
+    }
+
+  // dis-/enable global menu depending on editor's focus
+  enable_menu_shortcuts (! editor_has_focus);
 }
 
 void
--- a/libgui/src/main-window.h	Thu Dec 25 08:31:31 2014 +0100
+++ b/libgui/src/main-window.h	Thu Dec 25 15:48:43 2014 +0100
@@ -82,6 +82,7 @@
 signals:
 
   void active_dock_changed (octave_dock_widget *, octave_dock_widget *);
+  void editor_focus_changed (bool);
 
   void settings_changed (const QSettings *);
   void init_terminal_size_signal (void);