changeset 19580:cbd5d36c5472

maint: Periodic merge of gui-release to default.
author John W. Eaton <jwe@octave.org>
date Thu, 08 Jan 2015 12:51:35 -0500
parents e2b570e7224b (current diff) 77e58a7945b3 (diff)
children c5b8a91baec6
files libgui/src/m-editor/find-dialog.cc libgui/src/main-window.cc
diffstat 4 files changed, 110 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/find-dialog.cc	Wed Jan 07 18:12:01 2015 -0500
+++ b/libgui/src/m-editor/find-dialog.cc	Thu Jan 08 12:51:35 2015 -0500
@@ -288,6 +288,13 @@
                 col = 0;
             }
         }
+      else if (! do_forward)
+        {
+           // search from previous character if search backward
+           int currpos = _edit_area->positionFromLineIndex(line,col);
+           if(currpos > 0) currpos --;
+           _edit_area->lineIndexFromPosition(currpos, &line,&col);
+        }
     }
 
   if (_edit_area)
--- a/libgui/src/main-window.cc	Wed Jan 07 18:12:01 2015 -0500
+++ b/libgui/src/main-window.cc	Thu Jan 08 12:51:35 2015 -0500
@@ -174,6 +174,12 @@
       if (dock)
         break; // it is a QDockWidget ==> exit loop
 
+      if (qobject_cast <octave_qscintilla *> (w_new))
+        {
+          dock = static_cast <octave_dock_widget *> (editor_window);
+          break; // it is the editor window ==> exit loop
+        }
+
       w_new = qobject_cast <QWidget *> (w_new->previousInFocusChain ());
       if (w_new == start)
         break; // we have arrived where we began ==> exit loop
@@ -181,15 +187,16 @@
       count++;
     }
 
+  // editor needs extra handling
+  octave_dock_widget *edit_dock_widget =
+                        static_cast <octave_dock_widget *> (editor_window);
   // if new dock has focus, emit signal and store active focus
-  if (dock != _active_dock)
+  // except editor changes to a dialog (dock=0)
+  if ((dock || _active_dock != edit_dock_widget) && (dock != _active_dock))
     {
       // signal to all dock widgets for updating the style
       emit active_dock_changed (_active_dock, dock);
 
-      // if editor gets/loses focus, shortcuts and menus have to be updated
-      octave_dock_widget *edit_dock_widget =
-                        static_cast <octave_dock_widget *> (editor_window);
       if (edit_dock_widget == dock)
         emit editor_focus_changed (true);
       else if (edit_dock_widget == _active_dock)
--- a/libgui/src/workspace-view.cc	Wed Jan 07 18:12:01 2015 -0500
+++ b/libgui/src/workspace-view.cc	Thu Jan 08 12:51:35 2015 -0500
@@ -35,6 +35,8 @@
 #include <QVBoxLayout>
 #include <QPushButton>
 #include <QMenu>
+#include <QLabel>
+#include <QCompleter>
 
 #include "workspace-view.h"
 #include "resource-manager.h"
@@ -48,9 +50,25 @@
   set_title (tr ("Workspace"));
   setStatusTip (tr ("View the variables in the active workspace."));
 
+  _filter = new QComboBox (this);
+  _filter->setToolTip (tr ("Enter the path or filename"));
+  _filter->setEditable (true);
+  _filter->setMaxCount (MaxFilterHistory);
+  _filter->setInsertPolicy (QComboBox::NoInsert);
+  _filter->setSizeAdjustPolicy (
+            QComboBox::AdjustToMinimumContentsLengthWithIcon);
+  QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Maximum);
+  _filter->setSizePolicy (sizePol);
+  _filter->completer ()->setCaseSensitivity (Qt::CaseSensitive);
+
+  QLabel *filter_label = new QLabel (tr ("Filter"));
+
+  _filter_checkbox = new QCheckBox ();
+
   view->setWordWrap (false);
   view->setContextMenuPolicy (Qt::CustomContextMenu);
   view->setShowGrid (false);
+  (view->verticalHeader) ()->hide ();
   view->setAlternatingRowColors (true);
   view_previous_row_count = 0;
 
@@ -59,23 +77,46 @@
 
   // Create a new layout and add widgets to it.
   QVBoxLayout *vbox_layout = new QVBoxLayout ();
+  QHBoxLayout *hbox_layout = new QHBoxLayout ();
+  hbox_layout->addWidget (filter_label);
+  hbox_layout->addWidget (_filter_checkbox);
+  hbox_layout->addWidget (_filter);
+  vbox_layout->addLayout (hbox_layout);
   vbox_layout->addWidget (view);
   vbox_layout->setMargin (2);
 
   // Set the empty widget to have our layout.
   widget ()->setLayout (vbox_layout);
 
+  // Filter model
+  _filter_model = new QSortFilterProxyModel ();
+  _filter_model->setFilterKeyColumn(0);
+
   // Initialize collapse/expand state of the workspace subcategories.
 
   QSettings *settings = resource_manager::get_settings ();
 
   // Initialize column order and width of the workspace
-
   view->horizontalHeader ()->restoreState (
     settings->value ("workspaceview/column_state").toByteArray ());
 
+  // Init state of the filter
+  _filter->addItems (settings->value ("workspaceview/mru_list").toStringList ());
+
+  bool filter_state =
+            settings->value ("workspaceview/filter_active", false).toBool ();
+  _filter_checkbox->setChecked (filter_state);
+  filter_activate (filter_state);
+
   // Connect signals and slots.
 
+  connect (_filter, SIGNAL (editTextChanged (const QString&)),
+           this, SLOT (filter_update (const QString&)));
+  connect (_filter_checkbox, SIGNAL (toggled (bool)),
+           this, SLOT (filter_activate (bool)));
+  connect (_filter->lineEdit (), SIGNAL (editingFinished ()),
+           this, SLOT (update_filter_history ()));
+
   connect (view, SIGNAL (customContextMenuRequested (const QPoint&)),
            this, SLOT (contextmenu_requested (const QPoint&)));
 
@@ -90,13 +131,21 @@
 
   settings->setValue ("workspaceview/column_state",
                       view->horizontalHeader ()->saveState ());
+  settings->setValue ("workspaceview/filter_active",
+                      _filter_checkbox->isChecked ());
+
+  QStringList mru;
+  for (int i = 0; i < _filter->count (); i++)
+    mru.append (_filter->itemText (i));
+  settings->setValue ("workspaceview/mru_list", mru);
 
   settings->sync ();
 }
 
 void workspace_view::setModel (workspace_model *model)
 {
-  view->setModel (model);
+  _filter_model->setSourceModel (model);
+  view->setModel (_filter_model);
   _model = model;
 }
 
@@ -107,6 +156,33 @@
   QDockWidget::closeEvent (e);
 }
 
+void
+workspace_view::filter_update (const QString& expression)
+{
+  _filter_model->setFilterRegExp (QRegExp (expression, Qt::CaseSensitive));
+  handle_model_changed ();
+}
+
+void
+workspace_view::filter_activate (bool state)
+{
+  _filter->setEnabled (state);
+  _filter_model->setDynamicSortFilter (state);
+
+  if (state)
+    filter_update (_filter->currentText ());
+  else
+    filter_update (QString ());
+}
+
+void
+workspace_view::update_filter_history ()
+{
+  QString text = _filter->currentText ();
+  if (! text.isEmpty () && _filter->findText (text) == -1)
+    _filter->insertItem (0, _filter->currentText ());
+}
+
 QString
 workspace_view::get_var_name (QModelIndex index)
 {
@@ -256,11 +332,12 @@
 void
 workspace_view::handle_model_changed (void)
 {
+//  view->resizeRowsToContents ();
   // Just modify those rows that have been added rather than go through
   // the whole list.  For-loop test will handle when number of rows reduced.
   QFontMetrics fm = view->fontMetrics ();
   int row_height =  fm.height ();
-  int new_row_count = view->model ()->rowCount ();
+  int new_row_count = _filter_model->rowCount ();
   for (int i = view_previous_row_count; i < new_row_count; i++)
     view->setRowHeight (i, row_height);
   view_previous_row_count = new_row_count;
--- a/libgui/src/workspace-view.h	Wed Jan 07 18:12:01 2015 -0500
+++ b/libgui/src/workspace-view.h	Thu Jan 08 12:51:35 2015 -0500
@@ -27,6 +27,9 @@
 #include <QItemDelegate>
 #include <QTableView>
 #include <QSemaphore>
+#include <QComboBox>
+#include <QSortFilterProxyModel>
+#include <QCheckBox>
 
 #include "octave-dock-widget.h"
 #include "workspace-model.h"
@@ -73,6 +76,10 @@
   void copyClipboard ();
   void selectAll ();
 
+  void filter_update (const QString& expression);
+  void filter_activate (bool enable);
+  void update_filter_history ();
+
 private:
 
   void relay_contextmenu_command (const QString& cmdname);
@@ -81,6 +88,11 @@
   QTableView *view;
   int view_previous_row_count;
   workspace_model *_model;
+
+  QSortFilterProxyModel *_filter_model;
+  QCheckBox *_filter_checkbox;
+  QComboBox *_filter;
+  enum { MaxFilterHistory = 10 };
 };
 
 #endif