diff --git a/autotests/kstandardshortcuttest.cpp b/autotests/kstandardshortcuttest.cpp index 53a724f..8c4df02 100644 --- a/autotests/kstandardshortcuttest.cpp +++ b/autotests/kstandardshortcuttest.cpp @@ -1,46 +1,53 @@ /* This file is part of the KDE libraries SPDX-FileCopyrightText: 2005 David Faure SPDX-License-Identifier: LGPL-2.0-or-later */ #include #include "kstandardshortcuttest.h" QTEST_MAIN(KStandardShortcutTest) // GUI needed by KAccel #include void KStandardShortcutTest::testShortcutDefault() { QCOMPARE(QKeySequence::listToString(KStandardShortcut::hardcodedDefaultShortcut(KStandardShortcut::FullScreen)), QLatin1String("Ctrl+Shift+F")); QCOMPARE(QKeySequence::listToString(KStandardShortcut::hardcodedDefaultShortcut(KStandardShortcut::BeginningOfLine)), QLatin1String("Home")); QCOMPARE(QKeySequence::listToString(KStandardShortcut::hardcodedDefaultShortcut(KStandardShortcut::EndOfLine)), QLatin1String("End")); QCOMPARE(QKeySequence::listToString(KStandardShortcut::hardcodedDefaultShortcut(KStandardShortcut::Home)), QLatin1String("Alt+Home; Home Page")); } void KStandardShortcutTest::testName() { QCOMPARE(KStandardShortcut::name(KStandardShortcut::BeginningOfLine), QLatin1String("BeginningOfLine")); QCOMPARE(KStandardShortcut::name(KStandardShortcut::EndOfLine), QLatin1String("EndOfLine")); QCOMPARE(KStandardShortcut::name(KStandardShortcut::Home), QLatin1String("Home")); } void KStandardShortcutTest::testLabel() { // Tests run in English, right? QCOMPARE(KStandardShortcut::label(KStandardShortcut::FindNext), QLatin1String("Find Next")); QCOMPARE(KStandardShortcut::label(KStandardShortcut::Home), QLatin1String("Home")); } void KStandardShortcutTest::testShortcut() { QCOMPARE(QKeySequence::listToString(KStandardShortcut::shortcut(KStandardShortcut::ZoomIn)), QKeySequence::listToString(KStandardShortcut::zoomIn())); } void KStandardShortcutTest::testFindStdAccel() { QCOMPARE(KStandardShortcut::find(QString("Ctrl+F")), KStandardShortcut::Find); QCOMPARE(KStandardShortcut::find(QString("Ctrl+Shift+Alt+G")), KStandardShortcut::AccelNone); } +void KStandardShortcutTest::testFindByName() +{ + for (int i = KStandardShortcut::AccelNone + 1; i < KStandardShortcut::StandardShortcutCount; ++i) { + const auto id = static_cast(i); + QCOMPARE(id, KStandardShortcut::findByName(KStandardShortcut::name(id))); + } +} diff --git a/autotests/kstandardshortcuttest.h b/autotests/kstandardshortcuttest.h index 3d18622..ae48445 100644 --- a/autotests/kstandardshortcuttest.h +++ b/autotests/kstandardshortcuttest.h @@ -1,24 +1,25 @@ /* This file is part of the KDE libraries SPDX-FileCopyrightText: 2005 David Faure SPDX-License-Identifier: LGPL-2.0-or-later */ #ifndef KSTDACCELTEST_H #define KSTDACCELTEST_H #include class KStandardShortcutTest : public QObject { Q_OBJECT private Q_SLOTS: // KStandardShortcut tests void testShortcutDefault(); void testName(); void testLabel(); void testShortcut(); void testFindStdAccel(); + void testFindByName(); }; #endif diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 7c0c2f5..5a276f9 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -1,78 +1,78 @@ set(libkconfiggui_SRCS kconfiggui.cpp kconfiggroupgui.cpp kconfigloader.cpp kconfigskeleton.cpp kstandardshortcut.cpp kwindowconfig.cpp ) ecm_create_qm_loader(libkconfiggui_SRCS kconfig5_qt) add_library(KF5ConfigGui ${libkconfiggui_SRCS}) add_library(KF5::ConfigGui ALIAS KF5ConfigGui) ecm_generate_export_header(KF5ConfigGui BASE_NAME KConfigGui GROUP_BASE_NAME KF VERSION ${KF5_VERSION} DEPRECATED_BASE_VERSION 0 - DEPRECATION_VERSIONS 5.11 5.39 + DEPRECATION_VERSIONS 5.11 5.39 5.71 EXCLUDE_DEPRECATED_BEFORE_AND_AT ${EXCLUDE_DEPRECATED_BEFORE_AND_AT} ) target_include_directories(KF5ConfigGui INTERFACE "$") target_link_libraries(KF5ConfigGui PUBLIC Qt5::Gui Qt5::Xml KF5::ConfigCore) set_target_properties(KF5ConfigGui PROPERTIES VERSION ${KCONFIG_VERSION_STRING} SOVERSION ${KCONFIG_SOVERSION} EXPORT_NAME ConfigGui ) ecm_generate_headers(KConfigGui_HEADERS HEADER_NAMES KConfigGui KConfigLoader KConfigSkeleton KStandardShortcut KWindowConfig REQUIRED_HEADERS KConfigGui_HEADERS ) find_package(PythonModuleGeneration) if (PythonModuleGeneration_FOUND) ecm_generate_python_binding( TARGET KF5::ConfigGui PYTHONNAMESPACE PyKF5 MODULENAME KConfigGui RULES_FILE "${CMAKE_SOURCE_DIR}/cmake/rules_PyKF5.py" SIP_INCLUDES "${CMAKE_BINARY_DIR}/src/core/sip" SIP_DEPENDS QtGui/QtGuimod.sip PyKF5/KConfigCore/KConfigCoremod.sip HEADERS kconfiggui.h kconfigloader.h kconfigskeleton.h kstandardshortcut.h kwindowconfig.h ) endif() install(TARGETS KF5ConfigGui EXPORT KF5ConfigTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kconfiggui_export.h ${KConfigGui_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KConfigGui COMPONENT Devel ) # make available to ecm_add_qch in parent folder set(KConfigGui_APIDOX_SRCS ${KConfigGui_HEADERS} PARENT_SCOPE) set(KConfigGui_APIDOX_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE) include(ECMGeneratePriFile) ecm_generate_pri_file(BASE_NAME KConfigGui LIB_NAME KF5ConfigGui DEPS "gui xml KConfigCore" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KConfigGui) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) diff --git a/src/gui/kstandardshortcut.cpp b/src/gui/kstandardshortcut.cpp index 7d78891..825dfb8 100644 --- a/src/gui/kstandardshortcut.cpp +++ b/src/gui/kstandardshortcut.cpp @@ -1,566 +1,580 @@ /* This file is part of the KDE libraries SPDX-FileCopyrightText: 1997 Stefan Taferner SPDX-FileCopyrightText: 2000 Nicolas Hadacek SPDX-FileCopyrightText: 2001, 2002 Ellis Whitehead SPDX-License-Identifier: LGPL-2.0-only */ #include "kstandardshortcut.h" #include "kconfig.h" #include "ksharedconfig.h" #include #include #include #include namespace KStandardShortcut { struct KStandardShortcutInfo { //! The standard shortcut id. @see StandardShortcut StandardShortcut id; /** * Unique name for the given accel. The name is used to save the user * settings. It's not representable. Use description for that. * @warning NEVER EVER CHANGE IT OR TRANSLATE IT! */ const char *name; //! Localized label for user-visible display, including translation context. struct { const char *text; const char *context; } description; //! The keys for this shortcut int cutDefault, cutDefault2; //! A shortcut that is created with @a cutDefault and @cutDefault2 QList cut; //! If this struct is initialized. If not initialized @cut is not valid bool isInitialized; }; #define CTRL(x) Qt::CTRL+Qt::Key_##x #define SHIFT(x) Qt::SHIFT+Qt::Key_##x #define CTRLSHIFT(x) Qt::CTRL+Qt::SHIFT+Qt::Key_##x #define ALT(x) Qt::ALT+Qt::Key_##x #define ALTSHIFT(x) Qt::ALT+Qt::SHIFT+Qt::Key_##x /** Array of predefined KStandardShortcutInfo objects, which cover all the "standard" accelerators. Each enum value from StandardShortcut should appear in this table. */ // STUFF WILL BREAK IF YOU DON'T READ THIS!!! // Read the comments of the big enum in kstandardshortcut.h before you change anything! static KStandardShortcutInfo g_infoStandardShortcut[] = { //Group File, { AccelNone, nullptr, {nullptr, nullptr}, 0, 0, QList(), false }, { Open, "Open", QT_TRANSLATE_NOOP3("KStandardShortcut", "Open", "@action"), CTRL(O), 0, QList(), false }, { New, "New", QT_TRANSLATE_NOOP3("KStandardShortcut", "New", "@action"), CTRL(N), 0, QList(), false }, { Close, "Close", QT_TRANSLATE_NOOP3("KStandardShortcut", "Close", "@action"), CTRL(W), CTRL(Escape), QList(), false }, { Save, "Save", QT_TRANSLATE_NOOP3("KStandardShortcut", "Save", "@action"), CTRL(S), 0, QList(), false }, { Print, "Print", QT_TRANSLATE_NOOP3("KStandardShortcut", "Print", "@action"), CTRL(P), 0, QList(), false }, { Quit, "Quit", QT_TRANSLATE_NOOP3("KStandardShortcut", "Quit", "@action"), CTRL(Q), 0, QList(), false }, //Group Edit { Undo, "Undo", QT_TRANSLATE_NOOP3("KStandardShortcut", "Undo", "@action"), CTRL(Z), 0, QList(), false }, { Redo, "Redo", QT_TRANSLATE_NOOP3("KStandardShortcut", "Redo", "@action"), CTRLSHIFT(Z), 0, QList(), false }, // Both "Cut" and "Delete" use Shift+Delete, but this is okay; see // https://commits.kde.org/kxmlgui/8eabbf6725386e716b7536c71a9181dfe5d959f0 { Cut, "Cut", QT_TRANSLATE_NOOP3("KStandardShortcut", "Cut", "@action"), CTRL(X), SHIFT(Delete), QList(), false }, { Copy, "Copy", QT_TRANSLATE_NOOP3("KStandardShortcut", "Copy", "@action"), CTRL(C), CTRL(Insert), QList(), false }, { Paste, "Paste", QT_TRANSLATE_NOOP3("KStandardShortcut", "Paste", "@action"), CTRL(V), SHIFT(Insert), QList(), false }, { PasteSelection, "Paste Selection", QT_TRANSLATE_NOOP3("KStandardShortcut", "Paste Selection", "@action"), CTRLSHIFT(Insert), 0, QList(), false }, { SelectAll, "SelectAll", QT_TRANSLATE_NOOP3("KStandardShortcut", "Select All", "@action"), CTRL(A), 0, QList(), false }, { Deselect, "Deselect", QT_TRANSLATE_NOOP3("KStandardShortcut", "Deselect", "@action"), CTRLSHIFT(A), 0, QList(), false }, { DeleteWordBack, "DeleteWordBack", QT_TRANSLATE_NOOP3("KStandardShortcut", "Delete Word Backwards", "@action"), CTRL(Backspace), 0, QList(), false }, { DeleteWordForward, "DeleteWordForward", QT_TRANSLATE_NOOP3("KStandardShortcut", "Delete Word Forward", "@action"), CTRL(Delete), 0, QList(), false }, { Find, "Find", QT_TRANSLATE_NOOP3("KStandardShortcut", "Find", "@action"), CTRL(F), 0, QList(), false }, { FindNext, "FindNext", QT_TRANSLATE_NOOP3("KStandardShortcut", "Find Next", "@action"), Qt::Key_F3, 0, QList(), false }, { FindPrev, "FindPrev", QT_TRANSLATE_NOOP3("KStandardShortcut", "Find Prev", "@action"), SHIFT(F3), 0, QList(), false }, { Replace, "Replace", QT_TRANSLATE_NOOP3("KStandardShortcut", "Replace", "@action"), CTRL(R), 0, QList(), false }, //Group Navigation { Home, "Home", QT_TRANSLATE_NOOP3("KStandardShortcut", "Home", "@action Go to main page"), ALT(Home), Qt::Key_HomePage, QList(), false }, { Begin, "Begin", QT_TRANSLATE_NOOP3("KStandardShortcut", "Begin", "@action Beginning of document"), CTRL(Home), 0, QList(), false }, { End, "End", QT_TRANSLATE_NOOP3("KStandardShortcut", "End", "@action End of document"), CTRL(End), 0, QList(), false }, { Prior, "Prior", QT_TRANSLATE_NOOP3("KStandardShortcut", "Prior", "@action"), Qt::Key_PageUp, 0, QList(), false }, { Next, "Next", QT_TRANSLATE_NOOP3("KStandardShortcut", "Next", "@action Opposite to Prior"), Qt::Key_PageDown, 0, QList(), false }, { Up, "Up", QT_TRANSLATE_NOOP3("KStandardShortcut", "Up", "@action"), ALT(Up), 0, QList(), false }, { Back, "Back", QT_TRANSLATE_NOOP3("KStandardShortcut", "Back", "@action"), ALT(Left), Qt::Key_Back, QList(), false }, { Forward, "Forward", QT_TRANSLATE_NOOP3("KStandardShortcut", "Forward", "@action"), ALT(Right), Qt::Key_Forward, QList(), false }, { Reload, "Reload", QT_TRANSLATE_NOOP3("KStandardShortcut", "Reload", "@action"), Qt::Key_F5, Qt::Key_Refresh, QList(), false }, { BeginningOfLine, "BeginningOfLine", QT_TRANSLATE_NOOP3("KStandardShortcut", "Beginning of Line", "@action"), Qt::Key_Home, 0, QList(), false }, { EndOfLine, "EndOfLine", QT_TRANSLATE_NOOP3("KStandardShortcut", "End of Line", "@action"), Qt::Key_End, 0, QList(), false }, { GotoLine, "GotoLine", QT_TRANSLATE_NOOP3("KStandardShortcut", "Go to Line", "@action"), CTRL(G), 0, QList(), false }, { BackwardWord, "BackwardWord", QT_TRANSLATE_NOOP3("KStandardShortcut", "Backward Word", "@action"), CTRL(Left), 0, QList(), false }, { ForwardWord, "ForwardWord", QT_TRANSLATE_NOOP3("KStandardShortcut", "Forward Word", "@action"), CTRL(Right), 0, QList(), false }, { AddBookmark, "AddBookmark", QT_TRANSLATE_NOOP3("KStandardShortcut", "Add Bookmark", "@action"), CTRL(B), 0, QList(), false }, { ZoomIn, "ZoomIn", QT_TRANSLATE_NOOP3("KStandardShortcut", "Zoom In", "@action"), CTRL(Plus), CTRL(Equal), QList(), false }, { ZoomOut, "ZoomOut", QT_TRANSLATE_NOOP3("KStandardShortcut", "Zoom Out", "@action"), CTRL(Minus), 0, QList(), false }, { FullScreen, "FullScreen", QT_TRANSLATE_NOOP3("KStandardShortcut", "Full Screen Mode", "@action"), CTRLSHIFT(F), 0, QList(), false }, { ShowMenubar, "ShowMenubar", QT_TRANSLATE_NOOP3("KStandardShortcut", "Show Menu Bar", "@action"), CTRL(M), 0, QList(), false }, { TabNext, "Activate Next Tab", QT_TRANSLATE_NOOP3("KStandardShortcut", "Activate Next Tab", "@action"), CTRL(PageDown), CTRL(BracketRight), QList(), false }, { TabPrev, "Activate Previous Tab", QT_TRANSLATE_NOOP3("KStandardShortcut", "Activate Previous Tab", "@action"), CTRL(PageUp), CTRL(BracketLeft), QList(), false }, //Group Help { Help, "Help", QT_TRANSLATE_NOOP3("KStandardShortcut", "Help", "@action"), Qt::Key_F1, 0, QList(), false }, { WhatsThis, "WhatsThis", QT_TRANSLATE_NOOP3("KStandardShortcut", "What's This", "@action"), SHIFT(F1), 0, QList(), false }, //Group TextCompletion { TextCompletion, "TextCompletion", QT_TRANSLATE_NOOP3("KStandardShortcut", "Text Completion", "@action"), CTRL(E), 0, QList(), false }, { PrevCompletion, "PrevCompletion", QT_TRANSLATE_NOOP3("KStandardShortcut", "Previous Completion Match", "@action"), CTRL(Up), 0, QList(), false }, { NextCompletion, "NextCompletion", QT_TRANSLATE_NOOP3("KStandardShortcut", "Next Completion Match", "@action"), CTRL(Down), 0, QList(), false }, { SubstringCompletion, "SubstringCompletion", QT_TRANSLATE_NOOP3("KStandardShortcut", "Substring Completion", "@action"), CTRL(T), 0, QList(), false }, { RotateUp, "RotateUp", QT_TRANSLATE_NOOP3("KStandardShortcut", "Previous Item in List", "@action"), Qt::Key_Up, 0, QList(), false }, { RotateDown, "RotateDown", QT_TRANSLATE_NOOP3("KStandardShortcut", "Next Item in List", "@action"), Qt::Key_Down, 0, QList(), false }, { OpenRecent, "OpenRecent", QT_TRANSLATE_NOOP3("KStandardShortcut", "Open Recent", "@action"), 0, 0, QList(), false }, { SaveAs, "SaveAs", QT_TRANSLATE_NOOP3("KStandardShortcut", "Save As", "@action"), CTRLSHIFT(S), 0, QList(), false }, { Revert, "Revert", QT_TRANSLATE_NOOP3("KStandardShortcut", "Revert", "@action"), 0, 0, QList(), false }, { PrintPreview, "PrintPreview", QT_TRANSLATE_NOOP3("KStandardShortcut", "Print Preview", "@action"), 0, 0, QList(), false }, { Mail, "Mail", QT_TRANSLATE_NOOP3("KStandardShortcut", "Mail", "@action"), 0, 0, QList(), false }, { Clear, "Clear", QT_TRANSLATE_NOOP3("KStandardShortcut", "Clear", "@action"), 0, 0, QList(), false }, { ActualSize, "ActualSize", QT_TRANSLATE_NOOP3("KStandardShortcut", "Actual Size", "@action"), CTRL(0), 0, QList(), false }, { FitToPage, "FitToPage", QT_TRANSLATE_NOOP3("KStandardShortcut", "Fit To Page", "@action"), 0, 0, QList(), false }, { FitToWidth, "FitToWidth", QT_TRANSLATE_NOOP3("KStandardShortcut", "Fit To Width", "@action"), 0, 0, QList(), false }, { FitToHeight, "FitToHeight", QT_TRANSLATE_NOOP3("KStandardShortcut", "Fit To Height", "@action"), 0, 0, QList(), false }, { Zoom, "Zoom", QT_TRANSLATE_NOOP3("KStandardShortcut", "Zoom", "@action"), 0, 0, QList(), false }, { Goto, "Goto", QT_TRANSLATE_NOOP3("KStandardShortcut", "Goto", "@action"), 0, 0, QList(), false }, { GotoPage, "GotoPage", QT_TRANSLATE_NOOP3("KStandardShortcut", "Goto Page", "@action"), 0, 0, QList(), false }, { DocumentBack, "DocumentBack", QT_TRANSLATE_NOOP3("KStandardShortcut", "Document Back", "@action"), ALTSHIFT(Left), 0, QList(), false }, { DocumentForward, "DocumentForward", QT_TRANSLATE_NOOP3("KStandardShortcut", "Document Forward", "@action"), ALTSHIFT(Right), 0, QList(), false }, { EditBookmarks, "EditBookmarks", QT_TRANSLATE_NOOP3("KStandardShortcut", "Edit Bookmarks", "@action"), 0, 0, QList(), false }, { Spelling, "Spelling", QT_TRANSLATE_NOOP3("KStandardShortcut", "Spelling", "@action"), 0, 0, QList(), false }, { ShowToolbar, "ShowToolbar", QT_TRANSLATE_NOOP3("KStandardShortcut", "Show Toolbar", "@action"), 0, 0, QList(), false }, { ShowStatusbar, "ShowStatusbar", QT_TRANSLATE_NOOP3("KStandardShortcut", "Show Statusbar", "@action"), 0, 0, QList(), false }, #if KCONFIGGUI_BUILD_DEPRECATED_SINCE(5, 39) { SaveOptions, "SaveOptions", QT_TRANSLATE_NOOP3("KStandardShortcut", "Save Options", "@action"), 0, 0, QList(), false }, #else // dummy entry { SaveOptions_DEPRECATED_DO_NOT_USE, nullptr, {nullptr, nullptr}, 0, 0, QList(), false }, #endif { KeyBindings, "KeyBindings", QT_TRANSLATE_NOOP3("KStandardShortcut", "Key Bindings", "@action"), 0, 0, QList(), false }, { Preferences, "Preferences", QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Application", "@action"), CTRLSHIFT(Comma), 0, QList(), false }, { ConfigureToolbars, "ConfigureToolbars", QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Toolbars", "@action"), 0, 0, QList(), false }, { ConfigureNotifications, "ConfigureNotifications", QT_TRANSLATE_NOOP3("KStandardShortcut", "Configure Notifications", "@action"), 0, 0, QList(), false }, { TipofDay, "TipofDay", QT_TRANSLATE_NOOP3("KStandardShortcut", "Tip Of Day", "@action"), 0, 0, QList(), false }, { ReportBug, "ReportBug", QT_TRANSLATE_NOOP3("KStandardShortcut", "Report Bug", "@action"), 0, 0, QList(), false }, { SwitchApplicationLanguage, "SwitchApplicationLanguage", QT_TRANSLATE_NOOP3("KStandardShortcut", "Switch Application Language", "@action"), 0, 0, QList(), false }, { AboutApp, "AboutApp", QT_TRANSLATE_NOOP3("KStandardShortcut", "About Application", "@action"), 0, 0, QList(), false }, { AboutKDE, "AboutKDE", QT_TRANSLATE_NOOP3("KStandardShortcut", "About KDE", "@action"), 0, 0, QList(), false }, // Both "Cut" and "Delete" use Shift+Delete, but this is okay; see // https://commits.kde.org/kxmlgui/8eabbf6725386e716b7536c71a9181dfe5d959f0 { DeleteFile, "DeleteFile", QT_TRANSLATE_NOOP3("KStandardShortcut", "Delete", "@action"), SHIFT(Delete), 0, QList(), false }, { RenameFile, "RenameFile", QT_TRANSLATE_NOOP3("KStandardShortcut", "Rename", "@action"), Qt::Key_F2, 0, QList(), false }, { MoveToTrash, "MoveToTrash", QT_TRANSLATE_NOOP3("KStandardShortcut", "Move to Trash", "@action"), Qt::Key_Delete, 0, QList(), false }, { Donate, "Donate", QT_TRANSLATE_NOOP3("KStandardShortcut", "Donate", "@action"), 0, 0, QList(), false }, { ShowHideHiddenFiles, "ShowHideHiddenFiles", QT_TRANSLATE_NOOP3("KStandardShortcut", "Show/Hide Hidden Files", "@action"), CTRL(H), ALT(Period), QList(), false }, //dummy entry to catch simple off-by-one errors. Insert new entries before this line. { AccelNone, nullptr, {nullptr, nullptr}, 0, 0, QList(), false } }; /** Search for the KStandardShortcutInfo object associated with the given @p id. Return a dummy entry with no name and an empty shortcut if @p id is invalid. */ static KStandardShortcutInfo *guardedStandardShortcutInfo(StandardShortcut id) { if (id >= static_cast(sizeof(g_infoStandardShortcut) / sizeof(KStandardShortcutInfo)) || id < 0) { qWarning() << "KStandardShortcut: id not found!"; return &g_infoStandardShortcut[AccelNone]; } else { return &g_infoStandardShortcut[id]; } } // Sanitize the list for duplicates. For some reason some // people have kdeglobals entries like // Close=Ctrl+W; Ctrl+Esc; Ctrl+W; Ctrl+Esc; // having the same shortcut more than once in the shortcut // declaration is clearly bogus so fix it static void sanitizeShortcutList(QList *list) { for (int i = 0; i < list->size(); ++i) { const QKeySequence &ks = list->at(i); int other = list->indexOf(ks, i + 1); while (other != -1) { list->removeAt(other); other = list->indexOf(ks, other); } } } /** Initialize the accelerator @p id by checking if it is overridden in the configuration file (and if it isn't, use the default). On X11, if QApplication was initialized with GUI disabled, the default will always be used. */ static void initialize(StandardShortcut id) { KStandardShortcutInfo *info = guardedStandardShortcutInfo(id); // All three are needed. if (info->id != AccelNone) { Q_ASSERT(info->description.text); Q_ASSERT(info->description.context); Q_ASSERT(info->name); } KConfigGroup cg(KSharedConfig::openConfig(), "Shortcuts"); if (cg.hasKey(info->name)) { QString s = cg.readEntry(info->name); if (s != QLatin1String("none")) { info->cut = QKeySequence::listFromString(s); sanitizeShortcutList(&info->cut); } else { info->cut = QList(); } } else { info->cut = hardcodedDefaultShortcut(id); } info->isInitialized = true; } void saveShortcut(StandardShortcut id, const QList &newShortcut) { KStandardShortcutInfo *info = guardedStandardShortcutInfo(id); // If the action has no standard shortcut associated there is nothing to // save if (info->id == AccelNone) { return; } KConfigGroup cg(KSharedConfig::openConfig(), "Shortcuts"); info->cut = newShortcut; bool sameAsDefault = (newShortcut == hardcodedDefaultShortcut(id)); if (sameAsDefault) { // If the shortcut is the equal to the hardcoded one we remove it from // kdeglobal if necessary and return. if (cg.hasKey(info->name)) { cg.deleteEntry(info->name, KConfig::Global | KConfig::Persistent); } return; } // Write the changed shortcut to kdeglobals sanitizeShortcutList(&info->cut); cg.writeEntry(info->name, QKeySequence::listToString(info->cut), KConfig::Global | KConfig::Persistent); } QString name(StandardShortcut id) { return QString::fromLatin1(guardedStandardShortcutInfo(id)->name); } QString label(StandardShortcut id) { KStandardShortcutInfo *info = guardedStandardShortcutInfo(id); return QCoreApplication::translate("KStandardShortcut", info->description.text, info->description.context); } // TODO: Add psWhatsThis entry to KStandardShortcutInfo QString whatsThis(StandardShortcut /*id*/) { // KStandardShortcutInfo* info = guardedStandardShortcutInfo( id ); // if( info && info->whatsThis ) // return i18n(info->whatsThis); // else return QString(); } const QList &shortcut(StandardShortcut id) { KStandardShortcutInfo *info = guardedStandardShortcutInfo(id); if (!info->isInitialized) { initialize(id); } return info->cut; } StandardShortcut find(const QKeySequence &seq) { if (!seq.isEmpty()) { for (const KStandardShortcutInfo &shortcutInfo : g_infoStandardShortcut) { const StandardShortcut id = shortcutInfo.id; if (id != AccelNone) { if (!shortcutInfo.isInitialized) { initialize(id); } if (shortcutInfo.cut.contains(seq)) { return id; } } } } return AccelNone; } + +#if KCONFIGGUI_BUILD_DEPRECATED_SINCE(5, 71) StandardShortcut find(const char *keyName) { for (const KStandardShortcutInfo &shortcutInfo : g_infoStandardShortcut) { if (qstrcmp(shortcutInfo.name, keyName) == 0) { return shortcutInfo.id; } } return AccelNone; } +#endif + +StandardShortcut findByName(const QString &name) +{ + + for (const KStandardShortcutInfo &shortcutInfo : g_infoStandardShortcut) { + if (QString::fromLatin1(shortcutInfo.name) == name) { + return shortcutInfo.id; + } + } + return AccelNone; +} QList hardcodedDefaultShortcut(StandardShortcut id) { QList cut; KStandardShortcutInfo *info = guardedStandardShortcutInfo(id); if (info->cutDefault != 0) { cut << info->cutDefault; } if (info->cutDefault2 != 0) { if (cut.isEmpty()) { cut << QKeySequence(); } cut << info->cutDefault2; } return cut; } const QList &open() { return shortcut(Open); } const QList &openNew() { return shortcut(New); } const QList &close() { return shortcut(Close); } const QList &save() { return shortcut(Save); } const QList &print() { return shortcut(Print); } const QList &quit() { return shortcut(Quit); } const QList &cut() { return shortcut(Cut); } const QList ©() { return shortcut(Copy); } const QList &paste() { return shortcut(Paste); } const QList &pasteSelection() { return shortcut(PasteSelection); } const QList &deleteWordBack() { return shortcut(DeleteWordBack); } const QList &deleteWordForward() { return shortcut(DeleteWordForward); } const QList &undo() { return shortcut(Undo); } const QList &redo() { return shortcut(Redo); } const QList &find() { return shortcut(Find); } const QList &findNext() { return shortcut(FindNext); } const QList &findPrev() { return shortcut(FindPrev); } const QList &replace() { return shortcut(Replace); } const QList &home() { return shortcut(Home); } const QList &begin() { return shortcut(Begin); } const QList &end() { return shortcut(End); } const QList &beginningOfLine() { return shortcut(BeginningOfLine); } const QList &endOfLine() { return shortcut(EndOfLine); } const QList &prior() { return shortcut(Prior); } const QList &next() { return shortcut(Next); } const QList &backwardWord() { return shortcut(BackwardWord); } const QList &forwardWord() { return shortcut(ForwardWord); } const QList &gotoLine() { return shortcut(GotoLine); } const QList &addBookmark() { return shortcut(AddBookmark); } const QList &tabNext() { return shortcut(TabNext); } const QList &tabPrev() { return shortcut(TabPrev); } const QList &fullScreen() { return shortcut(FullScreen); } const QList &zoomIn() { return shortcut(ZoomIn); } const QList &zoomOut() { return shortcut(ZoomOut); } const QList &help() { return shortcut(Help); } const QList &completion() { return shortcut(TextCompletion); } const QList &prevCompletion() { return shortcut(PrevCompletion); } const QList &nextCompletion() { return shortcut(NextCompletion); } const QList &rotateUp() { return shortcut(RotateUp); } const QList &rotateDown() { return shortcut(RotateDown); } const QList &substringCompletion() { return shortcut(SubstringCompletion); } const QList &whatsThis() { return shortcut(WhatsThis); } const QList &reload() { return shortcut(Reload); } const QList &selectAll() { return shortcut(SelectAll); } const QList &up() { return shortcut(Up); } const QList &back() { return shortcut(Back); } const QList &forward() { return shortcut(Forward); } const QList &showMenubar() { return shortcut(ShowMenubar); } const QList &deleteFile() { return shortcut(DeleteFile); } const QList &renameFile() { return shortcut(RenameFile); } const QList &moveToTrash() { return shortcut(MoveToTrash); } const QList &preferences() { return shortcut(Preferences); } const QList &showHideHiddenFiles() { return shortcut(ShowHideHiddenFiles); } } diff --git a/src/gui/kstandardshortcut.h b/src/gui/kstandardshortcut.h index 69feee6..cda9fe9 100644 --- a/src/gui/kstandardshortcut.h +++ b/src/gui/kstandardshortcut.h @@ -1,540 +1,554 @@ /* This file is part of the KDE libraries SPDX-FileCopyrightText: 1997 Stefan Taferner SPDX-FileCopyrightText: 2000 Nicolas Hadacek SPDX-FileCopyrightText: 2001, 2002 Ellis Whitehead SPDX-License-Identifier: LGPL-2.0-only */ #ifndef KSTANDARDSHORTCUT_H #define KSTANDARDSHORTCUT_H #include #include #include /** * \namespace KStandardShortcut * Convenient methods for access to the common accelerator keys in * the key configuration. These are the standard keybindings that should * be used in all KDE applications. They will be configurable, * so do not hardcode the default behavior. */ namespace KStandardShortcut { // STUFF WILL BREAK IF YOU DON'T READ THIS!!! /* *Always add new std-accels to the end of this enum, never in the middle! *Don't forget to add the corresponding entries in g_infoStandardShortcut[] in kstandardshortcut.cpp, too. *Values of elements here and positions of the corresponding entries in *the big array g_infoStandardShortcut[] ABSOLUTELY MUST BE THE SAME. * !!! !!!! !!!!! !!!! * !!!! !!! !!!! !!!! * Remember to also update kdoctools/genshortcutents.cpp. * * Other Rules: * * - Never change the name of an existing shortcut * - Never translate the name of a shortcut */ /** * Defines the identifier of all standard accelerators. */ enum StandardShortcut { //C++ requires that the value of an enum symbol be one more than the previous one. //This means that everything will be well-ordered from here on. AccelNone = 0, // File menu Open, ///< Open file. New, ///< Create a new document. Close, ///< Close current document. Save, ///< Save current document. // The Print item Print, ///< Print current document. Quit, ///< Quit the program. // Edit menu Undo, ///< Undo last operation. Redo, ///< Redo last operation. Cut, ///< Cut selected area and store it in the clipboard. Copy, ///< Copy selected area into the clipboard. Paste, ///< Paste contents of clipboard at mouse/cursor position. PasteSelection, ///< Paste the selection at mouse/cursor position. SelectAll, ///< Select all. Deselect, ///< Deselect any selected elements. DeleteWordBack, ///< Delete a word back from mouse/cursor position. DeleteWordForward, ///< Delete a word forward from mouse/cursor position. Find, ///< Initiate a 'find' request in the current document. FindNext, ///< Find the next instance of a stored 'find'. FindPrev, ///< Find a previous instance of a stored 'find'. Replace, ///< Find and replace matches. // Navigation Home, ///< Go to home page. Begin, ///< Go to beginning of the document. End, ///< Go to end of the document. Prior, ///< Scroll up one page. Next, ///< Scroll down one page. Up, ///< Up. Back, ///< Back. Forward, ///< Forward. Reload, ///< Reload. // Text Navigation BeginningOfLine, ///< Go to beginning of current line. EndOfLine, ///< Go to end of current line. GotoLine, ///< Go to line. BackwardWord, ///< BackwardWord. ForwardWord, ///< ForwardWord. // View parameters AddBookmark, ///< Add current page to bookmarks. ZoomIn, ///< Zoom in. ZoomOut, ///< Zoom out. FullScreen, ///< Full Screen mode. ShowMenubar, ///< Show Menu Bar. // Tabular navigation TabNext, ///< Next Tab. TabPrev, ///< Previous Tab. // Help menu Help, ///< Help the user in the current situation. WhatsThis, ///< What's This button. // Text completion TextCompletion, ///< Complete text in input widgets. PrevCompletion, ///< Iterate through a list when completion returns multiple items. NextCompletion, ///< Iterate through a list when completion returns multiple items. SubstringCompletion, ///< Find a string within another string or list of strings. RotateUp, ///< Help users iterate through a list of entries. RotateDown, ///< Help users iterate through a list of entries. OpenRecent, ///< Open a recently used document. SaveAs, ///< Save the current document under a different name. Revert, ///< Revert the current document to the last saved version. PrintPreview, ///< Show a print preview of the current document. Mail, ///< Send the current document by mail. Clear, ///< Clear the content of the focus widget. ActualSize, ///< View the document at its actual size. FitToPage, ///< Fit the document view to the size of the current window. FitToWidth, ///< Fit the document view to the width of the current window. FitToHeight, ///< Fit the document view to the height of the current window. Zoom, ///< Select the current zoom level. Goto, ///< Jump to some specific location in the document. GotoPage, ///< Go to a specific page. DocumentBack, ///< Move back (document style menu). DocumentForward, ///< Move forward (document style menu). EditBookmarks, ///< Edit the application bookmarks. Spelling, ///< Pop up the spell checker. ShowToolbar, ///< Show/Hide the toolbar. ShowStatusbar, ///< Show/Hide the statusbar. #if KCONFIGGUI_ENABLE_DEPRECATED_SINCE(5, 39) SaveOptions, ///< @deprecated since 5.39 #else SaveOptions_DEPRECATED_DO_NOT_USE, #endif KeyBindings, ///< Display the configure key bindings dialog. Preferences, ///< Display the preferences/options dialog. ConfigureToolbars, ///< Display the toolbar configuration dialog. ConfigureNotifications, ///< Display the notifications configuration dialog. TipofDay, ///< Display the "Tip of the Day". ReportBug, ///< Display the Report Bug dialog. SwitchApplicationLanguage, ///< Display the Switch Application Language dialog. AboutApp, ///< Display the application's About dialog. AboutKDE, ///< Display the About KDE dialog. DeleteFile, ///< Permanently delete files or folders. @since 5.25 RenameFile, ///< Rename files or folders. @since 5.25 MoveToTrash, ///< Move files or folders to the trash. @since 5.25 Donate, ///< Open donation page on kde.org. @since 5.26 ShowHideHiddenFiles, ///< Toggle showing or hiding hidden files @since 5.70 // Insert new items here! StandardShortcutCount // number of standard shortcuts }; /** * Returns the keybinding for @p accel. * On X11, if QApplication was initialized with GUI disabled, the * default keybinding will always be returned. * @param id the id of the accelerator */ KCONFIGGUI_EXPORT const QList &shortcut(StandardShortcut id); /** * Returns a unique name for the given accel. * @param id the id of the accelerator * @return the unique name of the accelerator */ KCONFIGGUI_EXPORT QString name(StandardShortcut id); /** * Returns a localized label for user-visible display. * @param id the id of the accelerator * @return a localized label for the accelerator */ KCONFIGGUI_EXPORT QString label(StandardShortcut id); /** * Returns an extended WhatsThis description for the given accelerator. * @param id the id of the accelerator * @return a localized description of the accelerator */ KCONFIGGUI_EXPORT QString whatsThis(StandardShortcut id); /** * Return the StandardShortcut id of the standard accel action which * uses this key sequence, or AccelNone if none of them do. * This is used by class KKeyChooser. * @param keySeq the key sequence to search * @return the id of the standard accelerator, or AccelNone if there * is none */ KCONFIGGUI_EXPORT StandardShortcut find(const QKeySequence &keySeq); +#if KCONFIGGUI_ENABLE_DEPRECATED_SINCE(5, 71) /** * Return the StandardShortcut id of the standard accel action which * has \a keyName as its name, or AccelNone if none of them do. * This is used by class KKeyChooser. * @param keyName the key sequence to search * @return the id of the standard accelerator, or AccelNone if there * is none + * @deprecated since 5.71, use findByName(const QString &name) instead */ +KCONFIGGUI_DEPRECATED_VERSION(5, 71, "Use findByName(const QString &name) instead") KCONFIGGUI_EXPORT StandardShortcut find(const char *keyName); +#endif + +/** + * Return the StandardShortcut id of the standard accelerator action which + * has \p name as its name, or AccelNone if none of them do. + * @param name the name as returned by name(StandardShortcut id) + * @return the id of the standard accelerator with the given name or AccelNone + * if there is no such accelerator + * @since 5.71 + */ +KCONFIGGUI_EXPORT StandardShortcut findByName(const QString &name); /** * Returns the hardcoded default shortcut for @p id. * This does not take into account the user's configuration. * @param id the id of the accelerator * @return the default shortcut of the accelerator */ KCONFIGGUI_EXPORT QList hardcodedDefaultShortcut(StandardShortcut id); /** * Saves the new shortcut \a cut for standard accel \a id. */ KCONFIGGUI_EXPORT void saveShortcut(StandardShortcut id, const QList &newShortcut); /** * Open file. Default: Ctrl-o * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &open(); /** * Create a new document (or whatever). Default: Ctrl-n * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &openNew(); /** * Close current document. Default: Ctrl-w * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &close(); /** * Save current document. Default: Ctrl-s * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &save(); /** * Print current document. Default: Ctrl-p * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &print(); /** * Quit the program. Default: Ctrl-q * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &quit(); /** * Undo last operation. Default: Ctrl-z * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &undo(); /** * Redo last operation. Default: Shift-Ctrl-z * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &redo(); /** * Cut selected area and store it in the clipboard. Default: Ctrl-x * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &cut(); /** * Copy selected area into the clipboard. Default: Ctrl-c * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList ©(); /** * Paste contents of clipboard at mouse/cursor position. Default: Ctrl-v * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &paste(); /** * Paste the selection at mouse/cursor position. Default: Ctrl-Shift-Insert * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &pasteSelection(); /** * Select all. Default: Ctrl-A * @return the shortcut of the standard accelerator **/ KCONFIGGUI_EXPORT const QList &selectAll(); /** * Delete a word back from mouse/cursor position. Default: Ctrl-Backspace * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &deleteWordBack(); /** * Delete a word forward from mouse/cursor position. Default: Ctrl-Delete * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &deleteWordForward(); /** * Initiate a 'find' request in the current document. Default: Ctrl-f * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &find(); /** * Find the next instance of a stored 'find' Default: F3 * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &findNext(); /** * Find a previous instance of a stored 'find'. Default: Shift-F3 * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &findPrev(); /** * Find and replace matches. Default: Ctrl-r * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &replace(); /** * Zoom in. Default: Ctrl-Plus * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &zoomIn(); /** * Zoom out. Default: Ctrl-Minus * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &zoomOut(); /** * Go to home page. Default: Alt-Home * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &home(); /** * Go to beginning of the document. Default: Ctrl-Home * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &begin(); /** * Go to end of the document. Default: Ctrl-End * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &end(); /** * Go to beginning of current line. Default: Home * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &beginningOfLine(); /** * Go to end of current line. Default: End * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &endOfLine(); /** * Scroll up one page. Default: Prior * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &prior(); /** * Scroll down one page. Default: Next * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &next(); /** * Go to line. Default: Ctrl+G * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &gotoLine(); /** * Add current page to bookmarks. Default: Ctrl+B * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &addBookmark(); /** * Next Tab. Default: Ctrl-< * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &tabNext(); /** * Previous Tab. Default: Ctrl-> * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &tabPrev(); /** * Full Screen Mode. Default: Ctrl+Shift+F * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &fullScreen(); /** * Help the user in the current situation. Default: F1 * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &help(); /** * Complete text in input widgets. Default Ctrl+E * @return the shortcut of the standard accelerator **/ KCONFIGGUI_EXPORT const QList &completion(); /** * Iterate through a list when completion returns * multiple items. Default: Ctrl+Up * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &prevCompletion(); /** * Iterate through a list when completion returns * multiple items. Default: Ctrl+Down * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &nextCompletion(); /** * Find a string within another string or list of strings. * Default: Ctrl-T * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &substringCompletion(); /** * Help users iterate through a list of entries. Default: Up * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &rotateUp(); /** * Help users iterate through a list of entries. Default: Down * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &rotateDown(); /** * What's This button. Default: Shift+F1 * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &whatsThis(); /** * Reload. Default: F5 * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &reload(); /** * Up. Default: Alt+Up * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &up(); /** * Back. Default: Alt+Left * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &back(); /** * Forward. Default: ALT+Right * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &forward(); /** * BackwardWord. Default: Ctrl+Left * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &backwardWord(); /** * ForwardWord. Default: Ctrl+Right * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &forwardWord(); /** * Show Menu Bar. Default: Ctrl-M * @return the shortcut of the standard accelerator */ KCONFIGGUI_EXPORT const QList &showMenubar(); /** * Permanently delete files or folders. Default: Shift+Delete * @return the shortcut of the standard accelerator * @since 5.25 */ KCONFIGGUI_EXPORT const QList &deleteFile(); /** * Rename files or folders. Default: F2 * @return the shortcut of the standard accelerator * @since 5.25 */ KCONFIGGUI_EXPORT const QList &renameFile(); /** * Moves files or folders to the trash. Default: Delete * @return the shortcut of the standard accelerator * @since 5.25 */ KCONFIGGUI_EXPORT const QList &moveToTrash(); /** * Opens the app's settings window. Default: Ctrl+Shift+Comma * @return the shortcut of the standard accelerator * @since 5.64 */ KCONFIGGUI_EXPORT const QList &preferences(); /** * Shows or hides hidden files. Defaults: Ctrl+H, Alt+. * @return the shortcut of the standard accelerator * @since 5.70 */ KCONFIGGUI_EXPORT const QList &showHideHiddenFiles(); } #endif // KSTANDARDSHORTCUT_H