changeset 18689:fac35875f6eb gui-release

update enabled status of undo/redo actions in the editor * file-editor-tab.h: new inline function returning the qscintilla edit area * octave-qscintilla.cc (constructor): connect textChanged signal to new private slot text_changed; (text_changed): new slot emitting a signal on undo/redo availability * octave-qscintilla.h: new slot and new signal * file-editor.cc (edit_status_update): new slot for updating undo/redo actions; (construct): undo/redo actions disabled at the beginning; (add_new_edit_tab): connect new slot to the signal from the qscintilla edit area indicating undo/redo availability * file-editor.h: new slot
author Torsten <ttl@justmail.de>
date Sun, 27 Apr 2014 19:36:54 +0200
parents 02b75b57ed80
children 834f6e604dc3
files libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/m-editor/octave-qscintilla.cc libgui/src/m-editor/octave-qscintilla.h
diffstat 5 files changed, 27 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.h	Sun Apr 27 18:42:25 2014 +0200
+++ b/libgui/src/m-editor/file-editor-tab.h	Sun Apr 27 19:36:54 2014 +0200
@@ -47,6 +47,8 @@
 
   ~file_editor_tab (void);
 
+  octave_qscintilla *qsci_edit_area () { return _edit_area; }
+
 public slots:
 
   void update_window_title (bool modified);
--- a/libgui/src/m-editor/file-editor.cc	Sun Apr 27 18:42:25 2014 +0200
+++ b/libgui/src/m-editor/file-editor.cc	Sun Apr 27 19:36:54 2014 +0200
@@ -986,6 +986,13 @@
 }
 
 void
+file_editor::edit_status_update (bool undo, bool redo)
+{
+  _undo_action->setEnabled (undo);
+  _redo_action->setEnabled (redo);
+}
+
+void
 file_editor::handle_editor_state_changed (bool copy_available,
                                           const QString& file_name)
 {
@@ -1158,8 +1165,10 @@
 
   _undo_action = add_action (editMenu, QIcon (":/actions/icons/undo.png"),
           tr ("&Undo"), SLOT (request_undo (bool)));
+  _undo_action->setEnabled (false);
   _redo_action = add_action (editMenu, QIcon (":/actions/icons/redo.png"),
           tr ("&Redo"), SLOT (request_redo (bool)));
+  _redo_action->setEnabled (false);
 
   editMenu->addSeparator ();
 
@@ -1396,6 +1405,10 @@
 {
   _tab_widget->addTab (f, fn);
 
+  // signals from the qscintilla edit area
+  connect (f->qsci_edit_area (), SIGNAL (status_update (bool, bool)),
+           this, SLOT (edit_status_update (bool, bool)));
+
   // Signals from the file editor_tab
   connect (f, SIGNAL (file_name_changed (const QString&, const QString&)),
            this, SLOT (handle_file_name_changed (const QString&,
@@ -1640,8 +1653,6 @@
   _close_all_action->setEnabled (have_tabs);
   _close_others_action->setEnabled (have_tabs && _tab_widget->count () > 1);
 
-  _undo_action->setEnabled (have_tabs);
-  _redo_action->setEnabled (have_tabs);
   _selectall_action->setEnabled (have_tabs);
 }
 
--- a/libgui/src/m-editor/file-editor.h	Sun Apr 27 18:42:25 2014 +0200
+++ b/libgui/src/m-editor/file-editor.h	Sun Apr 27 19:36:54 2014 +0200
@@ -214,6 +214,7 @@
   void zoom_normal (bool);
 
   void create_context_menu (QMenu *);
+  void edit_status_update (bool, bool);
 
 protected:
 
--- a/libgui/src/m-editor/octave-qscintilla.cc	Sun Apr 27 18:42:25 2014 +0200
+++ b/libgui/src/m-editor/octave-qscintilla.cc	Sun Apr 27 19:36:54 2014 +0200
@@ -39,6 +39,8 @@
 octave_qscintilla::octave_qscintilla (QWidget *p)
   : QsciScintilla (p)
 {
+  connect (this, SIGNAL (textChanged ()), this, SLOT (text_changed ()));
+
   // clear scintilla edit shortcuts that are handled by the editor
   QsciCommandSet *cmd_set = standardCommands ();
 
@@ -263,4 +265,10 @@
   QsciScintilla::focusOutEvent(focusEvent);
 }
 
+void
+octave_qscintilla::text_changed ()
+{
+  emit status_update (isUndoAvailable (), isRedoAvailable ());
+}
+
 #endif
--- a/libgui/src/m-editor/octave-qscintilla.h	Sun Apr 27 18:42:25 2014 +0200
+++ b/libgui/src/m-editor/octave-qscintilla.h	Sun Apr 27 19:36:54 2014 +0200
@@ -52,6 +52,7 @@
   void execute_command_in_terminal_signal (const QString&);
   void create_context_menu_signal (QMenu*);
   void qsci_has_focus_signal (bool);
+  void status_update (bool,bool);
 
 private slots:
 
@@ -61,6 +62,8 @@
   void contextmenu_edit (bool);
   void contextmenu_run (bool);
 
+  void text_changed (void);
+
 protected:
 
   void focusInEvent (QFocusEvent *focusEvent);