changeset 31181:c6c4c6f04170

also restore bookmarks when restoring an editor session at startup * gui-preferences-ed.h: add setting for storing bookmarks of editor files * file-editor-interface.h: additional argument in request_open_file * file-editor-tab.cc (get_all_bookmarks): new function collecting all bookmarks and returning it in a list of numbers in a string; * file-editor-tab.h: new function get_all_bookmarks * file-editor.cc (restore_session): get list of bookmarks from settings file and them as argument to request_open_file; (save_session): collect all bookmarks of open files and store them into the settings file; (request_open_file): string with bookmarks as new argument, if string id non-empty, add all contained bookmarks to the file * file-editor.h: add bookmarks to session_data, new string argument with bookmarks for request_open_file
author Torsten Lilge <ttl-octave@mailbox.org>
date Wed, 10 Aug 2022 22:24:58 +0200
parents 6203e303c5ac
children 932e43d948a6
files libgui/src/gui-preferences-ed.h libgui/src/m-editor/file-editor-interface.h 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 6 files changed, 59 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/gui-preferences-ed.h	Tue Aug 09 10:46:06 2022 -0400
+++ b/libgui/src/gui-preferences-ed.h	Wed Aug 10 22:24:58 2022 +0200
@@ -199,6 +199,9 @@
 const gui_pref
 ed_session_lines ("editor/saved_session_lines", QVariant (QStringList ()));
 
+const gui_pref
+ed_session_bookmarks ("editor/saved_session_bookmarks", QVariant (QStringList ()));
+
 // Tabs
 const QStringList
 ed_tab_position_names (QStringList ()
--- a/libgui/src/m-editor/file-editor-interface.h	Tue Aug 09 10:46:06 2022 -0400
+++ b/libgui/src/m-editor/file-editor-interface.h	Wed Aug 10 22:24:58 2022 +0200
@@ -98,7 +98,8 @@
                                     bool breakpoint_marker = false,
                                     bool insert = true,
                                     const QString& cond = "",
-                                    int index = -1) = 0;
+                                    int index = -1,
+                                    const QString& bookmarks = QString ()) = 0;
   };
 }
 
--- a/libgui/src/m-editor/file-editor-tab.cc	Tue Aug 09 10:46:06 2022 -0400
+++ b/libgui/src/m-editor/file-editor-tab.cc	Wed Aug 10 22:24:58 2022 +0200
@@ -1134,6 +1134,27 @@
     m_edit_area->setCursorPosition (prevline, 0);
   }
 
+
+  QString file_editor_tab::get_all_bookmarks ()
+  {
+    QString bmlist;
+    int line = 0;
+
+    while (line > -1)
+      {
+        line = m_edit_area->markerFindNext (line, (1 << marker::bookmark));
+        if (line > -1)
+          {
+            if (! bmlist.isEmpty ())
+              bmlist += ",";
+            bmlist += QString::number (line);
+            line++;   // search from next line, otherwise same line found again
+          }
+      }
+
+    return bmlist;
+  }
+
   void file_editor_tab::remove_bookmark (const QWidget *ID)
   {
     if (ID != this)
--- a/libgui/src/m-editor/file-editor-tab.h	Tue Aug 09 10:46:06 2022 -0400
+++ b/libgui/src/m-editor/file-editor-tab.h	Wed Aug 10 22:24:58 2022 +0200
@@ -276,8 +276,12 @@
     void update_lexer (void);
 
     void show_dialog (QDialog *dlg, bool modal);
+
   public:
+
     int check_file_modified (bool remove = false);
+    QString get_all_bookmarks (void);
+
   private:
     void do_comment_selected_text (bool comment, bool input_str = false);
     void do_indent_selected_text (bool indent);
--- a/libgui/src/m-editor/file-editor.cc	Tue Aug 09 10:46:06 2022 -0400
+++ b/libgui/src/m-editor/file-editor.cc	Wed Aug 10 22:24:58 2022 +0200
@@ -337,12 +337,16 @@
     QStringList session_lines
       = settings->value (ed_session_lines).toStringList ();
 
+    QStringList session_bookmarks
+      = settings->value (ed_session_bookmarks).toStringList ();
+
     // fill a list of the struct and sort it (depending on index)
     QList<session_data> s_data;
 
     bool do_encoding = (session_encodings.count () == sessionFileNames.count ());
     bool do_index = (session_index.count () == sessionFileNames.count ());
     bool do_lines = (session_lines.count () == sessionFileNames.count ());
+    bool do_bookmarks = (session_bookmarks.count () == sessionFileNames.count ());
 
     for (int n = 0; n < sessionFileNames.count (); ++n)
       {
@@ -351,13 +355,15 @@
           continue;
 
         session_data item = { 0, -1, sessionFileNames.at (n),
-                              QString (), QString ()};
+                              QString (), QString (), QString ()};
         if (do_lines)
           item.line = session_lines.at (n).toInt ();
         if (do_index)
           item.index = session_index.at (n).toInt ();
         if (do_encoding)
           item.encoding = session_encodings.at (n);
+        if (do_bookmarks)
+          item.bookmarks = session_bookmarks.at (n);
 
         s_data << item;
       }
@@ -367,7 +373,8 @@
     // finally open the files with the desired encoding in the desired order
     for (int n = 0; n < s_data.count (); ++n)
       request_open_file (s_data.at (n).file_name, s_data.at (n).encoding,
-                         s_data.at (n).line);
+                         s_data.at (n).line, false, false, true, "", -1,
+                         s_data.at (n).bookmarks);
   }
 
   void file_editor::activate (void)
@@ -440,6 +447,7 @@
     QStringList fet_encodings;
     QStringList fet_index;
     QStringList fet_lines;
+    QStringList fet_bookmarks;
 
     std::list<file_editor_tab *> editor_tab_lst = m_tab_widget->tab_list ();
 
@@ -460,6 +468,8 @@
             int l, c;
             editor_tab->qsci_edit_area ()->getCursorPosition (&l, &c);
             fet_lines.append (index.setNum (l + 1));
+
+            fet_bookmarks.append (editor_tab->get_all_bookmarks ());
           }
       }
 
@@ -467,6 +477,7 @@
     settings->setValue (ed_session_enc.key, fet_encodings);
     settings->setValue (ed_session_ind.key, fet_index);
     settings->setValue (ed_session_lines.key, fet_lines);
+    settings->setValue (ed_session_bookmarks.key, fet_bookmarks);
     settings->sync ();
   }
 
@@ -1535,7 +1546,8 @@
                                        const QString& encoding,
                                        int line, bool debug_pointer,
                                        bool breakpoint_marker, bool insert,
-                                       const QString& cond, int index)
+                                       const QString& cond, int index,
+                                       const QString& bookmarks)
   {
     resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
     gui_settings *settings = rmgr.get_settings ();
@@ -1711,6 +1723,17 @@
                   }
               }
 
+            if (! bookmarks.isEmpty ())
+              {
+                // Restore bookmarks
+                for (const auto& bms : bookmarks.split (','))
+                  {
+                    int bm = bms.toInt ();
+                    if (fileEditorTab)
+                      fileEditorTab->qsci_edit_area ()->markerAdd (bm, marker::bookmark);
+                  }
+              }
+
             if (! ((breakpoint_marker || debug_pointer) && is_editor_console_tabbed ()))
               {
                 // update breakpoint pointers, really show editor
--- a/libgui/src/m-editor/file-editor.h	Tue Aug 09 10:46:06 2022 -0400
+++ b/libgui/src/m-editor/file-editor.h	Wed Aug 10 22:24:58 2022 +0200
@@ -82,6 +82,7 @@
       QString file_name;
       QString new_file_name;
       QString encoding;
+      QString bookmarks;
 
       bool operator < (const session_data& other) const
       {
@@ -313,7 +314,8 @@
                             const QString& encoding = QString (),
                             int line = -1, bool debug_pointer = false,
                             bool breakpoint_marker = false, bool insert = true,
-                            const QString& cond = "", int index = -1);
+                            const QString& cond = "", int index = -1,
+                            const QString& bookmarks = QString ());
     void request_preferences (bool);
     void request_styles_preferences (bool);