# HG changeset patch # User Torsten Lilge # Date 1621879523 -7200 # Node ID bbf5d4ea616c493b4838e3b5d762945376b7b750 # Parent 3ef50a8d01c59775bae97ba87f2eccb3c82ef5ce fix enabled state of editor save action depending on modification state * file-editor-tab.cc (set_file_name): signal editor_state_changed with additional boolean argument with modification state; (handle_copy_available): dito; (change_editor_state): dito * file-editor-tab.h: dito * file-editor.cc (file_editor): initialize new class variable m_current_tab_modified with modified state of current tab; (check_actions): enable save action depending on modification state (handle_file_name_changed): enable save action and set class related class variable; (handle_editor_state_changed): additional boolean argument with modification state, enable save action accordingly and set the related class variable * file-editor.h: handle_editor_state_changed with third argument, new class variable diff -r 3ef50a8d01c5 -r bbf5d4ea616c libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Fri May 21 17:00:54 2021 +0200 +++ b/libgui/src/m-editor/file-editor-tab.cc Mon May 24 20:05:23 2021 +0200 @@ -504,7 +504,8 @@ } // update the file editor with current editing directory - emit editor_state_changed (m_copy_available, m_is_octave_file); + emit editor_state_changed (m_copy_available, m_is_octave_file, + m_edit_area->isModified ()); // add the new file to the most-recently-used list emit mru_add_file (m_file_name, m_encoding); @@ -1645,7 +1646,8 @@ void file_editor_tab::handle_copy_available (bool enableCopy) { m_copy_available = enableCopy; - emit editor_state_changed (m_copy_available, m_is_octave_file); + emit editor_state_changed (m_copy_available, m_is_octave_file, + m_edit_area->isModified ()); } // show_dialog: shows a modal or non modal dialog depending on input arg @@ -2818,7 +2820,8 @@ if (ID != this) return; - emit editor_state_changed (m_copy_available, m_is_octave_file); + emit editor_state_changed (m_copy_available, m_is_octave_file, + m_edit_area->isModified ()); } void file_editor_tab::handle_file_reload_answer (int decision) diff -r 3ef50a8d01c5 -r bbf5d4ea616c libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Fri May 21 17:00:54 2021 +0200 +++ b/libgui/src/m-editor/file-editor-tab.h Mon May 24 20:05:23 2021 +0200 @@ -74,7 +74,8 @@ void file_name_changed (const QString& fileName, const QString& toolTip, bool modified); - void editor_state_changed (bool copy_available, bool is_octave_file); + void editor_state_changed (bool copy_available, bool is_octave_file, + bool is_modified); void set_focus_editor_signal (QWidget *); void edit_area_changed (octave_qscintilla *edit_area); void tab_remove_request (void); diff -r 3ef50a8d01c5 -r bbf5d4ea616c libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Fri May 21 17:00:54 2021 +0200 +++ b/libgui/src/m-editor/file-editor.cc Mon May 24 20:05:23 2021 +0200 @@ -121,6 +121,7 @@ m_copy_action_enabled = false; m_undo_action_enabled = false; + m_current_tab_modified = false; construct (); @@ -239,7 +240,7 @@ m_remove_all_breakpoints_action->setEnabled (have_tabs && m_is_octave_file); m_edit_function_action->setEnabled (have_tabs); - m_save_action->setEnabled (have_tabs); + m_save_action->setEnabled (have_tabs && m_current_tab_modified); m_save_as_action->setEnabled (have_tabs); m_close_action->setEnabled (have_tabs); m_close_all_action->setEnabled (have_tabs); @@ -956,6 +957,10 @@ { m_tab_widget->setTabText (i, fname); m_tab_widget->setTabToolTip (i, tip); + + m_save_action->setEnabled (modified); + m_current_tab_modified = modified; + if (modified) m_tab_widget->setTabIcon (i, rmgr.icon ("document-save")); else @@ -1005,14 +1010,19 @@ } void file_editor::handle_editor_state_changed (bool copy_available, - bool is_octave_file) + bool is_octave_file, + bool is_modified) { // In case there is some scenario where traffic could be coming from // all the file editor tabs, just process info from the current active tab. if (sender () == m_tab_widget->currentWidget ()) { + m_save_action->setEnabled (is_modified); + m_current_tab_modified = is_modified; + if (m_copy_action) m_copy_action->setEnabled (copy_available); + m_cut_action->setEnabled (copy_available); m_run_selection_action->setEnabled (copy_available); diff -r 3ef50a8d01c5 -r bbf5d4ea616c libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Fri May 21 17:00:54 2021 +0200 +++ b/libgui/src/m-editor/file-editor.h Mon May 24 20:05:23 2021 +0200 @@ -262,7 +262,8 @@ void handle_tab_close_request (int index); void handle_tab_remove_request (void); void active_tab_changed (int index); - void handle_editor_state_changed (bool enableCopy, bool is_octave_file); + void handle_editor_state_changed (bool enableCopy, bool is_octave_file, + bool is_modified); void handle_mru_add_file (const QString& file_name, const QString& encoding); void check_conflict_save (const QString& fileName, bool remove_on_success); @@ -458,6 +459,7 @@ bool m_copy_action_enabled; bool m_undo_action_enabled; bool m_is_octave_file; + bool m_current_tab_modified; QMenu *m_edit_menu; QMenu *m_edit_cmd_menu;