Commit 93c3ee1b authored by Thomas Hartmann's avatar Thomas Hartmann

QmlJSEditor: warn when editing .ui.qml, activate designer checks

Change-Id: I2f6d39633341bd1197d16c5c097573d4ab090896
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent e2456cf8
......@@ -568,12 +568,13 @@ Check::Check(Document::Ptr doc, const ContextPtr &context)
disableMessage(HintBinaryOperatorSpacing);
disableMessage(HintOneStatementPerLine);
disableMessage(HintExtraParentheses);
disableMessage(WarnImperativeCodeNotEditableInVisualDesigner);
disableMessage(WarnUnsupportedTypeInVisualDesigner);
disableMessage(WarnReferenceToParentItemNotSupportedByVisualDesigner);
disableMessage(WarnUndefinedValueForVisualDesigner);
disableMessage(WarnStatesOnlyInRootItemForVisualDesigner);
disableMessage(ErrUnsupportedRootTypeInVisualDesigner);
if (isQtQuick2Ui()) {
enableQmlDesignerChecks();
} else {
disableQmlDesignerChecks();
disableQmlDesignerUiFileChecks();
}
}
Check::~Check()
......@@ -601,6 +602,37 @@ void Check::disableMessage(Type type)
_enabledMessages.remove(type);
}
void Check::enableQmlDesignerChecks()
{
enableMessage(StaticAnalysis::WarnImperativeCodeNotEditableInVisualDesigner);
enableMessage(StaticAnalysis::WarnUnsupportedTypeInVisualDesigner);
enableMessage(StaticAnalysis::WarnReferenceToParentItemNotSupportedByVisualDesigner);
enableMessage(StaticAnalysis::WarnReferenceToParentItemNotSupportedByVisualDesigner);
enableMessage(StaticAnalysis::WarnAboutQtQuick1InsteadQtQuick2);
enableMessage(StaticAnalysis::ErrUnsupportedRootTypeInVisualDesigner);
//## triggers too often ## check.enableMessage(StaticAnalysis::WarnUndefinedValueForVisualDesigner);
}
void Check::disableQmlDesignerChecks()
{
disableMessage(WarnImperativeCodeNotEditableInVisualDesigner);
disableMessage(WarnUnsupportedTypeInVisualDesigner);
disableMessage(WarnReferenceToParentItemNotSupportedByVisualDesigner);
disableMessage(WarnUndefinedValueForVisualDesigner);
disableMessage(WarnStatesOnlyInRootItemForVisualDesigner);
disableMessage(ErrUnsupportedRootTypeInVisualDesigner);
}
void Check::enableQmlDesignerUiFileChecks()
{
}
void Check::disableQmlDesignerUiFileChecks()
{
}
bool Check::preVisit(Node *ast)
{
_chain.append(ast);
......
......@@ -59,6 +59,12 @@ public:
void enableMessage(StaticAnalysis::Type type);
void disableMessage(StaticAnalysis::Type type);
void enableQmlDesignerChecks();
void disableQmlDesignerChecks();
void enableQmlDesignerUiFileChecks();
void disableQmlDesignerUiFileChecks();
protected:
bool preVisit(AST::Node *ast) Q_DECL_OVERRIDE;
void postVisit(AST::Node *ast) Q_DECL_OVERRIDE;
......
......@@ -56,6 +56,7 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/id.h>
#include <coreplugin/infobar.h>
#include <coreplugin/modemanager.h>
#include <extensionsystem/pluginmanager.h>
......@@ -109,6 +110,7 @@ QmlJSEditorWidget::QmlJSEditorWidget()
{
m_outlineCombo = 0;
m_contextPane = 0;
m_firstSementicInfo = true;
m_findReferences = new FindReferences(this);
setParenthesesMatchingEnabled(true);
......@@ -788,6 +790,16 @@ void QmlJSEditorWidget::semanticInfoUpdated(const SemanticInfo &semanticInfo)
}
}
if (m_firstSementicInfo) {
m_firstSementicInfo = false;
if (semanticInfo.document->language() == Dialect::QmlQtQuick2Ui) {
Core::InfoBarEntry info(Core::Id(Constants::QML_UI_FILE_WARNING),
tr("This file should only be edited in <b>Design</b> mode."));
info.setCustomButtonInfo(tr("Switch Mode"), []() { ModeManager::activateMode(Core::Constants::MODE_DESIGN); });
textDocument()->infoBar()->addInfo(info);
}
}
updateUses();
}
......@@ -873,9 +885,16 @@ QmlJSEditor::QmlJSEditor()
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
IMode *mode = ModeManager::currentMode();
return mode && mode->id() == Core::Constants::MODE_DESIGN;
return alwaysPreferDesignMode
|| (mode && mode->id() == Core::Constants::MODE_DESIGN);
}
......
......@@ -135,6 +135,8 @@ private:
int m_oldCursorPosition;
FindReferences *m_findReferences;
bool m_firstSementicInfo;
};
......
......@@ -59,6 +59,8 @@ const char QML_SNIPPETS_GROUP_ID[] = "QML";
const char QML_CONTEXTPANE_KEY[] = "QmlJSEditor.ContextPaneEnabled";
const char QML_CONTEXTPANEPIN_KEY[] = "QmlJSEditor.ContextPanePinned";
const char QML_UI_FILE_WARNING[] = "QmlJSEditor.QmlUiFileWarning";
} // namespace Constants
} // namespace QmlJSEditor
......
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