From fe48286ecc6bed40a6cc5c7575d6d960dcfe7fa6 Mon Sep 17 00:00:00 2001
From: Lasse Holmstedt <lasse.holmstedt@nokia.com>
Date: Mon, 26 Apr 2010 10:19:19 +0200
Subject: [PATCH] Made Qt Quick Designer editor opening modal If you're in
 Design mode, any new editors will open in design mode as well. If you're in
 Edit mode, new editors will open in Edit mode.

Task-number: BAUHAUS-609
---
 .../qmldesigner/qmldesignerconstants.h        |  2 +-
 src/plugins/qmldesigner/settingspage.cpp      |  4 --
 src/plugins/qmldesigner/settingspage.ui       | 45 +------------------
 src/plugins/qmljseditor/qmljseditor.cpp       | 18 +++++---
 4 files changed, 14 insertions(+), 55 deletions(-)

diff --git a/src/plugins/qmldesigner/qmldesignerconstants.h b/src/plugins/qmldesigner/qmldesignerconstants.h
index 6c2817d6884..90cb1070be1 100644
--- a/src/plugins/qmldesigner/qmldesignerconstants.h
+++ b/src/plugins/qmldesigner/qmldesignerconstants.h
@@ -57,7 +57,7 @@ const char * const QML_DESIGNER_SETTINGS_GROUP = "Designer";
 const char * const QML_OPENDESIGNMODE_SETTINGS_KEY = "OpenDesignMode";
 const char * const QML_ITEMSPACING_KEY = "ItemSpacing";
 const char * const QML_SNAPMARGIN_KEY = "SnapMargin";
-enum { QML_OPENDESIGNMODE_DEFAULT = 0 };
+enum { QML_OPENDESIGNMODE_DEFAULT = 0 }; // 0 for text mode, 1 for design mode
 
 namespace Internal {
     enum { debug = 0 };
diff --git a/src/plugins/qmldesigner/settingspage.cpp b/src/plugins/qmldesigner/settingspage.cpp
index c8ab833df24..adc8d772bef 100644
--- a/src/plugins/qmldesigner/settingspage.cpp
+++ b/src/plugins/qmldesigner/settingspage.cpp
@@ -38,8 +38,6 @@
 using namespace QmlDesigner;
 using namespace QmlDesigner::Internal;
 
-enum EditModeCombo { EditModeDesign, EditModeEdit };
-
 SettingsPageWidget::SettingsPageWidget(QWidget *parent) :
     QWidget(parent)
 {
@@ -49,7 +47,6 @@ SettingsPageWidget::SettingsPageWidget(QWidget *parent) :
 DesignerSettings SettingsPageWidget::settings() const
 {
     DesignerSettings ds;
-    ds.openDesignMode = m_ui.editorModeComboBox->currentIndex() == EditModeDesign;
     ds.itemSpacing = m_ui.spinItemSpacing->value();
     ds.snapMargin = m_ui.spinSnapMargin->value();
     return ds;
@@ -57,7 +54,6 @@ DesignerSettings SettingsPageWidget::settings() const
 
 void SettingsPageWidget::setSettings(const DesignerSettings &s)
 {
-    m_ui.editorModeComboBox->setCurrentIndex(s.openDesignMode ? EditModeDesign : EditModeEdit);
     m_ui.spinItemSpacing->setValue(s.itemSpacing);
     m_ui.spinSnapMargin->setValue(s.snapMargin);
 }
diff --git a/src/plugins/qmldesigner/settingspage.ui b/src/plugins/qmldesigner/settingspage.ui
index dfa54673f32..fdd972cb3a4 100644
--- a/src/plugins/qmldesigner/settingspage.ui
+++ b/src/plugins/qmldesigner/settingspage.ui
@@ -15,49 +15,6 @@
   </property>
   <layout class="QGridLayout" name="gridLayout_2">
    <item row="2" column="0">
-    <widget class="QGroupBox" name="groupBox_2">
-     <property name="title">
-      <string>Files</string>
-     </property>
-     <layout class="QGridLayout" name="gridLayout_3">
-      <item row="0" column="0">
-       <widget class="QLabel" name="editorModeLabel">
-        <property name="text">
-         <string>Open file in:</string>
-        </property>
-       </widget>
-      </item>
-      <item row="0" 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>
-      <item row="0" column="2">
-       <spacer name="horizontalSpacer_3">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>40</width>
-          <height>20</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-     </layout>
-    </widget>
-   </item>
-   <item row="3" column="0">
     <widget class="QGroupBox" name="groupBox_3">
      <property name="title">
       <string>Snapping</string>
@@ -141,7 +98,7 @@
      </layout>
     </widget>
    </item>
-   <item row="4" column="0">
+   <item row="3" column="0">
     <spacer name="verticalSpacer">
      <property name="orientation">
       <enum>Qt::Vertical</enum>
diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp
index 9afd59c903b..2114e03dc03 100644
--- a/src/plugins/qmljseditor/qmljseditor.cpp
+++ b/src/plugins/qmljseditor/qmljseditor.cpp
@@ -595,16 +595,22 @@ static bool openInDesignMode()
     }
     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);
+
+    return bool(QmlDesigner::Constants::QML_OPENDESIGNMODE_DEFAULT);
 }
 
 QString QmlJSEditorEditable::preferredMode() const
 {
+    Core::ModeManager *modeManager = Core::ModeManager::instance();
+    if (modeManager->currentMode()->id() == Core::Constants::MODE_DESIGN
+        || modeManager->currentMode()->id() == Core::Constants::MODE_EDIT)
+    {
+        return modeManager->currentMode()->id();
+    }
+
+    // if we are in other mode than edit or design, use the hard-coded default.
+    // because the editor opening decision is modal, it would be confusing to
+    // have the user also access to this failsafe setting.
     if (editor()->mimeType() == QLatin1String(QmlJSEditor::Constants::QML_MIMETYPE)
         && openInDesignMode())
         return QLatin1String(Core::Constants::MODE_DESIGN);
-- 
GitLab