Commit 07563f2b authored by Daniel Teske's avatar Daniel Teske

EditorManager: Don't derive IEditorFactory from IDocumentFactory

Change-Id: Ie7e42dadbdbc38ecd357a2c6bca5319f024feaac
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 9f5949e6
......@@ -60,6 +60,7 @@
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
......
......@@ -32,13 +32,8 @@
#include <utils/qtcassert.h>
Core::IEditorFactory::IEditorFactory(QObject *parent)
: IDocumentFactory(parent)
: QObject(parent)
{
setOpener([](const QString &) -> Core::IDocument * {
qWarning("This should never be called, use IEditorFactor::createEditor, "
"or EditorManager::openEditor instead!");
QTC_CHECK(false);
return 0;
});
}
......@@ -36,14 +36,28 @@ namespace Core {
class IEditor;
class CORE_EXPORT IEditorFactory : public Core::IDocumentFactory
class CORE_EXPORT IEditorFactory : public QObject
{
Q_OBJECT
public:
IEditorFactory(QObject *parent = 0);
QString displayName() const { return m_displayName; }
void setDisplayName(const QString &displayName) { m_displayName = displayName; }
Id id() const { return m_id; }
void setId(Id id) { m_id = id; }
virtual IEditor *createEditor() = 0;
QStringList mimeTypes() const { return m_mimeTypes; }
void setMimeTypes(const QStringList &mimeTypes) { m_mimeTypes = mimeTypes; }
void addMimeType(const char *mimeType) { m_mimeTypes.append(QLatin1String(mimeType)); }
void addMimeType(const QString &mimeType) { m_mimeTypes.append(mimeType); }
private:
Id m_id;
QString m_displayName;
QStringList m_mimeTypes;
};
} // namespace Core
......
......@@ -51,13 +51,9 @@ public:
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; }
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)); }
void addMimeType(const QString &mimeType) { m_mimeTypes.append(mimeType); }
......
......@@ -743,14 +743,6 @@ void MainWindow::openFile()
openFiles(EditorManager::getOpenFileNames(), ICore::SwitchMode);
}
static QList<IDocumentFactory*> getNonEditorDocumentFactories()
{
return ExtensionSystem::PluginManager::getObjects<IDocumentFactory>(
[](IDocumentFactory *factory) {
return !qobject_cast<IEditorFactory *>(factory);
});
}
static IDocumentFactory *findDocumentFactory(const QList<IDocumentFactory*> &fileFactories,
const QFileInfo &fi)
{
......@@ -776,13 +768,13 @@ static IDocumentFactory *findDocumentFactory(const QList<IDocumentFactory*> &fil
*/
IDocument *MainWindow::openFiles(const QStringList &fileNames, ICore::OpenFilesFlags flags)
{
QList<IDocumentFactory*> nonEditorFileFactories = getNonEditorDocumentFactories();
QList<IDocumentFactory*> documentFactories = ExtensionSystem::PluginManager::getObjects<IDocumentFactory>();
IDocument *res = 0;
foreach (const QString &fileName, fileNames) {
const QFileInfo fi(fileName);
const QString absoluteFilePath = fi.absoluteFilePath();
if (IDocumentFactory *documentFactory = findDocumentFactory(nonEditorFileFactories, fi)) {
if (IDocumentFactory *documentFactory = findDocumentFactory(documentFactories, fi)) {
IDocument *document = documentFactory->open(absoluteFilePath);
if (!document) {
if (flags & ICore::StopOnLoadFail)
......
......@@ -1223,9 +1223,6 @@ void ProjectExplorerPlugin::extensionsInitialized()
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;
......
......@@ -206,8 +206,6 @@ bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMess
return false;
m_fileFactory = new IDocumentFactory;
m_fileFactory->setId("ProjectExplorer.TaskFileFactory");
m_fileFactory->setDisplayName(tr("Task file reader"));
m_fileFactory->addMimeType(QLatin1String("text/x-tasklist"));
m_fileFactory->setOpener([this](const QString &fileName) -> IDocument * {
ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment