From 38bb7aa285dc5e84482704e4143303c063abb74a Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 29 Dec 2021 12:16:52 +0000 Subject: [PATCH] Remove Ghost Entries of the Open Folder With There were two bugs with the previous implementation one is that it didn't took in consideration the Profile -> Mouse -> Advanced -> Underline Files With that enabled, right click on the name of the folder would give you a Open Folder With entry, so we would end with two actions. The other bug also triggered when that setting is enabled: we never marked the Open Folder With for removal, after inserting the menu for the underlined file. --- src/session/SessionController.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/session/SessionController.cpp b/src/session/SessionController.cpp index a3bac0570..e5d024e2b 100644 --- a/src/session/SessionController.cpp +++ b/src/session/SessionController.cpp @@ -1827,6 +1827,7 @@ void SessionController::showDisplayContextMenu(const QPoint &position) copy->setShortcut(Konsole::ACCEL | Qt::SHIFT | Qt::Key_C); #endif + // Adds a "Open Folder With" action const QUrl currentUrl = url().isLocalFile() ? url() : QUrl::fromLocalFile(QDir::homePath()); KFileItem item(currentUrl); @@ -1841,14 +1842,26 @@ void SessionController::showDisplayContextMenu(const QPoint &position) for (auto* elm : old) { neu.removeAll(elm); } + // Finish Ading the "Open Folder With" action. - QList toRemove = std::move(neu); + QList toRemove; // prepend content-specific actions such as "Open Link", "Copy Email Address" etc QSharedPointer hotSpot = view()->filterActions(position); if (hotSpot != nullptr) { popup->insertActions(popup->actions().value(0, nullptr), hotSpot->actions() << contentSeparator); popup->addAction(contentSeparator); toRemove = hotSpot->setupMenu(popup.data()); + + // Can happen if we click on a right click, on a folder. + // if this happens, we need to remove this action as we have + // already added the action before this if. + if (toRemove[0]->text() == i18n("&Open Folder With")) { + delete toRemove[0]; + toRemove.removeFirst(); + } + toRemove = toRemove + neu; + } else { + toRemove = neu; } // always update this submenu before showing the context menu,