Commit 71d98970 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: adding a distinguished context for the form editor

Since Actions like copy/paste and delete interfiere
with controls like LineEdit, I added a special context
for the form editor. Now copy/paste/delete on the Qml items
are only registered for the form editor context and copying the contens
of a LineEdit will not lead to copy an item instead, anymore.

Reviewed-by: Kai Koehne
parent 9f824f41
......@@ -261,6 +261,21 @@ void FormEditorWidget::setFeedbackNode(const QmlItemNode &node)
m_graphicsView->setFeedbackNode(node);
}
QString FormEditorWidget::contextHelpId() const
{
if (!m_formEditorView)
return QString();
QList<ModelNode> nodes = m_formEditorView->selectedModelNodes();
QString helpId;
if (!nodes.isEmpty()) {
helpId = nodes.first().type();
helpId.replace("Qt/", "QML.");
}
return helpId;
}
}
......@@ -68,6 +68,7 @@ public:
void setFeedbackNode(const QmlItemNode &node);
QString contextHelpId() const;
protected:
void enterEvent(QEvent *event);
......
......@@ -30,6 +30,7 @@
#include "designmodecontext.h"
#include "qmldesignerconstants.h"
#include "designmodewidget.h"
#include "formeditorwidget.h"
#include <QWidget>
......@@ -39,7 +40,7 @@ namespace Internal {
DesignModeContext::DesignModeContext(DesignModeWidget *widget)
: IContext(widget),
m_widget(widget),
m_context(Constants::C_FORMEDITOR, Constants::C_QT_QUICK_TOOLS_MENU)
m_context(Constants::C_QMLDESIGNER, Constants::C_QT_QUICK_TOOLS_MENU)
{
}
......@@ -62,6 +63,33 @@ QString DesignModeContext::contextHelpId() const
return m_widget->contextHelpId();
}
FormEditorContext::FormEditorContext(FormEditorWidget *widget)
: IContext(widget),
m_widget(widget),
m_context(Constants::C_QMLFORMEDITOR, Constants::C_QT_QUICK_TOOLS_MENU)
{
}
FormEditorContext::~FormEditorContext()
{
}
Core::Context FormEditorContext::context() const
{
return m_context;
}
QWidget *FormEditorContext::widget()
{
return m_widget;
}
QString FormEditorContext::contextHelpId() const
{
return m_widget->contextHelpId();
}
}
}
......@@ -38,6 +38,9 @@ class QWidget;
QT_END_NAMESPACE
namespace QmlDesigner {
class FormEditorWidget;
namespace Internal {
class DesignModeWidget;
......@@ -61,6 +64,22 @@ private:
const Core::Context m_context;
};
class FormEditorContext : public Core::IContext
{
public:
FormEditorContext(FormEditorWidget *widget);
~FormEditorContext();
Core::Context context() const;
QWidget *widget();
QString contextHelpId() const;
private:
FormEditorWidget *m_widget;
const Core::Context m_context;
};
}
}
......
......@@ -30,6 +30,7 @@
#include "designmodewidget.h"
#include "qmldesignerconstants.h"
#include "styledoutputpaneplaceholder.h"
#include "designmodecontext.h"
#include <model.h>
#include <rewriterview.h>
......@@ -685,6 +686,9 @@ void DesignModeWidget::setup()
//### we now own these here
rightLayout->addWidget(m_statesEditorWidget.data());
FormEditorContext *context = new FormEditorContext(m_formEditorView->widget());
Core::ICore::instance()->addContextObject(context);
// editor and output panes
m_outputPlaceholderSplitter->addWidget(m_formEditorView->widget());
m_outputPlaceholderSplitter->addWidget(m_outputPanePlaceholder);
......
......@@ -37,7 +37,8 @@ const char * const DELETE = "QmlDesigner.Delete";
// context
const char * const C_DESIGN_MODE = "QmlDesigner::DesignMode";
const char * const C_FORMEDITOR = "QmlDesigner::QmlFormEditor";
const char * const C_QMLDESIGNER = "QmlDesigner::QmlDesignerMain";
const char * const C_QMLFORMEDITOR = "QmlDesigner::FormEditor";
// special context for preview menu, shared b/w designer and text editor
const char * const C_QT_QUICK_TOOLS_MENU = "QmlDesigner::ToolsMenu";
......
......@@ -117,7 +117,7 @@ bool BauhausPlugin::initialize(const QStringList & /*arguments*/, QString *error
{
Core::ICore *core = Core::ICore::instance();
const Core::Context switchContext(QmlDesigner::Constants::C_FORMEDITOR,
const Core::Context switchContext(QmlDesigner::Constants::C_QMLDESIGNER,
QmlJSEditor::Constants::C_QMLJSEDITOR_ID);
Core::ActionManager *am = core->actionManager();
......@@ -162,85 +162,86 @@ void BauhausPlugin::createDesignModeWidget()
m_context = new DesignModeContext(m_mainWidget);
creatorCore->addContextObject(m_context);
Core::Context formEditorContext(Constants::C_FORMEDITOR);
Core::Context qmlDesignerMainContext(Constants::C_QMLDESIGNER);
Core::Context qmlDesignerFormEditorContext(Constants::C_QMLFORMEDITOR);
// Revert to saved
actionManager->registerAction(m_revertToSavedAction,
Core::Constants::REVERTTOSAVED, formEditorContext);
Core::Constants::REVERTTOSAVED, qmlDesignerMainContext);
connect(m_revertToSavedAction, SIGNAL(triggered()), m_editorManager, SLOT(revertToSaved()));
//Save
actionManager->registerAction(m_saveAction, Core::Constants::SAVE, formEditorContext);
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, formEditorContext);
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, formEditorContext);
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, formEditorContext);
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, formEditorContext);
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, formEditorContext);
actionManager->registerAction(m_mainWidget->redoAction(), Core::Constants::REDO, formEditorContext);
actionManager->registerAction(m_mainWidget->undoAction(), Core::Constants::UNDO, qmlDesignerMainContext);
actionManager->registerAction(m_mainWidget->redoAction(), Core::Constants::REDO, qmlDesignerMainContext);
Core::Command *command;
command = actionManager->registerAction(m_mainWidget->deleteAction(),
QmlDesigner::Constants::DELETE, formEditorContext);
QmlDesigner::Constants::DELETE, qmlDesignerFormEditorContext);
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, formEditorContext);
Core::Constants::CUT, qmlDesignerFormEditorContext);
command->setDefaultKeySequence(QKeySequence::Cut);
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
command = actionManager->registerAction(m_mainWidget->copyAction(),
Core::Constants::COPY, formEditorContext);
Core::Constants::COPY, qmlDesignerFormEditorContext);
command->setDefaultKeySequence(QKeySequence::Copy);
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
command = actionManager->registerAction(m_mainWidget->pasteAction(),
Core::Constants::PASTE, formEditorContext);
Core::Constants::PASTE, qmlDesignerFormEditorContext);
command->setDefaultKeySequence(QKeySequence::Paste);
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
command = actionManager->registerAction(m_mainWidget->selectAllAction(),
Core::Constants::SELECTALL, formEditorContext);
Core::Constants::SELECTALL, qmlDesignerFormEditorContext);
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, formEditorContext);
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, formEditorContext);
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, formEditorContext);
Constants::RESTORE_DEFAULT_VIEW, qmlDesignerMainContext);
command->setAttribute(Core::Command::CA_Hide);
viewsMenu->addAction(command);
command = actionManager->registerAction(m_mainWidget->hideSidebarsAction(),
Core::Constants::TOGGLE_SIDEBAR, formEditorContext);
Core::Constants::TOGGLE_SIDEBAR, qmlDesignerMainContext);
#ifdef Q_OS_MACX
// add second shortcut to trigger delete
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment