]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix delete action switching via 'Shift' when sub-context-menu is open
authorDerek Christ <christ.derek@gmail.com>
Thu, 15 Oct 2020 21:11:17 +0000 (23:11 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Mon, 23 Nov 2020 22:07:31 +0000 (22:07 +0000)
Switching the 'Move to Trash' action to 'Delete' using the shift key
does not work when the mouse hovers a submenu. This fix resolves the
issue by using an event filter instead of the key event functions.

BUG: 425997

src/dolphincontextmenu.cpp
src/dolphincontextmenu.h

index 126baf6e87dffa01e96fba87996bf76df14af620..0c192de38a99e8db232246372e2b310aa5c99277 100644 (file)
@@ -61,6 +61,8 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
     // or the items itself. To increase the performance both lists are cached.
     const DolphinView* view = m_mainWindow->activeViewContainer()->view();
     m_selectedItems = view->selectedItems();
+
+    installEventFilter(this);
 }
 
 DolphinContextMenu::~DolphinContextMenu()
@@ -110,20 +112,28 @@ DolphinContextMenu::Command DolphinContextMenu::open()
     return m_command;
 }
 
-void DolphinContextMenu::keyPressEvent(QKeyEvent *ev)
+void DolphinContextMenu::childEvent(QChildEvent* event)
 {
-    if (m_removeAction && ev->key() == Qt::Key_Shift) {
-        m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed);
+    if(event->added()) {
+        event->child()->installEventFilter(this);
     }
-    QMenu::keyPressEvent(ev);
+    QMenu::childEvent(event);
 }
 
-void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev)
+bool DolphinContextMenu::eventFilter(QObject* dest, QEvent* event)
 {
-    if (m_removeAction && ev->key() == Qt::Key_Shift) {
-        m_removeAction->update(DolphinRemoveAction::ShiftState::Released);
+    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) {
+                m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed);
+            } else {
+                m_removeAction->update(DolphinRemoveAction::ShiftState::Released);
+            }
+            return true;
+        }
     }
-    QMenu::keyReleaseEvent(ev);
+    return QMenu::eventFilter(dest, event);
 }
 
 void DolphinContextMenu::openTrashContextMenu()
@@ -198,6 +208,7 @@ void DolphinContextMenu::addDirectoryItemContextMenu(KFileItemActions &fileItemA
      QMenu* menu = newFileMenu->menu();
      menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
      menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
+     menu->setParent(this, Qt::Popup);
      addMenu(menu);
 
      addSeparator();
index 523c0555ad399045a572b11d0c2dda1febf6c33c..7f0b6988a682e25a265f0e3ef40621a440f48e41 100644 (file)
@@ -74,8 +74,8 @@ public:
     Command open();
 
 protected:
-    void keyPressEvent(QKeyEvent *ev) override;
-    void keyReleaseEvent(QKeyEvent *ev) override;
+    void childEvent(QChildEvent* event) override;
+    bool eventFilter(QObject* dest, QEvent* event) override;
 
 private:
     void openTrashContextMenu();