Switch less often to edit mode

This change
* Removes IMode::type, ModeManager::activateModeType, and
  IEditor::preferredModeType, and adds IEditor::isDesignModePreferred
  instead
* Adapts the mode switching code in EditorManager to handle multiple
  windows, for example switching to edit mode should only happen if
  the editor/view is in the main window. Otherwise the editor window
  should be raised and focused
* Renames EditorManager::NoActivate --> DoNotChangeCurrentEditor
* Reverts the EditorManager::ModeSwitch logic to switch mode or
  make the current editor visible by default, introducing
  DoNotMakeVisible flag instead
* Fixes a few instances where EditorManager::ModeSwitch should have been
  used

One non-trivial problem left: If you open a .ui file and switch to an
external editor window, edit mode is activated, because the current
editor no longer is a .ui file, which means that the design mode gets
deactivated.

Change-Id: I76c5c2391eb4090143b778fb103acff3a5a1ff41
Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
Eike Ziller
2013-05-31 12:52:53 +02:00
parent f99ce422b4
commit 7c8db79817
74 changed files with 135 additions and 233 deletions

View File

@@ -33,7 +33,6 @@
#include <qmljstools/qmljstoolsconstants.h>
#include <texteditor/texteditorconstants.h>
#include <qmldesigner/qmldesignerconstants.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <coreplugin/mimedatabase.h>
@@ -52,41 +51,13 @@ QmlJSEditorEditable::QmlJSEditorEditable(QmlJSTextEditorWidget *editor)
m_context.add(ProjectExplorer::Constants::LANG_QMLJS);
}
// 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::mode(Core::Constants::MODE_DESIGN))
if (const Core::DesignMode *designMode = qobject_cast<const Core::DesignMode *>(dm))
bauhausPresent = designMode->registeredMimeTypes().contains(QLatin1String(QmlJSTools::Constants::QML_MIMETYPE));
bauhausDetected = true;
}
if (!bauhausPresent)
return false;
return bool(QmlDesigner::Constants::QML_OPENDESIGNMODE_DEFAULT);
}
Core::Id QmlJSEditorEditable::preferredModeType() const
bool QmlJSEditorEditable::isDesignModePreferred() const
{
// stay in design mode if we are there
Core::IMode *mode = Core::ModeManager::currentMode();
if (mode && (mode->type() == Core::Constants::MODE_DESIGN_TYPE
|| mode->type() == Core::Constants::MODE_EDIT_TYPE))
{
return mode->type();
}
// 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 (editorWidget()->mimeType() == QLatin1String(QmlJSTools::Constants::QML_MIMETYPE)
&& openInDesignMode())
return Core::Id(Core::Constants::MODE_DESIGN_TYPE);
return Core::Id();
if (mode && mode->id() == Core::Constants::MODE_DESIGN)
return true;
return false;
}
void QmlJSEditorEditable::setTextCodec(QTextCodec *codec, TextCodecReason reason)