changeset 28788:aba2c4eadb83

add functions of loaded packages to auto-completion list (bug #56207) * file-editor-tab.cc (update_lexer_settings): add boolean argument for updating apis but no other settings, clear current apis entries before adding all current functions and keywords * file-editor-tab.h: (update_lexer_settings): add boolean argument for updating apis but no other settings and define as slot * file-editor.cc (make_file_editor_tab): connect new main window signal for updating auto completion word lists with the slot in file_editor_tab * main-window.cc (construct_octave_qt_link): connect new qt-link signal for updating auto completion word lists with the related new main window signal * main-window.h: new signal for word list update * qt-interpreter-events.cc (update_gui_lexer): new method emitting signal for updateing the auto completion word list * qt-interpreter-events.h: new method update_gui_lexer and new signal update_gui_lexer_signal * event-manager.cc (__event_manager_update_gui_lexer__): new function for requesting an update of the auto completion worf lists * event-manager.h (void update_gui_lexer): new method calling the virtual methos which is re-implemented in qt event manager * load_packages_and_dependencies.m: call __event_manager_update_gui_lexer__ after laoding a package if gui is running * unload_packages.m: call __event_manager_update_gui_lexer__ after unloading a packages if gui is running
author Torsten Lilge <ttl-octave@mailbox.org>
date Thu, 24 Sep 2020 20:49:43 +0200
parents 92beaab911c2
children 28de41192f3c
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/main-window.cc libgui/src/main-window.h libgui/src/qt-interpreter-events.cc libgui/src/qt-interpreter-events.h libinterp/corefcn/event-manager.cc libinterp/corefcn/event-manager.h scripts/pkg/private/load_packages_and_dependencies.m scripts/pkg/private/unload_packages.m
diffstat 11 files changed, 62 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Wed Sep 23 21:23:32 2020 +0200
+++ b/libgui/src/m-editor/file-editor-tab.cc	Thu Sep 24 20:49:43 2020 +0200
@@ -688,8 +688,11 @@
 
 
   // Update settings, which are lexer related and have to be updated
-  // when a) the lexer changes or b) the settings have changed.
-  void file_editor_tab::update_lexer_settings (void)
+  // when
+  //    a) the lexer changes,
+  //    b) the settings have changed, or
+  //    c) a package was loaded/unloaded
+  void file_editor_tab::update_lexer_settings (bool update_apis_only)
   {
     QsciLexer *lexer = m_edit_area->lexer ();
 
@@ -760,7 +763,8 @@
                 // if the file is older than a few minutes preventing from
                 // re-preparing data when the user opens several files.
                 QDateTime apis_time = apis_file.lastModified ();
-                if (QDateTime::currentDateTime () > apis_time.addSecs (180))
+                if (update_apis_only
+                    || QDateTime::currentDateTime () > apis_time.addSecs (180))
                   update_apis = true;
               }
 
@@ -792,6 +796,8 @@
 
             // create raw apis info
 
+            m_lexer_apis->clear (); // Clear current contents
+
             if (m_is_octave_file)
               {
                 emit interpreter_event
@@ -857,6 +863,9 @@
           }
       }
 
+    if (update_apis_only)
+      return;   // We are done here
+
     lexer->readSettings (*settings);
 
     m_edit_area->setCaretForegroundColor (lexer->color (0));
--- a/libgui/src/m-editor/file-editor-tab.h	Wed Sep 23 21:23:32 2020 +0200
+++ b/libgui/src/m-editor/file-editor-tab.h	Thu Sep 24 20:49:43 2020 +0200
@@ -204,6 +204,8 @@
 
     void update_breakpoints_handler (const octave_value_list& argout);
 
+    void update_lexer_settings (bool update_apis_only = false);
+
   private slots:
 
     // When user closes message box for decoding problems
@@ -281,7 +283,6 @@
     bool unchanged_or_saved (void);
 
     void update_lexer (void);
-    void update_lexer_settings (void);
 
     void show_dialog (QDialog *dlg, bool modal);
   public:
--- a/libgui/src/m-editor/file-editor.cc	Wed Sep 23 21:23:32 2020 +0200
+++ b/libgui/src/m-editor/file-editor.cc	Thu Sep 24 20:49:43 2020 +0200
@@ -2408,7 +2408,7 @@
     connect (f, SIGNAL (set_focus_editor_signal (QWidget*)),
              this, SLOT (set_focus (QWidget*)));
 
-    // Signals from the file_editor non-trivial operations
+    // Signals from the file_editor or main-win non-trivial operations
     connect (this, SIGNAL (fetab_settings_changed (const gui_settings *)),
              f, SLOT (notice_settings (const gui_settings *)));
 
@@ -2419,6 +2419,9 @@
                                             bool)),
              f, SLOT (save_file (const QWidget*, const QString&, bool)));
 
+    connect (main_win (), SIGNAL (update_gui_lexer_signal (bool)),
+             f, SLOT (update_lexer_settings (bool)));
+
     // Signals from the file_editor trivial operations
     connect (this, SIGNAL (fetab_recover_from_exit (void)),
              f, SLOT (recover_from_exit (void)));
--- a/libgui/src/main-window.cc	Wed Sep 23 21:23:32 2020 +0200
+++ b/libgui/src/main-window.cc	Thu Sep 24 20:49:43 2020 +0200
@@ -2251,6 +2251,9 @@
     connect (qt_link,
              SIGNAL (unregister_doc_signal (const QString &)),
              this, SLOT (handle_unregister_doc (const QString &)));
+
+    connect (qt_link, SIGNAL (update_gui_lexer_signal (bool)),
+             this, SIGNAL (update_gui_lexer_signal (bool)));
   }
 
   QAction* main_window::add_action (QMenu *menu, const QIcon& icon,
--- a/libgui/src/main-window.h	Wed Sep 23 21:23:32 2020 +0200
+++ b/libgui/src/main-window.h	Thu Sep 24 20:49:43 2020 +0200
@@ -106,6 +106,7 @@
     void show_doc_signal (const QString&);
     void register_doc_signal (const QString&);
     void unregister_doc_signal (const QString&);
+    void update_gui_lexer_signal (bool);
 
     void insert_debugger_pointer_signal (const QString& file, int line);
     void delete_debugger_pointer_signal (const QString& file, int line);
--- a/libgui/src/qt-interpreter-events.cc	Wed Sep 23 21:23:32 2020 +0200
+++ b/libgui/src/qt-interpreter-events.cc	Thu Sep 24 20:49:43 2020 +0200
@@ -447,6 +447,11 @@
     emit unregister_doc_signal (QString::fromStdString (file));
   }
 
+  void qt_interpreter_events::update_gui_lexer (void)
+  {
+    emit update_gui_lexer_signal (true);
+  }
+
   void qt_interpreter_events::directory_changed (const std::string& dir)
   {
     emit directory_changed_signal (QString::fromStdString (dir));
--- a/libgui/src/qt-interpreter-events.h	Wed Sep 23 21:23:32 2020 +0200
+++ b/libgui/src/qt-interpreter-events.h	Thu Sep 24 20:49:43 2020 +0200
@@ -141,6 +141,8 @@
 
     void unregister_doc (const std::string& file);
 
+    void update_gui_lexer (void);
+
     void directory_changed (const std::string& dir);
 
     void file_remove (const std::string& old_name,
@@ -240,6 +242,8 @@
 
     void unregister_doc_signal (const QString& file);
 
+    void update_gui_lexer_signal (bool update_apis_only);
+
     void edit_variable_signal (const QString& name, const octave_value& val);
 
     void refresh_variable_editor_signal (void);
--- a/libinterp/corefcn/event-manager.cc	Wed Sep 23 21:23:32 2020 +0200
+++ b/libinterp/corefcn/event-manager.cc	Thu Sep 24 20:49:43 2020 +0200
@@ -577,6 +577,17 @@
   return ovl (evmgr.unregister_doc (file));
 }
 
+DEFMETHOD (__event_manager_update_gui_lexer__, interp, , ,
+           doc: /* -*- texinfo -*-
+@deftypefn {} {} __event_manager_update_gui_lexer__ ()
+Undocumented internal function.
+@end deftypefn */)
+{
+  octave::event_manager& evmgr = interp.get_event_manager ();
+
+  return ovl (evmgr.update_gui_lexer ());
+}
+
 DEFMETHOD (__event_manager_copy_image_to_clipboard__, interp, args, ,
            doc: /* -*- texinfo -*-
 @deftypefn {} {} __event_manager_copy_image_to_clipboard__ (@var{filename})
--- a/libinterp/corefcn/event-manager.h	Wed Sep 23 21:23:32 2020 +0200
+++ b/libinterp/corefcn/event-manager.h	Thu Sep 24 20:49:43 2020 +0200
@@ -195,6 +195,8 @@
 
     virtual void unregister_doc (const std::string& /*file*/) { }
 
+    virtual void update_gui_lexer (void) { }
+
     // Notifications of events in the interpreter that a GUI will
     // normally wish to respond to.
 
@@ -495,7 +497,17 @@
         }
       else
         return false;
+    }
 
+    bool update_gui_lexer (void)
+    {
+      if (enabled ())
+        {
+          instance->update_gui_lexer ();
+          return true;
+        }
+      else
+        return false;
     }
 
     void directory_changed (const std::string& dir)
--- a/scripts/pkg/private/load_packages_and_dependencies.m	Wed Sep 23 21:23:32 2020 +0200
+++ b/scripts/pkg/private/load_packages_and_dependencies.m	Thu Sep 24 20:49:43 2020 +0200
@@ -61,6 +61,11 @@
     EXEC_PATH (execpath);
   endif
 
+  ## Update lexer for autocompletion if necessary
+  if isguirunning && (length (idx) > 0)
+    __event_manager_update_gui_lexer__;
+  endif
+
 endfunction
 
 
--- a/scripts/pkg/private/unload_packages.m	Wed Sep 23 21:23:32 2020 +0200
+++ b/scripts/pkg/private/unload_packages.m	Thu Sep 24 20:49:43 2020 +0200
@@ -100,6 +100,9 @@
     if (any (idx))
       rmpath (d);
       ## FIXME: We should also check if we need to remove items from EXEC_PATH.
+      if isguirunning
+        __event_manager_update_gui_lexer__;
+      endif
     endif
   endfor