QmlDesigner: Remove special completion action

It was necessary to override the existing completion action, because
that would always work on the current editor in the editor manager
instead of on the text editor in Design mode.
(Though instead of changing the context for the TextEditorView, the code
could just have registered a context for the text editor widget itself
for that purpose.)

Since 411100b037 the text editor widgets
have their own individual contexts and actions, without the detour via
the editor manager, so this workaround is no longer needed.

Change-Id: I7e2b18dd7b953a56b5f2c99152d2eeabdb76f726
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Eike Ziller
2024-07-09 12:00:22 +02:00
parent 30e44ae15f
commit a555bc3801
2 changed files with 5 additions and 31 deletions

View File

@@ -45,35 +45,15 @@ using namespace Core;
namespace QmlDesigner { namespace QmlDesigner {
const char TEXTEDITOR_CONTEXT_ID[] = "QmlDesigner.TextEditorContext";
TextEditorView::TextEditorView(ExternalDependenciesInterface &externalDependencies) TextEditorView::TextEditorView(ExternalDependenciesInterface &externalDependencies)
: AbstractView{externalDependencies} : AbstractView{externalDependencies}
, m_widget(new TextEditorWidget(this)) , m_widget(new TextEditorWidget(this))
, m_textEditorContext(new Core::IContext(m_widget))
{ {
m_textEditorContext->setWidget(m_widget); IContext::attach(m_widget,
m_textEditorContext->setContext(Context(Constants::C_QMLTEXTEDITOR, Constants::C_QT_QUICK_TOOLS_MENU)); Context(Constants::C_QMLTEXTEDITOR, Constants::C_QT_QUICK_TOOLS_MENU),
m_textEditorContext->setContextHelpProvider([this](const IContext::HelpCallback &callback) { [this](const IContext::HelpCallback &callback) {
m_widget->contextHelp(callback); m_widget->contextHelp(callback);
}); });
Core::ICore::addContextObject(m_textEditorContext);
Core::Context context(TEXTEDITOR_CONTEXT_ID);
/*
* We have to register our own active auto completion shortcut, because the original short cut will
* use the cursor position of the original editor in the editor manager.
*/
QAction *completionAction = new QAction(tr("Trigger Completion"), this);
Core::Command *command = Core::ActionManager::registerAction(completionAction, TextEditor::Constants::COMPLETE_THIS, context);
command->setDefaultKeySequence(QKeySequence(Core::useMacShortcuts ? tr("Meta+Space") : tr("Ctrl+Space")));
connect(completionAction, &QAction::triggered, this, [this] {
if (m_widget->textEditor())
m_widget->textEditor()->editorWidget()->invokeAssist(TextEditor::Completion);
});
} }
TextEditorView::~TextEditorView() TextEditorView::~TextEditorView()
@@ -91,11 +71,6 @@ void TextEditorView::modelAttached(Model *model)
auto textEditor = Utils::UniqueObjectLatePtr<TextEditor::BaseTextEditor>( auto textEditor = Utils::UniqueObjectLatePtr<TextEditor::BaseTextEditor>(
QmlDesignerPlugin::instance()->currentDesignDocument()->textEditor()->duplicate()); QmlDesignerPlugin::instance()->currentDesignDocument()->textEditor()->duplicate());
// Set the context of the text editor, but we add another special context to override shortcuts.
Core::Context context = textEditor->context();
context.prepend(TEXTEDITOR_CONTEXT_ID);
m_textEditorContext->setContext(context);
m_widget->setTextEditor(std::move(textEditor)); m_widget->setTextEditor(std::move(textEditor));
} }

View File

@@ -77,7 +77,6 @@ public:
private: private:
QPointer<TextEditorWidget> m_widget; QPointer<TextEditorWidget> m_widget;
Core::IContext *m_textEditorContext;
bool m_errorState = false; bool m_errorState = false;
}; };