From 8b90a2b1cb13b48feea322f5c12324d6953cb6a2 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 5 Feb 2024 17:57:02 +0100 Subject: [PATCH] TextEditor: Use more ActionBuilder Change-Id: I959c973012873cb8d56442cfdfc86fac5db9faa0 Reviewed-by: David Schulz --- src/plugins/texteditor/texteditorplugin.cpp | 64 +++++++++++---------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index dbb5ef0f2b6..6bb36d1c23c 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -121,45 +121,49 @@ void TextEditorPlugin::initialize() Context context(TextEditor::Constants::C_TEXTEDITOR); // Add shortcut for invoking automatic completion - QAction *completionAction = new QAction(Tr::tr("Trigger Completion"), this); - Command *command = ActionManager::registerAction(completionAction, Constants::COMPLETE_THIS, context); - command->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+Space") : Tr::tr("Ctrl+Space"))); - connect(completionAction, &QAction::triggered, this, [] { - if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) - editor->editorWidget()->invokeAssist(Completion); - }); + Command *command = nullptr; + ActionBuilder(this, Constants::COMPLETE_THIS) + .setText(Tr::tr("Trigger Completion")) + .setContext(context) + .bindCommand(&command) + .setDefaultKeySequence(Tr::tr("Meta+Space"), Tr::tr("Ctrl+Space")) + .addOnTriggered(this, [] { + if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) + editor->editorWidget()->invokeAssist(Completion); + }); + connect(command, &Command::keySequenceChanged, [command] { FancyLineEdit::setCompletionShortcut(command->keySequence()); }); FancyLineEdit::setCompletionShortcut(command->keySequence()); // Add shortcut for invoking function hint completion - QAction *functionHintAction = new QAction(Tr::tr("Display Function Hint"), this); - command = ActionManager::registerAction(functionHintAction, Constants::FUNCTION_HINT, context); - command->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+Shift+D") - : Tr::tr("Ctrl+Shift+D"))); - connect(functionHintAction, &QAction::triggered, this, [] { - if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) - editor->editorWidget()->invokeAssist(FunctionHint); - }); + ActionBuilder(this, Constants::FUNCTION_HINT) + .setText(Tr::tr("Display Function Hint")) + .setContext(context) + .setDefaultKeySequence(Tr::tr("Meta+Shift+D"), Tr::tr("Ctrl+Shift+D")) + .addOnTriggered(this, [] { + if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) + editor->editorWidget()->invokeAssist(FunctionHint); + }); // Add shortcut for invoking quick fix options - QAction *quickFixAction = new QAction(Tr::tr("Trigger Refactoring Action"), this); - Command *quickFixCommand = ActionManager::registerAction(quickFixAction, Constants::QUICKFIX_THIS, context); - quickFixCommand->setDefaultKeySequence(QKeySequence(Tr::tr("Alt+Return"))); - connect(quickFixAction, &QAction::triggered, this, [] { - if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) - editor->editorWidget()->invokeAssist(QuickFix); - }); + ActionBuilder(this, Constants::QUICKFIX_THIS) + .setText(Tr::tr("Trigger Refactoring Action")) + .setContext(context) + .setDefaultKeySequence(Tr::tr("Alt+Return")) + .addOnTriggered(this, [] { + if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) + editor->editorWidget()->invokeAssist(QuickFix); + }); - QAction *showContextMenuAction = new QAction(Tr::tr("Show Context Menu"), this); - ActionManager::registerAction(showContextMenuAction, - Constants::SHOWCONTEXTMENU, - context); - connect(showContextMenuAction, &QAction::triggered, this, [] { - if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) - editor->editorWidget()->showContextMenu(); - }); + ActionBuilder(this, Constants::SHOWCONTEXTMENU) + .setText(Tr::tr("Show Context Menu")) + .setContext(context) + .addOnTriggered(this, [] { + if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) + editor->editorWidget()->showContextMenu(); + }); // Add text snippet provider. SnippetProvider::registerGroup(Constants::TEXT_SNIPPET_GROUP_ID,