forked from qt-creator/qt-creator
TextEditor: Use more ActionBuilder
Change-Id: I959c973012873cb8d56442cfdfc86fac5db9faa0 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -121,45 +121,49 @@ 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)
|
||||||
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor())
|
.bindCommand(&command)
|
||||||
editor->editorWidget()->invokeAssist(Completion);
|
.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] {
|
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"))
|
||||||
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor())
|
.addOnTriggered(this, [] {
|
||||||
editor->editorWidget()->invokeAssist(QuickFix);
|
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor())
|
||||||
});
|
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();
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// Add text snippet provider.
|
// Add text snippet provider.
|
||||||
SnippetProvider::registerGroup(Constants::TEXT_SNIPPET_GROUP_ID,
|
SnippetProvider::registerGroup(Constants::TEXT_SNIPPET_GROUP_ID,
|
||||||
|
|||||||
Reference in New Issue
Block a user