]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix shift-action modifier in context menu
authorDerek Christ <christ.derek@gmail.com>
Fri, 18 Jun 2021 13:12:54 +0000 (15:12 +0200)
committerMéven Car <meven29@gmail.com>
Tue, 22 Jun 2021 08:53:55 +0000 (08:53 +0000)
Before this patch, the shift-action modifier in context menus did not
work when a sub-context menu is open, that does not have the main
context menu as its parent.
The new fix installs an event filter on QApplication whenever a new
context menu is opened to make the context menu aware of shift-presses
even when a sub-context menu is in focus.

BUG: 425997
FIXED-IN: 21.04

src/dolphincontextmenu.cpp
src/dolphincontextmenu.h

index eb3f641e5ae6ffe78e237c30e07d5b9cfbf67feb..2b216ce030b566687d9a20f1138656bbf530090a 100644 (file)
@@ -63,7 +63,7 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
     const DolphinView* view = m_mainWindow->activeViewContainer()->view();
     m_selectedItems = view->selectedItems();
 
-    installEventFilter(this);
+    QApplication::instance()->installEventFilter(this);
 }
 
 DolphinContextMenu::~DolphinContextMenu()
@@ -112,28 +112,23 @@ DolphinContextMenu::Command DolphinContextMenu::open()
     return m_command;
 }
 
-void DolphinContextMenu::childEvent(QChildEvent* event)
+bool DolphinContextMenu::eventFilter(QObject* object, QEvent* event)
 {
-    if(event->added()) {
-        event->child()->installEventFilter(this);
-    }
-    QMenu::childEvent(event);
-}
+    Q_UNUSED(object)
 
-bool DolphinContextMenu::eventFilter(QObject* dest, QEvent* event)
-{
     if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
         QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
-        if(m_removeAction && keyEvent->key() == Qt::Key_Shift) {
-            if(event->type() == QEvent::KeyPress) {
+
+        if (m_removeAction && keyEvent->key() == Qt::Key_Shift) {
+            if (event->type() == QEvent::KeyPress) {
                 m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed);
             } else {
                 m_removeAction->update(DolphinRemoveAction::ShiftState::Released);
             }
-            return true;
         }
     }
-    return QMenu::eventFilter(dest, event);
+
+    return false;
 }
 
 void DolphinContextMenu::openTrashContextMenu()
index 7f0b6988a682e25a265f0e3ef40621a440f48e41..afd8b8c4d8d77c0679266e097519e47a0b738644 100644 (file)
@@ -74,8 +74,7 @@ public:
     Command open();
 
 protected:
-    void childEvent(QChildEvent* event) override;
-    bool eventFilter(QObject* dest, QEvent* event) override;
+    bool eventFilter(QObject* object, QEvent* event) override;
 
 private:
     void openTrashContextMenu();