Commit 2edcc7ef authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Design mode: Give IEditor a 'preferred mode'.

... and switch to it in EditorManager::activateEditor.
There no longer is a need for special currentEditorChanged()
handling in the editor that use a special mode.

QmlDesigner receives an additional setting specifying the
desired edit mode. QmlJSEditor detects whether QmlDesigner
is present by checking the registered mimetypes of the
Design mode and retrieves the settings via keys.

Remove some obsolete code and clean up includes
on qmldesignerconstants.h

Reviewed-by: con
parent 33574581
......@@ -580,7 +580,6 @@ bool BaseFileWizard::postGenerateFiles(const QWizard *w, const GeneratedFiles &l
return false;
}
}
em->ensureEditorManagerVisible();
return true;
}
......
......@@ -127,6 +127,14 @@ QString DesignMode::id() const
return QLatin1String(Constants::MODE_DESIGN);
}
QStringList DesignMode::registeredMimeTypes() const
{
QStringList rc;
foreach(const DesignEditorInfo *i, m_editors)
rc += i->mimeTypes;
return rc;
}
void DesignMode::registerDesignWidget(QWidget *widget, const QStringList &mimeTypes, bool preferDesignMode)
{
int index = m_stackWidget->addWidget(widget);
......
......@@ -78,6 +78,9 @@ public:
void registerDesignWidget(QWidget *widget, const QStringList &mimeTypes,
bool preferDesignMode = false);
void unregisterDesignWidget(QWidget *widget);
QStringList registeredMimeTypes() const;
// IContext
QList<int> context() const;
QWidget *widget();
......
......@@ -928,8 +928,14 @@ Core::IEditor *EditorManager::activateEditor(Core::Internal::EditorView *view, C
if (!(flags & NoActivate)) {
setCurrentEditor(editor, (flags & IgnoreNavigationHistory));
if (!(flags & NoModeSwitch))
ensureEditorManagerVisible();
if (!(flags & NoModeSwitch)) {
const QString preferredMode = editor->preferredMode();
if (preferredMode.isEmpty() || preferredMode == Core::Constants::MODE_EDIT) {
ensureEditorManagerVisible();
} else {
ModeManager::instance()->activateMode(preferredMode);
}
}
if (isVisible())
editor->widget()->setFocus();
}
......
......@@ -48,6 +48,8 @@
(so /bold{not} every time the document changes, but /bold{only once}).
\o If duplication is supported, you need to ensure that all duplicates
return the same file().
\o QString preferredMode() const is the mode the editor manager should activate.
Some editors use a special mode (such as Design mode).
\endlist
\sa Core::EditorFactoryInterface Core::IContext
......
......@@ -65,6 +65,8 @@ public:
virtual QWidget *toolBar() = 0;
virtual QString preferredMode() const { return QString(); }
signals:
void changed();
};
......
......@@ -715,8 +715,6 @@ void FormEditorW::currentEditorChanged(Core::IEditor *editor)
m_fwm->setActiveFormWindow(fw->formWindow());
m_actionGroupEditMode->setVisible(true);
m_modeActionSeparator->setVisible(true);
// Now switch to design mode.
m_core->modeManager()->activateMode(QLatin1String(Core::Constants::MODE_DESIGN));
} else {
// Deactivate Designer if a non-form is being edited
m_actionGroupEditMode->setVisible(false);
......
......@@ -248,8 +248,10 @@ TextEditor::PlainTextEditorEditable *FormWindowEditor::textEditable()
return &d->m_textEditable;
}
QString FormWindowEditor::preferredMode() const
{
return QLatin1String(Core::Constants::MODE_DESIGN);
}
} // namespace Designer
......@@ -88,6 +88,8 @@ public:
virtual QWidget *toolBar();
virtual QString preferredMode() const;
// IContext
virtual QList<int> context() const;
virtual QWidget *widget();
......
......@@ -28,13 +28,12 @@
**************************************************************************/
#include "designersettings.h"
#include "qmldesignerconstants.h"
#include <QtCore/QSettings>
using namespace QmlDesigner;
static const char *qmlGroup = "Qml";
static const char *qmlDesignerGroup = "Designer";
static const char *snapToGridKey = "SnapToGrid";
static const char *showBoundingRectanglesKey = "ShowBoundingRectangles";
static const char *onlyShowItemsWithContentsKey = "OnlyShowItemsWithContents";
......@@ -43,29 +42,34 @@ DesignerSettings::DesignerSettings()
: snapToGrid(false)
, showBoundingRectangles(false)
, onlyShowItemsWithContents(false)
, openDesignMode(QmlDesigner::Constants::QML_OPENDESIGNMODE_DEFAULT)
{}
void DesignerSettings::fromSettings(QSettings *settings)
{
settings->beginGroup(QLatin1String(qmlGroup));
settings->beginGroup(QLatin1String(qmlDesignerGroup));
settings->beginGroup(QLatin1String(QmlDesigner::Constants::QML_SETTINGS_GROUP));
settings->beginGroup(QLatin1String(QmlDesigner::Constants::QML_DESIGNER_SETTINGS_GROUP));
snapToGrid = settings->value(QLatin1String(snapToGridKey), false).toBool();
showBoundingRectangles = settings->value(
QLatin1String(showBoundingRectanglesKey), false).toBool();
onlyShowItemsWithContents = settings->value(
QLatin1String(onlyShowItemsWithContentsKey), false).toBool();
openDesignMode = settings->value(
QLatin1String(QmlDesigner::Constants::QML_OPENDESIGNMODE_SETTINGS_KEY),
bool(QmlDesigner::Constants::QML_OPENDESIGNMODE_DEFAULT)).toBool();
settings->endGroup();
settings->endGroup();
}
void DesignerSettings::toSettings(QSettings *settings) const
{
settings->beginGroup(QLatin1String(qmlGroup));
settings->beginGroup(QLatin1String(qmlDesignerGroup));
settings->beginGroup(QLatin1String(QmlDesigner::Constants::QML_SETTINGS_GROUP));
settings->beginGroup(QLatin1String(QmlDesigner::Constants::QML_DESIGNER_SETTINGS_GROUP));
settings->setValue(QLatin1String(snapToGridKey), snapToGrid);
settings->setValue(QLatin1String(showBoundingRectanglesKey),
showBoundingRectangles);
settings->setValue(QLatin1String(onlyShowItemsWithContentsKey),
onlyShowItemsWithContents);
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_OPENDESIGNMODE_SETTINGS_KEY), openDesignMode);
settings->endGroup();
settings->endGroup();
}
......@@ -73,5 +77,7 @@ void DesignerSettings::toSettings(QSettings *settings) const
bool DesignerSettings::equals(const DesignerSettings &other) const
{
return snapToGrid == other.snapToGrid
&& showBoundingRectangles == other.showBoundingRectangles;
&& showBoundingRectangles == other.showBoundingRectangles
&& onlyShowItemsWithContents == other.onlyShowItemsWithContents
&& openDesignMode == other.openDesignMode;
}
......@@ -50,6 +50,7 @@ struct DesignerSettings {
bool snapToGrid;
bool showBoundingRectangles;
bool onlyShowItemsWithContents;
bool openDesignMode;
};
inline bool operator==(const DesignerSettings &s1, const DesignerSettings &s2)
......
......@@ -30,8 +30,6 @@
#ifndef QMLDESIGNERPLUGIN_CONSTANTS_H
#define QMLDESIGNERPLUGIN_CONSTANTS_H
#include <coreplugin/coreconstants.h>
namespace QmlDesigner {
namespace Constants {
......@@ -46,11 +44,16 @@ const char * const SWITCH_TEXT_DESIGN = "QmlDesigner.SwitchTextDesign";
// mode
const char * const DESIGN_MODE_NAME = "Design";
const int DESIGN_MODE_PRIORITY = Core::Constants::P_MODE_EDIT - 1;
// Wizard type
const char * const FORM_MIMETYPE = "application/x-qmldesigner";
// This setting is also accessed by the QMlJsEditor.
const char * const QML_SETTINGS_GROUP = "Qml";
const char * const QML_DESIGNER_SETTINGS_GROUP = "Designer";
const char * const QML_OPENDESIGNMODE_SETTINGS_KEY = "OpenDesignMode";
enum { QML_OPENDESIGNMODE_DEFAULT = 1 };
namespace Internal {
enum { debug = 0 };
}
......
......@@ -204,7 +204,6 @@ void BauhausPlugin::createDesignModeWidget()
Core::Constants::PASTE, m_context->context());
command->setDefaultKeySequence(QKeySequence::Paste);
editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
Core::ModeManager *modeManager = creatorCore->modeManager();
command = actionManager->registerAction(m_mainWidget->selectAllAction(),
Core::Constants::SELECTALL, m_context->context());
......@@ -222,9 +221,6 @@ void BauhausPlugin::createDesignModeWidget()
connect(m_editorManager, SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateEditor(Core::IEditor*)));
connect(modeManager, SIGNAL(currentModeChanged(Core::IMode*)),
this, SLOT(modeChanged(Core::IMode*)));
connect(m_editorManager, SIGNAL(editorsClosed(QList<Core::IEditor*>)),
this, SLOT(textEditorsClosed(QList<Core::IEditor*>)));
......@@ -240,19 +236,6 @@ void BauhausPlugin::updateEditor(Core::IEditor *editor)
}
}
void BauhausPlugin::modeChanged(Core::IMode *mode)
{
if (mode == m_designMode) {
m_isActive = true;
m_mainWidget->showEditor(m_editorManager->currentEditor());
} else {
if (m_isActive) {
m_isActive = false;
m_mainWidget->showEditor(0);
}
}
}
void BauhausPlugin::textEditorsClosed(QList<Core::IEditor*> editors)
{
m_mainWidget->closeEditors(editors);
......
......@@ -81,7 +81,6 @@ public:
private slots:
void switchTextDesign();
void modeChanged(Core::IMode *mode);
void textEditorsClosed(QList<Core::IEditor *> editors);
void updateActions(Core::IEditor* editor);
void updateEditor(Core::IEditor *editor);
......
......@@ -38,6 +38,8 @@
using namespace QmlDesigner;
using namespace QmlDesigner::Internal;
enum EditModeCombo { EditModeDesign, EditModeEdit };
SettingsPageWidget::SettingsPageWidget(QWidget *parent) :
QWidget(parent)
{
......@@ -51,6 +53,7 @@ DesignerSettings SettingsPageWidget::settings() const
ds.showBoundingRectangles = m_ui.showBoundingRectanglesCheckbox->isChecked();
ds.onlyShowItemsWithContents =
m_ui.onlyShowItemsWithContentsCheckBox->isChecked();
ds.openDesignMode = m_ui.editorModeComboBox->currentIndex() == EditModeDesign;
return ds;
}
......@@ -59,6 +62,7 @@ void SettingsPageWidget::setSettings(const DesignerSettings &s)
m_ui.snapToGridCheckbox->setChecked(s.snapToGrid);
m_ui.showBoundingRectanglesCheckbox->setChecked(s.showBoundingRectangles);
m_ui.onlyShowItemsWithContentsCheckBox->setChecked(s.onlyShowItemsWithContents);
m_ui.editorModeComboBox->setCurrentIndex(s.openDesignMode ? EditModeDesign : EditModeEdit);
}
QString SettingsPageWidget::searchKeywords() const
......
......@@ -19,28 +19,49 @@
<property name="title">
<string>GroupBox</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="snapToGridCheckbox">
<property name="text">
<string>&amp;Snap to Grid</string>
</property>
</widget>
</item>
<item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="showBoundingRectanglesCheckbox">
<property name="text">
<string>Show Bounding Rectangles</string>
</property>
</widget>
</item>
<item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="onlyShowItemsWithContentsCheckBox">
<property name="text">
<string>Only Show Items with Contents</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="editorModeLabel">
<property name="text">
<string>Open editor in:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="editorModeComboBox">
<item>
<property name="text">
<string>Design mode</string>
</property>
</item>
<item>
<property name="text">
<string>Edit mode</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
......
......@@ -45,6 +45,9 @@
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/designmode.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/uniqueidmanager.h>
#include <extensionsystem/pluginmanager.h>
......@@ -53,7 +56,7 @@
#include <texteditor/textblockiterator.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h>
#include <qmldesigner/qmldesignerconstants.h>
#include <utils/changeset.h>
#include <utils/uncommentselection.h>
......@@ -574,6 +577,36 @@ QmlJSEditorEditable::QmlJSEditorEditable(QmlJSTextEditor *editor)
m_context << uidm->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR);
}
// Use preferred mode from Bauhaus settings
static bool openInDesignMode()
{
static bool bauhausDetected = false;
static bool bauhausPresent = false;
// Check if Bauhaus is loaded, that is, a Design mode widget is
// registered for the QML mime type.
if (!bauhausDetected) {
if (const Core::IMode *dm = Core::ModeManager::instance()->mode(QLatin1String(Core::Constants::MODE_DESIGN)))
if (const Core::DesignMode *designMode = qobject_cast<const Core::DesignMode *>(dm))
bauhausPresent = designMode->registeredMimeTypes().contains(QLatin1String(QmlJSEditor::Constants::QML_MIMETYPE));
bauhausDetected = true;
}
if (!bauhausPresent)
return false;
// Query the bauhaus setting if it wants to be opened in Design mode.
const QString settingsKey = QLatin1String(QmlDesigner::Constants::QML_SETTINGS_GROUP)
+ QLatin1Char('/') + QLatin1String(QmlDesigner::Constants::QML_DESIGNER_SETTINGS_GROUP)
+ QLatin1Char('/') + QLatin1String(QmlDesigner::Constants::QML_OPENDESIGNMODE_SETTINGS_KEY);
const QVariant openDesignMode = Core::ICore::instance()->settings()->value(settingsKey);
return openDesignMode.isValid() ? openDesignMode.toBool() : bool(QmlDesigner::Constants::QML_OPENDESIGNMODE_DEFAULT);
}
QString QmlJSEditorEditable::preferredMode() const
{
if (openInDesignMode())
return QLatin1String(Core::Constants::MODE_DESIGN);
return QString();
}
QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
TextEditor::BaseTextEditor(parent),
m_methodCombo(0),
......
......@@ -69,12 +69,12 @@ public:
QString id() const;
bool isTemporary() const { return false; }
virtual bool open(const QString & fileName);
virtual QString preferredMode() const;
private:
QList<int> m_context;
};
struct Declaration
{
QString text;
......
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