forked from qt-creator/qt-creator
QmlJS: Use mime types to distinguish qml and js files.
This allows adding patterns to the qml mime type in the options dialog. Previously they were always parsed as js. Change-Id: Ifa344fb6ab8cbcda02becef991cf6807615a1caa Reviewed-on: http://codereview.qt-project.org/4515 Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
This commit is contained in:
@@ -83,23 +83,20 @@ using namespace QmlJS::AST;
|
||||
*/
|
||||
|
||||
|
||||
Document::Document(const QString &fileName)
|
||||
Document::Document(const QString &fileName, Language language)
|
||||
: _engine(0)
|
||||
, _pool(0)
|
||||
, _ast(0)
|
||||
, _bind(0)
|
||||
, _isQmlDocument(false)
|
||||
, _editorRevision(0)
|
||||
, _parsedCorrectly(false)
|
||||
, _fileName(QDir::cleanPath(fileName))
|
||||
, _editorRevision(0)
|
||||
, _language(language)
|
||||
, _parsedCorrectly(false)
|
||||
{
|
||||
QFileInfo fileInfo(fileName);
|
||||
_path = QDir::cleanPath(fileInfo.absolutePath());
|
||||
|
||||
// ### Should use mime type
|
||||
if (fileInfo.suffix() == QLatin1String("qml")
|
||||
|| fileInfo.suffix() == QLatin1String("qmlproject")) {
|
||||
_isQmlDocument = true;
|
||||
if (language == QmlLanguage) {
|
||||
_componentName = fileInfo.baseName();
|
||||
|
||||
if (! _componentName.isEmpty()) {
|
||||
@@ -123,9 +120,9 @@ Document::~Document()
|
||||
delete _pool;
|
||||
}
|
||||
|
||||
Document::Ptr Document::create(const QString &fileName)
|
||||
Document::Ptr Document::create(const QString &fileName, Language language)
|
||||
{
|
||||
Document::Ptr doc(new Document(fileName));
|
||||
Document::Ptr doc(new Document(fileName, language));
|
||||
doc->_ptr = doc;
|
||||
return doc;
|
||||
}
|
||||
@@ -137,12 +134,17 @@ Document::Ptr Document::ptr() const
|
||||
|
||||
bool Document::isQmlDocument() const
|
||||
{
|
||||
return _isQmlDocument;
|
||||
return _language == QmlLanguage;
|
||||
}
|
||||
|
||||
bool Document::isJSDocument() const
|
||||
{
|
||||
return ! _isQmlDocument;
|
||||
return _language == JavaScriptLanguage;
|
||||
}
|
||||
|
||||
Document::Language Document::language() const
|
||||
{
|
||||
return _language;
|
||||
}
|
||||
|
||||
AST::UiProgram *Document::qmlProgram() const
|
||||
@@ -422,9 +424,10 @@ void Snapshot::remove(const QString &fileName)
|
||||
}
|
||||
|
||||
Document::Ptr Snapshot::documentFromSource(const QString &code,
|
||||
const QString &fileName) const
|
||||
const QString &fileName,
|
||||
Document::Language language) const
|
||||
{
|
||||
Document::Ptr newDoc = Document::create(fileName);
|
||||
Document::Ptr newDoc = Document::create(fileName, language);
|
||||
|
||||
if (Document::Ptr thisDocument = document(fileName)) {
|
||||
newDoc->_editorRevision = thisDocument->_editorRevision;
|
||||
|
@@ -56,18 +56,26 @@ class QMLJS_EXPORT Document
|
||||
public:
|
||||
typedef QSharedPointer<Document> Ptr;
|
||||
|
||||
enum Language
|
||||
{
|
||||
QmlLanguage = 0,
|
||||
JavaScriptLanguage = 1,
|
||||
UnknownLanguage = 2
|
||||
};
|
||||
|
||||
protected:
|
||||
Document(const QString &fileName);
|
||||
Document(const QString &fileName, Language language);
|
||||
|
||||
public:
|
||||
~Document();
|
||||
|
||||
static Document::Ptr create(const QString &fileName);
|
||||
static Document::Ptr create(const QString &fileName, Language language);
|
||||
|
||||
Document::Ptr ptr() const;
|
||||
|
||||
bool isQmlDocument() const;
|
||||
bool isJSDocument() const;
|
||||
Language language() const;
|
||||
|
||||
AST::UiProgram *qmlProgram() const;
|
||||
AST::Program *jsProgram() const;
|
||||
@@ -107,15 +115,15 @@ private:
|
||||
NodePool *_pool;
|
||||
AST::Node *_ast;
|
||||
Bind *_bind;
|
||||
bool _isQmlDocument;
|
||||
int _editorRevision;
|
||||
bool _parsedCorrectly;
|
||||
QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
|
||||
QString _fileName;
|
||||
QString _path;
|
||||
QString _componentName;
|
||||
QString _source;
|
||||
QWeakPointer<Document> _ptr;
|
||||
int _editorRevision;
|
||||
Language _language : 2;
|
||||
bool _parsedCorrectly : 1;
|
||||
|
||||
// for documentFromSource
|
||||
friend class Snapshot;
|
||||
@@ -211,7 +219,8 @@ public:
|
||||
LibraryInfo libraryInfo(const QString &path) const;
|
||||
|
||||
Document::Ptr documentFromSource(const QString &code,
|
||||
const QString &fileName) const;
|
||||
const QString &fileName,
|
||||
Document::Language language) const;
|
||||
};
|
||||
|
||||
} // namespace QmlJS
|
||||
|
Reference in New Issue
Block a user