changeset 27633:fd009322dd9f

eliminate static variable in file_editor_tab class * file_editor_tab.h, file_editor_tab.cc (file_editor_tab::m_cancelled): Delete static variable and all uses. (file_editor_tab::reset_cancel, file_editor_tab::was_cancelled): Delete static functions. (file_editor_tab::check_modified_file): Delete slot. (file_editor_tab::check_file_modified): Declare public. * file-editor.h, file-editor.cc (file_editor_tab_widget::tab_list): New function to get list of widgets managed by QTabWidget object directly. (file_editor::check_closing): Directly loop over list of widgets to check for closing status. Break from loop if closing is canceled. (file_editor::fetab_check_modified_file): Delete signal. (file_editor::make_file_editor_tab): Delete connection from fetab_check_modified_file to check_modified_file.
author John W. Eaton <jwe@octave.org>
date Mon, 04 Nov 2019 17:05:09 -0500
parents 2f38c2681b3e
children 57b9cf9d8796
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, 40 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Mon Nov 04 12:22:23 2019 -0800
+++ b/libgui/src/m-editor/file-editor-tab.cc	Mon Nov 04 17:05:09 2019 -0500
@@ -86,8 +86,6 @@
 
 namespace octave
 {
-  bool file_editor_tab::m_cancelled = false;
-
   //! A file_editor_tab object consists of a text area and three left margins.
   //! The first holds breakpoints, bookmarks, and the debug program counter.
   //! The second holds line numbers.  The third holds "fold" marks, to hide
@@ -309,9 +307,6 @@
 
   void file_editor_tab::closeEvent (QCloseEvent *e)
   {
-    m_cancelled = false;  // prevent unwanted interaction of previous
-    // exits of octave which were canceled by the user
-
     int save_dialog = check_file_modified (true);
     if ((save_dialog == QMessageBox::Cancel) ||
         (save_dialog == QMessageBox::Save))
@@ -1001,15 +996,6 @@
     m_edit_area->context_edit ();
   }
 
-  void file_editor_tab::check_modified_file (void)
-  {
-    if (m_cancelled)
-      return;
-
-    if (check_file_modified (false) == QMessageBox::Cancel)
-      m_cancelled = true;
-  }
-
   void file_editor_tab::save_file (const QWidget *ID)
   {
     if (ID != this)
@@ -1875,10 +1861,7 @@
         decision = msgBox->exec (); // show_dialog (msgBox, true);
 
         if (decision == QMessageBox::Cancel)
-          {
-            m_cancelled = true;
-            m_edit_area->setReadOnly (false);
-          }
+          m_edit_area->setReadOnly (false);
         else if (decision == QMessageBox::Save)
           save_file (m_file_name, remove, false);   // Remove on success
       }
--- a/libgui/src/m-editor/file-editor-tab.h	Mon Nov 04 12:22:23 2019 -0800
+++ b/libgui/src/m-editor/file-editor-tab.h	Mon Nov 04 17:05:09 2019 -0500
@@ -63,9 +63,6 @@
     // Will initiate close if associated with the identifier tag.
     bool conditional_close (void);
 
-    static void reset_cancel (void) { m_cancelled = false; }
-    static bool was_cancelled (void) { return m_cancelled; }
-
     void update_breakpoints ();
 
   signals:
@@ -150,7 +147,6 @@
     void set_current_directory (const QString& dir);
     void context_help (const QWidget *ID, bool);
     void context_edit (const QWidget *ID);
-    void check_modified_file (void);
     void save_file (const QWidget *ID);
     void save_file (const QWidget *ID, const QString& fileName,
                     bool remove_on_success);
@@ -299,7 +295,9 @@
     void update_lexer_settings (void);
 
     void show_dialog (QDialog *dlg, bool modal);
+  public:
     int check_file_modified (bool remove = false);
+  private:
     void do_comment_selected_text (bool comment, bool input_str = false);
     void do_indent_selected_text (bool indent);
     void do_smart_indent_line_or_selected_text (void);
@@ -346,8 +344,6 @@
     QString m_prep_apis_path;
     QString m_prep_apis_file;
 
-    static bool m_cancelled;
-
     int m_line_break;
     bool m_line_break_comments;
     int m_line;
--- a/libgui/src/m-editor/file-editor.cc	Mon Nov 04 12:22:23 2019 -0800
+++ b/libgui/src/m-editor/file-editor.cc	Mon Nov 04 17:05:09 2019 -0500
@@ -81,6 +81,14 @@
     return qobject_cast<tab_bar *> (tabBar ());
   }
 
+  std::list<file_editor_tab *>
+  file_editor_tab_widget::tab_list (void) const
+  {
+    std::list<file_editor_tab *> retval;
+    for (int i = 0; i < count (); i++)
+      retval.push_back (static_cast<file_editor_tab *> (widget (i)));
+    return retval;
+  }
 
   // File editor
 
@@ -379,40 +387,36 @@
 
   bool file_editor::check_closing (void)
   {
-    // When the application or the editor is closing and the user wants to close
-    // all files in the latter case all editor tabs are checked whether
-    // they need to be saved. During these ckecked the tabs are not closed
-    // since the user might cancel closing octave during one of these saving
-    // dialogs. Therefore, saving the session for restoring at next start
-    // is not done before the application is definitely closing
-
-    // Have all file editor tabs signal what their filenames are.
-    m_editor_tab_map.clear ();
-    emit fetab_file_name_query (nullptr);
-
-    // Save all tabs with confirmation.
-    file_editor_tab::reset_cancel ();
-    emit fetab_check_modified_file ();
-
-    // If there was a cancellation, make the already saved/discarded tabs
-    // recovering from the exit by removing the read-only state and by
-    // recovering the debugger breakpoints. Finally return false in order to
-    // cancel closing the application or the editor
-    if (file_editor_tab::was_cancelled ())
+    // When the application or the editor is closing and the user wants
+    // to close all files in the latter case all editor tabs are checked
+    // whether they need to be saved. During these ckecked the tabs are
+    // not closed since the user might cancel closing octave during one
+    // of these saving dialogs. Therefore, saving the session for
+    // restoring at next start is not done before the application is
+    // definitely closing.
+
+    std::list<file_editor_tab *> fe_tab_lst = m_tab_widget->tab_list ();
+
+    for (auto fe_tab : fe_tab_lst)
       {
-        emit fetab_recover_from_exit ();
-        return false;
+        // If there was a cancellation, make the already saved/discarded
+        // tabs recovering from the exit by removing the read-only state
+        // and by recovering the debugger breakpoints. Finally return
+        // false in order to cancel closing the application or the
+        // editor
+
+        if (fe_tab->check_file_modified (false) == QMessageBox::Cancel)
+          {
+            emit fetab_recover_from_exit ();
+            return false;
+          }
       }
 
-    // Wait for all editor tabs to have saved their files if required
-    m_number_of_tabs = m_editor_tab_map.size ();
-
-    for (auto p = m_editor_tab_map.cbegin ();
-         p != m_editor_tab_map.cend (); p++)
+    for (auto fe_tab : fe_tab_lst)
       {
-        QString file_name = p->first;   // get file name of tab
-        connect (static_cast<file_editor_tab *> (m_editor_tab_map[file_name].fet_ID),
-                 SIGNAL (tab_ready_to_close (void)),
+        // Wait for all editor tabs to have saved their files if required
+
+        connect (fe_tab, SIGNAL (tab_ready_to_close (void)),
                  this, SLOT (handle_tab_ready_to_close (void)));
       }
 
@@ -2293,9 +2297,6 @@
                                             bool)),
              f, SLOT (save_file (const QWidget*, const QString&, bool)));
 
-    connect (this, SIGNAL (fetab_check_modified_file (void)),
-             f, SLOT (check_modified_file (void)));
-
     // Signals from the file_editor trivial operations
     connect (this, SIGNAL (fetab_recover_from_exit (void)),
              f, SLOT (recover_from_exit (void)));
--- a/libgui/src/m-editor/file-editor.h	Mon Nov 04 12:22:23 2019 -0800
+++ b/libgui/src/m-editor/file-editor.h	Mon Nov 04 17:05:09 2019 -0500
@@ -23,6 +23,7 @@
 #if ! defined (octave_file_editor_h)
 #define octave_file_editor_h 1
 
+#include <list>
 #include <map>
 
 #include <QAction>
@@ -56,6 +57,8 @@
     ~file_editor_tab_widget (void) = default;
 
     tab_bar * get_tab_bar (void) const;
+
+    std::list<file_editor_tab *> tab_list (void) const;
   };
 
   // the class for the file editor
@@ -134,7 +137,6 @@
     // No fetab_new, functionality in editor
     void fetab_context_help (const QWidget *ID, bool);
     void fetab_context_edit (const QWidget *ID);
-    void fetab_check_modified_file (void);
     void fetab_save_file (const QWidget *ID);
     void fetab_save_file_as (const QWidget *ID);
     void fetab_print_file (const QWidget *ID);