forked from qt-creator/qt-creator
Qt Quick: Separate Qt Quick Designer and QMLJS editor factories
Currently the QmlJSEditorFactory hardcodes that .qml.ui files are opened "in Design mode", without any option to explicitly open them directly in text mode. While this is the preferred way of working, there are always exceptions. Separate the "Edit mode by default" and the "Design mode by default" parts into separate editor factories. The former one is the default editor for .qml files, the latter for .qml.ui files. This allows users to explicitly choose "Open With > QML JS Editor" to open .qml.ui files directly in Edit mode. Fixes: QTCREATORBUG-18123 Change-Id: I72ab2d25fdc538210123782f6611f9c6e3157dea Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -1008,37 +1008,39 @@ QmlJSEditor::QmlJSEditor()
|
||||
addContext(ProjectExplorer::Constants::QMLJS_LANGUAGE_ID);
|
||||
}
|
||||
|
||||
QmlJSEditorDocument *QmlJSEditor::qmlJSDocument() const
|
||||
{
|
||||
return qobject_cast<QmlJSEditorDocument *>(document());
|
||||
}
|
||||
|
||||
bool QmlJSEditor::isDesignModePreferred() const
|
||||
{
|
||||
|
||||
bool alwaysPreferDesignMode = false;
|
||||
// always prefer design mode for .ui.qml files
|
||||
if (textDocument() && textDocument()->mimeType() == QLatin1String(QmlJSTools::Constants::QMLUI_MIMETYPE))
|
||||
alwaysPreferDesignMode = true;
|
||||
|
||||
// stay in design mode if we are there
|
||||
Id mode = ModeManager::currentModeId();
|
||||
return alwaysPreferDesignMode || mode == Core::Constants::MODE_DESIGN;
|
||||
const Id mode = ModeManager::currentModeId();
|
||||
return qmlJSDocument()->isDesignModePreferred() || mode == Core::Constants::MODE_DESIGN;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// QmlJSEditorFactory
|
||||
//
|
||||
|
||||
QmlJSEditorFactory::QmlJSEditorFactory()
|
||||
: QmlJSEditorFactory(Constants::C_QMLJSEDITOR_ID)
|
||||
{}
|
||||
|
||||
QmlJSEditorFactory::QmlJSEditorFactory(Core::Id _id)
|
||||
{
|
||||
setId(Constants::C_QMLJSEDITOR_ID);
|
||||
setId(_id);
|
||||
setDisplayName(QCoreApplication::translate("OpenWith::Editors", "QMLJS Editor"));
|
||||
|
||||
addMimeType(QmlJSTools::Constants::QML_MIMETYPE);
|
||||
addMimeType(QmlJSTools::Constants::QMLUI_MIMETYPE);
|
||||
addMimeType(QmlJSTools::Constants::QMLPROJECT_MIMETYPE);
|
||||
addMimeType(QmlJSTools::Constants::QBS_MIMETYPE);
|
||||
addMimeType(QmlJSTools::Constants::QMLTYPES_MIMETYPE);
|
||||
addMimeType(QmlJSTools::Constants::JS_MIMETYPE);
|
||||
|
||||
setDocumentCreator([]() { return new QmlJSEditorDocument; });
|
||||
setDocumentCreator([this]() { return new QmlJSEditorDocument(id()); });
|
||||
setEditorWidgetCreator([]() { return new QmlJSEditorWidget; });
|
||||
setEditorCreator([]() { return new QmlJSEditor; });
|
||||
setAutoCompleterCreator([]() { return new AutoCompleter; });
|
||||
|
||||
Reference in New Issue
Block a user