diff options
author | hjk <hjk121@nokiamail.com> | 2014-06-27 23:16:13 +0200 |
---|---|---|
committer | hjk <hjk121@nokiamail.com> | 2014-07-01 13:38:07 +0200 |
commit | 76c50db4e327cb77f6cac994e18c6f51e6c4ceee (patch) | |
tree | 0954b1119e2441552b11d155ee015c0f065a9819 | |
parent | 77c7cac4b6810f4f54fa8cf321590dc42d2d8b7f (diff) |
ProjectExplorer: Fold in simple IDocumentFactory subclasses
Change-Id: Ibc2f0bc8080573f046835e348ed1c67196a4db71
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
-rw-r--r-- | src/plugins/coreplugin/coreplugin.pro | 1 | ||||
-rw-r--r-- | src/plugins/coreplugin/coreplugin.qbs | 2 | ||||
-rw-r--r-- | src/plugins/coreplugin/editormanager/ieditorfactory.cpp | 14 | ||||
-rw-r--r-- | src/plugins/coreplugin/editormanager/ieditorfactory.h | 3 | ||||
-rw-r--r-- | src/plugins/coreplugin/idocumentfactory.cpp | 42 | ||||
-rw-r--r-- | src/plugins/coreplugin/idocumentfactory.h | 8 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectexplorer.cpp | 44 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectexplorer.pro | 2 | ||||
-rw-r--r-- | src/plugins/projectexplorer/projectexplorer.qbs | 1 | ||||
-rw-r--r-- | src/plugins/tasklist/taskfilefactory.cpp | 10 | ||||
-rw-r--r-- | src/plugins/tasklist/taskfilefactory.h | 1 |
11 files changed, 102 insertions, 26 deletions
diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index 7b23ff5211..840787e563 100644 --- a/src/plugins/coreplugin/coreplugin.pro +++ b/src/plugins/coreplugin/coreplugin.pro @@ -92,6 +92,7 @@ SOURCES += mainwindow.cpp \ fileutils.cpp \ featureprovider.cpp \ idocument.cpp \ + idocumentfactory.cpp \ textdocument.cpp \ documentmanager.cpp \ removefiledialog.cpp \ diff --git a/src/plugins/coreplugin/coreplugin.qbs b/src/plugins/coreplugin/coreplugin.qbs index 6406600478..cc1e6fecb6 100644 --- a/src/plugins/coreplugin/coreplugin.qbs +++ b/src/plugins/coreplugin/coreplugin.qbs @@ -54,7 +54,7 @@ QtcPlugin { "icorelistener.cpp", "icorelistener.h", "id.cpp", "id.h", "idocument.cpp", "idocument.h", - "idocumentfactory.h", + "idocumentfactory.cpp", "idocumentfactory.h", "ifilewizardextension.h", "imode.cpp", "imode.h", "inavigationwidgetfactory.cpp", "inavigationwidgetfactory.h", diff --git a/src/plugins/coreplugin/editormanager/ieditorfactory.cpp b/src/plugins/coreplugin/editormanager/ieditorfactory.cpp index 08e45fb182..1e1da4a758 100644 --- a/src/plugins/coreplugin/editormanager/ieditorfactory.cpp +++ b/src/plugins/coreplugin/editormanager/ieditorfactory.cpp @@ -31,10 +31,14 @@ #include <utils/qtcassert.h> -Core::IDocument *Core::IEditorFactory::open(const QString &) +Core::IEditorFactory::IEditorFactory(QObject *parent) + : IDocumentFactory(parent) { - qWarning("This should never be called, use IEditorFactor::createEditor, " - "or EditorManager::openEditor instead!"); - QTC_CHECK(false); - return 0; + setOpener([](const QString &) -> Core::IDocument * { + qWarning("This should never be called, use IEditorFactor::createEditor, " + "or EditorManager::openEditor instead!"); + QTC_CHECK(false); + return 0; + }); } + diff --git a/src/plugins/coreplugin/editormanager/ieditorfactory.h b/src/plugins/coreplugin/editormanager/ieditorfactory.h index 6a08caf9c5..9f2236cc52 100644 --- a/src/plugins/coreplugin/editormanager/ieditorfactory.h +++ b/src/plugins/coreplugin/editormanager/ieditorfactory.h @@ -41,10 +41,9 @@ class CORE_EXPORT IEditorFactory : public Core::IDocumentFactory Q_OBJECT public: - IEditorFactory(QObject *parent = 0) : IDocumentFactory(parent) {} + IEditorFactory(QObject *parent = 0); virtual IEditor *createEditor() = 0; - virtual IDocument *open(const QString &); }; } // namespace Core diff --git a/src/plugins/coreplugin/idocumentfactory.cpp b/src/plugins/coreplugin/idocumentfactory.cpp new file mode 100644 index 0000000000..4455745622 --- /dev/null +++ b/src/plugins/coreplugin/idocumentfactory.cpp @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "idocumentfactory.h" + +#include <utils/qtcassert.h> + +namespace Core { + +IDocument *IDocumentFactory::open(const QString &filename) +{ + QTC_ASSERT(m_opener, return 0); + return m_opener(filename); +} + +} // namespace Core diff --git a/src/plugins/coreplugin/idocumentfactory.h b/src/plugins/coreplugin/idocumentfactory.h index a168768a1d..facb2c6c85 100644 --- a/src/plugins/coreplugin/idocumentfactory.h +++ b/src/plugins/coreplugin/idocumentfactory.h @@ -35,6 +35,8 @@ #include <QObject> #include <QStringList> +#include <functional> + namespace Core { class IDocument; @@ -46,14 +48,15 @@ class CORE_EXPORT IDocumentFactory : public QObject public: IDocumentFactory(QObject *parent = 0) : QObject(parent) {} - virtual IDocument *open(const QString &fileName) = 0; + typedef std::function<IDocument *(const QString &fileName)> Opener; + IDocument *open(const QString &filename); Id id() const { return m_id; } QStringList mimeTypes() const { return m_mimeTypes; } QString displayName() const { return m_displayName; } -protected: void setId(Id id) { m_id = id; } + void setOpener(const Opener &opener) { m_opener = opener; } void setDisplayName(const QString &displayName) { m_displayName = displayName; } void setMimeTypes(const QStringList &mimeTypes) { m_mimeTypes = mimeTypes; } void addMimeType(const char *mimeType) { m_mimeTypes.append(QLatin1String(mimeType)); } @@ -61,6 +64,7 @@ protected: private: Id m_id; + Opener m_opener; QStringList m_mimeTypes; QString m_displayName; }; diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index e372b62bd9..5f8cd008ed 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -62,7 +62,6 @@ #include "iprojectmanager.h" #include "nodesvisitor.h" #include "appoutputpane.h" -#include "pluginfilefactory.h" #include "processstep.h" #include "kitinformation.h" #include "projectfilewizardextension.h" @@ -102,6 +101,7 @@ #include <coreplugin/icore.h> #include <coreplugin/editormanager/ieditor.h> #include <coreplugin/id.h> +#include <coreplugin/idocumentfactory.h> #include <coreplugin/coreconstants.h> #include <coreplugin/documentmanager.h> #include <coreplugin/imode.h> @@ -239,7 +239,7 @@ struct ProjectExplorerPluginPrivate { Context m_lastProjectContext; Node *m_currentNode; - QList<Internal::ProjectFileFactory*> m_fileFactories; + QList<IDocumentFactory *> m_fileFactories; QStringList m_profileMimeTypes; Internal::AppOutputPane *m_outputPane; @@ -1210,11 +1210,43 @@ void ProjectExplorerPlugin::closeAllProjects() void ProjectExplorerPlugin::extensionsInitialized() { d->m_proWindow->extensionsInitialized(); - d->m_fileFactories = ProjectFileFactory::createFactories(&d->m_projectFilterString); - foreach (ProjectFileFactory *pf, d->m_fileFactories) { - d->m_profileMimeTypes += pf->mimeTypes(); - addAutoReleasedObject(pf); + + // Register factories for all project managers + QList<IProjectManager*> projectManagers = + ExtensionSystem::PluginManager::getObjects<IProjectManager>(); + + QList<Core::MimeGlobPattern> allGlobPatterns; + + const QString filterSeparator = QLatin1String(";;"); + QStringList filterStrings; + foreach (IProjectManager *manager, projectManagers) { + auto factory = new IDocumentFactory; + factory->setId(Constants::FILE_FACTORY_ID); + factory->setDisplayName(tr("Project File Factory", + "ProjectExplorer::ProjectFileFactory display name.")); + factory->addMimeType(manager->mimeType()); + factory->setOpener([this](const QString &fileName) -> IDocument* { + QString errorMessage; + ProjectExplorerPlugin::instance()->openProject(fileName, &errorMessage); + if (!errorMessage.isEmpty()) + QMessageBox::critical(Core::ICore::mainWindow(), + tr("Failed to open project"), errorMessage); + return 0; + }); + d->m_fileFactories.push_back(factory); + const QString mimeType = manager->mimeType(); + MimeType mime = MimeDatabase::findByType(mimeType); + allGlobPatterns.append(mime.globPatterns()); + filterStrings.append(mime.filterString()); + + d->m_profileMimeTypes += factory->mimeTypes(); + addAutoReleasedObject(factory); } + + filterStrings.prepend(MimeType::formatFilterString( + tr("All Projects"), allGlobPatterns)); + d->m_projectFilterString = filterStrings.join(filterSeparator); + BuildManager::extensionsInitialized(); DeviceManager::instance()->addDevice(IDevice::Ptr(new DesktopDevice)); diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro index c8c0b03c4e..94173369c3 100644 --- a/src/plugins/projectexplorer/projectexplorer.pro +++ b/src/plugins/projectexplorer/projectexplorer.pro @@ -59,7 +59,6 @@ HEADERS += projectexplorer.h \ projectexplorersettings.h \ corelistenercheckingforrunningbuild.h \ project.h \ - pluginfilefactory.h \ iprojectmanager.h \ currentprojectfilter.h \ allprojectsfind.h \ @@ -203,7 +202,6 @@ SOURCES += projectexplorer.cpp \ currentprojectfilter.cpp \ allprojectsfind.cpp \ project.cpp \ - pluginfilefactory.cpp \ buildstep.cpp \ buildconfiguration.cpp \ buildsettingspropertiespage.cpp \ diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index ef21d10fb8..e1e148ad10 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -106,7 +106,6 @@ QtcPlugin { "namedwidget.cpp", "namedwidget.h", "nodesvisitor.cpp", "nodesvisitor.h", "osparser.cpp", "osparser.h", - "pluginfilefactory.cpp", "pluginfilefactory.h", "processparameters.cpp", "processparameters.h", "processstep.cpp", "processstep.h", "processstep.ui", "project.cpp", "project.h", diff --git a/src/plugins/tasklist/taskfilefactory.cpp b/src/plugins/tasklist/taskfilefactory.cpp index 8daa3b50d6..f8aea9f034 100644 --- a/src/plugins/tasklist/taskfilefactory.cpp +++ b/src/plugins/tasklist/taskfilefactory.cpp @@ -50,12 +50,10 @@ TaskFileFactory::TaskFileFactory(QObject * parent) : setId("ProjectExplorer.TaskFileFactory"); setDisplayName(tr("Task file reader")); addMimeType(QLatin1String("text/x-tasklist")); -} - -Core::IDocument *TaskFileFactory::open(const QString &fileName) -{ - ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject(); - return open(project ? project->projectDirectory().toString() : QString(), fileName); + setOpener([this](const QString &fileName) -> Core::IDocument * { + ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject(); + return this->open(project ? project->projectDirectory().toString() : QString(), fileName); + }); } Core::IDocument *TaskFileFactory::open(const QString &base, const QString &fileName) diff --git a/src/plugins/tasklist/taskfilefactory.h b/src/plugins/tasklist/taskfilefactory.h index 96fcb7d30c..894f49f5fa 100644 --- a/src/plugins/tasklist/taskfilefactory.h +++ b/src/plugins/tasklist/taskfilefactory.h @@ -47,7 +47,6 @@ class TaskFileFactory : public Core::IDocumentFactory public: TaskFileFactory(QObject *parent = 0); - Core::IDocument *open(const QString &fileName); Core::IDocument *open(const QString &base, const QString &fileName); void closeAllFiles(); |