2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2016-09-15 17:55:28 +02:00
|
|
|
|
|
|
|
|
#include "mainwidget.h"
|
|
|
|
|
#include "scxmleditorconstants.h"
|
2022-08-23 13:05:04 +02:00
|
|
|
#include "scxmleditordata.h"
|
2016-09-15 17:55:28 +02:00
|
|
|
#include "scxmleditordocument.h"
|
|
|
|
|
#include "scxmleditorstack.h"
|
2022-08-23 13:05:04 +02:00
|
|
|
#include "scxmleditortr.h"
|
2016-09-15 17:55:28 +02:00
|
|
|
#include "scxmltexteditor.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/designmode.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/idocument.h>
|
|
|
|
|
#include <coreplugin/minisplitter.h>
|
|
|
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
|
#include <coreplugin/outputpane.h>
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
|
2016-10-17 16:29:08 +02:00
|
|
|
#include <utils/icon.h>
|
2020-06-17 12:23:44 +02:00
|
|
|
#include <utils/infobar.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
2016-12-12 12:55:19 +01:00
|
|
|
#include <utils/utilsicons.h>
|
2016-09-15 17:55:28 +02:00
|
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
using namespace ScxmlEditor::Common;
|
|
|
|
|
using namespace ScxmlEditor::PluginInterface;
|
2020-06-26 13:59:38 +02:00
|
|
|
using namespace Utils;
|
2016-09-15 17:55:28 +02:00
|
|
|
|
|
|
|
|
namespace ScxmlEditor {
|
|
|
|
|
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class ScxmlTextEditorWidget : public TextEditor::TextEditorWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-11-24 20:21:25 +01:00
|
|
|
ScxmlTextEditorWidget() = default;
|
2016-09-15 17:55:28 +02:00
|
|
|
|
2018-11-24 20:21:25 +01:00
|
|
|
void finalizeInitialization() override
|
2016-09-15 17:55:28 +02:00
|
|
|
{
|
|
|
|
|
setReadOnly(true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ScxmlTextEditorFactory : public TextEditor::TextEditorFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ScxmlTextEditorFactory()
|
|
|
|
|
{
|
|
|
|
|
setId(ScxmlEditor::Constants::K_SCXML_EDITOR_ID);
|
2022-12-07 20:59:51 +01:00
|
|
|
setEditorCreator([] { return new ScxmlTextEditor; });
|
|
|
|
|
setEditorWidgetCreator([] { return new ScxmlTextEditorWidget; });
|
2016-09-15 17:55:28 +02:00
|
|
|
setUseGenericHighlighter(true);
|
|
|
|
|
setDuplicatedSupported(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScxmlTextEditor *create(ScxmlEditor::Common::MainWidget *designWidget)
|
|
|
|
|
{
|
2022-12-07 20:59:51 +01:00
|
|
|
setDocumentCreator([designWidget] { return new ScxmlEditorDocument(designWidget); });
|
2016-09-15 17:55:28 +02:00
|
|
|
return qobject_cast<ScxmlTextEditor*>(createEditor());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-11 17:55:15 +01:00
|
|
|
ScxmlEditorData::ScxmlEditorData()
|
2016-09-15 17:55:28 +02:00
|
|
|
{
|
|
|
|
|
m_contexts.add(ScxmlEditor::Constants::C_SCXMLEDITOR);
|
|
|
|
|
|
2022-12-07 20:59:51 +01:00
|
|
|
QObject::connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
|
|
|
|
|
this, [this](IEditor *editor) {
|
2016-09-15 17:55:28 +02:00
|
|
|
if (editor && editor->document()->id() == Constants::K_SCXML_EDITOR_ID) {
|
|
|
|
|
auto xmlEditor = qobject_cast<ScxmlTextEditor*>(editor);
|
|
|
|
|
QTC_ASSERT(xmlEditor, return );
|
|
|
|
|
QWidget *dw = m_widgetStack->widgetForEditor(xmlEditor);
|
|
|
|
|
QTC_ASSERT(dw, return );
|
|
|
|
|
m_widgetStack->setVisibleEditor(xmlEditor);
|
|
|
|
|
m_mainToolBar->setCurrentEditor(xmlEditor);
|
|
|
|
|
updateToolBar();
|
|
|
|
|
auto designWidget = static_cast<MainWidget*>(m_widgetStack->currentWidget());
|
|
|
|
|
if (designWidget)
|
|
|
|
|
designWidget->refresh();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
m_xmlEditorFactory = new ScxmlTextEditorFactory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScxmlEditorData::~ScxmlEditorData()
|
|
|
|
|
{
|
|
|
|
|
if (m_modeWidget) {
|
2018-01-23 09:09:46 +01:00
|
|
|
DesignMode::unregisterDesignWidget(m_modeWidget);
|
2016-09-15 17:55:28 +02:00
|
|
|
delete m_modeWidget;
|
|
|
|
|
m_modeWidget = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete m_xmlEditorFactory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScxmlEditorData::fullInit()
|
|
|
|
|
{
|
|
|
|
|
// Create widget-stack, toolbar, mainToolbar and whole design-mode widget
|
|
|
|
|
m_widgetStack = new ScxmlEditorStack;
|
|
|
|
|
m_widgetToolBar = new QToolBar;
|
|
|
|
|
m_mainToolBar = createMainToolBar();
|
|
|
|
|
m_modeWidget = createModeWidget();
|
|
|
|
|
|
|
|
|
|
// Create undo/redo group/actions
|
|
|
|
|
m_undoGroup = new QUndoGroup(m_widgetToolBar);
|
|
|
|
|
m_undoAction = m_undoGroup->createUndoAction(m_widgetToolBar);
|
2016-12-12 12:55:19 +01:00
|
|
|
m_undoAction->setIcon(Utils::Icons::UNDO_TOOLBAR.icon());
|
2022-08-23 13:05:04 +02:00
|
|
|
m_undoAction->setToolTip(Tr::tr("Undo (Ctrl + Z)"));
|
2016-09-15 17:55:28 +02:00
|
|
|
|
|
|
|
|
m_redoAction = m_undoGroup->createRedoAction(m_widgetToolBar);
|
2016-12-12 12:55:19 +01:00
|
|
|
m_redoAction->setIcon(Utils::Icons::REDO_TOOLBAR.icon());
|
2022-08-23 13:05:04 +02:00
|
|
|
m_redoAction->setToolTip(Tr::tr("Redo (Ctrl + Y)"));
|
2016-09-15 17:55:28 +02:00
|
|
|
|
|
|
|
|
ActionManager::registerAction(m_undoAction, Core::Constants::UNDO, m_contexts);
|
|
|
|
|
ActionManager::registerAction(m_redoAction, Core::Constants::REDO, m_contexts);
|
|
|
|
|
|
|
|
|
|
Context scxmlContexts = m_contexts;
|
|
|
|
|
scxmlContexts.add(Core::Constants::C_EDITORMANAGER);
|
2020-05-26 16:07:10 +02:00
|
|
|
auto context = new IContext(this);
|
|
|
|
|
context->setContext(scxmlContexts);
|
|
|
|
|
context->setWidget(m_modeWidget);
|
2020-05-26 14:48:38 +02:00
|
|
|
ICore::addContextObject(context);
|
2016-09-15 17:55:28 +02:00
|
|
|
|
2018-01-23 09:09:46 +01:00
|
|
|
DesignMode::registerDesignWidget(m_modeWidget, QStringList(QLatin1String(ProjectExplorer::Constants::SCXML_MIMETYPE)), m_contexts);
|
2016-09-15 17:55:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEditor *ScxmlEditorData::createEditor()
|
|
|
|
|
{
|
|
|
|
|
auto designWidget = new MainWidget;
|
|
|
|
|
ScxmlTextEditor *xmlEditor = m_xmlEditorFactory->create(designWidget);
|
|
|
|
|
|
|
|
|
|
m_undoGroup->addStack(designWidget->undoStack());
|
|
|
|
|
m_widgetStack->add(xmlEditor, designWidget);
|
|
|
|
|
m_mainToolBar->addEditor(xmlEditor);
|
|
|
|
|
|
|
|
|
|
if (xmlEditor) {
|
2020-06-17 12:23:44 +02:00
|
|
|
Utils::InfoBarEntry info(Id(Constants::INFO_READ_ONLY),
|
2022-08-23 13:05:04 +02:00
|
|
|
Tr::tr("This file can only be edited in <b>Design</b> mode."));
|
2022-12-07 20:59:51 +01:00
|
|
|
info.addCustomButton(Tr::tr("Switch Mode"),
|
|
|
|
|
[] { ModeManager::activateMode(Core::Constants::MODE_DESIGN); });
|
2016-09-15 17:55:28 +02:00
|
|
|
xmlEditor->document()->infoBar()->addInfo(info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return xmlEditor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScxmlEditorData::updateToolBar()
|
|
|
|
|
{
|
|
|
|
|
auto designWidget = static_cast<MainWidget*>(m_widgetStack->currentWidget());
|
|
|
|
|
if (designWidget && m_widgetToolBar) {
|
|
|
|
|
m_undoGroup->setActiveStack(designWidget->undoStack());
|
|
|
|
|
m_widgetToolBar->clear();
|
|
|
|
|
m_widgetToolBar->addAction(m_undoAction);
|
|
|
|
|
m_widgetToolBar->addAction(m_redoAction);
|
|
|
|
|
m_widgetToolBar->addSeparator();
|
|
|
|
|
m_widgetToolBar->addAction(designWidget->action(ActionCopy));
|
|
|
|
|
m_widgetToolBar->addAction(designWidget->action(ActionCut));
|
|
|
|
|
m_widgetToolBar->addAction(designWidget->action(ActionPaste));
|
|
|
|
|
m_widgetToolBar->addAction(designWidget->action(ActionScreenshot));
|
|
|
|
|
m_widgetToolBar->addAction(designWidget->action(ActionExportToImage));
|
|
|
|
|
m_widgetToolBar->addAction(designWidget->action(ActionFullNamespace));
|
|
|
|
|
m_widgetToolBar->addSeparator();
|
|
|
|
|
m_widgetToolBar->addAction(designWidget->action(ActionZoomIn));
|
|
|
|
|
m_widgetToolBar->addAction(designWidget->action(ActionZoomOut));
|
|
|
|
|
m_widgetToolBar->addAction(designWidget->action(ActionPan));
|
|
|
|
|
m_widgetToolBar->addAction(designWidget->action(ActionFitToView));
|
|
|
|
|
m_widgetToolBar->addSeparator();
|
|
|
|
|
m_widgetToolBar->addWidget(designWidget->toolButton(ToolButtonAdjustment));
|
|
|
|
|
m_widgetToolBar->addWidget(designWidget->toolButton(ToolButtonAlignment));
|
|
|
|
|
m_widgetToolBar->addWidget(designWidget->toolButton(ToolButtonStateColor));
|
|
|
|
|
m_widgetToolBar->addWidget(designWidget->toolButton(ToolButtonFontColor));
|
|
|
|
|
m_widgetToolBar->addWidget(designWidget->toolButton(ToolButtonColorTheme));
|
|
|
|
|
m_widgetToolBar->addSeparator();
|
|
|
|
|
m_widgetToolBar->addAction(designWidget->action(ActionMagnifier));
|
|
|
|
|
m_widgetToolBar->addAction(designWidget->action(ActionNavigator));
|
|
|
|
|
m_widgetToolBar->addSeparator();
|
|
|
|
|
m_widgetToolBar->addAction(designWidget->action(ActionStatistics));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EditorToolBar *ScxmlEditorData::createMainToolBar()
|
|
|
|
|
{
|
|
|
|
|
auto toolBar = new EditorToolBar;
|
|
|
|
|
toolBar->setToolbarCreationFlags(EditorToolBar::FlagsStandalone);
|
|
|
|
|
toolBar->setNavigationVisible(false);
|
|
|
|
|
toolBar->addCenterToolBar(m_widgetToolBar);
|
|
|
|
|
|
|
|
|
|
return toolBar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *ScxmlEditorData::createModeWidget()
|
|
|
|
|
{
|
|
|
|
|
auto widget = new QWidget;
|
|
|
|
|
|
|
|
|
|
widget->setObjectName("ScxmlEditorDesignModeWidget");
|
|
|
|
|
auto layout = new QVBoxLayout;
|
2019-08-29 10:36:01 +02:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2016-09-15 17:55:28 +02:00
|
|
|
layout->setSpacing(0);
|
|
|
|
|
layout->addWidget(m_mainToolBar);
|
|
|
|
|
// Avoid mode switch to 'Edit' mode when the application started by
|
|
|
|
|
// 'Run' in 'Design' mode emits output.
|
|
|
|
|
auto splitter = new MiniSplitter(Qt::Vertical);
|
|
|
|
|
splitter->addWidget(m_widgetStack);
|
2018-01-23 09:09:46 +01:00
|
|
|
auto outputPane = new OutputPanePlaceHolder(Core::Constants::MODE_DESIGN, splitter);
|
2016-09-15 17:55:28 +02:00
|
|
|
outputPane->setObjectName("DesignerOutputPanePlaceHolder");
|
|
|
|
|
splitter->addWidget(outputPane);
|
|
|
|
|
layout->addWidget(splitter);
|
|
|
|
|
widget->setLayout(layout);
|
|
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ScxmlEditor
|