void DesignerActionManager::polishActions() const { QList<ActionInterface* > actions = Utils::filtered(designerActions(), [](ActionInterface *action) { return action->type() != ActionInterface::ContextMenu; }); Core::Context qmlDesignerFormEditorContext(Constants::C_QMLFORMEDITOR); Core::Context qmlDesignerNavigatorContext(Constants::C_QMLNAVIGATOR); Core::Context qmlDesignerUIContext; qmlDesignerUIContext.add(qmlDesignerFormEditorContext); qmlDesignerUIContext.add(qmlDesignerNavigatorContext); for (auto *action : actions) { if (!action->menuId().isEmpty()) { const QString id = QString("QmlDesigner.%1").arg(QString::fromLatin1(action->menuId())); Core::Command *cmd = Core::ActionManager::registerAction(action->action(), id.toLatin1().constData(), qmlDesignerUIContext); cmd->setDefaultKeySequence(action->action()->shortcut()); cmd->setDescription(action->action()->toolTip()); action->action()->setToolTip(cmd->action()->toolTip()); action->action()->setShortcut(cmd->action()->shortcut()); action->action()->setShortcutContext(Qt::WidgetShortcut); //Hack to avoid conflicting shortcuts. We use the Core::Command for the shortcut. } } }
void QmlDesignerPlugin::createDesignModeWidget() { d->mainWidget = new Internal::DesignModeWidget; d->context = new Internal::DesignModeContext(d->mainWidget); Core::ICore::addContextObject(d->context); Core::Context qmlDesignerMainContext(Constants::C_QMLDESIGNER); Core::Context qmlDesignerFormEditorContext(Constants::C_QMLFORMEDITOR); Core::Context qmlDesignerNavigatorContext(Constants::C_QMLNAVIGATOR); d->context->context().add(qmlDesignerMainContext); d->context->context().add(qmlDesignerFormEditorContext); d->context->context().add(qmlDesignerNavigatorContext); d->context->context().add(ProjectExplorer::Constants::LANG_QMLJS); d->shortCutManager.registerActions(qmlDesignerMainContext, qmlDesignerFormEditorContext, qmlDesignerNavigatorContext); connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, [=] (Core::IEditor *editor) { if (d && checkIfEditorIsQtQuick(editor) && isInDesignerMode()) { d->shortCutManager.updateActions(editor); changeEditor(); } }); connect(Core::EditorManager::instance(), &Core::EditorManager::editorsClosed, [=] (QList<Core::IEditor*> editors) { if (d) { if (d->documentManager.hasCurrentDesignDocument() && editors.contains(d->documentManager.currentDesignDocument()->textEditor())) hideDesigner(); d->documentManager.removeEditors(editors); } }); connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeChanged, [=] (Core::Id newMode, Core::Id oldMode) { if (d && Core::EditorManager::currentEditor() && checkIfEditorIsQtQuick (Core::EditorManager::currentEditor()) && !documentIsAlreadyOpen( currentDesignDocument(), Core::EditorManager::currentEditor(), newMode)) { if (!isDesignerMode(newMode) && isDesignerMode(oldMode)) hideDesigner(); else if (Core::EditorManager::currentEditor() && isDesignerMode(newMode)) showDesigner(); else if (currentDesignDocument()) hideDesigner(); } }); }
void QmlDesignerPlugin::createDesignModeWidget() { m_mainWidget = new Internal::DesignModeWidget; m_context = new Internal::DesignModeContext(m_mainWidget); Core::ICore::addContextObject(m_context); Core::Context qmlDesignerMainContext(Constants::C_QMLDESIGNER); Core::Context qmlDesignerFormEditorContext(Constants::C_QMLFORMEDITOR); Core::Context qmlDesignerNavigatorContext(Constants::C_QMLNAVIGATOR); m_context->context().add(qmlDesignerMainContext); m_context->context().add(qmlDesignerFormEditorContext); m_context->context().add(qmlDesignerNavigatorContext); m_context->context().add(ProjectExplorer::Constants::LANG_QMLJS); m_shortCutManager.registerActions(qmlDesignerMainContext, qmlDesignerFormEditorContext, qmlDesignerNavigatorContext); connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), this, SLOT(onCurrentEditorChanged(Core::IEditor*))); connect(Core::EditorManager::instance(), SIGNAL(editorsClosed(QList<Core::IEditor*>)), this, SLOT(onTextEditorsClosed(QList<Core::IEditor*>))); // connect(Core::ICore::editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)), // &m_documentManager, SLOT(currentTextEditorChanged(Core::IEditor*))); // connect(Core::ICore::instance(), SIGNAL(contextChanged(Core::IContext*,Core::Context)), // this, SLOT(contextChanged(Core::IContext*,Core::Context))); connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*,Core::IMode*)), SLOT(onCurrentModeChanged(Core::IMode*,Core::IMode*))); }
void BauhausPlugin::createDesignModeWidget() { Core::ICore *creatorCore = Core::ICore::instance(); Core::ActionManager *actionManager = creatorCore->actionManager(); m_editorManager = creatorCore->editorManager(); Core::ActionContainer *editMenu = actionManager->actionContainer(Core::Constants::M_EDIT); m_mainWidget = new DesignModeWidget; m_context = new DesignModeContext(m_mainWidget); creatorCore->addContextObject(m_context); Core::Context qmlDesignerMainContext(Constants::C_QMLDESIGNER); Core::Context qmlDesignerFormEditorContext(Constants::C_QMLFORMEDITOR); Core::Context qmlDesignerNavigatorContext(Constants::C_QMLNAVIGATOR); // Revert to saved actionManager->registerAction(m_revertToSavedAction, Core::Constants::REVERTTOSAVED, qmlDesignerMainContext); connect(m_revertToSavedAction, SIGNAL(triggered()), m_editorManager, SLOT(revertToSaved())); //Save actionManager->registerAction(m_saveAction, Core::Constants::SAVE, qmlDesignerMainContext); connect(m_saveAction, SIGNAL(triggered()), m_editorManager, SLOT(saveFile())); //Save As actionManager->registerAction(m_saveAsAction, Core::Constants::SAVEAS, qmlDesignerMainContext); connect(m_saveAsAction, SIGNAL(triggered()), m_editorManager, SLOT(saveFileAs())); //Close Editor actionManager->registerAction(m_closeCurrentEditorAction, Core::Constants::CLOSE, qmlDesignerMainContext); connect(m_closeCurrentEditorAction, SIGNAL(triggered()), m_editorManager, SLOT(closeEditor())); //Close All actionManager->registerAction(m_closeAllEditorsAction, Core::Constants::CLOSEALL, qmlDesignerMainContext); connect(m_closeAllEditorsAction, SIGNAL(triggered()), m_editorManager, SLOT(closeAllEditors())); //Close All Others Action actionManager->registerAction(m_closeOtherEditorsAction, Core::Constants::CLOSEOTHERS, qmlDesignerMainContext); connect(m_closeOtherEditorsAction, SIGNAL(triggered()), m_editorManager, SLOT(closeOtherEditors())); // Undo / Redo actionManager->registerAction(m_mainWidget->undoAction(), Core::Constants::UNDO, qmlDesignerMainContext); actionManager->registerAction(m_mainWidget->redoAction(), Core::Constants::REDO, qmlDesignerMainContext); Core::Command *command; //GoIntoComponent command = actionManager->registerAction(m_mainWidget->goIntoComponentAction(), Constants::GO_INTO_COMPONENT, qmlDesignerMainContext); command->setDefaultKeySequence(QKeySequence(Qt::Key_F2)); //Edit Menu command = actionManager->registerAction(m_mainWidget->deleteAction(), QmlDesigner::Constants::DELETE, qmlDesignerFormEditorContext); command = actionManager->registerAction(m_mainWidget->deleteAction(), QmlDesigner::Constants::DELETE, qmlDesignerNavigatorContext); command->setDefaultKeySequence(QKeySequence::Delete); command->setAttribute(Core::Command::CA_Hide); // don't show delete in other modes editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE); command = actionManager->registerAction(m_mainWidget->cutAction(), Core::Constants::CUT, qmlDesignerFormEditorContext); command = actionManager->registerAction(m_mainWidget->cutAction(), Core::Constants::CUT, qmlDesignerNavigatorContext); command->setDefaultKeySequence(QKeySequence::Cut); editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE); command = actionManager->registerAction(m_mainWidget->copyAction(), Core::Constants::COPY, qmlDesignerFormEditorContext); command = actionManager->registerAction(m_mainWidget->copyAction(), Core::Constants::COPY, qmlDesignerNavigatorContext); command->setDefaultKeySequence(QKeySequence::Copy); editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE); command = actionManager->registerAction(m_mainWidget->pasteAction(), Core::Constants::PASTE, qmlDesignerFormEditorContext); command = actionManager->registerAction(m_mainWidget->pasteAction(), Core::Constants::PASTE, qmlDesignerNavigatorContext); command->setDefaultKeySequence(QKeySequence::Paste); editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE); command = actionManager->registerAction(m_mainWidget->selectAllAction(), Core::Constants::SELECTALL, qmlDesignerFormEditorContext); command = actionManager->registerAction(m_mainWidget->selectAllAction(), Core::Constants::SELECTALL, qmlDesignerNavigatorContext); command->setDefaultKeySequence(QKeySequence::SelectAll); editMenu->addAction(command, Core::Constants::G_EDIT_SELECTALL); Core::ActionContainer *viewsMenu = actionManager->actionContainer(Core::Constants::M_WINDOW_VIEWS); command = actionManager->registerAction(m_mainWidget->toggleLeftSidebarAction(), Constants::TOGGLE_LEFT_SIDEBAR, qmlDesignerMainContext); command->setAttribute(Core::Command::CA_Hide); command->setDefaultKeySequence(QKeySequence("Ctrl+Alt+0")); viewsMenu->addAction(command); command = actionManager->registerAction(m_mainWidget->toggleRightSidebarAction(), Constants::TOGGLE_RIGHT_SIDEBAR, qmlDesignerMainContext); command->setAttribute(Core::Command::CA_Hide); command->setDefaultKeySequence(QKeySequence("Ctrl+Alt+Shift+0")); viewsMenu->addAction(command); command = actionManager->registerAction(m_mainWidget->restoreDefaultViewAction(), Constants::RESTORE_DEFAULT_VIEW, qmlDesignerMainContext); command->setAttribute(Core::Command::CA_Hide); viewsMenu->addAction(command); command = actionManager->registerAction(m_mainWidget->hideSidebarsAction(), Core::Constants::TOGGLE_SIDEBAR, qmlDesignerMainContext); #ifdef Q_OS_MACX // add second shortcut to trigger delete QAction *deleteAction = new QAction(m_mainWidget); deleteAction->setShortcut(QKeySequence(QLatin1String("Backspace"))); connect(deleteAction, SIGNAL(triggered()), m_mainWidget->deleteAction(), SIGNAL(triggered())); m_mainWidget->addAction(deleteAction); #endif // Q_OS_MACX connect(m_editorManager, SIGNAL(currentEditorChanged(Core::IEditor*)), this, SLOT(updateEditor(Core::IEditor*))); connect(m_editorManager, SIGNAL(editorsClosed(QList<Core::IEditor*>)), this, SLOT(textEditorsClosed(QList<Core::IEditor*>))); connect(creatorCore, SIGNAL(contextChanged(Core::IContext*,Core::Context)), this, SLOT(contextChanged(Core::IContext*,Core::Context))); }