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
This commit is contained in:
Thomas Hartmann
2010-11-17 12:59:08 +01:00
parent 9f824f4165
commit 71d98970cf
7 changed files with 90 additions and 21 deletions

View File

@@ -261,6 +261,21 @@ void FormEditorWidget::setFeedbackNode(const QmlItemNode &node)
m_graphicsView->setFeedbackNode(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;
}
} }

View File

@@ -68,6 +68,7 @@ public:
void setFeedbackNode(const QmlItemNode &node); void setFeedbackNode(const QmlItemNode &node);
QString contextHelpId() const;
protected: protected:
void enterEvent(QEvent *event); void enterEvent(QEvent *event);

View File

@@ -30,6 +30,7 @@
#include "designmodecontext.h" #include "designmodecontext.h"
#include "qmldesignerconstants.h" #include "qmldesignerconstants.h"
#include "designmodewidget.h" #include "designmodewidget.h"
#include "formeditorwidget.h"
#include <QWidget> #include <QWidget>
@@ -39,7 +40,7 @@ namespace Internal {
DesignModeContext::DesignModeContext(DesignModeWidget *widget) DesignModeContext::DesignModeContext(DesignModeWidget *widget)
: IContext(widget), : IContext(widget),
m_widget(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(); 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();
}
} }
} }

View File

@@ -38,6 +38,9 @@ class QWidget;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace QmlDesigner { namespace QmlDesigner {
class FormEditorWidget;
namespace Internal { namespace Internal {
class DesignModeWidget; class DesignModeWidget;
@@ -61,6 +64,22 @@ private:
const Core::Context m_context; 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;
};
} }
} }

View File

@@ -30,6 +30,7 @@
#include "designmodewidget.h" #include "designmodewidget.h"
#include "qmldesignerconstants.h" #include "qmldesignerconstants.h"
#include "styledoutputpaneplaceholder.h" #include "styledoutputpaneplaceholder.h"
#include "designmodecontext.h"
#include <model.h> #include <model.h>
#include <rewriterview.h> #include <rewriterview.h>
@@ -685,6 +686,9 @@ void DesignModeWidget::setup()
//### we now own these here //### we now own these here
rightLayout->addWidget(m_statesEditorWidget.data()); rightLayout->addWidget(m_statesEditorWidget.data());
FormEditorContext *context = new FormEditorContext(m_formEditorView->widget());
Core::ICore::instance()->addContextObject(context);
// editor and output panes // editor and output panes
m_outputPlaceholderSplitter->addWidget(m_formEditorView->widget()); m_outputPlaceholderSplitter->addWidget(m_formEditorView->widget());
m_outputPlaceholderSplitter->addWidget(m_outputPanePlaceholder); m_outputPlaceholderSplitter->addWidget(m_outputPanePlaceholder);

View File

@@ -37,7 +37,8 @@ const char * const DELETE = "QmlDesigner.Delete";
// context // context
const char * const C_DESIGN_MODE = "QmlDesigner::DesignMode"; 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 // special context for preview menu, shared b/w designer and text editor
const char * const C_QT_QUICK_TOOLS_MENU = "QmlDesigner::ToolsMenu"; const char * const C_QT_QUICK_TOOLS_MENU = "QmlDesigner::ToolsMenu";

View File

@@ -117,7 +117,7 @@ bool BauhausPlugin::initialize(const QStringList & /*arguments*/, QString *error
{ {
Core::ICore *core = Core::ICore::instance(); 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); QmlJSEditor::Constants::C_QMLJSEDITOR_ID);
Core::ActionManager *am = core->actionManager(); Core::ActionManager *am = core->actionManager();
@@ -162,85 +162,86 @@ void BauhausPlugin::createDesignModeWidget()
m_context = new DesignModeContext(m_mainWidget); m_context = new DesignModeContext(m_mainWidget);
creatorCore->addContextObject(m_context); 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 // Revert to saved
actionManager->registerAction(m_revertToSavedAction, actionManager->registerAction(m_revertToSavedAction,
Core::Constants::REVERTTOSAVED, formEditorContext); Core::Constants::REVERTTOSAVED, qmlDesignerMainContext);
connect(m_revertToSavedAction, SIGNAL(triggered()), m_editorManager, SLOT(revertToSaved())); connect(m_revertToSavedAction, SIGNAL(triggered()), m_editorManager, SLOT(revertToSaved()));
//Save //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())); connect(m_saveAction, SIGNAL(triggered()), m_editorManager, SLOT(saveFile()));
//Save As //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())); connect(m_saveAsAction, SIGNAL(triggered()), m_editorManager, SLOT(saveFileAs()));
//Close Editor //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())); connect(m_closeCurrentEditorAction, SIGNAL(triggered()), m_editorManager, SLOT(closeEditor()));
//Close All //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())); connect(m_closeAllEditorsAction, SIGNAL(triggered()), m_editorManager, SLOT(closeAllEditors()));
//Close All Others Action //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())); connect(m_closeOtherEditorsAction, SIGNAL(triggered()), m_editorManager, SLOT(closeOtherEditors()));
// Undo / Redo // Undo / Redo
actionManager->registerAction(m_mainWidget->undoAction(), Core::Constants::UNDO, formEditorContext); actionManager->registerAction(m_mainWidget->undoAction(), Core::Constants::UNDO, qmlDesignerMainContext);
actionManager->registerAction(m_mainWidget->redoAction(), Core::Constants::REDO, formEditorContext); actionManager->registerAction(m_mainWidget->redoAction(), Core::Constants::REDO, qmlDesignerMainContext);
Core::Command *command; Core::Command *command;
command = actionManager->registerAction(m_mainWidget->deleteAction(), command = actionManager->registerAction(m_mainWidget->deleteAction(),
QmlDesigner::Constants::DELETE, formEditorContext); QmlDesigner::Constants::DELETE, qmlDesignerFormEditorContext);
command->setDefaultKeySequence(QKeySequence::Delete); command->setDefaultKeySequence(QKeySequence::Delete);
command->setAttribute(Core::Command::CA_Hide); // don't show delete in other modes command->setAttribute(Core::Command::CA_Hide); // don't show delete in other modes
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE); editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
command = actionManager->registerAction(m_mainWidget->cutAction(), command = actionManager->registerAction(m_mainWidget->cutAction(),
Core::Constants::CUT, formEditorContext); Core::Constants::CUT, qmlDesignerFormEditorContext);
command->setDefaultKeySequence(QKeySequence::Cut); command->setDefaultKeySequence(QKeySequence::Cut);
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE); editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
command = actionManager->registerAction(m_mainWidget->copyAction(), command = actionManager->registerAction(m_mainWidget->copyAction(),
Core::Constants::COPY, formEditorContext); Core::Constants::COPY, qmlDesignerFormEditorContext);
command->setDefaultKeySequence(QKeySequence::Copy); command->setDefaultKeySequence(QKeySequence::Copy);
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE); editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
command = actionManager->registerAction(m_mainWidget->pasteAction(), command = actionManager->registerAction(m_mainWidget->pasteAction(),
Core::Constants::PASTE, formEditorContext); Core::Constants::PASTE, qmlDesignerFormEditorContext);
command->setDefaultKeySequence(QKeySequence::Paste); command->setDefaultKeySequence(QKeySequence::Paste);
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE); editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
command = actionManager->registerAction(m_mainWidget->selectAllAction(), command = actionManager->registerAction(m_mainWidget->selectAllAction(),
Core::Constants::SELECTALL, formEditorContext); Core::Constants::SELECTALL, qmlDesignerFormEditorContext);
command->setDefaultKeySequence(QKeySequence::SelectAll); command->setDefaultKeySequence(QKeySequence::SelectAll);
editMenu->addAction(command, Core::Constants::G_EDIT_SELECTALL); editMenu->addAction(command, Core::Constants::G_EDIT_SELECTALL);
Core::ActionContainer *viewsMenu = actionManager->actionContainer(Core::Constants::M_WINDOW_VIEWS); Core::ActionContainer *viewsMenu = actionManager->actionContainer(Core::Constants::M_WINDOW_VIEWS);
command = actionManager->registerAction(m_mainWidget->toggleLeftSidebarAction(), command = actionManager->registerAction(m_mainWidget->toggleLeftSidebarAction(),
Constants::TOGGLE_LEFT_SIDEBAR, formEditorContext); Constants::TOGGLE_LEFT_SIDEBAR, qmlDesignerMainContext);
command->setAttribute(Core::Command::CA_Hide); command->setAttribute(Core::Command::CA_Hide);
command->setDefaultKeySequence(QKeySequence("Ctrl+Alt+0")); command->setDefaultKeySequence(QKeySequence("Ctrl+Alt+0"));
viewsMenu->addAction(command); viewsMenu->addAction(command);
command = actionManager->registerAction(m_mainWidget->toggleRightSidebarAction(), command = actionManager->registerAction(m_mainWidget->toggleRightSidebarAction(),
Constants::TOGGLE_RIGHT_SIDEBAR, formEditorContext); Constants::TOGGLE_RIGHT_SIDEBAR, qmlDesignerMainContext);
command->setAttribute(Core::Command::CA_Hide); command->setAttribute(Core::Command::CA_Hide);
command->setDefaultKeySequence(QKeySequence("Ctrl+Alt+Shift+0")); command->setDefaultKeySequence(QKeySequence("Ctrl+Alt+Shift+0"));
viewsMenu->addAction(command); viewsMenu->addAction(command);
command = actionManager->registerAction(m_mainWidget->restoreDefaultViewAction(), command = actionManager->registerAction(m_mainWidget->restoreDefaultViewAction(),
Constants::RESTORE_DEFAULT_VIEW, formEditorContext); Constants::RESTORE_DEFAULT_VIEW, qmlDesignerMainContext);
command->setAttribute(Core::Command::CA_Hide); command->setAttribute(Core::Command::CA_Hide);
viewsMenu->addAction(command); viewsMenu->addAction(command);
command = actionManager->registerAction(m_mainWidget->hideSidebarsAction(), command = actionManager->registerAction(m_mainWidget->hideSidebarsAction(),
Core::Constants::TOGGLE_SIDEBAR, formEditorContext); Core::Constants::TOGGLE_SIDEBAR, qmlDesignerMainContext);
#ifdef Q_OS_MACX #ifdef Q_OS_MACX
// add second shortcut to trigger delete // add second shortcut to trigger delete