changeset 16350:d4b6ad43bc87

use direct callbacks instead to handle history and workspace list updates * history-docwidget.h, history-dockwidget.cc (history_dock_widget::_update_event_enabled): Delete data member and all uses. * history-dockwidget.cc (history_dock_widget::construct): Don't install a timer. (history_dock_widget::update_history_callback): Now public. * workspace-model.cc (workspace_model::workspace_model): Don't install a timer. (workspace_model::_update_event_enabled): Delete data member and all uses. (workspace_model::update_workspace_callback): Now public. * workspace-view (workspace_view::model_changed): call workspace_model::update_workspace_callback. * main-window.h, main-window.cc (main_window::update_workspace, main_window::update_history): New functions. (main_window::construct): Connect them to corresponding signals. * octave-event-listener.h (octave_event_listener::update_workspace, octave_event_listener::update_history): New virtual functions. * octave-link.h, octave-link.cc (octave_link::update_workspace, octave_link::update_history, octave_link::do_update_workspace, octave_link::do_update_history, octave_link::post_input_event_hook_fcn, octave_link::do_post_input_event_hook_fcn): New functions. * octave-main-thread.cc (pre_input_event_hook_fcn, post_input_event_hook_fcn): New functions. (octave_main_thread::run): Install pre- and post- input event callback functions. * octave-qt-event-listener.h, octave-qt-event-listener.cc (octave_qt_event_listener::update_workspace octave_qt_event_listener::update_history): New functions. (octave_qt_event_listener::update_workspace_signal, octave_qt_event_listener::update_history_signal): New signals.
author John W. Eaton <jwe@octave.org>
date Thu, 21 Mar 2013 02:28:48 -0400
parents 610617eb84d1
children d8babb249f65
files libgui/src/history-dockwidget.cc libgui/src/history-dockwidget.h libgui/src/main-window.cc libgui/src/main-window.h libgui/src/octave-adapter/octave-event-listener.h libgui/src/octave-adapter/octave-link.cc libgui/src/octave-adapter/octave-link.h libgui/src/octave-adapter/octave-main-thread.cc libgui/src/octave-qt-event-listener.cc libgui/src/octave-qt-event-listener.h libgui/src/workspace-model.cc libgui/src/workspace-model.h libgui/src/workspace-view.cc
diffstat 13 files changed, 151 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/history-dockwidget.cc	Thu Mar 21 02:14:19 2013 -0400
+++ b/libgui/src/history-dockwidget.cc	Thu Mar 21 02:28:48 2013 -0400
@@ -77,17 +77,6 @@
   connect (_history_list_view, SIGNAL (doubleClicked (QModelIndex)),
            this, SLOT (handle_double_click (QModelIndex)));
 
-  _update_event_enabled = true;
-  _update_history_model_timer.setInterval (500);
-  _update_history_model_timer.setSingleShot (false);
-
-  connect (&_update_history_model_timer,
-           SIGNAL (timeout ()),
-           this,
-           SLOT (request_history_model_update ()));
-
-  _update_history_model_timer.start ();
-
   setFocusProxy (_filter_line_edit);
 }
 
@@ -133,11 +122,7 @@
 void
 history_dock_widget::request_history_model_update ()
 {
-  if (_update_event_enabled)
-    {
-      _update_event_enabled = false;  // no more update until this one is processed
-      octave_link::post_event (this, &history_dock_widget::update_history_callback);
-    }
+  octave_link::post_event (this, &history_dock_widget::update_history_callback);
 }
 
 void
@@ -185,8 +170,4 @@
 
       _history_list_view->scrollToBottom ();
     }
-
-  // update is processed, re-enable further updates events triggered by timer
-    _update_event_enabled = true;
-
 }
--- a/libgui/src/history-dockwidget.h	Thu Mar 21 02:14:19 2013 -0400
+++ b/libgui/src/history-dockwidget.h	Thu Mar 21 02:28:48 2013 -0400
@@ -27,7 +27,6 @@
 #include <QListView>
 #include <QSortFilterProxyModel>
 #include <QStringListModel>
-#include <QTimer>
 #include "octave-dock-widget.h"
 
 class history_dock_widget : public octave_dock_widget
@@ -36,6 +35,8 @@
   public:
   history_dock_widget (QWidget *parent = 0);
 
+  void update_history_callback (void);
+
 public slots:
   void request_history_model_update ();
   void reset_model ();
@@ -46,8 +47,6 @@
   /** Emitted, whenever the user double-clicked a command in the history. */
   void command_double_clicked (const QString& command);
 
-protected:
-
 private slots:
   void handle_double_click (QModelIndex modelIndex);
   void handle_contextmenu_copy(bool flag);
@@ -62,11 +61,6 @@
 
   /** Stores the current history_model. */
   QStringListModel *_history_model;
-
-  QTimer _update_history_model_timer;
-
-  void update_history_callback (void);
-  bool _update_event_enabled;
 };
 
 #endif // HISTORYDOCKWIDGET_H
--- a/libgui/src/main-window.cc	Thu Mar 21 02:14:19 2013 -0400
+++ b/libgui/src/main-window.cc	Thu Mar 21 02:28:48 2013 -0400
@@ -300,6 +300,18 @@
 }
 
 void
+main_window::update_workspace (void)
+{
+  _workspace_view->model_changed ();
+}
+
+void
+main_window::update_history (void)
+{
+  _history_dock_widget->update_history_callback ();
+}
+
+void
 main_window::change_current_working_directory ()
 {
   QString directory =
@@ -1125,6 +1137,16 @@
            SLOT (current_working_directory_has_changed (QString)));
 
   connect (_octave_qt_event_listener,
+           SIGNAL (update_workspace_signal ()),
+           this,
+           SLOT (update_workspace ()));
+
+  connect (_octave_qt_event_listener,
+           SIGNAL (update_history_signal ()),
+           this,
+           SLOT (update_history ()));
+
+  connect (_octave_qt_event_listener,
            SIGNAL (entered_debug_mode_signal ()),
            this,
            SLOT(handle_entered_debug_mode ()));
--- a/libgui/src/main-window.h	Thu Mar 21 02:14:19 2013 -0400
+++ b/libgui/src/main-window.h	Thu Mar 21 02:28:48 2013 -0400
@@ -96,6 +96,8 @@
   void prepare_for_quit ();
   void reset_windows ();
   void current_working_directory_has_changed (const QString& directory);
+  void update_workspace (void);
+  void update_history (void);
   void change_current_working_directory ();
   void set_current_working_directory (const QString& directory);
   void current_working_directory_up ();
--- a/libgui/src/octave-adapter/octave-event-listener.h	Thu Mar 21 02:14:19 2013 -0400
+++ b/libgui/src/octave-adapter/octave-event-listener.h	Thu Mar 21 02:28:48 2013 -0400
@@ -34,6 +34,12 @@
     virtual void
     current_directory_has_changed (const std::string& directory) = 0;
 
+    virtual void
+    update_workspace (void) = 0;
+
+    virtual void
+    update_history (void) = 0;
+
     virtual void about_to_exit () = 0;
 
     virtual void entered_debug_mode () = 0;
--- a/libgui/src/octave-adapter/octave-link.cc	Thu Mar 21 02:14:19 2013 -0400
+++ b/libgui/src/octave-adapter/octave-link.cc	Thu Mar 21 02:28:48 2013 -0400
@@ -134,6 +134,40 @@
   return last_cwd;
 }
 
+void
+octave_link::do_update_workspace (void)
+{
+  if (event_listener)
+    {
+      event_listener->update_workspace ();
+
+      do_process_events ();
+    }
+}
+
+void
+octave_link::do_update_history (void)
+{
+  if (event_listener)
+    {
+      event_listener->update_history ();
+
+      do_process_events ();
+    }
+}
+
+void
+octave_link::do_pre_input_event_hook_fcn (void)
+{
+  do_update_workspace ();
+}
+
+void
+octave_link::do_post_input_event_hook_fcn (void)
+{
+  do_update_history ();
+}
+
 bool
 octave_link::instance_ok (void)
 {
--- a/libgui/src/octave-adapter/octave-link.h	Thu Mar 21 02:14:19 2013 -0400
+++ b/libgui/src/octave-adapter/octave-link.h	Thu Mar 21 02:28:48 2013 -0400
@@ -120,6 +120,30 @@
       ? instance->do_last_working_directory () : std::string ();
   }
 
+  static void update_workspace (void)
+  {
+    if (instance_ok ())
+      instance->do_update_workspace ();
+  }
+
+  static void update_history (void)
+  {
+    if (instance_ok ())
+      instance->do_update_history ();
+  }
+
+  static void pre_input_event_hook_fcn (void)
+  {
+    if (instance_ok ())
+      instance->do_pre_input_event_hook_fcn ();
+  }
+
+  static void post_input_event_hook_fcn (void)
+  {
+    if (instance_ok ())
+      instance->do_post_input_event_hook_fcn ();
+  }
+
 private:
 
   static octave_link *instance;
@@ -180,6 +204,11 @@
   void do_finished_readline_hook (void) { }
 
   std::string do_last_working_directory (void);
+  void do_update_workspace (void);
+  void do_update_history (void);
+
+  void do_pre_input_event_hook_fcn (void);
+  void do_post_input_event_hook_fcn (void);
 };
 
 #endif // OCTAVELINK_H
--- a/libgui/src/octave-adapter/octave-main-thread.cc	Thu Mar 21 02:14:19 2013 -0400
+++ b/libgui/src/octave-adapter/octave-main-thread.cc	Thu Mar 21 02:28:48 2013 -0400
@@ -27,11 +27,34 @@
 #include <clocale>
 #include <string>
 
+#include "builtin-defun-decls.h"
 #include "octave.h"
+#include "ov-builtin.h"
+#include "ov-fcn-handle.h"
 
 #include "octave-main-thread.h"
 #include "octave-link.h"
 
+static octave_value_list
+pre_input_event_hook_fcn (const octave_value_list&, int)
+{
+  octave_value_list retval;
+
+  octave_link::pre_input_event_hook_fcn ();
+
+  return retval;
+}
+
+static octave_value_list
+post_input_event_hook_fcn (const octave_value_list&, int)
+{
+  octave_value_list retval;
+
+  octave_link::post_input_event_hook_fcn ();
+
+  return retval;
+}
+
 octave_main_thread::octave_main_thread () : QThread ()
 {
 }
@@ -47,5 +70,16 @@
   octave_initialize_interpreter (octave_cmdline_argc, octave_cmdline_argv,
                                  octave_embedded);
 
+  octave_value pre_fcn (new octave_builtin (pre_input_event_hook_fcn));
+  octave_value pre_fcn_handle (new octave_fcn_handle (pre_fcn));
+  Fadd_pre_input_event_hook (pre_fcn_handle);
+
+  octave_value post_fcn (new octave_builtin (post_input_event_hook_fcn));
+  octave_value post_fcn_handle (new octave_fcn_handle (post_fcn));
+  Fadd_post_input_event_hook (post_fcn_handle);
+
+  // Prime the history list.
+  octave_link::update_history ();
+
   octave_execute_interpreter ();
 }
--- a/libgui/src/octave-qt-event-listener.cc	Thu Mar 21 02:14:19 2013 -0400
+++ b/libgui/src/octave-qt-event-listener.cc	Thu Mar 21 02:28:48 2013 -0400
@@ -40,6 +40,18 @@
 }
 
 void
+octave_qt_event_listener::update_workspace (void)
+{
+  emit update_workspace_signal ();
+}
+
+void
+octave_qt_event_listener::update_history (void)
+{
+  emit update_history_signal ();
+}
+
+void
 octave_qt_event_listener::about_to_exit ()
 {
   qApp->quit ();
--- a/libgui/src/octave-qt-event-listener.h	Thu Mar 21 02:14:19 2013 -0400
+++ b/libgui/src/octave-qt-event-listener.h	Thu Mar 21 02:28:48 2013 -0400
@@ -35,6 +35,8 @@
   octave_qt_event_listener (QObject *parent = 0);
 
   void current_directory_has_changed (const std::string& directory);
+  void update_workspace (void);
+  void update_history (void);
   void about_to_exit ();
 
   void entered_debug_mode ();
@@ -42,6 +44,8 @@
 
 signals:
   void current_directory_has_changed_signal (const QString& directory);
+  void update_workspace_signal (void);
+  void update_history_signal (void);
   void entered_debug_mode_signal ();
   void quit_debug_mode_signal ();
 };
--- a/libgui/src/workspace-model.cc	Thu Mar 21 02:14:19 2013 -0400
+++ b/libgui/src/workspace-model.cc	Thu Mar 21 02:28:48 2013 -0400
@@ -46,16 +46,6 @@
   insert_top_level_item(0, new tree_item ("Local"));
   insert_top_level_item(1, new tree_item ("Global"));
   insert_top_level_item(2, new tree_item ("Persistent"));
-
-  connect(&_update_workspace_model_timer,
-          SIGNAL (timeout ()),
-          this,
-          SLOT (request_update_workspace()));
-
-  _update_event_enabled = true;
-  _update_workspace_model_timer.setInterval (500);
-  _update_workspace_model_timer.setSingleShot (false);
-  _update_workspace_model_timer.start ();
 }
 
 workspace_model::~workspace_model()
@@ -66,11 +56,7 @@
 void
 workspace_model::request_update_workspace ()
 {
-  if (_update_event_enabled)
-    {
-      _update_event_enabled = false;  // no more update until this one is processed
-      octave_link::post_event (this, &workspace_model::update_workspace_callback);
-    }
+  octave_link::post_event (this, &workspace_model::update_workspace_callback);
 }
 
 QModelIndex
@@ -226,9 +212,4 @@
     }
 
   endResetModel();
-  emit model_changed();
-
-  // update is processed, re-enable further updates events triggered by timer
-  _update_event_enabled = true;
-
 }
--- a/libgui/src/workspace-model.h	Thu Mar 21 02:14:19 2013 -0400
+++ b/libgui/src/workspace-model.h	Thu Mar 21 02:28:48 2013 -0400
@@ -27,7 +27,6 @@
 #include <QAbstractItemModel>
 #include <QVector>
 #include <QSemaphore>
-#include <QTimer>
 
 #include "symbol-information.h"
 
@@ -132,6 +131,8 @@
   void insert_top_level_item (int at, tree_item *treeItem);
   tree_item *top_level_item (int at);
 
+  void update_workspace_callback (void);
+
 public slots:
   void request_update_workspace ();
 
@@ -140,14 +141,6 @@
 
 private:
 
-  bool _update_event_enabled;
-
-  void update_workspace_callback (void);
-
-  /** Timer for periodically updating the workspace model from the current
-   * symbol information. */
-  QTimer _update_workspace_model_timer;
-
   /** Stores the current symbol information. */
   QList <symbol_information> _symbol_information;
   tree_item *_rootItem;
--- a/libgui/src/workspace-view.cc	Thu Mar 21 02:14:19 2013 -0400
+++ b/libgui/src/workspace-view.cc	Thu Mar 21 02:28:48 2013 -0400
@@ -114,6 +114,8 @@
 void
 workspace_view::model_changed ()
 {
+  _workspace_model->update_workspace_callback ();
+
   // This code is very quirky and requires some explanation.
   // Usually, we should not deal with collapsing or expanding ourselves,
   // because the view itself determines (based on the model) whether it