Mercurial > hg > octave-nkf
changeset 18455:f1312db94896 stable
apply the context menu of the file browser to the correct item (bug #41430)
* files-dock-widget.cc (contextmenu_requested): if right-clicked item is not
selected clear the actual selection and select right-clicked item
author | Torsten <ttl@justmail.de> |
---|---|
date | Sat, 25 Jan 2014 13:51:25 +0100 |
parents | 7e39cbefe299 |
children | 226285bce729 |
files | libgui/src/files-dock-widget.cc |
diffstat | 1 files changed, 13 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/files-dock-widget.cc +++ b/libgui/src/files-dock-widget.cc @@ -456,12 +456,23 @@ QMenu menu (this); QModelIndex index = _file_tree_view->indexAt (mpos); - //QAbstractItemModel *m = _file_tree_view->model (); if (index.isValid ()) { QFileInfo info = _file_system_model->fileInfo (index); + QItemSelectionModel *m = _file_tree_view->selectionModel (); + QModelIndexList sel = m->selectedRows (); + + // check if item at mouse position is seleccted + if (! sel.contains (index)) + { // is not selected -> clear actual selection and select this item + m->setCurrentIndex(index, + QItemSelectionModel::Clear | QItemSelectionModel::Select | + QItemSelectionModel::Rows); + } + + // construct the context menu depending on item menu.addAction (QIcon (":/actions/icons/fileopen.png"), tr ("Open"), this, SLOT (contextmenu_open (bool))); @@ -505,6 +516,7 @@ this, SLOT (contextmenu_newdir (bool))); } + // show the menu menu.exec (_file_tree_view->mapToGlobal (mpos)); }