From db49ac4e1916f87143574b064b36ec86f8407145 Mon Sep 17 00:00:00 2001 From: Albert Mkhitaryan Date: Fri, 20 Feb 2026 08:48:54 +0000 Subject: Add keyboard shortcut support for service menu actions Introduce ServiceMenuShortcutManager, which registers all service menu actions with KActionCollection at startup allowing users to assign keyboard shortcuts in Configure Keyboard Shorcuts. Save/Load of configs happens via KXMLGUI in dolphinui.rc. Notes: - Manager initializes before setupGUI() for shortcut restoration - Execution and validation handled entirely by KFileItemAction in KIO. BUG: 260266 --- src/dolphinmainwindow.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/dolphinmainwindow.cpp') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 62ff2fa45..110bef2f3 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -28,6 +28,9 @@ #include "panels/terminal/terminalpanel.h" #include "search/dolphinquery.h" #include "selectionmode/actiontexthelper.h" +#if KIO_VERSION >= QT_VERSION_CHECK(6, 24, 0) +#include "servicemenushortcutmanager.h" +#endif #include "settings/dolphinsettingsdialog.h" #include "statusbar/diskspaceusagemenu.h" #include "statusbar/dolphinstatusbar.h" @@ -206,6 +209,11 @@ DolphinMainWindow::DolphinMainWindow() setupDockWidgets(); +#if KIO_VERSION >= QT_VERSION_CHECK(6, 24, 0) + m_serviceMenuShortcutManager = new ServiceMenuShortcutManager(actionCollection(), this); +#endif + setupFileItemActions(); + const bool usePhoneUi{KRuntimePlatform::runtimePlatform().contains(QLatin1String("phone"))}; setupGUI(Save | Create | ToolBar, usePhoneUi ? QStringLiteral("dolphinuiforphones.rc") : QString() /* load the default dolphinui.rc file */); stateChanged(QStringLiteral("new_file")); @@ -256,8 +264,6 @@ DolphinMainWindow::DolphinMainWindow() QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction); - setupFileItemActions(); - m_serviceMenuConfigWatcher = KConfigWatcher::create(KSharedConfig::openConfig(QStringLiteral("kservicemenurc"))); connect(m_serviceMenuConfigWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup & /*group*/, const QByteArrayList & /*names*/) { setupFileItemActions(); @@ -431,6 +437,10 @@ void DolphinMainWindow::slotSelectionChanged(const KFileItemList &selection) { updateFileAndEditActions(); + if (m_fileItemActions) { + m_fileItemActions->setItemListProperties(KFileItemListProperties(selection)); + } + const int selectedUrlsCount = m_tabWidget->currentTabPage()->selectedItemsCount(); QAction *compareFilesAction = actionCollection()->action(QStringLiteral("compare_files")); @@ -1783,6 +1793,10 @@ void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString &mo void DolphinMainWindow::slotKeyBindings() { +#if KIO_VERSION >= QT_VERSION_CHECK(6, 24, 0) + m_serviceMenuShortcutManager->cleanupStaleShortcuts(this); +#endif + KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this); dialog.addCollection(actionCollection()); if (m_terminalPanel) { @@ -2624,6 +2638,10 @@ void DolphinMainWindow::setupFileItemActions() connect(m_fileItemActions, &KFileItemActions::error, this, [this](const QString &errorMessage) { showErrorMessage(errorMessage); }); + +#if KIO_VERSION >= QT_VERSION_CHECK(6, 24, 0) + m_serviceMenuShortcutManager->refresh(m_fileItemActions); +#endif } void DolphinMainWindow::updateFileAndEditActions() -- cgit v1.3