# HG changeset patch # User John W. Eaton # Date 1420739495 18000 # Node ID cbd5d36c54728b66919f92c534e647d56afca77b # Parent e2b570e7224b3aa62445e1efde721a00187876fe# Parent 77e58a7945b39c6d839067781b8f62a9c7690b57 maint: Periodic merge of gui-release to default. diff --git a/libgui/src/m-editor/find-dialog.cc b/libgui/src/m-editor/find-dialog.cc --- a/libgui/src/m-editor/find-dialog.cc +++ b/libgui/src/m-editor/find-dialog.cc @@ -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) diff --git a/libgui/src/m-editor/find-dialog.h b/libgui/src/m-editor/find-dialog.h diff --git a/libgui/src/main-window.cc b/libgui/src/main-window.cc --- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -174,6 +174,12 @@ if (dock) break; // it is a QDockWidget ==> exit loop + if (qobject_cast (w_new)) + { + dock = static_cast (editor_window); + break; // it is the editor window ==> exit loop + } + w_new = qobject_cast (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 (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 (editor_window); if (edit_dock_widget == dock) emit editor_focus_changed (true); else if (edit_dock_widget == _active_dock) diff --git a/libgui/src/workspace-view.cc b/libgui/src/workspace-view.cc --- a/libgui/src/workspace-view.cc +++ b/libgui/src/workspace-view.cc @@ -35,6 +35,8 @@ #include #include #include +#include +#include #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; diff --git a/libgui/src/workspace-view.h b/libgui/src/workspace-view.h --- a/libgui/src/workspace-view.h +++ b/libgui/src/workspace-view.h @@ -27,6 +27,9 @@ #include #include #include +#include +#include +#include #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