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
|
2014-08-22 08:42:04 +02:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
#include "shortcutmanager.h"
|
|
|
|
|
|
2022-09-15 15:01:49 +02:00
|
|
|
#include <designersettings.h>
|
2016-10-07 12:15:33 +02:00
|
|
|
|
2017-01-05 17:44:10 +01:00
|
|
|
#include <viewmanager.h>
|
|
|
|
|
#include <designeractionmanagerview.h>
|
|
|
|
|
#include <componentcore_constants.h>
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2013-01-23 12:31:22 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2013-07-05 16:08:38 +02:00
|
|
|
#include <coreplugin/editormanager/documentmodel.h>
|
2015-02-26 13:22:35 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2013-01-23 12:31:22 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2016-10-07 12:15:33 +02:00
|
|
|
#include <qmljseditor/qmljseditorconstants.h>
|
|
|
|
|
|
2017-03-09 15:11:03 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2017-01-05 17:44:10 +01:00
|
|
|
#include <utils/proxyaction.h>
|
2016-10-07 12:15:33 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2018-03-26 10:44:10 +02:00
|
|
|
#include <utils/stringutils.h>
|
|
|
|
|
#include <utils/utilsicons.h>
|
2016-10-07 12:15:33 +02:00
|
|
|
|
|
|
|
|
#include <qmljs/qmljsreformatter.h>
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
#include "qmldesignerconstants.h"
|
|
|
|
|
#include "qmldesignerplugin.h"
|
|
|
|
|
|
2017-01-05 17:44:10 +01:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QClipboard>
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
|
|
ShortCutManager::ShortCutManager()
|
|
|
|
|
: QObject(),
|
2018-04-16 14:10:14 +02:00
|
|
|
m_exportAsImageAction(tr("Export as &Image...")),
|
|
|
|
|
m_undoAction(tr("&Undo")),
|
|
|
|
|
m_redoAction(tr("&Redo")),
|
|
|
|
|
m_deleteAction(tr("Delete")),
|
|
|
|
|
m_cutAction(tr("Cu&t")),
|
|
|
|
|
m_copyAction(tr("&Copy")),
|
|
|
|
|
m_pasteAction(tr("&Paste")),
|
|
|
|
|
m_selectAllAction(tr("Select &All")),
|
2016-10-16 00:48:52 +03:00
|
|
|
m_escapeAction(this)
|
2013-01-23 12:31:22 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-11 13:28:59 +01:00
|
|
|
void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContext,
|
|
|
|
|
const Core::Context &qmlDesignerFormEditorContext,
|
2020-03-12 15:55:30 +02:00
|
|
|
const Core::Context &qmlDesignerEditor3DContext,
|
2022-08-04 12:40:06 +03:00
|
|
|
const Core::Context &qmlDesignerNavigatorContext,
|
|
|
|
|
const Core::Context &qmlDesignerMaterialBrowserContext)
|
2013-01-23 12:31:22 +01:00
|
|
|
{
|
2022-08-04 12:40:06 +03:00
|
|
|
Q_UNUSED(qmlDesignerMaterialBrowserContext)
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
Core::ActionContainer *editMenu = Core::ActionManager::actionContainer(Core::Constants::M_EDIT);
|
2017-01-19 09:29:20 +01:00
|
|
|
Core::ActionContainer *fileMenu = Core::ActionManager::actionContainer(Core::Constants::M_FILE);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2017-01-17 15:33:18 +01:00
|
|
|
connect(&m_undoAction, &QAction::triggered, this, &ShortCutManager::undo);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2017-01-17 15:33:18 +01:00
|
|
|
connect(&m_redoAction, &QAction::triggered, this, &ShortCutManager::redo);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2017-01-17 15:33:18 +01:00
|
|
|
connect(&m_deleteAction, &QAction::triggered, this, &ShortCutManager::deleteSelected);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2017-01-17 15:33:18 +01:00
|
|
|
connect(&m_cutAction, &QAction::triggered, this, &ShortCutManager::cutSelected);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2017-01-17 15:33:18 +01:00
|
|
|
connect(&m_copyAction, &QAction::triggered, this, &ShortCutManager::copySelected);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2017-01-17 15:33:18 +01:00
|
|
|
connect(&m_pasteAction, &QAction::triggered, this, &ShortCutManager::paste);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2017-01-17 15:33:18 +01:00
|
|
|
connect(&m_selectAllAction,&QAction::triggered, this, &ShortCutManager::selectAll);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
// Revert to saved
|
2016-10-07 12:15:33 +02:00
|
|
|
Core::EditorManager *em = Core::EditorManager::instance();
|
2013-01-23 12:31:22 +01:00
|
|
|
Core::ActionManager::registerAction(&m_revertToSavedAction,Core::Constants::REVERTTOSAVED, qmlDesignerMainContext);
|
2017-01-17 15:33:18 +01:00
|
|
|
connect(&m_revertToSavedAction, &QAction::triggered, em, &Core::EditorManager::revertToSaved);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
//Save
|
|
|
|
|
Core::ActionManager::registerAction(&m_saveAction, Core::Constants::SAVE, qmlDesignerMainContext);
|
2018-08-01 13:46:30 +02:00
|
|
|
connect(&m_saveAction, &QAction::triggered, em, [] {
|
2017-01-19 12:09:09 +01:00
|
|
|
QmlDesignerPlugin::instance()->viewManager().reformatFileUsingTextEditorView();
|
2018-08-01 13:46:30 +02:00
|
|
|
Core::EditorManager::saveDocument();
|
2016-10-07 12:15:33 +02:00
|
|
|
});
|
|
|
|
|
|
2017-01-05 17:44:10 +01:00
|
|
|
Core::Command *command = nullptr;
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
//Save As
|
|
|
|
|
Core::ActionManager::registerAction(&m_saveAsAction, Core::Constants::SAVEAS, qmlDesignerMainContext);
|
2017-01-17 15:33:18 +01:00
|
|
|
connect(&m_saveAsAction, &QAction::triggered, em, &Core::EditorManager::saveDocumentAs);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2017-01-19 09:29:20 +01:00
|
|
|
//Export as Image
|
|
|
|
|
command = Core::ActionManager::registerAction(&m_exportAsImageAction, QmlDesigner::Constants::EXPORT_AS_IMAGE, qmlDesignerMainContext);
|
|
|
|
|
command->setAttribute(Core::Command::CA_Hide);
|
|
|
|
|
connect(&m_exportAsImageAction, &QAction::triggered, [] {
|
|
|
|
|
QmlDesignerPlugin::instance()->viewManager().exportAsImage();
|
|
|
|
|
});
|
|
|
|
|
fileMenu->addAction(command, Core::Constants::G_FILE_SAVE);
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
//Close Editor
|
|
|
|
|
Core::ActionManager::registerAction(&m_closeCurrentEditorAction, Core::Constants::CLOSE, qmlDesignerMainContext);
|
2017-01-17 15:33:18 +01:00
|
|
|
connect(&m_closeCurrentEditorAction, &QAction::triggered, em, &Core::EditorManager::slotCloseCurrentEditorOrDocument);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2017-01-05 17:44:10 +01:00
|
|
|
DesignerActionManager &designerActionManager = QmlDesignerPlugin::instance()->viewManager().designerActionManager();
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
//Close All
|
|
|
|
|
Core::ActionManager::registerAction(&m_closeAllEditorsAction, Core::Constants::CLOSEALL, qmlDesignerMainContext);
|
2019-02-22 15:46:19 +01:00
|
|
|
connect(&m_closeAllEditorsAction, &QAction::triggered, em, &Core::EditorManager::closeAllDocuments);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
//Close All Others Action
|
|
|
|
|
Core::ActionManager::registerAction(&m_closeOtherEditorsAction, Core::Constants::CLOSEOTHERS, qmlDesignerMainContext);
|
2017-09-07 17:05:47 +02:00
|
|
|
connect(&m_closeOtherEditorsAction, &QAction::triggered, em, [] {
|
2017-01-17 15:33:18 +01:00
|
|
|
Core::EditorManager::closeOtherDocuments();
|
|
|
|
|
});
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
// Undo / Redo
|
2017-01-05 17:44:10 +01:00
|
|
|
command = Core::ActionManager::registerAction(&m_undoAction, Core::Constants::UNDO, qmlDesignerMainContext);
|
|
|
|
|
designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 310, Utils::Icons::UNDO_TOOLBAR.icon());
|
|
|
|
|
command = Core::ActionManager::registerAction(&m_redoAction, Core::Constants::REDO, qmlDesignerMainContext);
|
|
|
|
|
designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 300, Utils::Icons::REDO_TOOLBAR.icon());
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
//Edit Menu
|
|
|
|
|
|
2017-01-05 17:44:10 +01:00
|
|
|
m_deleteAction.setIcon(QIcon::fromTheme(QLatin1String("edit-cut"), Utils::Icons::EDIT_CLEAR_TOOLBAR.icon()));
|
|
|
|
|
|
2017-03-09 15:11:03 +01:00
|
|
|
command = Core::ActionManager::registerAction(&m_deleteAction, QmlDesigner::Constants::C_DELETE, qmlDesignerMainContext);
|
2021-09-06 16:49:56 +02:00
|
|
|
command->setDefaultKeySequences({Qt::Key_Backspace, Qt::Key_Delete});
|
2019-07-01 16:24:30 +02:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
command->setAttribute(Core::Command::CA_Hide); // don't show delete in other modes
|
2014-04-09 13:27:47 +02:00
|
|
|
if (!Utils::HostOsInfo::isMacHost())
|
|
|
|
|
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
|
2017-01-05 17:44:10 +01:00
|
|
|
designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 280);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2014-08-04 14:19:07 +02:00
|
|
|
Core::ActionManager::registerAction(&m_cutAction, Core::Constants::CUT, qmlDesignerFormEditorContext);
|
2020-03-12 15:55:30 +02:00
|
|
|
Core::ActionManager::registerAction(&m_cutAction, Core::Constants::CUT, qmlDesignerEditor3DContext);
|
2013-01-23 12:31:22 +01:00
|
|
|
command = Core::ActionManager::registerAction(&m_cutAction, Core::Constants::CUT, qmlDesignerNavigatorContext);
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence::Cut);
|
|
|
|
|
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
|
2017-01-05 17:44:10 +01:00
|
|
|
designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 260, Utils::Icons::CUT_TOOLBAR.icon());
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2014-08-04 14:19:07 +02:00
|
|
|
Core::ActionManager::registerAction(&m_copyAction, Core::Constants::COPY, qmlDesignerFormEditorContext);
|
2020-03-12 15:55:30 +02:00
|
|
|
Core::ActionManager::registerAction(&m_copyAction, Core::Constants::COPY, qmlDesignerEditor3DContext);
|
2013-01-23 12:31:22 +01:00
|
|
|
command = Core::ActionManager::registerAction(&m_copyAction, Core::Constants::COPY, qmlDesignerNavigatorContext);
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence::Copy);
|
|
|
|
|
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
|
2017-01-05 17:44:10 +01:00
|
|
|
designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 250, Utils::Icons::COPY_TOOLBAR.icon());
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2014-08-04 14:19:07 +02:00
|
|
|
Core::ActionManager::registerAction(&m_pasteAction, Core::Constants::PASTE, qmlDesignerFormEditorContext);
|
2020-03-12 15:55:30 +02:00
|
|
|
Core::ActionManager::registerAction(&m_pasteAction, Core::Constants::PASTE, qmlDesignerEditor3DContext);
|
2013-01-23 12:31:22 +01:00
|
|
|
command = Core::ActionManager::registerAction(&m_pasteAction, Core::Constants::PASTE, qmlDesignerNavigatorContext);
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence::Paste);
|
|
|
|
|
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
|
2017-01-05 17:44:10 +01:00
|
|
|
designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 240, Utils::Icons::PASTE_TOOLBAR.icon());
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2014-08-04 14:19:07 +02:00
|
|
|
Core::ActionManager::registerAction(&m_selectAllAction, Core::Constants::SELECTALL, qmlDesignerFormEditorContext);
|
2013-01-23 12:31:22 +01:00
|
|
|
command = Core::ActionManager::registerAction(&m_selectAllAction, Core::Constants::SELECTALL, qmlDesignerNavigatorContext);
|
|
|
|
|
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence::SelectAll);
|
|
|
|
|
editMenu->addAction(command, Core::Constants::G_EDIT_SELECTALL);
|
|
|
|
|
|
2016-10-14 17:18:24 +02:00
|
|
|
/* Registering disabled action for Escape, because Qt Quick does not support shortcut overrides. */
|
|
|
|
|
command = Core::ActionManager::registerAction(&m_escapeAction, Core::Constants::S_RETURNTOEDITOR, qmlDesignerMainContext);
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence(Qt::Key_Escape));
|
|
|
|
|
m_escapeAction.setEnabled(false);
|
|
|
|
|
|
2017-02-07 12:59:38 +01:00
|
|
|
connect(designerActionManager.view(), &DesignerActionManagerView::selectionChanged, this, [this](bool itemsSelected, bool rootItemIsSelected) {
|
|
|
|
|
m_deleteAction.setEnabled(itemsSelected && !rootItemIsSelected);
|
|
|
|
|
m_cutAction.setEnabled(itemsSelected && !rootItemIsSelected);
|
2017-01-05 17:44:10 +01:00
|
|
|
m_copyAction.setEnabled(itemsSelected);
|
2018-04-16 14:21:01 +02:00
|
|
|
m_pasteAction.setEnabled(true);
|
2017-01-05 17:44:10 +01:00
|
|
|
});
|
|
|
|
|
|
2022-08-04 12:40:06 +03:00
|
|
|
connect(Core::ICore::instance(), &Core::ICore::contextChanged, this, [&](const Core::Context &context) {
|
|
|
|
|
isMatBrowserActive = context.contains(Constants::C_QMLMATERIALBROWSER);
|
|
|
|
|
|
|
|
|
|
if (!context.contains(Constants::C_QMLFORMEDITOR) && !context.contains(Constants::C_QMLEDITOR3D)
|
|
|
|
|
&& !context.contains(Constants::C_QMLNAVIGATOR)) {
|
|
|
|
|
m_deleteAction.setEnabled(isMatBrowserActive);
|
2017-03-09 15:11:03 +01:00
|
|
|
m_cutAction.setEnabled(false);
|
|
|
|
|
m_copyAction.setEnabled(false);
|
|
|
|
|
m_pasteAction.setEnabled(false);
|
2017-10-17 13:14:04 +02:00
|
|
|
} else {
|
|
|
|
|
designerActionManager.view()->emitSelectionChanged();
|
2017-03-09 15:11:03 +01:00
|
|
|
}
|
|
|
|
|
});
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2013-02-04 18:49:56 +01:00
|
|
|
void ShortCutManager::updateActions(Core::IEditor* currentEditor)
|
2013-01-23 12:31:22 +01:00
|
|
|
{
|
2014-06-13 16:21:25 +02:00
|
|
|
int openedCount = Core::DocumentModel::entryCount();
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2018-04-16 14:10:14 +02:00
|
|
|
Core::IDocument *document = nullptr;
|
2014-05-21 20:21:52 +03:00
|
|
|
if (currentEditor)
|
|
|
|
|
document = currentEditor->document();
|
|
|
|
|
m_saveAction.setEnabled(document && document->isModified());
|
|
|
|
|
m_saveAsAction.setEnabled(document && document->isSaveAsAllowed());
|
|
|
|
|
m_revertToSavedAction.setEnabled(document
|
|
|
|
|
&& !document->filePath().isEmpty()
|
|
|
|
|
&& document->isModified());
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
QString quotedName;
|
2014-09-11 11:05:45 +02:00
|
|
|
if (currentEditor && document)
|
2018-03-26 10:44:10 +02:00
|
|
|
quotedName = '"' + Utils::quoteAmpersands(document->displayName()) + '"';
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
m_saveAsAction.setText(tr("Save %1 As...").arg(quotedName));
|
|
|
|
|
m_saveAction.setText(tr("&Save %1").arg(quotedName));
|
|
|
|
|
m_revertToSavedAction.setText(tr("Revert %1 to Saved").arg(quotedName));
|
|
|
|
|
|
2018-04-16 14:10:14 +02:00
|
|
|
m_closeCurrentEditorAction.setEnabled(currentEditor != nullptr);
|
2013-01-23 12:31:22 +01:00
|
|
|
m_closeCurrentEditorAction.setText(tr("Close %1").arg(quotedName));
|
|
|
|
|
m_closeAllEditorsAction.setEnabled(openedCount > 0);
|
|
|
|
|
m_closeOtherEditorsAction.setEnabled(openedCount > 1);
|
|
|
|
|
m_closeOtherEditorsAction.setText((openedCount > 1 ? tr("Close All Except %1").arg(quotedName) : tr("Close Others")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShortCutManager::undo()
|
|
|
|
|
{
|
|
|
|
|
if (currentDesignDocument())
|
|
|
|
|
currentDesignDocument()->undo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShortCutManager::redo()
|
|
|
|
|
{
|
|
|
|
|
if (currentDesignDocument())
|
|
|
|
|
currentDesignDocument()->redo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShortCutManager::deleteSelected()
|
|
|
|
|
{
|
2022-08-04 12:40:06 +03:00
|
|
|
if (isMatBrowserActive) {
|
|
|
|
|
DesignerActionManager &designerActionManager = QmlDesignerPlugin::instance()->viewManager().designerActionManager();
|
|
|
|
|
designerActionManager.view()->emitCustomNotification("delete_selected_material");
|
|
|
|
|
} else if (currentDesignDocument()) {
|
2013-01-23 12:31:22 +01:00
|
|
|
currentDesignDocument()->deleteSelected();
|
2022-08-04 12:40:06 +03:00
|
|
|
}
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShortCutManager::cutSelected()
|
|
|
|
|
{
|
|
|
|
|
if (currentDesignDocument())
|
|
|
|
|
currentDesignDocument()->cutSelected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShortCutManager::copySelected()
|
|
|
|
|
{
|
|
|
|
|
if (currentDesignDocument())
|
|
|
|
|
currentDesignDocument()->copySelected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShortCutManager::paste()
|
|
|
|
|
{
|
|
|
|
|
if (currentDesignDocument())
|
|
|
|
|
currentDesignDocument()->paste();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShortCutManager::selectAll()
|
|
|
|
|
{
|
|
|
|
|
if (currentDesignDocument())
|
|
|
|
|
currentDesignDocument()->selectAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShortCutManager::connectUndoActions(DesignDocument *designDocument)
|
|
|
|
|
{
|
|
|
|
|
if (designDocument) {
|
2017-03-19 00:19:33 +02:00
|
|
|
connect(designDocument, &DesignDocument::undoAvailable, this, &ShortCutManager::undoAvailable);
|
|
|
|
|
connect(designDocument, &DesignDocument::redoAvailable, this, &ShortCutManager::redoAvailable);
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShortCutManager::disconnectUndoActions(DesignDocument *designDocument)
|
|
|
|
|
{
|
|
|
|
|
if (currentDesignDocument()) {
|
2017-03-19 00:19:33 +02:00
|
|
|
disconnect(designDocument, &DesignDocument::undoAvailable, this, &ShortCutManager::undoAvailable);
|
|
|
|
|
disconnect(designDocument, &DesignDocument::redoAvailable, this, &ShortCutManager::redoAvailable);
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShortCutManager::updateUndoActions(DesignDocument *designDocument)
|
|
|
|
|
{
|
|
|
|
|
if (designDocument) {
|
|
|
|
|
m_undoAction.setEnabled(designDocument->isUndoAvailable());
|
|
|
|
|
m_redoAction.setEnabled(designDocument->isRedoAvailable());
|
|
|
|
|
} else {
|
|
|
|
|
m_undoAction.setEnabled(false);
|
|
|
|
|
m_redoAction.setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DesignDocument *ShortCutManager::currentDesignDocument() const
|
|
|
|
|
{
|
|
|
|
|
return QmlDesignerPlugin::instance()->currentDesignDocument();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShortCutManager::undoAvailable(bool isAvailable)
|
|
|
|
|
{
|
2018-07-24 23:56:45 +02:00
|
|
|
auto documentController = qobject_cast<DesignDocument*>(sender());
|
2013-01-23 12:31:22 +01:00
|
|
|
if (currentDesignDocument() &&
|
|
|
|
|
currentDesignDocument() == documentController) {
|
|
|
|
|
m_undoAction.setEnabled(isAvailable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShortCutManager::redoAvailable(bool isAvailable)
|
|
|
|
|
{
|
2018-07-24 23:56:45 +02:00
|
|
|
auto documentController = qobject_cast<DesignDocument*>(sender());
|
2013-01-23 12:31:22 +01:00
|
|
|
if (currentDesignDocument() &&
|
|
|
|
|
currentDesignDocument() == documentController) {
|
|
|
|
|
m_redoAction.setEnabled(isAvailable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShortCutManager::goIntoComponent()
|
|
|
|
|
{
|
2013-08-05 16:07:31 +02:00
|
|
|
if (currentDesignDocument()
|
|
|
|
|
&& currentDesignDocument()->currentModel()
|
|
|
|
|
&& currentDesignDocument()->rewriterView()
|
|
|
|
|
&& currentDesignDocument()->rewriterView()->hasSingleSelectedModelNode()) {
|
|
|
|
|
DocumentManager::goIntoComponent(currentDesignDocument()->rewriterView()->singleSelectedModelNode());
|
|
|
|
|
}
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace QmlDesigner
|