forked from qt-creator/qt-creator
Json: Use the javascript editor for json files.
Task-number: QTCREATORBUG-4639 Change-Id: Icd0fda434d5ca66056d784dd87240db76e8a442c Reviewed-on: http://codereview.qt-project.org/6035 Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
@@ -132,11 +132,6 @@ bool Document::isQmlDocument() const
|
||||
return _language == QmlLanguage;
|
||||
}
|
||||
|
||||
bool Document::isJSDocument() const
|
||||
{
|
||||
return _language == JavaScriptLanguage;
|
||||
}
|
||||
|
||||
Document::Language Document::language() const
|
||||
{
|
||||
return _language;
|
||||
|
||||
@@ -55,11 +55,13 @@ class QMLJS_EXPORT Document
|
||||
public:
|
||||
typedef QSharedPointer<Document> Ptr;
|
||||
|
||||
// used in a 3-bit bitfield
|
||||
enum Language
|
||||
{
|
||||
QmlLanguage = 0,
|
||||
JavaScriptLanguage = 1,
|
||||
UnknownLanguage = 2
|
||||
JsonLanguage = 2,
|
||||
UnknownLanguage = 3
|
||||
};
|
||||
|
||||
protected:
|
||||
@@ -73,7 +75,6 @@ public:
|
||||
Document::Ptr ptr() const;
|
||||
|
||||
bool isQmlDocument() const;
|
||||
bool isJSDocument() const;
|
||||
Language language() const;
|
||||
|
||||
AST::UiProgram *qmlProgram() const;
|
||||
@@ -119,7 +120,7 @@ private:
|
||||
QString _source;
|
||||
QWeakPointer<Document> _ptr;
|
||||
int _editorRevision;
|
||||
Language _language : 2;
|
||||
Language _language : 3;
|
||||
bool _parsedCorrectly : 1;
|
||||
|
||||
// for documentFromSource
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include <utils/networkaccessmanager.h>
|
||||
|
||||
#include <cpptools/cpptoolsconstants.h>
|
||||
#include <qmljseditor/qmljseditorconstants.h>
|
||||
#include <qmljstools/qmljstoolsconstants.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
|
||||
@@ -89,8 +89,9 @@ Protocol::ContentType Protocol::contentType(const QString &mt)
|
||||
|| mt == QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)
|
||||
|| mt == QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE))
|
||||
return C;
|
||||
if (mt == QLatin1String(QmlJSEditor::Constants::QML_MIMETYPE)
|
||||
|| mt == QLatin1String(QmlJSEditor::Constants::JS_MIMETYPE))
|
||||
if (mt == QLatin1String(QmlJSTools::Constants::QML_MIMETYPE)
|
||||
|| mt == QLatin1String(QmlJSTools::Constants::JS_MIMETYPE)
|
||||
|| mt == QLatin1String(QmlJSTools::Constants::JSON_MIMETYPE))
|
||||
return JavaScript;
|
||||
if (mt == QLatin1String("text/x-patch"))
|
||||
return Diff;
|
||||
|
||||
@@ -17,4 +17,9 @@
|
||||
<glob pattern="*.qs"/>
|
||||
<glob pattern="*.qtt"/>
|
||||
</mime-type>
|
||||
<mime-type type="application/json">
|
||||
<sub-class-of type="text/plain"/>
|
||||
<comment>JSON file</comment>
|
||||
<glob pattern="*.json"/>
|
||||
</mime-type>
|
||||
</mime-info>
|
||||
|
||||
@@ -30,9 +30,10 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "qmljseditorconstants.h"
|
||||
#include "jsfilewizard.h"
|
||||
|
||||
#include <qmljstools/qmljstoolsconstants.h>
|
||||
|
||||
#include <utils/filewizarddialog.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/filewizarddialog.h>
|
||||
@@ -104,7 +105,7 @@ Core::GeneratedFiles JsFileWizard::generateFiles(const QWizard *w,
|
||||
const QString path = wizardDialog->path();
|
||||
const QString name = wizardDialog->fileName();
|
||||
|
||||
const QString mimeType = QLatin1String(Constants::JS_MIMETYPE);
|
||||
const QString mimeType = QLatin1String(QmlJSTools::Constants::JS_MIMETYPE);
|
||||
const QString fileName = Core::BaseFileWizard::buildFileName(path, name, preferredSuffix(mimeType));
|
||||
|
||||
Core::GeneratedFile file(fileName);
|
||||
|
||||
@@ -30,9 +30,10 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "qmljseditorconstants.h"
|
||||
#include "qmlfilewizard.h"
|
||||
|
||||
#include <qmljstools/qmljstoolsconstants.h>
|
||||
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QTextStream>
|
||||
|
||||
@@ -49,7 +50,7 @@ Core::GeneratedFiles QmlFileWizard::generateFilesFromPath(const QString &path,
|
||||
QString * /*errorMessage*/) const
|
||||
|
||||
{
|
||||
const QString mimeType = QLatin1String(Constants::QML_MIMETYPE);
|
||||
const QString mimeType = QLatin1String(QmlJSTools::Constants::QML_MIMETYPE);
|
||||
const QString fileName = Core::BaseFileWizard::buildFileName(path, name, preferredSuffix(mimeType));
|
||||
|
||||
Core::GeneratedFile file(fileName);
|
||||
|
||||
@@ -58,9 +58,6 @@ const char * const RENAME_USAGES = "QmlJSEditor.RenameUsages";
|
||||
const char * const RUN_SEMANTIC_SCAN = "QmlJSEditor.RunSemanticScan";
|
||||
const char * const SHOW_QT_QUICK_HELPER = "QmlJSEditor.ShowQtQuickHelper";
|
||||
|
||||
const char * const QML_MIMETYPE = "application/x-qml";
|
||||
const char * const JS_MIMETYPE = "application/javascript";
|
||||
|
||||
const char *const TASK_CATEGORY_QML = "Task.Category.Qml";
|
||||
const char *const TASK_CATEGORY_QML_ANALYSIS = "Task.Category.QmlAnalysis";
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "qmljseditor.h"
|
||||
#include "qmljseditorconstants.h"
|
||||
|
||||
#include <qmljstools/qmljstoolsconstants.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <qmldesigner/qmldesignerconstants.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
@@ -64,7 +65,7 @@ static bool openInDesignMode()
|
||||
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));
|
||||
bauhausPresent = designMode->registeredMimeTypes().contains(QLatin1String(QmlJSTools::Constants::QML_MIMETYPE));
|
||||
bauhausDetected = true;
|
||||
}
|
||||
if (!bauhausPresent)
|
||||
@@ -86,7 +87,7 @@ QString QmlJSEditorEditable::preferredModeType() const
|
||||
// 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(QmlJSEditor::Constants::QML_MIMETYPE)
|
||||
if (editorWidget()->mimeType() == QLatin1String(QmlJSTools::Constants::QML_MIMETYPE)
|
||||
&& openInDesignMode())
|
||||
return QLatin1String(Core::Constants::MODE_DESIGN_TYPE);
|
||||
return QString();
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#include "qmljseditorconstants.h"
|
||||
#include "qmljseditorplugin.h"
|
||||
|
||||
#include <qmljstools/qmljstoolsconstants.h>
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <extensionsystem/pluginspec.h>
|
||||
|
||||
@@ -90,8 +92,9 @@ QmlJSEditorFactory::QmlJSEditorFactory(QObject *parent)
|
||||
: Core::IEditorFactory(parent)
|
||||
{
|
||||
m_mimeTypes
|
||||
<< QLatin1String(QmlJSEditor::Constants::QML_MIMETYPE)
|
||||
<< QLatin1String(QmlJSEditor::Constants::JS_MIMETYPE)
|
||||
<< QLatin1String(QmlJSTools::Constants::QML_MIMETYPE)
|
||||
<< QLatin1String(QmlJSTools::Constants::JS_MIMETYPE)
|
||||
<< QLatin1String(QmlJSTools::Constants::JSON_MIMETYPE)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -146,9 +146,10 @@ SemanticInfo SemanticInfoUpdater::semanticInfo(const SemanticInfoUpdaterSource &
|
||||
QmlJS::ScopeChain *scopeChain = new QmlJS::ScopeChain(doc, semanticInfo.context);
|
||||
semanticInfo.m_rootScopeChain = QSharedPointer<const QmlJS::ScopeChain>(scopeChain);
|
||||
|
||||
QmlJS::Check checker(doc, semanticInfo.context);
|
||||
foreach (const QmlJS::StaticAnalysis::Message &msg, checker()) {
|
||||
semanticInfo.semanticMessages += msg.toDiagnosticMessage();
|
||||
if (doc->language() != QmlJS::Document::JsonLanguage) {
|
||||
QmlJS::Check checker(doc, semanticInfo.context);
|
||||
foreach (const QmlJS::StaticAnalysis::Message &msg, checker()) {
|
||||
semanticInfo.semanticMessages += msg.toDiagnosticMessage();
|
||||
}
|
||||
|
||||
return semanticInfo;
|
||||
|
||||
@@ -75,6 +75,7 @@ QmlJS::Document::Language QmlJSTools::languageOfFile(const QString &fileName)
|
||||
{
|
||||
QStringList jsSuffixes("js");
|
||||
QStringList qmlSuffixes("qml");
|
||||
QStringList jsonSuffixes("json");
|
||||
|
||||
if (Core::ICore::instance()) {
|
||||
Core::MimeDatabase *db = Core::ICore::instance()->mimeDatabase();
|
||||
@@ -82,6 +83,8 @@ QmlJS::Document::Language QmlJSTools::languageOfFile(const QString &fileName)
|
||||
jsSuffixes = jsSourceTy.suffixes();
|
||||
Core::MimeType qmlSourceTy = db->findByType(Constants::QML_MIMETYPE);
|
||||
qmlSuffixes = qmlSourceTy.suffixes();
|
||||
Core::MimeType jsonSourceTy = db->findByType(Constants::JSON_MIMETYPE);
|
||||
jsonSuffixes = jsonSourceTy.suffixes();
|
||||
}
|
||||
|
||||
const QFileInfo info(fileName);
|
||||
@@ -90,6 +93,8 @@ QmlJS::Document::Language QmlJSTools::languageOfFile(const QString &fileName)
|
||||
return QmlJS::Document::JavaScriptLanguage;
|
||||
if (qmlSuffixes.contains(fileSuffix))
|
||||
return QmlJS::Document::QmlLanguage;
|
||||
if (jsonSuffixes.contains(fileSuffix))
|
||||
return QmlJS::Document::JsonLanguage;
|
||||
return QmlJS::Document::UnknownLanguage;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ namespace Constants {
|
||||
|
||||
const char * const QML_MIMETYPE = "application/x-qml";
|
||||
const char * const JS_MIMETYPE = "application/javascript";
|
||||
const char * const JSON_MIMETYPE = "application/json";
|
||||
|
||||
const char * const TASK_INDEX = "QmlJSEditor.TaskIndex";
|
||||
|
||||
|
||||
@@ -119,6 +119,9 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
|
||||
textEditorSettings->registerMimeTypeForLanguageId(
|
||||
QLatin1String(Constants::JS_MIMETYPE),
|
||||
Constants::QML_JS_SETTINGS_ID);
|
||||
textEditorSettings->registerMimeTypeForLanguageId(
|
||||
QLatin1String(Constants::JSON_MIMETYPE),
|
||||
Constants::QML_JS_SETTINGS_ID);
|
||||
}
|
||||
|
||||
QmlJSToolsSettings::~QmlJSToolsSettings()
|
||||
|
||||
Reference in New Issue
Block a user