From b0c3377f1daaee0cdaf9a7b695e9391226d50c66 Mon Sep 17 00:00:00 2001 From: Ali Kianian Date: Thu, 20 Apr 2023 11:11:52 +0300 Subject: [PATCH] QmlDesigner: Fix the crash caused by calling GlobalAnnotations - Calling global annotations does nothing if we are not in the design mode - Related actions and buttons are blocked while we are not in the design mode Task-number: QDS-9729 Change-Id: Ib4d5e8c5adcbb080f42a2344cd76ce7c36532240 Reviewed-by: Qt CI Bot Reviewed-by: Tim Jenssen --- share/qtcreator/qmldesigner/toolbar/Main.qml | 1 + .../components/toolbar/toolbarbackend.cpp | 2 ++ src/plugins/qmldesigner/shortcutmanager.cpp | 13 +++++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/share/qtcreator/qmldesigner/toolbar/Main.qml b/share/qtcreator/qmldesigner/toolbar/Main.qml index 7f6a8a311c8..ebed433e724 100644 --- a/share/qtcreator/qmldesigner/toolbar/Main.qml +++ b/share/qtcreator/qmldesigner/toolbar/Main.qml @@ -254,6 +254,7 @@ Rectangle { ToolbarButton { id: annotations visible: false + enabled: backend.isInDesignMode anchors.verticalCenter: parent.verticalCenter anchors.right: shareButton.left anchors.rightMargin: 10 diff --git a/src/plugins/qmldesigner/components/toolbar/toolbarbackend.cpp b/src/plugins/qmldesigner/components/toolbar/toolbarbackend.cpp index f563e5eeca7..1919aeedad6 100644 --- a/src/plugins/qmldesigner/components/toolbar/toolbarbackend.cpp +++ b/src/plugins/qmldesigner/components/toolbar/toolbarbackend.cpp @@ -644,6 +644,8 @@ bool ToolBarBackend::projectOpened() const void ToolBarBackend::launchGlobalAnnotations() { QmlDesignerPlugin::emitUsageStatistics(Constants::EVENT_TOOLBAR_EDIT_GLOBAL_ANNOTATION); + + QTC_ASSERT(currentDesignDocument(), return); ModelNode node = currentDesignDocument()->rewriterView()->rootModelNode(); if (node.isValid()) { diff --git a/src/plugins/qmldesigner/shortcutmanager.cpp b/src/plugins/qmldesigner/shortcutmanager.cpp index add971a8c1f..87a873339df 100644 --- a/src/plugins/qmldesigner/shortcutmanager.cpp +++ b/src/plugins/qmldesigner/shortcutmanager.cpp @@ -14,11 +14,12 @@ #include #include #include -#include -#include #include #include #include +#include +#include +#include #include #include @@ -109,10 +110,16 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex QmlDesignerPlugin::instance()->viewManager().exportAsImage(); }); + // Edit Global Annotations QAction *action = new QAction(tr("Edit Global Annotations..."), this); command = Core::ActionManager::registerAction(action, "Edit.Annotations", qmlDesignerMainContext); Core::ActionManager::actionContainer(Core::Constants::M_EDIT) ->addAction(command, Core::Constants::G_EDIT_OTHER); + connect(action, &QAction::triggered, this, [] { ToolBarBackend::launchGlobalAnnotations(); }); + connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeChanged, this, [action] { + action->setEnabled(Core::ModeManager::currentModeId() == Core::Constants::MODE_DESIGN); + }); + action->setEnabled(false); command = Core::ActionManager::registerAction(&m_takeScreenshotAction, QmlDesigner::Constants::TAKE_SCREENSHOT); @@ -131,8 +138,6 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex qWarning() << "screenshot" << file << b << pixmap; }); - connect(action, &QAction::triggered, this, [] { ToolBarBackend::launchGlobalAnnotations(); }); - Core::ActionContainer *exportMenu = Core::ActionManager::actionContainer( QmlProjectManager::Constants::EXPORT_MENU);