changeset 29698:bbf5d4ea616c

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
author Torsten Lilge <ttl-octave@mailbox.org>
date Mon, 24 May 2021 20:05:23 +0200
parents 3ef50a8d01c5
children b98ae05c6b7e
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h
diffstat 4 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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);
--- 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);
--- 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;