changeset 20154:f7a805f02723

link undo in main window to editor if the latter has focus (bug #44402) * file-editor.cc (editor_tab_has_focus): helper function checking whether an edit area has the focus; (copyClipboard, pasteClipboard, selectAll): use this helper function; (do_undo): new slot for the undo action triggered from the main window * file-editor.h: new helper function and new slots * main-window.cc (handle_undo_request): emit a signal for undo instead of undoing in terminal window when terminal does not have focus * main-window.h: new undo signal * octave-dock-widget.cc (octave_dock_widget): connect undo signal from main-window to new virtual slot; * octave-dock-widget.h: new virtual slot do_undo, doing nothing
author Torsten <ttl@justmail.de>
date Sat, 14 Mar 2015 18:54:23 +0100
parents 941e782d0429
children 4910b70d7328
files libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/main-window.cc libgui/src/main-window.h libgui/src/octave-dock-widget.cc libgui/src/octave-dock-widget.h
diffstat 6 files changed, 36 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc
+++ b/libgui/src/m-editor/file-editor.cc
@@ -1759,35 +1759,39 @@
   check_actions ();
 }
 
+bool
+file_editor::editor_tab_has_focus ()
+{
+  QWidget * foc_w = focusWidget ();
+  if (foc_w && foc_w->inherits ("octave_qscintilla"))
+    return true;
+  return false;
+}
+
 void
 file_editor::copyClipboard ()
 {
-  QWidget * foc_w = focusWidget ();
-
-  if (foc_w && foc_w->inherits ("octave_qscintilla"))
-    {
-      request_copy (true);
-    }
+  if (editor_tab_has_focus ())
+    request_copy (true);
 }
 void
 file_editor::pasteClipboard ()
 {
-  QWidget * foc_w = focusWidget ();
-
-  if (foc_w && foc_w->inherits ("octave_qscintilla"))
-    {
-      request_paste (true);
-    }
+  if (editor_tab_has_focus ())
+    request_paste (true);
 }
 void
 file_editor::selectAll ()
 {
-  QWidget * foc_w = focusWidget ();
+  if (editor_tab_has_focus ())
+    request_selectall (true);
+}
 
-  if (foc_w && foc_w->inherits ("octave_qscintilla"))
-    {
-      request_selectall (true);
-    }
+void
+file_editor::do_undo ()
+{
+  if (editor_tab_has_focus ())
+    request_undo (true);
 }
 
 void
--- a/libgui/src/m-editor/file-editor.h
+++ b/libgui/src/m-editor/file-editor.h
@@ -213,6 +213,7 @@
   void copyClipboard ();
   void pasteClipboard ();
   void selectAll ();
+  void do_undo ();
 
 private slots:
 
@@ -252,6 +253,8 @@
 
   void toggle_preference (const QString& preference, bool def);
 
+  bool editor_tab_has_focus ();
+
   QWidget *find_tab_widget (const QString& openFileName) const;
   QAction *add_action (QMenu *menu, const QIcon &icon, const QString &text,
                        const char *member);
--- a/libgui/src/main-window.cc
+++ b/libgui/src/main-window.cc
@@ -287,7 +287,10 @@
 void
 main_window::handle_undo_request (void)
 {
-  octave_link::post_event (this, &main_window::command_window_undo_callback);
+  if (command_window_has_focus ())
+    octave_link::post_event (this, &main_window::command_window_undo_callback);
+  else
+    emit undo_signal ();
 }
 
 void
--- a/libgui/src/main-window.h
+++ b/libgui/src/main-window.h
@@ -103,6 +103,7 @@
   void copyClipboard_signal (void);
   void pasteClipboard_signal (void);
   void selectAll_signal (void);
+  void undo_signal (void);
 
 public slots:
 
--- a/libgui/src/octave-dock-widget.cc
+++ b/libgui/src/octave-dock-widget.cc
@@ -115,6 +115,8 @@
            this, SLOT (pasteClipboard ()));
   connect (p, SIGNAL (selectAll_signal ()),
            this, SLOT (selectAll ()));
+  // undo handling
+  connect (p, SIGNAL (undo_signal ()), this, SLOT (do_undo ()));
 
   installEventFilter (this);
 
--- a/libgui/src/octave-dock-widget.h
+++ b/libgui/src/octave-dock-widget.h
@@ -97,15 +97,11 @@
       emit active_changed (true);
   }
   /** slots to handle copy & paste */
-  virtual void copyClipboard ()
-  {
-  }
-  virtual void pasteClipboard ()
-  {
-  }
-  virtual void selectAll ()
-  {
-  }
+  virtual void copyClipboard () {  }
+  virtual void pasteClipboard () {  }
+  virtual void selectAll () {  }
+  /** slots to handle undo */
+  virtual void do_undo () {  }
 
   // event filter for double clicks into the window decoration elements
   bool eventFilter(QObject *obj, QEvent *e);