forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -92,6 +92,7 @@ SOURCES += mainwindow.cpp \
|
||||
fileutils.cpp \
|
||||
featureprovider.cpp \
|
||||
idocument.cpp \
|
||||
idocumentfactory.cpp \
|
||||
textdocument.cpp \
|
||||
documentmanager.cpp \
|
||||
removefiledialog.cpp \
|
||||
|
@@ -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",
|
||||
|
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
42
src/plugins/coreplugin/idocumentfactory.cpp
Normal file
42
src/plugins/coreplugin/idocumentfactory.cpp
Normal file
@@ -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
|
@@ -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;
|
||||
};
|
||||
|
@@ -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));
|
||||
|
@@ -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 \
|
||||
|
@@ -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",
|
||||
|
@@ -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)
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user