diff --git a/src/plugins/qmljseditor/qmlmodelmanager.cpp b/src/plugins/qmljseditor/qmlmodelmanager.cpp index 6efbc801f1532eb9a1492510725a64e34139bdba..a885181eec3030873441afa1fe5947f9c76b40c7 100644 --- a/src/plugins/qmljseditor/qmlmodelmanager.cpp +++ b/src/plugins/qmljseditor/qmlmodelmanager.cpp @@ -170,10 +170,11 @@ void QmlModelManager::parse(QFutureInterface<void> &future, doc->setSource(contents); const QFileInfo fileInfo(fileName); + Core::MimeType fileMimeTy = db->findByFile(fileInfo); - if (jsSourceTy.matchesFile(fileInfo)) + if (matchesMimeType(fileMimeTy, jsSourceTy)) doc->parseJavaScript(); - else if (qmlSourceTy.matchesFile(fileInfo)) + else if (matchesMimeType(fileMimeTy, qmlSourceTy)) doc->parseQml(); else qWarning() << "Don't know how to treat" << fileName; @@ -183,3 +184,23 @@ void QmlModelManager::parse(QFutureInterface<void> &future, future.setProgressValue(files.size()); } + +// Check whether fileMimeType is the same or extends knownMimeType +bool QmlModelManager::matchesMimeType(const Core::MimeType &fileMimeType, const Core::MimeType &knownMimeType) +{ + Core::MimeDatabase *db = Core::ICore::instance()->mimeDatabase(); + + const QStringList knownTypeNames = QStringList(knownMimeType.type()) + knownMimeType.aliases(); + + foreach (const QString knownTypeName, knownTypeNames) + if (fileMimeType.matchesType(knownTypeName)) + return true; + + // recursion to parent types of fileMimeType + foreach (const QString &parentMimeType, fileMimeType.subClassesOf()) { + if (matchesMimeType(db->findByType(parentMimeType), knownMimeType)) + return true; + } + + return false; +} diff --git a/src/plugins/qmljseditor/qmlmodelmanager.h b/src/plugins/qmljseditor/qmlmodelmanager.h index 4677248bd86b6926821453e896dbcd3ad5d68ace..9ac884abd461d687fa0cbafcaa41d7a472ec26c4 100644 --- a/src/plugins/qmljseditor/qmlmodelmanager.h +++ b/src/plugins/qmljseditor/qmlmodelmanager.h @@ -40,6 +40,7 @@ namespace Core { class ICore; +class MimeType; } namespace QmlJSEditor { @@ -82,6 +83,8 @@ protected: QmlModelManager *modelManager); private: + static bool matchesMimeType(const Core::MimeType &fileMimeType, const Core::MimeType &knownMimeType); + mutable QMutex m_mutex; Core::ICore *m_core; QmlJS::Snapshot _snapshot; diff --git a/src/plugins/qmlprojectmanager/QmlProject.mimetypes.xml b/src/plugins/qmlprojectmanager/QmlProject.mimetypes.xml index 28ba62a569c9b96382305ed36fbfa129ca45ef6d..b1d98ca63149e3c899e682a098b0bf393f916288 100644 --- a/src/plugins/qmlprojectmanager/QmlProject.mimetypes.xml +++ b/src/plugins/qmlprojectmanager/QmlProject.mimetypes.xml @@ -1,8 +1,8 @@ <?xml version="1.0"?> <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'> - <mime-type type="text/x-qml-project"> - <sub-class-of type="text/plain"/> + <mime-type type="application/x-qmlproject"> + <sub-class-of type="application/x-qml"/> <comment>Qml Project file</comment> <glob pattern="*.qmlproject"/> </mime-type> diff --git a/src/plugins/qmlprojectmanager/qmlprojectconstants.h b/src/plugins/qmlprojectmanager/qmlprojectconstants.h index 9f60a33ce439bc7886eb7ad45ec0fad09c09ca89..5acfde79830777ced7fb3ad38b80e532ed77d6ff 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectconstants.h +++ b/src/plugins/qmlprojectmanager/qmlprojectconstants.h @@ -35,7 +35,7 @@ namespace Constants { const char *const PROJECTCONTEXT = "QmlProject.ProjectContext"; const char *const LANG_QML = "QML"; -const char *const QMLMIMETYPE = "text/x-qml-project"; // ### FIXME +const char *const QMLMIMETYPE = "application/x-qmlproject"; const char *const QMLRUNCONFIGURATION = "QmlProject.QmlLocalApplicationRunConfiguration"; const char *const MAKESTEP = "QmlProject.QmlMakeStep"; diff --git a/src/plugins/qmlprojectmanager/qmlprojectfileseditor.cpp b/src/plugins/qmlprojectmanager/qmlprojectfileseditor.cpp deleted file mode 100644 index 5c710cc3b702e6525bfd54fc1f79c240bd3b11b0..0000000000000000000000000000000000000000 --- a/src/plugins/qmlprojectmanager/qmlprojectfileseditor.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "qmlprojectfileseditor.h" -#include "qmlprojectmanager.h" -#include "qmlprojectconstants.h" - -#include <coreplugin/uniqueidmanager.h> -#include <coreplugin/editormanager/editormanager.h> -#include <texteditor/fontsettings.h> -#include <texteditor/texteditoractionhandler.h> -#include <texteditor/texteditorsettings.h> - -using namespace QmlProjectManager; -using namespace QmlProjectManager::Internal; - - -//////////////////////////////////////////////////////////////////////////////////////// -// ProjectFilesFactory -//////////////////////////////////////////////////////////////////////////////////////// - -ProjectFilesFactory::ProjectFilesFactory(Manager *manager, - TextEditor::TextEditorActionHandler *handler) - : Core::IEditorFactory(manager), - m_manager(manager), - m_actionHandler(handler) -{ - m_mimeTypes.append(QLatin1String(Constants::FILES_MIMETYPE)); -} - -ProjectFilesFactory::~ProjectFilesFactory() -{ -} - -Manager *ProjectFilesFactory::manager() const -{ - return m_manager; -} - -Core::IEditor *ProjectFilesFactory::createEditor(QWidget *parent) -{ - ProjectFilesEditor *ed = new ProjectFilesEditor(parent, this, m_actionHandler); - TextEditor::TextEditorSettings::instance()->initializeEditor(ed); - return ed->editableInterface(); -} - -QStringList ProjectFilesFactory::mimeTypes() const -{ - return m_mimeTypes; -} - -QString ProjectFilesFactory::id() const -{ - return QLatin1String(Constants::FILES_EDITOR_ID); -} - -QString ProjectFilesFactory::displayName() const -{ - return tr(Constants::FILES_EDITOR_DISPLAY_NAME); -} - -Core::IFile *ProjectFilesFactory::open(const QString &fileName) -{ - Core::EditorManager *editorManager = Core::EditorManager::instance(); - - if (Core::IEditor *editor = editorManager->openEditor(fileName, id())) - return editor->file(); - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////////////// -// ProjectFilesEditable -//////////////////////////////////////////////////////////////////////////////////////// - -ProjectFilesEditable::ProjectFilesEditable(ProjectFilesEditor *editor) - : TextEditor::BaseTextEditorEditable(editor) -{ - Core::UniqueIDManager *uidm = Core::UniqueIDManager::instance(); - m_context << uidm->uniqueIdentifier(Constants::C_FILESEDITOR); -} - -ProjectFilesEditable::~ProjectFilesEditable() -{ } - -QList<int> ProjectFilesEditable::context() const -{ - return m_context; -} - -QString ProjectFilesEditable::id() const -{ - return Constants::FILES_EDITOR_ID; -} - -bool ProjectFilesEditable::duplicateSupported() const -{ - return true; -} - -Core::IEditor *ProjectFilesEditable::duplicate(QWidget *parent) -{ - ProjectFilesEditor *parentEditor = qobject_cast<ProjectFilesEditor *>(editor()); - ProjectFilesEditor *editor = new ProjectFilesEditor(parent, - parentEditor->factory(), - parentEditor->actionHandler()); - TextEditor::TextEditorSettings::instance()->initializeEditor(editor); - return editor->editableInterface(); -} - -//////////////////////////////////////////////////////////////////////////////////////// -// ProjectFilesEditor -//////////////////////////////////////////////////////////////////////////////////////// - -ProjectFilesEditor::ProjectFilesEditor(QWidget *parent, ProjectFilesFactory *factory, - TextEditor::TextEditorActionHandler *handler) - : TextEditor::BaseTextEditor(parent), - m_factory(factory), - m_actionHandler(handler) -{ - Manager *manager = factory->manager(); - ProjectFilesDocument *doc = new ProjectFilesDocument(manager); - setBaseTextDocument(doc); - - handler->setupActions(this); -} - -ProjectFilesEditor::~ProjectFilesEditor() -{ } - -ProjectFilesFactory *ProjectFilesEditor::factory() const -{ - return m_factory; -} - -TextEditor::TextEditorActionHandler *ProjectFilesEditor::actionHandler() const -{ - return m_actionHandler; -} - -TextEditor::BaseTextEditorEditable *ProjectFilesEditor::createEditableInterface() -{ - return new ProjectFilesEditable(this); -} - -//////////////////////////////////////////////////////////////////////////////////////// -// ProjectFilesDocument -//////////////////////////////////////////////////////////////////////////////////////// - -ProjectFilesDocument::ProjectFilesDocument(Manager *manager) - : m_manager(manager) -{ - setMimeType(QLatin1String(Constants::FILES_MIMETYPE)); -} - -ProjectFilesDocument::~ProjectFilesDocument() -{ } - -bool ProjectFilesDocument::save(const QString &name) -{ - if (! BaseTextDocument::save(name)) - return false; - - m_manager->notifyChanged(name); - return true; -} diff --git a/src/plugins/qmlprojectmanager/qmlprojectfileseditor.h b/src/plugins/qmlprojectmanager/qmlprojectfileseditor.h deleted file mode 100644 index 727b3b279657b8380682d536bb2df7bff5725ea6..0000000000000000000000000000000000000000 --- a/src/plugins/qmlprojectmanager/qmlprojectfileseditor.h +++ /dev/null @@ -1,125 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef QMLPROJECTFILESEDITOR_H -#define QMLPROJECTFILESEDITOR_H - -#include <texteditor/basetexteditor.h> -#include <texteditor/basetextdocument.h> - -#include <coreplugin/editormanager/ieditorfactory.h> - -namespace QmlProjectManager { -namespace Internal { - -class Manager; -class ProjectFilesEditable; -class ProjectFilesEditor; -class ProjectFilesDocument; -class ProjectFilesFactory; - -class ProjectFilesFactory: public Core::IEditorFactory -{ - Q_OBJECT - -public: - ProjectFilesFactory(Manager *manager, TextEditor::TextEditorActionHandler *handler); - virtual ~ProjectFilesFactory(); - - Manager *manager() const; - - virtual Core::IEditor *createEditor(QWidget *parent); - - virtual QStringList mimeTypes() const; - virtual QString id() const; - virtual QString displayName() const; - virtual Core::IFile *open(const QString &fileName); - -private: - Manager *m_manager; - TextEditor::TextEditorActionHandler *m_actionHandler; - QStringList m_mimeTypes; -}; - -class ProjectFilesEditable: public TextEditor::BaseTextEditorEditable -{ - Q_OBJECT - -public: - ProjectFilesEditable(ProjectFilesEditor *editor); - virtual ~ProjectFilesEditable(); - - virtual QList<int> context() const; - virtual QString id() const; - - virtual bool duplicateSupported() const; - virtual Core::IEditor *duplicate(QWidget *parent); - virtual bool isTemporary() const { return false; } - -private: - QList<int> m_context; -}; - -class ProjectFilesEditor: public TextEditor::BaseTextEditor -{ - Q_OBJECT - -public: - ProjectFilesEditor(QWidget *parent, ProjectFilesFactory *factory, - TextEditor::TextEditorActionHandler *handler); - virtual ~ProjectFilesEditor(); - - ProjectFilesFactory *factory() const; - TextEditor::TextEditorActionHandler *actionHandler() const; - - virtual TextEditor::BaseTextEditorEditable *createEditableInterface(); - -private: - ProjectFilesFactory *m_factory; - TextEditor::TextEditorActionHandler *m_actionHandler; -}; - -class ProjectFilesDocument: public TextEditor::BaseTextDocument -{ - Q_OBJECT - -public: - ProjectFilesDocument(Manager *manager); - virtual ~ProjectFilesDocument(); - - virtual bool save(const QString &name); - -private: - Manager *m_manager; -}; - -} // end of namespace Internal -} // end of namespace QmlProjectManager - -#endif // QMLPROJECTFILESEDITOR_H diff --git a/src/plugins/qmlprojectmanager/qmlprojectmanager.pro b/src/plugins/qmlprojectmanager/qmlprojectmanager.pro index ad0eb7cf71df2d543b579fe47c5e111fd400372a..6b55476c99b5afd24f7ec504c0779f2afa508ab8 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectmanager.pro +++ b/src/plugins/qmlprojectmanager/qmlprojectmanager.pro @@ -16,7 +16,6 @@ HEADERS += qmlproject.h \ qmlprojectwizard.h \ qmlnewprojectwizard.h \ qmltaskmanager.h \ - qmlprojectfileseditor.h \ qmlprojectmanager_global.h SOURCES += qmlproject.cpp \ qmlprojectplugin.cpp \ @@ -24,8 +23,7 @@ SOURCES += qmlproject.cpp \ qmlprojectnodes.cpp \ qmlprojectwizard.cpp \ qmlnewprojectwizard.cpp \ - qmltaskmanager.cpp \ - qmlprojectfileseditor.cpp + qmltaskmanager.cpp RESOURCES += qmlproject.qrc OTHER_FILES += QmlProjectManager.pluginspec diff --git a/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp b/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp index 56e058c2c8ac56529cf187880ba503b1322890a4..aaa84b111d5d4df056b59cf9b12d4e2a3c0ba0ce 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp @@ -32,7 +32,6 @@ #include "qmlprojectwizard.h" #include "qmlnewprojectwizard.h" #include "qmlprojectconstants.h" -#include "qmlprojectfileseditor.h" #include "qmlproject.h" #include "qmltaskmanager.h" @@ -52,14 +51,11 @@ using namespace QmlProjectManager; using namespace QmlProjectManager::Internal; QmlProjectPlugin::QmlProjectPlugin() : - m_projectFilesEditorFactory(0), m_qmlTaskManager(0) { } QmlProjectPlugin::~QmlProjectPlugin() { - removeObject(m_projectFilesEditorFactory); - delete m_projectFilesEditorFactory; } bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage) @@ -76,12 +72,6 @@ bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage) Manager *manager = new Manager; - TextEditor::TextEditorActionHandler *actionHandler = - new TextEditor::TextEditorActionHandler(Constants::C_FILESEDITOR); - - m_projectFilesEditorFactory = new ProjectFilesFactory(manager, actionHandler); - addObject(m_projectFilesEditorFactory); - m_qmlTaskManager = new QmlTaskManager(this); addAutoReleasedObject(manager); diff --git a/src/plugins/qmlprojectmanager/qmlprojectplugin.h b/src/plugins/qmlprojectmanager/qmlprojectplugin.h index ab5d13a57a22c84e32fde3b477a0c6a3a3046d69..5e0c1685f965b58b43cd23bb913b28cb459a2830 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectplugin.h +++ b/src/plugins/qmlprojectmanager/qmlprojectplugin.h @@ -52,7 +52,6 @@ public: virtual void extensionsInitialized(); private: - ProjectFilesFactory *m_projectFilesEditorFactory; QmlTaskManager *m_qmlTaskManager; };