From 955e2b229609458bd90418d8a986272fec19f2cf Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 18 Nov 2020 11:04:40 +0100 Subject: TextEditor: only track actions which are updated Change-Id: I323e8a9c0a8088d9c6ab338b32a225a228bd7061 Reviewed-by: Christian Stenger --- src/plugins/texteditor/texteditoractionhandler.cpp | 175 ++++++--------------- 1 file changed, 50 insertions(+), 125 deletions(-) diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index 51d06d5090..af6ab459ea 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -127,62 +127,14 @@ public: QAction *m_redoAction = nullptr; QAction *m_copyAction = nullptr; QAction *m_cutAction = nullptr; - QAction *m_pasteAction = nullptr; - QAction *m_circularPasteAction = nullptr; - QAction *m_switchUtf8bomAction = nullptr; - QAction *m_selectAllAction = nullptr; - QAction *m_gotoAction = nullptr; - QAction *m_printAction = nullptr; QAction *m_autoIndentAction = nullptr; QAction *m_autoFormatAction = nullptr; - QAction *m_rewrapParagraphAction = nullptr; QAction *m_visualizeWhitespaceAction = nullptr; - QAction *m_cleanWhitespaceAction = nullptr; QAction *m_textWrappingAction = nullptr; QAction *m_unCommentSelectionAction = nullptr; QAction *m_unfoldAllAction = nullptr; - QAction *m_foldAction = nullptr; - QAction *m_unfoldAction = nullptr; - QAction *m_cutLineAction = nullptr; - QAction *m_copyLineAction = nullptr; - QAction *m_duplicateSelectionAction = nullptr; - QAction *m_duplicateSelectionAndCommentAction = nullptr; - QAction *m_deleteLineAction = nullptr; - QAction *m_deleteEndOfLineAction = nullptr; - QAction *m_deleteEndOfWordAction = nullptr; - QAction *m_deleteEndOfWordCamelCaseAction = nullptr; - QAction *m_deleteStartOfLineAction = nullptr; - QAction *m_deleteStartOfWordAction = nullptr; - QAction *m_deleteStartOfWordCamelCaseAction = nullptr; - QAction *m_selectEncodingAction = nullptr; - QAction *m_increaseFontSizeAction = nullptr; - QAction *m_decreaseFontSizeAction = nullptr; - QAction *m_resetFontSizeAction = nullptr; - QAction *m_gotoBlockStartAction = nullptr; - QAction *m_gotoBlockEndAction = nullptr; - QAction *m_gotoBlockStartWithSelectionAction = nullptr; - QAction *m_gotoBlockEndWithSelectionAction = nullptr; - QAction *m_selectBlockUpAction = nullptr; - QAction *m_selectBlockDownAction = nullptr; - QAction *m_viewPageUpAction = nullptr; - QAction *m_viewPageDownAction = nullptr; - QAction *m_viewLineUpAction = nullptr; - QAction *m_viewLineDownAction = nullptr; - QAction *m_moveLineUpAction = nullptr; - QAction *m_moveLineDownAction = nullptr; - QAction *m_copyLineUpAction = nullptr; - QAction *m_copyLineDownAction = nullptr; - QAction *m_joinLinesAction = nullptr; - QAction *m_insertLineAboveAction = nullptr; - QAction *m_insertLineBelowAction = nullptr; - QAction *m_upperCaseSelectionAction = nullptr; - QAction *m_lowerCaseSelectionAction = nullptr; - QAction *m_sortSelectedLinesAction = nullptr; - QAction *m_indentAction = nullptr; - QAction *m_unindentAction = nullptr; QAction *m_followSymbolAction = nullptr; QAction *m_followSymbolInNextSplitAction = nullptr; - QAction *m_findUsageAction = nullptr; QAction *m_renameSymbolAction = nullptr; QAction *m_jumpToFileAction = nullptr; QAction *m_jumpToFileInNextSplitAction = nullptr; @@ -218,66 +170,66 @@ void TextEditorActionHandlerPrivate::createActions() [] (TextEditorWidget *w) { w->copy(); }, true); m_cutAction = registerAction(CUT, [] (TextEditorWidget *w) { w->cut(); }, true); - m_pasteAction = registerAction(PASTE, + m_modifyingActions << registerAction(PASTE, [] (TextEditorWidget *w) { w->paste(); }, true); - m_selectAllAction = registerAction(SELECTALL, + registerAction(SELECTALL, [] (TextEditorWidget *w) { w->selectAll(); }, true); - m_gotoAction = registerAction(GOTO, [] (TextEditorWidget *) { + registerAction(GOTO, [] (TextEditorWidget *) { QString locatorString = TextEditorPlugin::lineNumberFilter()->shortcutString(); locatorString += QLatin1Char(' '); const int selectionStart = locatorString.size(); locatorString += tr(":"); Core::LocatorManager::show(locatorString, selectionStart, locatorString.size() - selectionStart); }); - m_printAction = registerAction(PRINT, + m_modifyingActions << registerAction(PRINT, [] (TextEditorWidget *widget) { widget->print(Core::ICore::printer()); }); - m_deleteLineAction = registerAction(DELETE_LINE, + m_modifyingActions << registerAction(DELETE_LINE, [] (TextEditorWidget *w) { w->deleteLine(); }, true, tr("Delete &Line")); - m_deleteEndOfLineAction = registerAction(DELETE_END_OF_LINE, + m_modifyingActions << registerAction(DELETE_END_OF_LINE, [] (TextEditorWidget *w) { w->deleteEndOfLine(); }, true, tr("Delete Line from Cursor On")); - m_deleteEndOfWordAction = registerAction(DELETE_END_OF_WORD, + m_modifyingActions << registerAction(DELETE_END_OF_WORD, [] (TextEditorWidget *w) { w->deleteEndOfWord(); }, true, tr("Delete Word from Cursor On")); - m_deleteEndOfWordCamelCaseAction = registerAction(DELETE_END_OF_WORD_CAMEL_CASE, + m_modifyingActions << registerAction(DELETE_END_OF_WORD_CAMEL_CASE, [] (TextEditorWidget *w) { w->deleteEndOfWordCamelCase(); }, true, tr("Delete Word Camel Case from Cursor On")); - m_deleteStartOfLineAction = registerAction(DELETE_START_OF_LINE, + m_modifyingActions << registerAction(DELETE_START_OF_LINE, [] (TextEditorWidget *w) { w->deleteStartOfLine(); }, true, tr("Delete Line up to Cursor"), Core::useMacShortcuts ? QKeySequence(tr("Ctrl+Backspace")) : QKeySequence()); - m_deleteStartOfWordAction = registerAction(DELETE_START_OF_WORD, + m_modifyingActions << registerAction(DELETE_START_OF_WORD, [] (TextEditorWidget *w) { w->deleteStartOfWord(); }, true, tr("Delete Word up to Cursor")); - m_deleteStartOfWordCamelCaseAction = registerAction(DELETE_START_OF_WORD_CAMEL_CASE, + m_modifyingActions << registerAction(DELETE_START_OF_WORD_CAMEL_CASE, [] (TextEditorWidget *w) { w->deleteStartOfWordCamelCase(); }, true, tr("Delete Word Camel Case up to Cursor")); - m_gotoBlockStartWithSelectionAction = registerAction(GOTO_BLOCK_START_WITH_SELECTION, + registerAction(GOTO_BLOCK_START_WITH_SELECTION, [] (TextEditorWidget *w) { w->gotoBlockStartWithSelection(); }, true, tr("Go to Block Start with Selection"), QKeySequence(tr("Ctrl+{"))); - m_gotoBlockEndWithSelectionAction = registerAction(GOTO_BLOCK_END_WITH_SELECTION, + registerAction(GOTO_BLOCK_END_WITH_SELECTION, [] (TextEditorWidget *w) { w->gotoBlockEndWithSelection(); }, true, tr("Go to Block End with Selection"), QKeySequence(tr("Ctrl+}"))); - m_moveLineUpAction = registerAction(MOVE_LINE_UP, + m_modifyingActions << registerAction(MOVE_LINE_UP, [] (TextEditorWidget *w) { w->moveLineUp(); }, true, tr("Move Line Up"), QKeySequence(tr("Ctrl+Shift+Up"))); - m_moveLineDownAction = registerAction(MOVE_LINE_DOWN, + m_modifyingActions << registerAction(MOVE_LINE_DOWN, [] (TextEditorWidget *w) { w->moveLineDown(); }, true, tr("Move Line Down"), QKeySequence(tr("Ctrl+Shift+Down"))); - m_copyLineUpAction = registerAction(COPY_LINE_UP, + m_modifyingActions << registerAction(COPY_LINE_UP, [] (TextEditorWidget *w) { w->copyLineUp(); }, true, tr("Copy Line Up"), QKeySequence(tr("Ctrl+Alt+Up"))); - m_copyLineDownAction = registerAction(COPY_LINE_DOWN, + m_modifyingActions << registerAction(COPY_LINE_DOWN, [] (TextEditorWidget *w) { w->copyLineDown(); }, true, tr("Copy Line Down"), QKeySequence(tr("Ctrl+Alt+Down"))); - m_joinLinesAction = registerAction(JOIN_LINES, + m_modifyingActions << registerAction(JOIN_LINES, [] (TextEditorWidget *w) { w->joinLines(); }, true, tr("Join Lines"), QKeySequence(tr("Ctrl+J"))); - m_insertLineAboveAction = registerAction(INSERT_LINE_ABOVE, + m_modifyingActions << registerAction(INSERT_LINE_ABOVE, [] (TextEditorWidget *w) { w->insertLineAbove(); }, true, tr("Insert Line Above Current Line"), QKeySequence(tr("Ctrl+Shift+Return"))); - m_insertLineBelowAction = registerAction(INSERT_LINE_BELOW, + m_modifyingActions << registerAction(INSERT_LINE_BELOW, [] (TextEditorWidget *w) { w->insertLineBelow(); }, true, tr("Insert Line Below Current Line"), QKeySequence(tr("Ctrl+Return"))); - m_switchUtf8bomAction = registerAction(SWITCH_UTF8BOM, + m_modifyingActions << registerAction(SWITCH_UTF8BOM, [] (TextEditorWidget *w) { w->switchUtf8bom(); }, true, tr("Toggle UTF-8 BOM")); - m_indentAction = registerAction(INDENT, + m_modifyingActions << registerAction(INDENT, [] (TextEditorWidget *w) { w->indent(); }, true, tr("Indent")); - m_unindentAction = registerAction(UNINDENT, + m_modifyingActions << registerAction(UNINDENT, [] (TextEditorWidget *w) { w->unindent(); }, true, tr("Unindent")); m_followSymbolAction = registerAction(FOLLOW_SYMBOL_UNDER_CURSOR, [] (TextEditorWidget *w) { w->openLinkUnderCursor(); }, true, tr("Follow Symbol Under Cursor"), @@ -285,7 +237,7 @@ void TextEditorActionHandlerPrivate::createActions() m_followSymbolInNextSplitAction = registerAction(FOLLOW_SYMBOL_UNDER_CURSOR_IN_NEXT_SPLIT, [] (TextEditorWidget *w) { w->openLinkUnderCursorInNextSplit(); }, true, tr("Follow Symbol Under Cursor in Next Split"), QKeySequence(Utils::HostOsInfo::isMacHost() ? tr("Meta+E, F2") : tr("Ctrl+E, F2"))); - m_findUsageAction = registerAction(FIND_USAGES, + registerAction(FIND_USAGES, [] (TextEditorWidget *w) { w->findUsages(); }, true, tr("Find References to Symbol Under Cursor"), QKeySequence(tr("Ctrl+Shift+U"))); m_renameSymbolAction = registerAction(RENAME_SYMBOL, @@ -298,28 +250,28 @@ void TextEditorActionHandlerPrivate::createActions() [] (TextEditorWidget *w) { w->openLinkUnderCursorInNextSplit(); }, true, tr("Jump to File Under Cursor in Next Split"), QKeySequence(Utils::HostOsInfo::isMacHost() ? tr("Meta+E, F2") : tr("Ctrl+E, F2")).toString()); - m_viewPageUpAction = registerAction(VIEW_PAGE_UP, + registerAction(VIEW_PAGE_UP, [] (TextEditorWidget *w) { w->viewPageUp(); }, true, tr("Move the View a Page Up and Keep the Cursor Position"), QKeySequence(tr("Ctrl+PgUp"))); - m_viewPageDownAction = registerAction(VIEW_PAGE_DOWN, + registerAction(VIEW_PAGE_DOWN, [] (TextEditorWidget *w) { w->viewPageDown(); }, true, tr("Move the View a Page Down and Keep the Cursor Position"), QKeySequence(tr("Ctrl+PgDown"))); - m_viewLineUpAction = registerAction(VIEW_LINE_UP, + registerAction(VIEW_LINE_UP, [] (TextEditorWidget *w) { w->viewLineUp(); }, true, tr("Move the View a Line Up and Keep the Cursor Position"), QKeySequence(tr("Ctrl+Up"))); - m_viewLineDownAction = registerAction(VIEW_LINE_DOWN, + registerAction(VIEW_LINE_DOWN, [] (TextEditorWidget *w) { w->viewLineDown(); }, true, tr("Move the View a Line Down and Keep the Cursor Position"), QKeySequence(tr("Ctrl+Down"))); // register "Edit" Menu Actions Core::ActionContainer *editMenu = Core::ActionManager::actionContainer(M_EDIT); - m_selectEncodingAction = registerAction(SELECT_ENCODING, + registerAction(SELECT_ENCODING, [] (TextEditorWidget *w) { w->selectEncoding(); }, false, tr("Select Encoding..."), QKeySequence(), G_EDIT_OTHER, editMenu); - m_circularPasteAction = registerAction(CIRCULAR_PASTE, + m_modifyingActions << registerAction(CIRCULAR_PASTE, [] (TextEditorWidget *w) { w->circularPaste(); }, false, tr("Paste from Clipboard History"), QKeySequence(tr("Ctrl+Shift+V")), G_EDIT_COPYPASTE, editMenu); - m_circularPasteAction = registerAction(NO_FORMAT_PASTE, + m_modifyingActions << registerAction(NO_FORMAT_PASTE, [] (TextEditorWidget *w) { w->pasteWithoutFormat(); }, false, tr("Paste without Formatting"), QKeySequence(Core::useMacShortcuts ? tr("Cmd+Opt+Shift+V") : QString()), G_EDIT_COPYPASTE, editMenu); @@ -333,7 +285,7 @@ void TextEditorActionHandlerPrivate::createActions() [] (TextEditorWidget *w) { w->autoFormat(); }, true, tr("Auto-&format Selection"), QKeySequence(tr("Ctrl+;")), G_EDIT_FORMAT, advancedEditMenu); - m_rewrapParagraphAction = registerAction(REWRAP_PARAGRAPH, + m_modifyingActions << registerAction(REWRAP_PARAGRAPH, [] (TextEditorWidget *w) { w->rewrapParagraph(); }, true, tr("&Rewrap Paragraph"), QKeySequence(Core::useMacShortcuts ? tr("Meta+E, R") : tr("Ctrl+E, R")), G_EDIT_FORMAT, advancedEditMenu); @@ -349,7 +301,7 @@ void TextEditorActionHandlerPrivate::createActions() QKeySequence(Core::useMacShortcuts ? tr("Meta+E, Meta+V") : tr("Ctrl+E, Ctrl+V")), G_EDIT_FORMAT, advancedEditMenu); m_visualizeWhitespaceAction->setCheckable(true); - m_cleanWhitespaceAction = registerAction(CLEAN_WHITESPACE, + m_modifyingActions << registerAction(CLEAN_WHITESPACE, [] (TextEditorWidget *w) { w->cleanWhitespace(); }, true, tr("Clean Whitespace"), QKeySequence(), G_EDIT_FORMAT, advancedEditMenu); @@ -369,39 +321,39 @@ void TextEditorActionHandlerPrivate::createActions() [] (TextEditorWidget *w) { w->unCommentSelection(); }, true, tr("Toggle Comment &Selection"), QKeySequence(tr("Ctrl+/")), G_EDIT_FORMAT, advancedEditMenu); - m_cutLineAction = registerAction(CUT_LINE, + m_modifyingActions << registerAction(CUT_LINE, [] (TextEditorWidget *w) { w->cutLine(); }, true, tr("Cut &Line"), QKeySequence(tr("Shift+Del")), G_EDIT_TEXT, advancedEditMenu); - m_copyLineAction = registerAction(COPY_LINE, + registerAction(COPY_LINE, [] (TextEditorWidget *w) { w->copyLine(); }, false, tr("Copy &Line"), QKeySequence(tr("Ctrl+Ins")), G_EDIT_TEXT, advancedEditMenu); - m_duplicateSelectionAction = registerAction(DUPLICATE_SELECTION, + m_modifyingActions << registerAction(DUPLICATE_SELECTION, [] (TextEditorWidget *w) { w->duplicateSelection(); }, false, tr("&Duplicate Selection"), QKeySequence(), G_EDIT_TEXT, advancedEditMenu); - m_duplicateSelectionAndCommentAction = registerAction(DUPLICATE_SELECTION_AND_COMMENT, + m_modifyingActions << registerAction(DUPLICATE_SELECTION_AND_COMMENT, [] (TextEditorWidget *w) { w->duplicateSelectionAndComment(); }, false, tr("&Duplicate Selection and Comment"), QKeySequence(), G_EDIT_TEXT, advancedEditMenu); - m_upperCaseSelectionAction = registerAction(UPPERCASE_SELECTION, + m_modifyingActions << registerAction(UPPERCASE_SELECTION, [] (TextEditorWidget *w) { w->uppercaseSelection(); }, true, tr("Uppercase Selection"), QKeySequence(Core::useMacShortcuts ? tr("Meta+Shift+U") : tr("Alt+Shift+U")), G_EDIT_TEXT, advancedEditMenu); - m_lowerCaseSelectionAction = registerAction(LOWERCASE_SELECTION, + m_modifyingActions << registerAction(LOWERCASE_SELECTION, [] (TextEditorWidget *w) { w->lowercaseSelection(); }, true, tr("Lowercase Selection"), QKeySequence(Core::useMacShortcuts ? tr("Meta+U") : tr("Alt+U")), G_EDIT_TEXT, advancedEditMenu); - m_sortSelectedLinesAction = registerAction(SORT_SELECTED_LINES, + m_modifyingActions << registerAction(SORT_SELECTED_LINES, [] (TextEditorWidget *w) { w->sortSelectedLines(); }, false, tr("&Sort Selected Lines"), QKeySequence(Core::useMacShortcuts ? tr("Meta+Shift+S") : tr("Alt+Shift+S")), G_EDIT_TEXT, advancedEditMenu); - m_foldAction = registerAction(FOLD, + registerAction(FOLD, [] (TextEditorWidget *w) { w->fold(); }, true, tr("Fold"), QKeySequence(tr("Ctrl+<")), G_EDIT_COLLAPSING, advancedEditMenu); - m_unfoldAction = registerAction(UNFOLD, + registerAction(UNFOLD, [] (TextEditorWidget *w) { w->unfold(); }, true, tr("Unfold"), QKeySequence(tr("Ctrl+>")), G_EDIT_COLLAPSING, advancedEditMenu); @@ -409,31 +361,31 @@ void TextEditorActionHandlerPrivate::createActions() [] (TextEditorWidget *w) { w->unfoldAll(); }, true, tr("Toggle &Fold All"), QKeySequence(), G_EDIT_COLLAPSING, advancedEditMenu); - m_increaseFontSizeAction = registerAction(INCREASE_FONT_SIZE, + registerAction(INCREASE_FONT_SIZE, [] (TextEditorWidget *w) { w->zoomF(1.f); }, false, tr("Increase Font Size"), QKeySequence(tr("Ctrl++")), G_EDIT_FONT, advancedEditMenu); - m_decreaseFontSizeAction = registerAction(DECREASE_FONT_SIZE, + registerAction(DECREASE_FONT_SIZE, [] (TextEditorWidget *w) { w->zoomF(-1.f); }, false, tr("Decrease Font Size"), QKeySequence(tr("Ctrl+-")), G_EDIT_FONT, advancedEditMenu); - m_resetFontSizeAction = registerAction(RESET_FONT_SIZE, + registerAction(RESET_FONT_SIZE, [] (TextEditorWidget *w) { w->zoomReset(); }, false, tr("Reset Font Size"), QKeySequence(Core::useMacShortcuts ? tr("Meta+0") : tr("Ctrl+0")), G_EDIT_FONT, advancedEditMenu); - m_gotoBlockStartAction = registerAction(GOTO_BLOCK_START, + registerAction(GOTO_BLOCK_START, [] (TextEditorWidget *w) { w->gotoBlockStart(); }, true, tr("Go to Block Start"), QKeySequence(tr("Ctrl+[")), G_EDIT_BLOCKS, advancedEditMenu); - m_gotoBlockEndAction = registerAction(GOTO_BLOCK_END, + registerAction(GOTO_BLOCK_END, [] (TextEditorWidget *w) { w->gotoBlockEnd(); }, true, tr("Go to Block End"), QKeySequence(tr("Ctrl+]")), G_EDIT_BLOCKS, advancedEditMenu); - m_selectBlockUpAction = registerAction(SELECT_BLOCK_UP, + registerAction(SELECT_BLOCK_UP, [] (TextEditorWidget *w) { w->selectBlockUp(); }, true, tr("Select Block Up"), QKeySequence(tr("Ctrl+U")), G_EDIT_BLOCKS, advancedEditMenu); - m_selectBlockDownAction = registerAction(SELECT_BLOCK_DOWN, + registerAction(SELECT_BLOCK_DOWN, [] (TextEditorWidget *w) { w->selectBlockDown(); }, true, tr("Select Block Down"), QKeySequence(tr("Ctrl+Shift+Alt+U")), G_EDIT_BLOCKS, advancedEditMenu); @@ -489,38 +441,11 @@ void TextEditorActionHandlerPrivate::createActions() registerAction(GOTO_NEXT_WORD_CAMEL_CASE_WITH_SELECTION, [] (TextEditorWidget *w) { w->gotoNextWordCamelCaseWithSelection(); }, false, tr("Go to Next Word Camel Case with Selection")); - // Collect all modifying actions so we can check for them inside a readonly file + // Collect additional modifying actions so we can check for them inside a readonly file // and disable them - m_modifyingActions << m_circularPasteAction; - m_modifyingActions << m_cleanWhitespaceAction; - m_modifyingActions << m_copyLineDownAction; - m_modifyingActions << m_copyLineUpAction; - m_modifyingActions << m_cutLineAction; - m_modifyingActions << m_deleteEndOfLineAction; - m_modifyingActions << m_deleteEndOfWordAction; - m_modifyingActions << m_deleteEndOfWordCamelCaseAction; - m_modifyingActions << m_deleteLineAction; - m_modifyingActions << m_deleteStartOfLineAction; - m_modifyingActions << m_deleteStartOfWordAction; - m_modifyingActions << m_deleteStartOfWordCamelCaseAction; - m_modifyingActions << m_duplicateSelectionAction; - m_modifyingActions << m_duplicateSelectionAndCommentAction; m_modifyingActions << m_autoIndentAction; m_modifyingActions << m_autoFormatAction; - m_modifyingActions << m_indentAction; - m_modifyingActions << m_insertLineAboveAction; - m_modifyingActions << m_insertLineBelowAction; - m_modifyingActions << m_joinLinesAction; - m_modifyingActions << m_lowerCaseSelectionAction; - m_modifyingActions << m_moveLineDownAction; - m_modifyingActions << m_moveLineUpAction; - m_modifyingActions << m_pasteAction; - m_modifyingActions << m_rewrapParagraphAction; - m_modifyingActions << m_switchUtf8bomAction; m_modifyingActions << m_unCommentSelectionAction; - m_modifyingActions << m_unindentAction; - m_modifyingActions << m_upperCaseSelectionAction; - m_modifyingActions << m_sortSelectedLinesAction; updateOptionalActions(); } -- cgit v1.2.3