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 <qt_ci_bot@qt-project.org>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Ali Kianian
2023-04-20 11:11:52 +03:00
parent 94ab3edb37
commit b0c3377f1d
3 changed files with 12 additions and 4 deletions

View File

@@ -254,6 +254,7 @@ Rectangle {
ToolbarButton { ToolbarButton {
id: annotations id: annotations
visible: false visible: false
enabled: backend.isInDesignMode
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.right: shareButton.left anchors.right: shareButton.left
anchors.rightMargin: 10 anchors.rightMargin: 10

View File

@@ -644,6 +644,8 @@ bool ToolBarBackend::projectOpened() const
void ToolBarBackend::launchGlobalAnnotations() void ToolBarBackend::launchGlobalAnnotations()
{ {
QmlDesignerPlugin::emitUsageStatistics(Constants::EVENT_TOOLBAR_EDIT_GLOBAL_ANNOTATION); QmlDesignerPlugin::emitUsageStatistics(Constants::EVENT_TOOLBAR_EDIT_GLOBAL_ANNOTATION);
QTC_ASSERT(currentDesignDocument(), return);
ModelNode node = currentDesignDocument()->rewriterView()->rootModelNode(); ModelNode node = currentDesignDocument()->rewriterView()->rootModelNode();
if (node.isValid()) { if (node.isValid()) {

View File

@@ -14,11 +14,12 @@
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h> #include <coreplugin/actionmanager/command.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <coreplugin/editormanager/documentmodel.h> #include <coreplugin/editormanager/documentmodel.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <coreplugin/modemanager.h>
#include <qmljseditor/qmljseditorconstants.h> #include <qmljseditor/qmljseditorconstants.h>
#include <qmlprojectmanager/qmlprojectmanagerconstants.h> #include <qmlprojectmanager/qmlprojectmanagerconstants.h>
@@ -109,10 +110,16 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex
QmlDesignerPlugin::instance()->viewManager().exportAsImage(); QmlDesignerPlugin::instance()->viewManager().exportAsImage();
}); });
// Edit Global Annotations
QAction *action = new QAction(tr("Edit Global Annotations..."), this); QAction *action = new QAction(tr("Edit Global Annotations..."), this);
command = Core::ActionManager::registerAction(action, "Edit.Annotations", qmlDesignerMainContext); command = Core::ActionManager::registerAction(action, "Edit.Annotations", qmlDesignerMainContext);
Core::ActionManager::actionContainer(Core::Constants::M_EDIT) Core::ActionManager::actionContainer(Core::Constants::M_EDIT)
->addAction(command, Core::Constants::G_EDIT_OTHER); ->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, command = Core::ActionManager::registerAction(&m_takeScreenshotAction,
QmlDesigner::Constants::TAKE_SCREENSHOT); QmlDesigner::Constants::TAKE_SCREENSHOT);
@@ -131,8 +138,6 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex
qWarning() << "screenshot" << file << b << pixmap; qWarning() << "screenshot" << file << b << pixmap;
}); });
connect(action, &QAction::triggered, this, [] { ToolBarBackend::launchGlobalAnnotations(); });
Core::ActionContainer *exportMenu = Core::ActionManager::actionContainer( Core::ActionContainer *exportMenu = Core::ActionManager::actionContainer(
QmlProjectManager::Constants::EXPORT_MENU); QmlProjectManager::Constants::EXPORT_MENU);