Commit b772001c authored by hjk's avatar hjk

EditorFactory: Replace some virtual functions with data members

Change-Id: I014cb57460c4e3a36bf7403960908b5ffec867ff
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent be112d85
......@@ -44,21 +44,9 @@ AndroidManifestEditorFactory::AndroidManifestEditorFactory(QObject *parent)
: Core::IEditorFactory(parent),
m_actionHandler(new TextEditor::TextEditorActionHandler(Constants::ANDROID_MANIFEST_EDITOR_CONTEXT))
{
}
QStringList AndroidManifestEditorFactory::mimeTypes() const
{
return QStringList() << QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE);
}
Core::Id AndroidManifestEditorFactory::id() const
{
return Constants::ANDROID_MANIFEST_EDITOR_ID;
}
QString AndroidManifestEditorFactory::displayName() const
{
return tr("Android Manifest editor");
setId(Constants::ANDROID_MANIFEST_EDITOR_ID);
setDisplayName(tr("Android Manifest editor"));
addMimeType(Constants::ANDROID_MANIFEST_MIME_TYPE);
}
Core::IEditor *AndroidManifestEditorFactory::createEditor(QWidget *parent)
......
......@@ -40,14 +40,12 @@ namespace Internal {
class AndroidManifestEditorFactory : public Core::IEditorFactory
{
Q_OBJECT
public:
explicit AndroidManifestEditorFactory(QObject *parent = 0);
QStringList mimeTypes() const;
Core::Id id() const;
QString displayName() const;
Core::IEditor *createEditor(QWidget *parent);
private:
TextEditor::TextEditorActionHandler *m_actionHandler;
};
......
......@@ -402,19 +402,11 @@ private:
///////////////////////////////// BinEditorFactory //////////////////////////////////
BinEditorFactory::BinEditorFactory(BinEditorPlugin *owner) :
m_mimeTypes(QLatin1String(Constants::C_BINEDITOR_MIMETYPE)),
m_owner(owner)
{
}
Core::Id BinEditorFactory::id() const
{
return Core::Id(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
}
QString BinEditorFactory::displayName() const
{
return qApp->translate("OpenWith::Editors", Constants::C_BINEDITOR_DISPLAY_NAME);
setId(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
setDisplayName(qApp->translate("OpenWith::Editors", Constants::C_BINEDITOR_DISPLAY_NAME));
addMimeType(Constants::C_BINEDITOR_MIMETYPE);
}
Core::IEditor *BinEditorFactory::createEditor(QWidget *parent)
......@@ -426,10 +418,6 @@ Core::IEditor *BinEditorFactory::createEditor(QWidget *parent)
return editor;
}
QStringList BinEditorFactory::mimeTypes() const
{
return m_mimeTypes;
}
/*!
\class BINEditor::BinEditorWidgetFactory
......
......@@ -102,13 +102,9 @@ class BinEditorFactory : public Core::IEditorFactory
public:
explicit BinEditorFactory(BinEditorPlugin *owner);
QStringList mimeTypes() const;
Core::IEditor *createEditor(QWidget *parent);
Core::Id id() const;
QString displayName() const;
private:
const QStringList m_mimeTypes;
BinEditorPlugin *m_owner;
};
......
......@@ -43,12 +43,15 @@ using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;
CMakeEditorFactory::CMakeEditorFactory(CMakeManager *manager)
: m_mimeTypes(QStringList() << QLatin1String(CMakeProjectManager::Constants::CMAKEMIMETYPE)),
m_manager(manager)
: m_manager(manager)
{
using namespace Core;
using namespace TextEditor;
setId(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
setDisplayName(tr(CMakeProjectManager::Constants::CMAKE_EDITOR_DISPLAY_NAME));
addMimeType(CMakeProjectManager::Constants::CMAKEMIMETYPE);
m_actionHandler =
new TextEditorActionHandler(Constants::C_CMAKEEDITOR,
TextEditorActionHandler::UnCommentSelection
......@@ -67,24 +70,9 @@ CMakeEditorFactory::CMakeEditorFactory(CMakeManager *manager)
contextMenu->addAction(cmd);
}
Core::Id CMakeEditorFactory::id() const
{
return Core::Id(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
}
QString CMakeEditorFactory::displayName() const
{
return tr(CMakeProjectManager::Constants::CMAKE_EDITOR_DISPLAY_NAME);
}
Core::IEditor *CMakeEditorFactory::createEditor(QWidget *parent)
{
CMakeEditorWidget *rc = new CMakeEditorWidget(parent, this, m_actionHandler);
TextEditor::TextEditorSettings::instance()->initializeEditor(rc);
return rc->editor();
}
QStringList CMakeEditorFactory::mimeTypes() const
{
return m_mimeTypes;
}
......@@ -34,11 +34,7 @@
#include <coreplugin/editormanager/ieditorfactory.h>
#include <QStringList>
namespace TextEditor {
class TextEditorActionHandler;
}
namespace TextEditor { class TextEditorActionHandler; }
namespace CMakeProjectManager {
namespace Internal {
......@@ -49,11 +45,6 @@ class CMakeEditorFactory : public Core::IEditorFactory
public:
CMakeEditorFactory(CMakeManager *parent);
// IEditorFactory
QStringList mimeTypes() const;
Core::Id id() const;
QString displayName() const;
Core::IEditor *createEditor(QWidget *parent);
private:
......
......@@ -30,18 +30,14 @@
#ifndef IDOCUMENTFACTORY_H
#define IDOCUMENTFACTORY_H
#include "core_global.h"
#include "id.h"
#include <QObject>
QT_BEGIN_NAMESPACE
class QStringList;
QT_END_NAMESPACE
#include <QStringList>
namespace Core {
class IDocument;
class Id;
class CORE_EXPORT IDocumentFactory : public QObject
{
......@@ -50,10 +46,23 @@ class CORE_EXPORT IDocumentFactory : public QObject
public:
IDocumentFactory(QObject *parent = 0) : QObject(parent) {}
virtual QStringList mimeTypes() const = 0;
virtual Id id() const = 0;
virtual QString displayName() const = 0;
virtual IDocument *open(const QString &fileName) = 0;
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 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); }
private:
Id m_id;
QStringList m_mimeTypes;
QString m_displayName;
};
} // namespace Core
......
......@@ -68,10 +68,12 @@ enum { QUICKFIX_INTERVAL = 20 };
CppEditorFactory::CppEditorFactory(CppEditorPlugin *owner) :
m_owner(owner)
{
m_mimeTypes << QLatin1String(CppEditor::Constants::C_SOURCE_MIMETYPE)
<< QLatin1String(CppEditor::Constants::C_HEADER_MIMETYPE)
<< QLatin1String(CppEditor::Constants::CPP_SOURCE_MIMETYPE)
<< QLatin1String(CppEditor::Constants::CPP_HEADER_MIMETYPE);
setId(CppEditor::Constants::CPPEDITOR_ID);
setDisplayName(qApp->translate("OpenWith::Editors", CppEditor::Constants::CPPEDITOR_DISPLAY_NAME));
addMimeType(CppEditor::Constants::C_SOURCE_MIMETYPE);
addMimeType(CppEditor::Constants::C_HEADER_MIMETYPE);
addMimeType(CppEditor::Constants::CPP_SOURCE_MIMETYPE);
addMimeType(CppEditor::Constants::CPP_HEADER_MIMETYPE);
if (!Utils::HostOsInfo::isMacHost() && !Utils::HostOsInfo::isWindowsHost()) {
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
......@@ -85,16 +87,6 @@ CppEditorFactory::CppEditorFactory(CppEditorPlugin *owner) :
}
}
Core::Id CppEditorFactory::id() const
{
return Core::Id(CppEditor::Constants::CPPEDITOR_ID);
}
QString CppEditorFactory::displayName() const
{
return qApp->translate("OpenWith::Editors", CppEditor::Constants::CPPEDITOR_DISPLAY_NAME);
}
Core::IEditor *CppEditorFactory::createEditor(QWidget *parent)
{
CPPEditorWidget *editor = new CPPEditorWidget(parent);
......@@ -103,11 +95,6 @@ Core::IEditor *CppEditorFactory::createEditor(QWidget *parent)
return editor->editor();
}
QStringList CppEditorFactory::mimeTypes() const
{
return m_mimeTypes;
}
///////////////////////////////// CppEditorPlugin //////////////////////////////////
CppEditorPlugin *CppEditorPlugin::m_instance = 0;
......
......@@ -35,7 +35,6 @@
#include <extensionsystem/iplugin.h>
#include <QtPlugin>
#include <QStringList>
#include <QAction>
namespace TextEditor {
......@@ -286,15 +285,10 @@ class CppEditorFactory : public Core::IEditorFactory
public:
CppEditorFactory(CppEditorPlugin *owner);
// IEditorFactory
QStringList mimeTypes() const;
Core::IEditor *createEditor(QWidget *parent);
Core::Id id() const;
QString displayName() const;
private:
CppEditorPlugin *m_owner;
QStringList m_mimeTypes;
};
} // namespace Internal
......
......@@ -48,24 +48,17 @@ namespace Designer {
namespace Internal {
FormEditorFactory::FormEditorFactory()
: Core::IEditorFactory(Core::ICore::instance()),
m_mimeTypes(QLatin1String(FORM_MIMETYPE))
: Core::IEditorFactory(Core::ICore::instance())
{
setId(K_DESIGNER_XML_EDITOR_ID);
setDisplayName(qApp->translate("Designer", C_DESIGNER_XML_DISPLAY_NAME));
addMimeType(FORM_MIMETYPE);
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
iconProvider->registerIconOverlayForSuffix(QIcon(QLatin1String(":/formeditor/images/qt_ui.png")),
QLatin1String("ui"));
}
Core::Id FormEditorFactory::id() const
{
return Core::Id(K_DESIGNER_XML_EDITOR_ID);
}
QString FormEditorFactory::displayName() const
{
return qApp->translate("Designer", C_DESIGNER_XML_DISPLAY_NAME);
}
Core::IEditor *FormEditorFactory::createEditor(QWidget *parent)
{
const EditorData data = FormEditorW::instance()->createEditor(parent);
......@@ -78,11 +71,6 @@ Core::IEditor *FormEditorFactory::createEditor(QWidget *parent)
return data.formWindowEditor;
}
QStringList FormEditorFactory::mimeTypes() const
{
return m_mimeTypes;
}
void FormEditorFactory::designerModeClicked()
{
Core::ModeManager::activateMode(Core::Constants::MODE_DESIGN);
......@@ -90,5 +78,3 @@ void FormEditorFactory::designerModeClicked()
} // namespace Internal
} // namespace Designer
......@@ -32,8 +32,6 @@
#include <coreplugin/editormanager/ieditorfactory.h>
#include <QStringList>
namespace Designer {
namespace Internal {
......@@ -44,17 +42,10 @@ class FormEditorFactory : public Core::IEditorFactory
public:
FormEditorFactory();
// IEditorFactory
QStringList mimeTypes() const;
Core::Id id() const;
QString displayName() const;
Core::IEditor *createEditor(QWidget *parent);
private slots:
void designerModeClicked();
private:
const QStringList m_mimeTypes;
};
} // namespace Internal
......
......@@ -45,7 +45,6 @@
#include <coreplugin/editormanager/editormanager.h>
namespace DiffEditor {
namespace Internal {
DiffEditorPlugin::DiffEditorPlugin()
......
......@@ -54,9 +54,11 @@ ProjectFilesFactory::ProjectFilesFactory(Manager *manager, TextEditorActionHandl
: Core::IEditorFactory(manager),
m_actionHandler(handler)
{
m_mimeTypes.append(QLatin1String(Constants::FILES_MIMETYPE));
m_mimeTypes.append(QLatin1String(Constants::INCLUDES_MIMETYPE));
m_mimeTypes.append(QLatin1String(Constants::CONFIG_MIMETYPE));
setId(Constants::FILES_EDITOR_ID);
setDisplayName(QCoreApplication::translate("OpenWith::Editors", ".files Editor"));
addMimeType(Constants::FILES_MIMETYPE);
addMimeType(Constants::INCLUDES_MIMETYPE);
addMimeType(Constants::CONFIG_MIMETYPE);
}
Core::IEditor *ProjectFilesFactory::createEditor(QWidget *parent)
......@@ -66,21 +68,6 @@ Core::IEditor *ProjectFilesFactory::createEditor(QWidget *parent)
return ed->editor();
}
QStringList ProjectFilesFactory::mimeTypes() const
{
return m_mimeTypes;
}
Core::Id ProjectFilesFactory::id() const
{
return Core::Id(Constants::FILES_EDITOR_ID);
}
QString ProjectFilesFactory::displayName() const
{
return QCoreApplication::translate("OpenWith::Editors", ".files Editor");
}
////////////////////////////////////////////////////////////////////////////////////////
//
// ProjectFilesEditable
......
......@@ -56,13 +56,8 @@ public:
Core::IEditor *createEditor(QWidget *parent);
QStringList mimeTypes() const;
Core::Id id() const;
QString displayName() const;
private:
TextEditor::TextEditorActionHandler *m_actionHandler;
QStringList m_mimeTypes;
};
class ProjectFilesEditor : public TextEditor::BaseTextEditor
......
......@@ -37,14 +37,9 @@
#include <extensionsystem/pluginspec.h>
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <QCoreApplication>
#include <QFileInfo>
#include <QDebug>
#include <QSettings>
#include <QMessageBox>
#include <QPushButton>
using namespace GLSLEditor::Internal;
using namespace GLSLEditor::Constants;
......@@ -52,23 +47,13 @@ using namespace GLSLEditor::Constants;
GLSLEditorFactory::GLSLEditorFactory(QObject *parent)
: Core::IEditorFactory(parent)
{
m_mimeTypes
<< QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE)
<< QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_VERT)
<< QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG)
<< QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_VERT_ES)
<< QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG_ES)
;
}
Core::Id GLSLEditorFactory::id() const
{
return Core::Id(C_GLSLEDITOR_ID);
}
QString GLSLEditorFactory::displayName() const
{
return qApp->translate("OpenWith::Editors", C_GLSLEDITOR_DISPLAY_NAME);
setId(C_GLSLEDITOR_ID);
setDisplayName(qApp->translate("OpenWith::Editors", C_GLSLEDITOR_DISPLAY_NAME));
addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE);
addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_VERT);
addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG);
addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_VERT_ES);
addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG_ES);
}
Core::IEditor *GLSLEditorFactory::createEditor(QWidget *parent)
......@@ -78,11 +63,6 @@ Core::IEditor *GLSLEditorFactory::createEditor(QWidget *parent)
return rc->editor();
}
QStringList GLSLEditorFactory::mimeTypes() const
{
return m_mimeTypes;
}
void GLSLEditorFactory::updateEditorInfoBar(Core::IEditor *)
{
}
......@@ -32,8 +32,6 @@
#include <coreplugin/editormanager/ieditorfactory.h>
#include <QStringList>
namespace GLSLEditor {
namespace Internal {
......@@ -44,17 +42,10 @@ class GLSLEditorFactory : public Core::IEditorFactory
public:
GLSLEditorFactory(QObject *parent);
// IEditorFactory
QStringList mimeTypes() const;
Core::Id id() const;
QString displayName() const;
Core::IEditor *createEditor(QWidget *parent);
private slots:
void updateEditorInfoBar(Core::IEditor *editor);
private:
QStringList m_mimeTypes;
};
} // namespace Internal
......
......@@ -43,7 +43,6 @@ namespace Internal {
struct ImageViewerFactoryPrivate
{
QStringList mimeTypes;
QPointer<ImageViewerActionHandler> actionHandler;
};
......@@ -51,30 +50,33 @@ ImageViewerFactory::ImageViewerFactory(QObject *parent) :
Core::IEditorFactory(parent),
d(new ImageViewerFactoryPrivate)
{
setId(Constants::IMAGEVIEWER_ID);
setDisplayName(qApp->translate("OpenWith::Editors", Constants::IMAGEVIEWER_DISPLAY_NAME));
d->actionHandler = new ImageViewerActionHandler(this);
QMap<QByteArray, QString> possibleMimeTypes;
possibleMimeTypes.insert("bmp", QLatin1String("image/bmp"));
possibleMimeTypes.insert("gif", QLatin1String("image/gif"));
possibleMimeTypes.insert("ico", QLatin1String("image/x-icon"));
possibleMimeTypes.insert("jpeg", QLatin1String("image/jpeg"));
possibleMimeTypes.insert("jpg", QLatin1String("image/jpeg"));
possibleMimeTypes.insert("mng", QLatin1String("video/x-mng"));
possibleMimeTypes.insert("pbm", QLatin1String("image/x-portable-bitmap"));
possibleMimeTypes.insert("pgm", QLatin1String("image/x-portable-graymap"));
possibleMimeTypes.insert("png", QLatin1String("image/png"));
possibleMimeTypes.insert("ppm", QLatin1String("image/x-portable-pixmap"));
possibleMimeTypes.insert("svg", QLatin1String("image/svg+xml"));
possibleMimeTypes.insert("tif", QLatin1String("image/tiff"));
possibleMimeTypes.insert("tiff", QLatin1String("image/tiff"));
possibleMimeTypes.insert("xbm", QLatin1String("image/xbm"));
possibleMimeTypes.insert("xpm", QLatin1String("image/xpm"));
QMap<QByteArray, const char *> possibleMimeTypes;
possibleMimeTypes.insert("bmp", "image/bmp");
possibleMimeTypes.insert("gif", "image/gif");
possibleMimeTypes.insert("ico", "image/x-icon");
possibleMimeTypes.insert("jpeg","image/jpeg");
possibleMimeTypes.insert("jpg", "image/jpeg");
possibleMimeTypes.insert("mng", "video/x-mng");
possibleMimeTypes.insert("pbm", "image/x-portable-bitmap");
possibleMimeTypes.insert("pgm", "image/x-portable-graymap");
possibleMimeTypes.insert("png", "image/png");
possibleMimeTypes.insert("ppm", "image/x-portable-pixmap");
possibleMimeTypes.insert("svg", "image/svg+xml");
possibleMimeTypes.insert("tif", "image/tiff");
possibleMimeTypes.insert("tiff","image/tiff");
possibleMimeTypes.insert("xbm", "image/xbm");
possibleMimeTypes.insert("xpm", "image/xpm");
QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
foreach (const QByteArray &format, supportedFormats) {
const QString &value = possibleMimeTypes.value(format);
if (!value.isEmpty())
d->mimeTypes.append(value);
const char *value = possibleMimeTypes.value(format);
if (value)
addMimeType(value);
}
}
......@@ -88,21 +90,6 @@ Core::IEditor *ImageViewerFactory::createEditor(QWidget *parent)
return new ImageViewer(parent);
}
QStringList ImageViewerFactory::mimeTypes() const
{
return d->mimeTypes;
}
Core::Id ImageViewerFactory::id() const
{
return Core::Id(Constants::IMAGEVIEWER_ID);
}
QString ImageViewerFactory::displayName() const
{
return qApp->translate("OpenWith::Editors", Constants::IMAGEVIEWER_DISPLAY_NAME);
}
void ImageViewerFactory::extensionsInitialized()
{
d->actionHandler->createActions();
......
......@@ -47,10 +47,6 @@ public:
Core::IEditor *createEditor(QWidget *parent);
QStringList mimeTypes() const;
Core::Id id() const;
QString displayName() const;
void extensionsInitialized();
private:
......
......@@ -49,24 +49,11 @@ using namespace ProjectExplorer::Internal;
*/
ProjectFileFactory::ProjectFileFactory(IProjectManager *manager)
: m_mimeTypes(manager->mimeType()),
m_manager(manager)
: m_manager(manager)
{
}
QStringList ProjectFileFactory::mimeTypes() const
{
return m_mimeTypes;
}
Core::Id ProjectFileFactory::id() const
{
return Core::Id(Constants::FILE_FACTORY_ID);
}
QString ProjectFileFactory::displayName() const
{
return tr("Project File Factory", "ProjectExplorer::ProjectFileFactory display name.");
setId(Constants::FILE_FACTORY_ID);
setDisplayName(tr("Project File Factory", "ProjectExplorer::ProjectFileFactory display name."));
addMimeType(manager->mimeType());
}