# HG changeset patch # User Torsten # Date 1398620214 -7200 # Node ID fac35875f6eb7011d7a42bced12096dcb3060a61 # Parent 02b75b57ed80dde2711d2bc8a3242e97977ca54c 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 diff -r 02b75b57ed80 -r fac35875f6eb libgui/src/m-editor/file-editor-tab.h --- 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); diff -r 02b75b57ed80 -r fac35875f6eb libgui/src/m-editor/file-editor.cc --- 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); } diff -r 02b75b57ed80 -r fac35875f6eb libgui/src/m-editor/file-editor.h --- 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: diff -r 02b75b57ed80 -r fac35875f6eb libgui/src/m-editor/octave-qscintilla.cc --- 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 diff -r 02b75b57ed80 -r fac35875f6eb libgui/src/m-editor/octave-qscintilla.h --- 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);