Mercurial > octave-nkf
comparison libgui/src/files-dock-widget.cc @ 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 | 99a57611d58a |
children | 25e418d23a4b |
comparison
equal
deleted
inserted
replaced
16621:2df11dd7a589 | 16622:38fef1e833ea |
---|---|
26 | 26 |
27 #include "resource-manager.h" | 27 #include "resource-manager.h" |
28 #include "files-dock-widget.h" | 28 #include "files-dock-widget.h" |
29 | 29 |
30 #include <QApplication> | 30 #include <QApplication> |
31 #include <QClipboard> | |
31 #include <QFileInfo> | 32 #include <QFileInfo> |
32 #include <QCompleter> | 33 #include <QCompleter> |
33 #include <QProcess> | 34 #include <QProcess> |
34 #include <QDebug> | 35 #include <QDebug> |
35 #include <QHeaderView> | 36 #include <QHeaderView> |
43 #include <QDesktopServices> | 44 #include <QDesktopServices> |
44 #include <QFileDialog> | 45 #include <QFileDialog> |
45 | 46 |
46 #include "load-save.h" | 47 #include "load-save.h" |
47 | 48 |
49 class FileTreeViewer : public QTreeView | |
50 { | |
51 public: | |
52 | |
53 FileTreeViewer (QWidget *p) : QTreeView (p) { } | |
54 | |
55 void mousePressEvent (QMouseEvent *e) | |
56 { | |
57 if (e->button () != Qt::RightButton) | |
58 QTreeView::mousePressEvent (e); | |
59 } | |
60 }; | |
61 | |
48 files_dock_widget::files_dock_widget (QWidget *p) | 62 files_dock_widget::files_dock_widget (QWidget *p) |
49 : octave_dock_widget (p) | 63 : octave_dock_widget (p) |
50 { | 64 { |
51 setObjectName ("FilesDockWidget"); | 65 setObjectName ("FilesDockWidget"); |
52 setWindowIcon (QIcon(":/actions/icons/logo.png")); | 66 setWindowIcon (QIcon(":/actions/icons/logo.png")); |
129 _file_system_model->setFilter (QDir::NoDotAndDotDot | QDir::AllEntries); | 143 _file_system_model->setFilter (QDir::NoDotAndDotDot | QDir::AllEntries); |
130 QModelIndex rootPathIndex = _file_system_model->setRootPath ( | 144 QModelIndex rootPathIndex = _file_system_model->setRootPath ( |
131 curr_dir.absolutePath ()); | 145 curr_dir.absolutePath ()); |
132 | 146 |
133 // Attach the model to the QTreeView and set the root index | 147 // Attach the model to the QTreeView and set the root index |
134 _file_tree_view = new QTreeView (container); | 148 _file_tree_view = new FileTreeViewer (container); |
149 _file_tree_view->setSelectionMode (QAbstractItemView::ExtendedSelection); | |
135 _file_tree_view->setModel (_file_system_model); | 150 _file_tree_view->setModel (_file_system_model); |
136 _file_tree_view->setRootIndex (rootPathIndex); | 151 _file_tree_view->setRootIndex (rootPathIndex); |
137 _file_tree_view->setSortingEnabled (true); | 152 _file_tree_view->setSortingEnabled (true); |
138 _file_tree_view->setAlternatingRowColors (true); | 153 _file_tree_view->setAlternatingRowColors (true); |
139 _file_tree_view->setAnimated (true); | 154 _file_tree_view->setAnimated (true); |
326 this, SLOT(contextmenu_open(bool))); | 341 this, SLOT(contextmenu_open(bool))); |
327 | 342 |
328 menu.addAction (tr("Open in Default Application"), | 343 menu.addAction (tr("Open in Default Application"), |
329 this, SLOT (contextmenu_open_in_app (bool))); | 344 this, SLOT (contextmenu_open_in_app (bool))); |
330 | 345 |
346 menu.addAction (tr("Copy Selection to Clipboard"), | |
347 this, SLOT (contextmenu_copy_selection (bool))); | |
348 | |
331 if (info.isFile () && info.suffix () == "m") | 349 if (info.isFile () && info.suffix () == "m") |
332 menu.addAction (QIcon (":/actions/icons/artsbuilderexecute.png"), | 350 menu.addAction (QIcon (":/actions/icons/artsbuilderexecute.png"), |
333 tr("Run"), this, SLOT(contextmenu_run(bool))); | 351 tr("Run"), this, SLOT(contextmenu_run(bool))); |
334 | 352 |
335 if (info.isFile ()) | 353 if (info.isFile ()) |
386 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++) | 404 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++) |
387 open_item_in_app (*it); | 405 open_item_in_app (*it); |
388 } | 406 } |
389 | 407 |
390 void | 408 void |
409 files_dock_widget::contextmenu_copy_selection (bool) | |
410 { | |
411 QItemSelectionModel *m = _file_tree_view->selectionModel (); | |
412 QModelIndexList rows = m->selectedRows (); | |
413 | |
414 QStringList selection; | |
415 | |
416 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++) | |
417 { | |
418 QFileInfo info = _file_system_model->fileInfo (*it); | |
419 | |
420 selection << info.fileName (); | |
421 } | |
422 | |
423 QClipboard *clipboard = QApplication::clipboard (); | |
424 | |
425 clipboard->setText (selection.join ("\n")); | |
426 } | |
427 | |
428 void | |
391 files_dock_widget::contextmenu_load (bool) | 429 files_dock_widget::contextmenu_load (bool) |
392 { | 430 { |
393 QItemSelectionModel *m = _file_tree_view->selectionModel (); | 431 QItemSelectionModel *m = _file_tree_view->selectionModel (); |
394 QModelIndexList rows = m->selectedRows (); | 432 QModelIndexList rows = m->selectedRows (); |
395 | 433 |