From 7db2a1166dca04736b8aedad6aca7e83fe3bbb4d Mon Sep 17 00:00:00 2001 From: marvin Date: Tue, 26 Nov 2024 04:41:13 +0800 Subject: [PATCH] feat: Add some shortcuts (#676) * refact: modify the default shortcut storage structure * feat: add some shortcut --- src/settings/include/shortcuts.h | 32 +- src/settings/src/shortcuts.cpp | 862 ++++++++++++++++++++----------- src/ui/src/mainwindow.cpp | 10 + src/ui/src/optionsdialog.cpp | 14 +- 4 files changed, 616 insertions(+), 302 deletions(-) diff --git a/src/settings/include/shortcuts.h b/src/settings/include/shortcuts.h index 8c0f04e3..1142f0a5 100644 --- a/src/settings/include/shortcuts.h +++ b/src/settings/include/shortcuts.h @@ -31,8 +31,10 @@ class QShortcut; struct ShortcutAction { static constexpr auto CrawlerChangeVisibilityForward = "crawler.change_visibility_type"; - static constexpr auto CrawlerChangeVisibilityBackward = "crawler.change_visibility_type_backward"; - static constexpr auto CrawlerChangeVisibilityToMarksAndMatches = "crawler.change_visibility_to_marks_and_matches"; + static constexpr auto CrawlerChangeVisibilityBackward + = "crawler.change_visibility_type_backward"; + static constexpr auto CrawlerChangeVisibilityToMarksAndMatches + = "crawler.change_visibility_to_marks_and_matches"; static constexpr auto CrawlerChangeVisibilityToMarks = "crawler.change_visibility_to_marks"; static constexpr auto CrawlerChangeVisibilityToMatches = "crawler.change_visibility_to_matches"; static constexpr auto CrawlerIncreseTopViewSize = "crawler.increase_top_view_size"; @@ -52,6 +54,10 @@ struct ShortcutAction { static constexpr auto MainWindowCloseFile = "mainwindow.close_file"; static constexpr auto MainWindowCloseAll = "mainwindow.close_all"; static constexpr auto MainWindowQuit = "mainwindow.quit"; + static constexpr auto MainWindowFullScreen = "mainwindow.fullscreen"; + static constexpr auto MainWindowMax = "mainwindow.max_window"; + static constexpr auto MainWindowMin = "mainwindow.min_window"; + static constexpr auto MainWindowPreference = "mainwindow.preference"; static constexpr auto MainWindowCopy = "mainwindow.copy_selection"; static constexpr auto MainWindowSelectAll = "mainwindow.select_all"; static constexpr auto MainWindowOpenQf = "mainwindow.open_qf"; @@ -110,21 +116,28 @@ struct ShortcutAction { static constexpr auto LogViewAddNextColorLabel = "logview.add_next_color_label"; static constexpr auto LogViewSendSelectionToScratchpad = "logview.send_selection_to_scratchpad"; - static constexpr auto LogViewReplaceScratchpadWithSelection = "logview.replace_scratchpad_with_selection"; + static constexpr auto LogViewReplaceScratchpadWithSelection + = "logview.replace_scratchpad_with_selection"; static constexpr auto LogViewAddToSearch = "logview.add_to_search"; static constexpr auto LogViewExcludeFromSearch = "logview.exclude_from_search"; static constexpr auto LogViewReplaceSearch = "logview.replace_search"; static constexpr auto LogViewSelectLinesUp = "logview.select_lines_up"; static constexpr auto LogViewSelectLinesDown = "logview.select_lines_down"; - - static const std::map& defaultShortcuts(); - static QStringList defaultShortcuts( const std::string& action ); +private: + struct ShortcutDesc { + QString name; + QStringList keySequence; + }; - static QString actionName( const std::string& action ); +public: + using Shortcut = ShortcutDesc; + using ShortcutList = std::map; // + using ConfiguredShortcuts = std::map; // + + static const ShortcutList& defaultShortcutList(); - using ConfiguredShortcuts = std::map; static void registerShortcut( const ConfiguredShortcuts& configuredShortcuts, std::map& shortcutsStorage, QWidget* shortcutsParent, Qt::ShortcutContext context, @@ -137,6 +150,9 @@ struct ShortcutAction { static QList shortcutKeys( const std::string& action, const ConfiguredShortcuts& configuredShortcuts ); + +private: + static QStringList defaultShortcutKeys( const std::string& action ); }; #endif diff --git a/src/settings/src/shortcuts.cpp b/src/settings/src/shortcuts.cpp index 9c5ca8ad..8241c651 100644 --- a/src/settings/src/shortcuts.cpp +++ b/src/settings/src/shortcuts.cpp @@ -25,298 +25,21 @@ #include "shortcuts.h" -const std::map& ShortcutAction::defaultShortcuts() +QStringList getKeyBindings( QKeySequence::StandardKey standardKey ) { - static const std::map defaultShortcuts = []() { - std::map shortcuts; + auto bindings = QKeySequence::keyBindings( standardKey ); + QStringList stringBindings; + std::transform( bindings.cbegin(), bindings.cend(), std::back_inserter( stringBindings ), + []( const auto& keySequence ) { return keySequence.toString(); } ); - auto getKeyBindings = []( QKeySequence::StandardKey standardKey ) { - auto bindings = QKeySequence::keyBindings( standardKey ); - QStringList stringBindings; - std::transform( bindings.cbegin(), bindings.cend(), - std::back_inserter( stringBindings ), - []( const auto& keySequence ) { return keySequence.toString(); } ); - - return stringBindings; - }; - - shortcuts.emplace( MainWindowNewWindow, QStringList() ); - shortcuts.emplace( MainWindowOpenFile, getKeyBindings( QKeySequence::Open ) ); - shortcuts.emplace( MainWindowCloseFile, getKeyBindings( QKeySequence::Close ) ); - shortcuts.emplace( MainWindowCloseAll, QStringList() ); - shortcuts.emplace( MainWindowQuit, QStringList() << "Ctrl+Q" ); - shortcuts.emplace( MainWindowCopy, getKeyBindings( QKeySequence::Copy ) ); - shortcuts.emplace( MainWindowSelectAll, QStringList() << "Ctrl+A" ); - shortcuts.emplace( MainWindowFocusSearchInput, QStringList() << "Ctrl+S" - << "Ctrl+Shift+F" ); - shortcuts.emplace( MainWindowOpenQf, getKeyBindings( QKeySequence::Find ) ); - shortcuts.emplace( MainWindowOpenQfForward, - QStringList() << QKeySequence( Qt::Key_Apostrophe ).toString() ); - shortcuts.emplace( MainWindowOpenQfBackward, - QStringList() << QKeySequence( Qt::Key_QuoteDbl ).toString() ); - - shortcuts.emplace( MainWindowClearFile, getKeyBindings( QKeySequence::Cut ) ); - shortcuts.emplace( MainWindowOpenContainingFolder, QStringList() ); - shortcuts.emplace( MainWindowOpenInEditor, QStringList() ); - shortcuts.emplace( MainWindowCopyPathToClipboard, QStringList() ); - shortcuts.emplace( MainWindowOpenFromClipboard, getKeyBindings( QKeySequence::Paste ) ); - shortcuts.emplace( MainWindowOpenFromUrl, QStringList() ); - shortcuts.emplace( MainWindowFollowFile, QStringList() - << QKeySequence( Qt::Key_F ).toString() - << QKeySequence( Qt::Key_F10 ).toString() ); - shortcuts.emplace( MainWindowTextWrap, QStringList() - << QKeySequence( Qt::Key_W ).toString() ); - shortcuts.emplace( MainWindowReload, getKeyBindings( QKeySequence::Refresh ) ); - shortcuts.emplace( MainWindowStop, getKeyBindings( QKeySequence::Cancel ) ); - shortcuts.emplace( MainWindowScratchpad, QStringList() ); - shortcuts.emplace( MainWindowSelectOpenFile, QStringList() << "Ctrl+Shift+O" ); - - shortcuts.emplace( CrawlerChangeVisibilityForward, QStringList() - << QKeySequence( Qt::Key_V ).toString() ); - shortcuts.emplace( CrawlerChangeVisibilityBackward, QStringList() - << "Shift+V" ); - shortcuts.emplace( CrawlerChangeVisibilityToMarksAndMatches, - QStringList() << QKeySequence( Qt::Key_1 ).toString() ); - shortcuts.emplace( CrawlerChangeVisibilityToMarks, - QStringList() << QKeySequence( Qt::Key_2 ).toString() ); - shortcuts.emplace( CrawlerChangeVisibilityToMatches, - QStringList() << QKeySequence( Qt::Key_3 ).toString() ); - shortcuts.emplace( CrawlerIncreseTopViewSize, - QStringList() << QKeySequence( Qt::Key_Plus ).toString() ); - shortcuts.emplace( CrawlerDecreaseTopViewSize, - QStringList() << QKeySequence( Qt::Key_Minus ).toString() ); - shortcuts.emplace( CrawlerEnableCaseMatching, - QStringList() << QKeySequence( Qt::Key_4 ).toString() ); - shortcuts.emplace( CrawlerEnableRegex, - QStringList() << QKeySequence( Qt::Key_5 ).toString() ); - shortcuts.emplace( CrawlerEnableInverseMatching, - QStringList() << QKeySequence( Qt::Key_6 ).toString() ); - shortcuts.emplace( CrawlerEnableRegexCombining, - QStringList() << QKeySequence( Qt::Key_7 ).toString() ); - shortcuts.emplace( CrawlerEnableAutoRefresh, - QStringList() << QKeySequence( Qt::Key_8 ).toString() ); - shortcuts.emplace( CrawlerKeepResults, - QStringList() << QKeySequence( Qt::Key_9 ).toString() ); - - // shortcuts.emplace( QfFindNext, getKeyBindings( QKeySequence::FindNext ) ); - // shortcuts.emplace( QfFindPrev, getKeyBindings( QKeySequence::FindPrevious ) ); - - shortcuts.emplace( LogViewMark, QStringList() << QKeySequence( Qt::Key_M ).toString() ); - - shortcuts.emplace( LogViewNextMark, - QStringList() << QKeySequence( Qt::Key_BracketRight ).toString() ); - shortcuts.emplace( LogViewPrevMark, QStringList() - << QKeySequence( Qt::Key_BracketLeft ).toString() ); - shortcuts.emplace( LogViewSelectionUp, QStringList() - << QKeySequence( Qt::Key_Up ).toString() - << QKeySequence( Qt::Key_K ).toString() ); - shortcuts.emplace( LogViewSelectionDown, QStringList() - << QKeySequence( Qt::Key_Down ).toString() - << QKeySequence( Qt::Key_J ).toString() ); - shortcuts.emplace( LogViewScrollUp, QStringList() << "Ctrl+Up" ); - shortcuts.emplace( LogViewScrollDown, QStringList() << "Ctrl+Down" ); - shortcuts.emplace( LogViewScrollLeft, QStringList() - << QKeySequence( Qt::Key_Left ).toString() - << QKeySequence( Qt::Key_H ).toString() ); - shortcuts.emplace( LogViewScrollRight, QStringList() - << QKeySequence( Qt::Key_Right ).toString() - << QKeySequence( Qt::Key_L ).toString() ); - shortcuts.emplace( LogViewJumpToStartOfLine, - QStringList() << QKeySequence( Qt::Key_Home ).toString() - << QKeySequence( Qt::Key_AsciiCircum ).toString() ); - shortcuts.emplace( LogViewJumpToEndOfLine, - QStringList() << QKeySequence( Qt::Key_Dollar ).toString() ); - shortcuts.emplace( LogViewJumpToRightOfScreen, - QStringList() << QKeySequence( Qt::Key_End ).toString() ); - shortcuts.emplace( LogViewJumpToBottom, QStringList() << "Ctrl+End" - << "Shift+G" ); - shortcuts.emplace( LogViewJumpToTop, QStringList() << "Ctrl+Home" ); - shortcuts.emplace( LogViewJumpToLine, QStringList() << "Ctrl+L" ); - shortcuts.emplace( LogViewQfForward, getKeyBindings( QKeySequence::FindNext ) - << QKeySequence( Qt::Key_N ).toString() - << "Ctrl+G" ); - shortcuts.emplace( LogViewQfBackward, getKeyBindings( QKeySequence::FindPrevious ) - << "Shift+N" - << "Ctrl+Shift+G" ); - - shortcuts.emplace( LogViewQfSelectedForward, - QStringList() << QKeySequence( Qt::Key_Asterisk ).toString() - << QKeySequence( Qt::Key_Period ).toString() ); - shortcuts.emplace( LogViewQfSelectedBackward, - QStringList() << QKeySequence( Qt::Key_Slash ).toString() - << QKeySequence( Qt::Key_Comma ).toString() ); - shortcuts.emplace( LogViewExitView, QStringList() - << QKeySequence( Qt::Key_Space ).toString() ); - - shortcuts.emplace( LogViewAddColorLabel1, QStringList() << "Ctrl+Shift+1" ); - shortcuts.emplace( LogViewAddColorLabel2, QStringList() << "Ctrl+Shift+2" ); - shortcuts.emplace( LogViewAddColorLabel3, QStringList() << "Ctrl+Shift+3" ); - shortcuts.emplace( LogViewAddColorLabel4, QStringList() << "Ctrl+Shift+4" ); - shortcuts.emplace( LogViewAddColorLabel5, QStringList() << "Ctrl+Shift+5" ); - shortcuts.emplace( LogViewAddColorLabel6, QStringList() << "Ctrl+Shift+6" ); - shortcuts.emplace( LogViewAddColorLabel7, QStringList() << "Ctrl+Shift+7" ); - shortcuts.emplace( LogViewAddColorLabel8, QStringList() << "Ctrl+Shift+8" ); - shortcuts.emplace( LogViewAddColorLabel9, QStringList() << "Ctrl+Shift+9" ); - shortcuts.emplace( LogViewClearColorLabels, QStringList() << "Ctrl+Shift+0" ); - shortcuts.emplace( LogViewAddNextColorLabel, QStringList() << "Ctrl+D" ); - - shortcuts.emplace( LogViewSendSelectionToScratchpad, QStringList() << "Ctrl+Z" ); - shortcuts.emplace( LogViewReplaceScratchpadWithSelection, QStringList() << "Ctrl+Shift+Z" ); - - shortcuts.emplace( LogViewAddToSearch, QStringList() << "Shift+A" ); - shortcuts.emplace( LogViewExcludeFromSearch, QStringList() << "Shift+E" ); - shortcuts.emplace( LogViewReplaceSearch, QStringList() << "Shift+R" ); - - shortcuts.emplace( LogViewSelectLinesUp, QStringList() << "Shift+Up" ); - shortcuts.emplace( LogViewSelectLinesDown, QStringList() << "Shift+Down" ); - - return shortcuts; - }(); - - return defaultShortcuts; + return stringBindings; } -QStringList ShortcutAction::defaultShortcuts( const std::string& action ) +QStringList ShortcutAction::defaultShortcutKeys( const std::string& action ) { - const auto& shortcuts = defaultShortcuts(); + const auto& shortcuts = defaultShortcutList(); const auto actionShortcuts = shortcuts.find( action ); - if ( actionShortcuts == shortcuts.end() ) { - return {}; - } - - return actionShortcuts->second; -} - -QString ShortcutAction::actionName( const std::string& action ) -{ - static const std::map actionNames = []() { - std::map shortcuts; - - shortcuts.emplace( MainWindowNewWindow, QApplication::tr( "Open new window" ) ); - shortcuts.emplace( MainWindowOpenFile, QApplication::tr( "Open file" ) ); - shortcuts.emplace( MainWindowCloseFile, QApplication::tr( "Close file" ) ); - shortcuts.emplace( MainWindowCloseAll, QApplication::tr( "Close all files" ) ); - shortcuts.emplace( MainWindowSelectAll, QApplication::tr( "Select all" ) ); - shortcuts.emplace( MainWindowCopy, QApplication::tr( "Copy selection to clipboard" ) ); - shortcuts.emplace( MainWindowQuit, QApplication::tr( "Exit application" ) ); - shortcuts.emplace( MainWindowOpenQf, QApplication::tr( "Open quick find" ) ); - shortcuts.emplace( MainWindowOpenQfForward, QApplication::tr( "Quick find forward" ) ); - shortcuts.emplace( MainWindowOpenQfBackward, QApplication::tr( "Quick find backward" ) ); - shortcuts.emplace( MainWindowFocusSearchInput, - QApplication::tr( "Set focus to search input" ) ); - shortcuts.emplace( MainWindowClearFile, QApplication::tr( "Clear file" ) ); - shortcuts.emplace( MainWindowOpenContainingFolder, - QApplication::tr( "Open containing folder" ) ); - shortcuts.emplace( MainWindowOpenInEditor, QApplication::tr( "Open file in editor" ) ); - shortcuts.emplace( MainWindowCopyPathToClipboard, - QApplication::tr( "Copy file path to clipboard" ) ); - shortcuts.emplace( MainWindowOpenFromClipboard, - QApplication::tr( "Paste text from clipboard" ) ); - shortcuts.emplace( MainWindowOpenFromUrl, QApplication::tr( "Open file from URL" ) ); - shortcuts.emplace( MainWindowFollowFile, QApplication::tr( "Monitor file changes" ) ); - shortcuts.emplace( MainWindowTextWrap, QApplication::tr( "Toggle text wrap" ) ); - shortcuts.emplace( MainWindowReload, QApplication::tr( "Reload file" ) ); - shortcuts.emplace( MainWindowStop, QApplication::tr( "Stop file loading" ) ); - shortcuts.emplace( MainWindowScratchpad, QApplication::tr( "Open scratchpad" ) ); - shortcuts.emplace( MainWindowSelectOpenFile, QApplication::tr( "Switch to file" ) ); - - shortcuts.emplace( CrawlerChangeVisibilityForward, - QApplication::tr( "Change filtered lines visibility forward" ) ); - shortcuts.emplace( CrawlerChangeVisibilityBackward, - QApplication::tr( "Change filtered lines visibility backward" ) ); - shortcuts.emplace( CrawlerChangeVisibilityToMarksAndMatches, - QApplication::tr( "Change filtered lines visibility to marks and matches" ) ); - shortcuts.emplace( CrawlerChangeVisibilityToMarks, - QApplication::tr( "Change filtered lines visibility to marks" ) ); - shortcuts.emplace( CrawlerChangeVisibilityToMatches, - QApplication::tr( "Change filtered lines visibility to matches" ) ); - shortcuts.emplace( CrawlerIncreseTopViewSize, QApplication::tr( "Increase main view" ) ); - shortcuts.emplace( CrawlerDecreaseTopViewSize, QApplication::tr( "Decrease main view" ) ); - shortcuts.emplace( CrawlerEnableCaseMatching, QApplication::tr( "Enable case matching" ) ); - shortcuts.emplace( CrawlerEnableRegex, QApplication::tr( "Enable regex" ) ); - shortcuts.emplace( CrawlerEnableInverseMatching, QApplication::tr( "Enable inverse matching" ) ); - shortcuts.emplace( CrawlerEnableRegexCombining, QApplication::tr( "Enable regex combining" ) ); - shortcuts.emplace( CrawlerEnableAutoRefresh, QApplication::tr( "Enable auto refresh" ) ); - shortcuts.emplace( CrawlerKeepResults, QApplication::tr( "Keep search results" ) ); - - shortcuts.emplace( QfFindNext, QApplication::tr( "QuickFind: Find next" ) ); - shortcuts.emplace( QfFindPrev, QApplication::tr( "QuickFind: Find previous" ) ); - - shortcuts.emplace( LogViewMark, QApplication::tr( "Add line mark" ) ); - - shortcuts.emplace( LogViewNextMark, QApplication::tr( "Jump to next mark" ) ); - shortcuts.emplace( LogViewPrevMark, QApplication::tr( "Jump to previous mark" ) ); - shortcuts.emplace( LogViewSelectionUp, QApplication::tr( "Move selection up" ) ); - shortcuts.emplace( LogViewSelectionDown, QApplication::tr( "Move selection down" ) ); - shortcuts.emplace( LogViewScrollUp, QApplication::tr( "Scroll up" ) ); - shortcuts.emplace( LogViewScrollDown, QApplication::tr( "Scroll down" ) ); - shortcuts.emplace( LogViewScrollLeft, QApplication::tr( "Scroll left" ) ); - shortcuts.emplace( LogViewScrollRight, QApplication::tr( "Scroll right" ) ); - shortcuts.emplace( LogViewJumpToStartOfLine, - QApplication::tr( "Jump to the beginning of the current line" ) ); - shortcuts.emplace( LogViewJumpToEndOfLine, - QApplication::tr( "Jump to the end start of the current line" ) ); - shortcuts.emplace( LogViewJumpToRightOfScreen, - QApplication::tr( "Jump to the right of the text" ) ); - shortcuts.emplace( LogViewJumpToBottom, - QApplication::tr( "Jump to the bottom of the text" ) ); - shortcuts.emplace( LogViewJumpToTop, QApplication::tr( "Jump to the top of the text" ) ); - shortcuts.emplace( LogViewJumpToLine, QApplication::tr( "Jump to line" ) ); - shortcuts.emplace( LogViewQfForward, QApplication::tr( "Main view: find next" ) ); - shortcuts.emplace( LogViewQfBackward, QApplication::tr( "Main view: find previous" ) ); - - shortcuts.emplace( LogViewQfSelectedForward, - QApplication::tr( "Set selection to QuickFind and find next" ) ); - shortcuts.emplace( LogViewQfSelectedBackward, - QApplication::tr( "Set selection to QuickFind and find previous" ) ); - - shortcuts.emplace( LogViewExitView, QApplication::tr( "Release focus from view" ) ); - - shortcuts.emplace( LogViewAddColorLabel1, - QApplication::tr( "Highlight text with color 1" ) ); - shortcuts.emplace( LogViewAddColorLabel2, - QApplication::tr( "Highlight text with color 2" ) ); - shortcuts.emplace( LogViewAddColorLabel3, - QApplication::tr( "Highlight text with color 3" ) ); - shortcuts.emplace( LogViewAddColorLabel4, - QApplication::tr( "Highlight text with color 4" ) ); - shortcuts.emplace( LogViewAddColorLabel5, - QApplication::tr( "Highlight text with color 5" ) ); - shortcuts.emplace( LogViewAddColorLabel6, - QApplication::tr( "Highlight text with color 6" ) ); - shortcuts.emplace( LogViewAddColorLabel7, - QApplication::tr( "Highlight text with color 7" ) ); - shortcuts.emplace( LogViewAddColorLabel8, - QApplication::tr( "Highlight text with color 8" ) ); - shortcuts.emplace( LogViewAddColorLabel9, - QApplication::tr( "Highlight text with color 9" ) ); - - shortcuts.emplace( LogViewAddNextColorLabel, - QApplication::tr( "Highlight text with next color" ) ); - - shortcuts.emplace( LogViewClearColorLabels, QApplication::tr( "Clear all color labels" ) ); - - shortcuts.emplace( LogViewSendSelectionToScratchpad, - QApplication::tr( "Send selection to scratchpad" ) ); - shortcuts.emplace( LogViewReplaceScratchpadWithSelection, - QApplication::tr( "Replace scratchpad with selection" ) ); - - shortcuts.emplace( LogViewAddToSearch, - QApplication::tr( "Add selection to search pattern" ) ); - shortcuts.emplace( LogViewExcludeFromSearch, - QApplication::tr( "Exclude selection from search pattern " ) ); - shortcuts.emplace( LogViewReplaceSearch, - QApplication::tr( "Replace search pattern with selection" ) ); - - shortcuts.emplace( LogViewSelectLinesUp, QApplication::tr( "Select lines down" ) ); - shortcuts.emplace( LogViewSelectLinesDown, QApplication::tr( "Select lines up" ) ); - - return shortcuts; - }(); - - const auto name = actionNames.find( action ); - - return name != actionNames.end() ? name->second : QString::fromStdString( action ); + return actionShortcuts != shortcuts.end() ? actionShortcuts->second.keySequence : QStringList{}; } void ShortcutAction::registerShortcut( const ConfiguredShortcuts& configuredShortcuts, @@ -328,7 +51,7 @@ void ShortcutAction::registerShortcut( const ConfiguredShortcuts& configuredShor const auto keysConfiguration = configuredShortcuts.find( action ); const auto keys = keysConfiguration != configuredShortcuts.end() ? keysConfiguration->second - : ShortcutAction::defaultShortcuts( action ); + : ShortcutAction::defaultShortcutKeys( action ); for ( const auto& key : keys ) { if ( key.isEmpty() ) { @@ -362,7 +85,7 @@ QList ShortcutAction::shortcutKeys( const std::string& action, const auto keysConfiguration = configuredShortcuts.find( action ); const auto keys = keysConfiguration != configuredShortcuts.end() ? keysConfiguration->second - : ShortcutAction::defaultShortcuts( action ); + : ShortcutAction::defaultShortcutKeys( action ); QList shortcuts; std::transform( keys.cbegin(), keys.cend(), std::back_inserter( shortcuts ), @@ -370,3 +93,566 @@ QList ShortcutAction::shortcutKeys( const std::string& action, return shortcuts; } + +const ShortcutAction::ShortcutList& ShortcutAction::defaultShortcutList() +{ + static ShortcutList defaultShortcutKeys = { + { + MainWindowNewWindow, + { + QApplication::tr( "Open new window" ), + QStringList{}, + }, + }, + { + MainWindowOpenFile, + { + QApplication::tr( "Open file" ), + getKeyBindings( QKeySequence::Open ), + }, + }, + { + MainWindowCloseFile, + { + QApplication::tr( "Close file" ), + getKeyBindings( QKeySequence::Close ), + }, + }, + { + MainWindowCloseAll, + { + QApplication::tr( "Close all files" ), + QStringList{}, + }, + }, + { + MainWindowSelectAll, + { + QApplication::tr( "Select all" ), + QStringList{ "Ctrl+A" }, + }, + }, + { + MainWindowCopy, + { + QApplication::tr( "Copy selection to clipboard" ), + getKeyBindings( QKeySequence::Copy ), + }, + }, + { + MainWindowQuit, + { + QApplication::tr( "Exit application" ), + QStringList{ "Ctrl+Q" }, + }, + }, + { + MainWindowFullScreen, + { + QApplication::tr( "Full Screen" ), + QStringList{}, + }, + }, + { + MainWindowMax, + { + QApplication::tr( "Maximize window" ), + QStringList{}, + }, + }, + { + MainWindowMin, + { + QApplication::tr( "Minimize Window" ), + QStringList{}, + }, + }, + { + MainWindowPreference, + { + QApplication::tr( "Preferences" ), + QStringList{}, + }, + }, + { + MainWindowOpenQf, + { + QApplication::tr( "Open quick find" ), + getKeyBindings( QKeySequence::Find ), + }, + }, + { + MainWindowOpenQfForward, + { + QApplication::tr( "Quick find forward" ), + QStringList{ QKeySequence( Qt::Key_Apostrophe ).toString() }, + }, + }, + { + MainWindowOpenQfBackward, + { + QApplication::tr( "Quick find backward" ), + QStringList{ QKeySequence( Qt::Key_QuoteDbl ).toString() }, + }, + }, + { + MainWindowFocusSearchInput, + { + QApplication::tr( "Set focus to search input" ), + QStringList{ { "Ctrl+S", "Ctrl+Shift+F" } }, + }, + }, + { + MainWindowClearFile, + { + QApplication::tr( "Clear file" ), + QStringList{ getKeyBindings( QKeySequence::Cut ) }, + }, + }, + { + MainWindowOpenContainingFolder, + { + QApplication::tr( "Open containing folder" ), + QStringList{}, + }, + }, + { + MainWindowOpenInEditor, + { + QApplication::tr( "Open file in editor" ), + QStringList{}, + }, + }, + { + MainWindowCopyPathToClipboard, + { + QApplication::tr( "Copy file path to clipboard" ), + QStringList{}, + }, + }, + { + MainWindowOpenFromClipboard, + { + QApplication::tr( "Paste text from clipboard" ), + getKeyBindings( QKeySequence::Paste ), + }, + }, + { + MainWindowOpenFromUrl, + { + QApplication::tr( "Open file from URL" ), + QStringList{}, + }, + }, + { + MainWindowFollowFile, + { + QApplication::tr( "Monitor file changes" ), + { { QKeySequence( Qt::Key_F ).toString(), + QKeySequence( Qt::Key_F10 ).toString() } }, + }, + }, + { + MainWindowTextWrap, + { + QApplication::tr( "Toggle text wrap" ), + QStringList{ QKeySequence( Qt::Key_W ).toString() }, + }, + }, + { + MainWindowReload, + { + QApplication::tr( "Reload file" ), + QStringList{ getKeyBindings( QKeySequence::Refresh ) }, + }, + }, + { + MainWindowStop, + { + QApplication::tr( "Stop file loading" ), + QStringList{ getKeyBindings( QKeySequence::Cancel ) }, + }, + }, + { + MainWindowScratchpad, + { + QApplication::tr( "Open scratchpad" ), + QStringList{}, + }, + }, + { + MainWindowSelectOpenFile, + { + QApplication::tr( "Switch to file" ), + QStringList{ "Ctrl+Shift+O" }, + }, + }, + { + CrawlerChangeVisibilityForward, + { + QApplication::tr( "Change filtered lines visibility forward" ), + QStringList{ QKeySequence( Qt::Key_V ).toString() }, + }, + }, + { + CrawlerChangeVisibilityBackward, + { + QApplication::tr( "Change filtered lines visibility backward" ), + QStringList{ "Shift+V" }, + }, + }, + { + CrawlerChangeVisibilityToMarksAndMatches, + { + QApplication::tr( "Change filtered lines visibility to marks and matches" ), + QStringList{ QKeySequence( Qt::Key_1 ).toString() }, + }, + }, + { + CrawlerChangeVisibilityToMarks, + { + QApplication::tr( "Change filtered lines visibility to marks" ), + QStringList{ QKeySequence( Qt::Key_2 ).toString() }, + }, + }, + { + CrawlerChangeVisibilityToMatches, + { + QApplication::tr( "Change filtered lines visibility to matches" ), + QStringList{ QKeySequence( Qt::Key_3 ).toString() }, + }, + }, + { + CrawlerIncreseTopViewSize, + { + QApplication::tr( "Increase main view" ), + QStringList{ QKeySequence( Qt::Key_Plus ).toString() }, + }, + }, + { + CrawlerDecreaseTopViewSize, + { + QApplication::tr( "Decrease main view" ), + QStringList{ QKeySequence( Qt::Key_Minus ).toString() }, + }, + }, + { + CrawlerEnableCaseMatching, + { + QApplication::tr( "Enable case matching" ), + QStringList{ QKeySequence( Qt::Key_4 ).toString() }, + }, + }, + { + CrawlerEnableRegex, + { + QApplication::tr( "Enable regex" ), + QStringList{ QKeySequence( Qt::Key_5 ).toString() }, + }, + }, + { + CrawlerEnableInverseMatching, + { + QApplication::tr( "Enable inverse matching" ), + QStringList{ QKeySequence( Qt::Key_6 ).toString() }, + }, + }, + { + CrawlerEnableRegexCombining, + { + QApplication::tr( "Enable regex combining" ), + QStringList{ QKeySequence( Qt::Key_7 ).toString() }, + }, + }, + { + CrawlerEnableAutoRefresh, + { + QApplication::tr( "Enable auto refresh" ), + QStringList{ QKeySequence( Qt::Key_8 ).toString() }, + }, + }, + { + CrawlerKeepResults, + { + QApplication::tr( "Keep search results" ), + QStringList{ QKeySequence( Qt::Key_9 ).toString() }, + }, + }, + // remove by commit 0b75b9d6 + // { QfFindNext, { QApplication::tr( "QuickFind: Find next" ), QStringList{ getKeyBindings( + // QKeySequence::FindNext ) } } }, { QfFindPrev, { QApplication::tr( "QuickFind: Find + // previous" + // ), QStringList{ getKeyBindings( QKeySequence::FindPrevious ) } } }, + { + LogViewMark, + { + QApplication::tr( "Add line mark" ), + QStringList{ QKeySequence( Qt::Key_M ).toString() }, + }, + }, + { + LogViewNextMark, + { + QApplication::tr( "Jump to next mark" ), + QStringList{ QKeySequence( Qt::Key_BracketRight ).toString() }, + }, + }, + { + LogViewPrevMark, + { + QApplication::tr( "Jump to previous mark" ), + QStringList{ QKeySequence( Qt::Key_BracketLeft ).toString() }, + }, + }, + { + LogViewSelectionUp, + { + QApplication::tr( "Move selection up" ), + { { QKeySequence( Qt::Key_Up ).toString(), QKeySequence( Qt::Key_K ).toString() } }, + }, + }, + { + LogViewSelectionDown, + { + QApplication::tr( "Move selection down" ), + { { QKeySequence( Qt::Key_Down ).toString(), + QKeySequence( Qt::Key_J ).toString() } }, + }, + }, + { + LogViewScrollUp, + { + QApplication::tr( "Scroll up" ), + QStringList{ "Ctrl+Up" }, + }, + }, + { + LogViewScrollDown, + { + QApplication::tr( "Scroll down" ), + QStringList{ "Ctrl+Down" }, + }, + }, + { + LogViewScrollLeft, + { + QApplication::tr( "Scroll left" ), + { { QKeySequence( Qt::Key_Left ).toString(), + QKeySequence( Qt::Key_H ).toString() } }, + }, + }, + { + LogViewScrollRight, + { + QApplication::tr( "Scroll right" ), + { { QKeySequence( Qt::Key_Right ).toString(), + QKeySequence( Qt::Key_L ).toString() } }, + }, + }, + { + LogViewJumpToStartOfLine, + { + QApplication::tr( "Jump to the beginning of the current line" ), + { QKeySequence( Qt::Key_Home ).toString(), + QKeySequence( Qt::Key_AsciiCircum ).toString() }, + }, + }, + { + LogViewJumpToEndOfLine, + { + QApplication::tr( "Jump to the end start of the current line" ), + QStringList{ QKeySequence( Qt::Key_Dollar ).toString() }, + }, + }, + { + LogViewJumpToRightOfScreen, + { + QApplication::tr( "Jump to the right of the text" ), + QStringList{ QKeySequence( Qt::Key_End ).toString() }, + }, + }, + { + LogViewJumpToBottom, + { + QApplication::tr( "Jump to the bottom of the text" ), + QStringList{ { "Ctrl+End", "Shift+G" } }, + }, + }, + { + LogViewJumpToTop, + { + QApplication::tr( "Jump to the top of the text" ), + QStringList{ "Ctrl+Home" }, + }, + }, + { + LogViewJumpToLine, + { + QApplication::tr( "Jump to line" ), + QStringList{ "Ctrl+L" }, + }, + }, + { + LogViewQfForward, + { + QApplication::tr( "Main view: find next" ), + getKeyBindings( QKeySequence::FindNext ) + << QKeySequence( Qt::Key_N ).toString() << "Ctrl+G", + }, + }, + { + LogViewQfBackward, + { QApplication::tr( "Main view: find previous" ), + getKeyBindings( QKeySequence::FindPrevious ) << "Shift+N" + << "Ctrl+Shift+G" }, + }, + { + LogViewQfSelectedForward, + { QApplication::tr( "Set selection to QuickFind and find next" ), + { QKeySequence( Qt::Key_Asterisk ).toString(), + QKeySequence( Qt::Key_Period ).toString() } }, + }, + { + LogViewQfSelectedBackward, + { + QApplication::tr( "Set selection to QuickFind and find previous" ), + QStringList{ QKeySequence( Qt::Key_Slash ).toString(), + QKeySequence( Qt::Key_Comma ).toString() }, + }, + }, + { + LogViewExitView, + { + QApplication::tr( "Release focus from view" ), + QStringList{ QKeySequence( Qt::Key_Space ).toString() }, + }, + }, + { + LogViewAddColorLabel1, + { + QApplication::tr( "Highlight text with color 1" ), + QStringList{ "Ctrl+Shift+1" }, + }, + }, + { + LogViewAddColorLabel2, + { + QApplication::tr( "Highlight text with color 2" ), + QStringList{ "Ctrl+Shift+2" }, + }, + }, + { + LogViewAddColorLabel3, + { + QApplication::tr( "Highlight text with color 3" ), + QStringList{ "Ctrl+Shift+3" }, + }, + }, + { + LogViewAddColorLabel4, + { + QApplication::tr( "Highlight text with color 4" ), + QStringList{ "Ctrl+Shift+4" }, + }, + }, + { + LogViewAddColorLabel5, + { + QApplication::tr( "Highlight text with color 5" ), + QStringList{ "Ctrl+Shift+5" }, + }, + }, + { + LogViewAddColorLabel6, + { + QApplication::tr( "Highlight text with color 6" ), + QStringList{ "Ctrl+Shift+6" }, + }, + }, + { + LogViewAddColorLabel7, + { + QApplication::tr( "Highlight text with color 7" ), + QStringList{ "Ctrl+Shift+7" }, + }, + }, + { + LogViewAddColorLabel8, + { + QApplication::tr( "Highlight text with color 8" ), + QStringList{ "Ctrl+Shift+8" }, + }, + }, + { + LogViewAddColorLabel9, + { + QApplication::tr( "Highlight text with color 9" ), + QStringList{ "Ctrl+Shift+9" }, + }, + }, + { + LogViewAddNextColorLabel, + { + QApplication::tr( "Highlight text with next color" ), + QStringList{ "Ctrl+D" }, + }, + }, + { + LogViewClearColorLabels, + { + QApplication::tr( "Clear all color labels" ), + QStringList{ "Ctrl+Shift+0" }, + }, + }, + { + LogViewSendSelectionToScratchpad, + { + QApplication::tr( "Send selection to scratchpad" ), + QStringList{ "Ctrl+Z" }, + }, + }, + { + LogViewReplaceScratchpadWithSelection, + { + QApplication::tr( "Replace scratchpad with selection" ), + QStringList{ "Ctrl+Shift+Z" }, + }, + }, + { + LogViewAddToSearch, + { + QApplication::tr( "Add selection to search pattern" ), + QStringList{ "Shift+A" }, + }, + }, + { + LogViewExcludeFromSearch, + { + QApplication::tr( "Exclude selection from search pattern " ), + QStringList{ "Shift+E" }, + }, + }, + { + LogViewReplaceSearch, + { + QApplication::tr( "Replace search pattern with selection" ), + QStringList{ "Shift+R" }, + }, + }, + { + LogViewSelectLinesUp, + { + QApplication::tr( "Select lines down" ), + QStringList{ "Shift+Up" }, + }, + }, + { + LogViewSelectLinesDown, + { + QApplication::tr( "Select lines up" ), + QStringList{ "Shift+Down" }, + }, + }, + }; + return defaultShortcutKeys; +} diff --git a/src/ui/src/mainwindow.cpp b/src/ui/src/mainwindow.cpp index 7797d653..92d0786c 100644 --- a/src/ui/src/mainwindow.cpp +++ b/src/ui/src/mainwindow.cpp @@ -689,6 +689,15 @@ void MainWindow::updateShortcuts() crawler->focusSearchEdit(); } } ); + ShortcutAction::registerShortcut( shortcuts, shortcuts_, this, Qt::WindowShortcut, + ShortcutAction::MainWindowFullScreen, + [ this ] { this->showFullScreen(); } ); + ShortcutAction::registerShortcut( shortcuts, shortcuts_, this, Qt::WindowShortcut, + ShortcutAction::MainWindowMax, + [ this ] { this->showMaximized(); } ); + ShortcutAction::registerShortcut( shortcuts, shortcuts_, this, Qt::WindowShortcut, + ShortcutAction::MainWindowMin, + [ this ] { this->showMinimized(); } ); auto setShortcuts = [ &shortcuts ]( auto* action, const auto& actionName ) { action->setShortcuts( ShortcutAction::shortcutKeys( actionName, shortcuts ) ); @@ -715,6 +724,7 @@ void MainWindow::updateShortcuts() setShortcuts( showScratchPadAction, ShortcutAction::MainWindowScratchpad ); setShortcuts( selectOpenFileAction, ShortcutAction::MainWindowSelectOpenFile ); setShortcuts( goToLineAction, ShortcutAction::LogViewJumpToLine ); + setShortcuts( optionsAction, ShortcutAction::MainWindowPreference ); } void MainWindow::loadIcons() diff --git a/src/ui/src/optionsdialog.cpp b/src/ui/src/optionsdialog.cpp index 3625d1e9..7f441451 100644 --- a/src/ui/src/optionsdialog.cpp +++ b/src/ui/src/optionsdialog.cpp @@ -669,29 +669,31 @@ void OptionsDialog::buildShortcutsTable( bool useDefaultsOnly ) shortcutsTable->setRowCount( 0 ); const auto& config = Configuration::get(); - auto shortcuts = ShortcutAction::defaultShortcuts(); + auto shortcutList = ShortcutAction::defaultShortcutList(); if ( !useDefaultsOnly ) { for ( const auto& [ action, keys ] : config.shortcuts() ) { - shortcuts[ action ] = keys; + shortcutList[ action ].keySequence = keys; } } - for ( const auto& [ action, keys ] : shortcuts ) { + for ( const auto& [ action, shortCut ] : shortcutList ) { auto currentRow = shortcutsTable->rowCount(); shortcutsTable->insertRow( currentRow ); - auto keyItem = new QTableWidgetItem( ShortcutAction::actionName( action ) ); + auto keyItem = new QTableWidgetItem( shortCut.name ); keyItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); keyItem->setData( Qt::UserRole, QString::fromStdString( action ) ); shortcutsTable->setItem( currentRow, 0, keyItem ); - auto primaryKeySequence = new KeySequencePresenter( keys.size() > 0 ? keys[ 0 ] : "" ); + auto primaryKeySequence = new KeySequencePresenter( + shortCut.keySequence.size() > 0 ? shortCut.keySequence[ 0 ] : "" ); shortcutsTable->setItem( currentRow, 1, new QTableWidgetItem ); shortcutsTable->setCellWidget( currentRow, 1, primaryKeySequence ); connect( primaryKeySequence, &KeySequencePresenter::edited, this, &OptionsDialog::checkShortcutsOnDuplicate ); - auto secondaryKeySequence = new KeySequencePresenter( keys.size() > 1 ? keys[ 1 ] : "" ); + auto secondaryKeySequence = new KeySequencePresenter( + shortCut.keySequence.size() > 1 ? shortCut.keySequence[ 1 ] : "" ); shortcutsTable->setItem( currentRow, 2, new QTableWidgetItem ); shortcutsTable->setCellWidget( currentRow, 2, secondaryKeySequence ); connect( secondaryKeySequence, &KeySequencePresenter::edited, this,