Mercurial > hg > octave-shane
changeset 16622:38fef1e833ea
handle copying names file browser to clipboard; allow multiple selections
* files-dock-widget.cc (class FileTreeViewer): New class.
(files_dock_widget::files_dock_widget): Use it for _file_tree_view.
New context menu action to copy selection to clipboard.
Set extended selection mode for _file_tree_view.
(files_dock_widget::contextmenu_copy_selection): New function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 May 2013 07:45:53 -0400 |
parents | 2df11dd7a589 |
children | 9c0487bb205b |
files | libgui/src/files-dock-widget.cc libgui/src/files-dock-widget.h |
diffstat | 2 files changed, 41 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/files-dock-widget.cc +++ b/libgui/src/files-dock-widget.cc @@ -28,6 +28,7 @@ #include "files-dock-widget.h" #include <QApplication> +#include <QClipboard> #include <QFileInfo> #include <QCompleter> #include <QProcess> @@ -45,6 +46,19 @@ #include "load-save.h" +class FileTreeViewer : public QTreeView +{ +public: + + FileTreeViewer (QWidget *p) : QTreeView (p) { } + + void mousePressEvent (QMouseEvent *e) + { + if (e->button () != Qt::RightButton) + QTreeView::mousePressEvent (e); + } +}; + files_dock_widget::files_dock_widget (QWidget *p) : octave_dock_widget (p) { @@ -131,7 +145,8 @@ curr_dir.absolutePath ()); // Attach the model to the QTreeView and set the root index - _file_tree_view = new QTreeView (container); + _file_tree_view = new FileTreeViewer (container); + _file_tree_view->setSelectionMode (QAbstractItemView::ExtendedSelection); _file_tree_view->setModel (_file_system_model); _file_tree_view->setRootIndex (rootPathIndex); _file_tree_view->setSortingEnabled (true); @@ -328,6 +343,9 @@ menu.addAction (tr("Open in Default Application"), this, SLOT (contextmenu_open_in_app (bool))); + menu.addAction (tr("Copy Selection to Clipboard"), + this, SLOT (contextmenu_copy_selection (bool))); + if (info.isFile () && info.suffix () == "m") menu.addAction (QIcon (":/actions/icons/artsbuilderexecute.png"), tr("Run"), this, SLOT(contextmenu_run(bool))); @@ -388,6 +406,26 @@ } void +files_dock_widget::contextmenu_copy_selection (bool) +{ + QItemSelectionModel *m = _file_tree_view->selectionModel (); + QModelIndexList rows = m->selectedRows (); + + QStringList selection; + + for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++) + { + QFileInfo info = _file_system_model->fileInfo (*it); + + selection << info.fileName (); + } + + QClipboard *clipboard = QApplication::clipboard (); + + clipboard->setText (selection.join ("\n")); +} + +void files_dock_widget::contextmenu_load (bool) { QItemSelectionModel *m = _file_tree_view->selectionModel ();
--- a/libgui/src/files-dock-widget.h +++ b/libgui/src/files-dock-widget.h @@ -34,6 +34,7 @@ #include <QVBoxLayout> #include <QAction> #include <QTreeView> +#include <QMouseEvent> #include <QComboBox> #include "octave-dock-widget.h" @@ -85,6 +86,7 @@ /* context menu actions */ void contextmenu_open (bool); void contextmenu_open_in_app (bool); + void contextmenu_copy_selection (bool); void contextmenu_run (bool); void contextmenu_load (bool); void contextmenu_rename (bool);