TextEditor: Use more ActionBuilder

Change-Id: I959c973012873cb8d56442cfdfc86fac5db9faa0
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2024-02-05 17:57:02 +01:00
parent 980605ecb0
commit 8b90a2b1cb

View File

@@ -121,42 +121,46 @@ void TextEditorPlugin::initialize()
Context context(TextEditor::Constants::C_TEXTEDITOR); Context context(TextEditor::Constants::C_TEXTEDITOR);
// Add shortcut for invoking automatic completion // Add shortcut for invoking automatic completion
QAction *completionAction = new QAction(Tr::tr("Trigger Completion"), this); Command *command = nullptr;
Command *command = ActionManager::registerAction(completionAction, Constants::COMPLETE_THIS, context); ActionBuilder(this, Constants::COMPLETE_THIS)
command->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+Space") : Tr::tr("Ctrl+Space"))); .setText(Tr::tr("Trigger Completion"))
connect(completionAction, &QAction::triggered, this, [] { .setContext(context)
.bindCommand(&command)
.setDefaultKeySequence(Tr::tr("Meta+Space"), Tr::tr("Ctrl+Space"))
.addOnTriggered(this, [] {
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor())
editor->editorWidget()->invokeAssist(Completion); editor->editorWidget()->invokeAssist(Completion);
}); });
connect(command, &Command::keySequenceChanged, [command] { connect(command, &Command::keySequenceChanged, [command] {
FancyLineEdit::setCompletionShortcut(command->keySequence()); FancyLineEdit::setCompletionShortcut(command->keySequence());
}); });
FancyLineEdit::setCompletionShortcut(command->keySequence()); FancyLineEdit::setCompletionShortcut(command->keySequence());
// Add shortcut for invoking function hint completion // Add shortcut for invoking function hint completion
QAction *functionHintAction = new QAction(Tr::tr("Display Function Hint"), this); ActionBuilder(this, Constants::FUNCTION_HINT)
command = ActionManager::registerAction(functionHintAction, Constants::FUNCTION_HINT, context); .setText(Tr::tr("Display Function Hint"))
command->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+Shift+D") .setContext(context)
: Tr::tr("Ctrl+Shift+D"))); .setDefaultKeySequence(Tr::tr("Meta+Shift+D"), Tr::tr("Ctrl+Shift+D"))
connect(functionHintAction, &QAction::triggered, this, [] { .addOnTriggered(this, [] {
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor())
editor->editorWidget()->invokeAssist(FunctionHint); editor->editorWidget()->invokeAssist(FunctionHint);
}); });
// Add shortcut for invoking quick fix options // Add shortcut for invoking quick fix options
QAction *quickFixAction = new QAction(Tr::tr("Trigger Refactoring Action"), this); ActionBuilder(this, Constants::QUICKFIX_THIS)
Command *quickFixCommand = ActionManager::registerAction(quickFixAction, Constants::QUICKFIX_THIS, context); .setText(Tr::tr("Trigger Refactoring Action"))
quickFixCommand->setDefaultKeySequence(QKeySequence(Tr::tr("Alt+Return"))); .setContext(context)
connect(quickFixAction, &QAction::triggered, this, [] { .setDefaultKeySequence(Tr::tr("Alt+Return"))
.addOnTriggered(this, [] {
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor())
editor->editorWidget()->invokeAssist(QuickFix); editor->editorWidget()->invokeAssist(QuickFix);
}); });
QAction *showContextMenuAction = new QAction(Tr::tr("Show Context Menu"), this); ActionBuilder(this, Constants::SHOWCONTEXTMENU)
ActionManager::registerAction(showContextMenuAction, .setText(Tr::tr("Show Context Menu"))
Constants::SHOWCONTEXTMENU, .setContext(context)
context); .addOnTriggered(this, [] {
connect(showContextMenuAction, &QAction::triggered, this, [] {
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor())
editor->editorWidget()->showContextMenu(); editor->editorWidget()->showContextMenu();
}); });