Mercurial > hg > octave-max
changeset 15448:352349219529
Added multiline copy and execution to command history in IDE (bug #36884)
* history-dockwidget.cc (history_dock_widget::ctxMenu) : New function.
(history_dock_widget::handle_contextmenu_copy) : New function.
(history_dock_widget::handle_contextmenu_evaluate) : New function.
(history_dock_widget::history_dock_widget) : Connected popup menu to QListView.
(history_dock_widget::handle_double_click) : Append <CR> to selected history to actually execute the command.
author | John Swensen <jpswensen@gmail.com> |
---|---|
date | Thu, 27 Sep 2012 13:24:59 -0400 |
parents | 137de4fbeaf6 |
children | 0a0912a9ab6e |
files | libgui/src/history-dockwidget.cc libgui/src/history-dockwidget.h |
diffstat | 2 files changed, 44 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/history-dockwidget.cc +++ b/libgui/src/history-dockwidget.cc @@ -24,7 +24,10 @@ #include <config.h> #endif +#include <QApplication> +#include <QClipboard> #include <QVBoxLayout> +#include <QMenu> #include "error.h" @@ -50,6 +53,10 @@ _history_list_view->setAlternatingRowColors (true); _history_list_view->setEditTriggers (QAbstractItemView::NoEditTriggers); _history_list_view->setStatusTip (tr ("Doubleclick a command to transfer it to the terminal.")); + _history_list_view->setSelectionMode (QAbstractItemView::ExtendedSelection); + _history_list_view->setContextMenuPolicy(Qt::CustomContextMenu); + connect(_history_list_view, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ctxMenu(const QPoint &))); + _filter_line_edit = new QLineEdit (this); _filter_line_edit->setStatusTip (tr ("Enter text to filter the command history.")); QVBoxLayout *vbox_layout = new QVBoxLayout (); @@ -91,10 +98,43 @@ setFocusProxy (_filter_line_edit); } +void history_dock_widget::ctxMenu(const QPoint &pos) { + QMenu *menu = new QMenu; + menu->addAction(tr("Copy"), this, SLOT(handle_contextmenu_copy(bool))); + menu->addAction(tr("Evaluate"), this, SLOT(handle_contextmenu_evaluate(bool))); + menu->exec(_history_list_view->mapToGlobal(pos)); +} + +void history_dock_widget::handle_contextmenu_copy(bool flag) +{ + QString text; + QItemSelectionModel *selectionModel = _history_list_view->selectionModel(); + QModelIndexList rows = selectionModel->selectedRows(); + QModelIndexList::iterator it; + for (it=rows.begin() ; it != rows.end(); it++) { + if ((*it).isValid()) { + text += (*it).data().toString()+"\n"; + } + } + QApplication::clipboard()->setText(text); +} + +void history_dock_widget::handle_contextmenu_evaluate(bool flag) +{ + QItemSelectionModel *selectionModel = _history_list_view->selectionModel(); + QModelIndexList rows = selectionModel->selectedRows(); + QModelIndexList::iterator it; + for (it=rows.begin() ; it != rows.end(); it++) { + if ((*it).isValid()) { + emit command_double_clicked ((*it).data().toString()+"\n"); + } + } +} + void history_dock_widget::handle_double_click (QModelIndex modelIndex) { - emit command_double_clicked (modelIndex.data().toString()); + emit command_double_clicked (modelIndex.data().toString()+"\n"); } void
--- a/libgui/src/history-dockwidget.h +++ b/libgui/src/history-dockwidget.h @@ -53,6 +53,9 @@ void closeEvent (QCloseEvent *event); private slots: void handle_double_click (QModelIndex modelIndex); + void handle_contextmenu_copy(bool flag); + void handle_contextmenu_evaluate(bool flag); + void ctxMenu(const QPoint &pos); private: void construct ();