summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Uwe Broulik <[email protected]>2017-03-07 15:59:46 +0100
committerKai Uwe Broulik <[email protected]>2017-03-07 15:59:46 +0100
commit895f617f08876e6d02185514a00d9597c56bf455 (patch)
treea33af146fae65c69520be226375bb32a9335e1e8
parentd1e81740d37289ac62dce56ceac860f6fd302718 (diff)
[Folder View] Open context menu when pressing Menu key
If items are selected, show their context menu next to the first selected item, otherwise ignore the signal and let the containment handle it which then opens the standard context menu. Differential Revision: https://phabricator.kde.org/D4962
-rw-r--r--containments/desktop/package/contents/ui/FolderView.qml10
-rw-r--r--containments/desktop/plugins/folder/foldermodel.cpp8
-rw-r--r--containments/desktop/plugins/folder/foldermodel.h2
3 files changed, 12 insertions, 8 deletions
diff --git a/containments/desktop/package/contents/ui/FolderView.qml b/containments/desktop/package/contents/ui/FolderView.qml
index edd7a00..160e6c7 100644
--- a/containments/desktop/package/contents/ui/FolderView.qml
+++ b/containments/desktop/package/contents/ui/FolderView.qml
@@ -775,12 +775,12 @@ Item {
}
Keys.onMenuPressed: {
- // FIXME TODO: Correct popup position.
- return;
-
- if (currentIndex != -1 && dir.hasSelection()) {
+ if (currentIndex != -1 && dir.hasSelection() && currentItem) {
dir.setSelected(positioner.map(currentIndex));
- dir.openContextMenu();
+ dir.openContextMenu(currentItem.frame);
+ } else {
+ // Otherwise let the containment handle it.
+ event.accepted = false;
}
}
diff --git a/containments/desktop/plugins/folder/foldermodel.cpp b/containments/desktop/plugins/folder/foldermodel.cpp
index 3be923d..2eb9dfc 100644
--- a/containments/desktop/plugins/folder/foldermodel.cpp
+++ b/containments/desktop/plugins/folder/foldermodel.cpp
@@ -1382,7 +1382,7 @@ void FolderModel::updateActions()
}
}
-void FolderModel::openContextMenu()
+void FolderModel::openContextMenu(QQuickItem *visualParent)
{
QModelIndexList indexes = m_selectionModel->selectedIndexes();
@@ -1511,7 +1511,11 @@ void FolderModel::openContextMenu()
}
- menu->popup(QCursor::pos());
+ if (visualParent) {
+ menu->popup(visualParent->mapToGlobal(QPointF(0, visualParent->height())).toPoint());
+ } else {
+ menu->popup(QCursor::pos());
+ }
connect(menu, &QMenu::aboutToHide, [menu]() { menu->deleteLater(); });
}
diff --git a/containments/desktop/plugins/folder/foldermodel.h b/containments/desktop/plugins/folder/foldermodel.h
index 0aa3d72..457ef68 100644
--- a/containments/desktop/plugins/folder/foldermodel.h
+++ b/containments/desktop/plugins/folder/foldermodel.h
@@ -198,7 +198,7 @@ class FolderModel : public QSortFilterProxyModel
Q_INVOKABLE QAction* action(const QString& name) const;
QObject* newMenu() const;
Q_INVOKABLE void updateActions();
- Q_INVOKABLE void openContextMenu();
+ Q_INVOKABLE void openContextMenu(QQuickItem *visualParent = nullptr);
Q_INVOKABLE void linkHere(const QUrl &sourceUrl);