Commit 66ab323e authored by hjk's avatar hjk Committed by hjk

use Core::Id for IEditorFactory::id

Change-Id: Iefd67a0461d9016b8ba0f3371df7ec6d42e188c5
Reviewed-on: http://codereview.qt-project.org/4321Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent b51524c5
...@@ -573,7 +573,7 @@ void BazaarPlugin::showCommitWidget(const QList<VCSBase::VCSBaseClient::StatusIt ...@@ -573,7 +573,7 @@ void BazaarPlugin::showCommitWidget(const QList<VCSBase::VCSBaseClient::StatusIt
} }
Core::IEditor *editor = m_core->editorManager()->openEditor(m_changeLog->fileName(), Core::IEditor *editor = m_core->editorManager()->openEditor(m_changeLog->fileName(),
QLatin1String(Constants::COMMIT_ID), Constants::COMMIT_ID,
Core::EditorManager::ModeSwitch); Core::EditorManager::ModeSwitch);
if (!editor) { if (!editor) {
outputWindow->appendError(tr("Unable to create an editor for the commit.")); outputWindow->appendError(tr("Unable to create an editor for the commit."));
......
...@@ -416,9 +416,9 @@ BinEditorFactory::BinEditorFactory(BinEditorPlugin *owner) : ...@@ -416,9 +416,9 @@ BinEditorFactory::BinEditorFactory(BinEditorPlugin *owner) :
{ {
} }
QString BinEditorFactory::id() const Core::Id BinEditorFactory::id() const
{ {
return QLatin1String(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID); return Core::Constants::K_DEFAULT_BINARY_EDITOR_ID;
} }
QString BinEditorFactory::displayName() const QString BinEditorFactory::displayName() const
......
...@@ -57,7 +57,6 @@ public: ...@@ -57,7 +57,6 @@ public:
namespace Internal { namespace Internal {
class BinEditorFactory; class BinEditorFactory;
class BinEditorPlugin : public ExtensionSystem::IPlugin class BinEditorPlugin : public ExtensionSystem::IPlugin
{ {
Q_OBJECT Q_OBJECT
...@@ -105,10 +104,9 @@ class BinEditorFactory : public Core::IEditorFactory ...@@ -105,10 +104,9 @@ class BinEditorFactory : public Core::IEditorFactory
public: public:
explicit BinEditorFactory(BinEditorPlugin *owner); explicit BinEditorFactory(BinEditorPlugin *owner);
virtual QStringList mimeTypes() const; QStringList mimeTypes() const;
Core::IEditor *createEditor(QWidget *parent); Core::IEditor *createEditor(QWidget *parent);
QString id() const; Core::Id id() const;
QString displayName() const; QString displayName() const;
Core::IFile *open(const QString &fileName); Core::IFile *open(const QString &fileName);
......
...@@ -48,13 +48,9 @@ CMakeEditorFactory::CMakeEditorFactory(CMakeManager *manager, TextEditor::TextEd ...@@ -48,13 +48,9 @@ CMakeEditorFactory::CMakeEditorFactory(CMakeManager *manager, TextEditor::TextEd
} }
CMakeEditorFactory::~CMakeEditorFactory() Core::Id CMakeEditorFactory::id() const
{ {
} return CMakeProjectManager::Constants::CMAKE_EDITOR_ID;
QString CMakeEditorFactory::id() const
{
return QLatin1String(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
} }
QString CMakeEditorFactory::displayName() const QString CMakeEditorFactory::displayName() const
......
...@@ -33,21 +33,17 @@ ...@@ -33,21 +33,17 @@
#ifndef CMAKEEDITORFACTORY_H #ifndef CMAKEEDITORFACTORY_H
#define CMAKEEDITORFACTORY_H #define CMAKEEDITORFACTORY_H
#include <coreplugin/editormanager/ieditorfactory.h>
#include "cmakeprojectmanager.h" #include "cmakeprojectmanager.h"
#include <QtCore/QStringList> #include <coreplugin/editormanager/ieditorfactory.h>
QT_BEGIN_NAMESPACE #include <QtCore/QStringList>
class QAction;
QT_END_NAMESPACE
namespace TextEditor { namespace TextEditor {
class TextEditorActionHandler; class TextEditorActionHandler;
} }
namespace CMakeProjectManager { namespace CMakeProjectManager {
namespace Internal { namespace Internal {
class CMakeEditorFactory : public Core::IEditorFactory class CMakeEditorFactory : public Core::IEditorFactory
...@@ -56,11 +52,11 @@ class CMakeEditorFactory : public Core::IEditorFactory ...@@ -56,11 +52,11 @@ class CMakeEditorFactory : public Core::IEditorFactory
public: public:
CMakeEditorFactory(CMakeManager *parent, TextEditor::TextEditorActionHandler *handler); CMakeEditorFactory(CMakeManager *parent, TextEditor::TextEditorActionHandler *handler);
~CMakeEditorFactory();
virtual QStringList mimeTypes() const; // IEditorFactory
virtual QString id() const; QStringList mimeTypes() const;
virtual QString displayName() const; Core::Id id() const;
QString displayName() const;
Core::IFile *open(const QString &fileName); Core::IFile *open(const QString &fileName);
Core::IEditor *createEditor(QWidget *parent); Core::IEditor *createEditor(QWidget *parent);
......
...@@ -1148,8 +1148,7 @@ EditorManager::ExternalEditorList ...@@ -1148,8 +1148,7 @@ EditorManager::ExternalEditorList
/* For something that has a 'QString id' (IEditorFactory /* For something that has a 'QString id' (IEditorFactory
* or IExternalEditor), find the one matching a id. */ * or IExternalEditor), find the one matching a id. */
template <class EditorFactoryLike> template <class EditorFactoryLike>
inline EditorFactoryLike *findById(ExtensionSystem::PluginManager *pm, EditorFactoryLike *findById(ExtensionSystem::PluginManager *pm, const Core::Id &id)
const QString &id)
{ {
const QList<EditorFactoryLike *> factories = pm->template getObjects<EditorFactoryLike>(); const QList<EditorFactoryLike *> factories = pm->template getObjects<EditorFactoryLike>();
foreach(EditorFactoryLike *efl, factories) foreach(EditorFactoryLike *efl, factories)
...@@ -1158,20 +1157,19 @@ template <class EditorFactoryLike> ...@@ -1158,20 +1157,19 @@ template <class EditorFactoryLike>
return 0; return 0;
} }
IEditor *EditorManager::createEditor(const QString &editorId, IEditor *EditorManager::createEditor(const Id &editorId, const QString &fileName)
const QString &fileName)
{ {
if (debugEditorManager) if (debugEditorManager)
qDebug() << Q_FUNC_INFO << editorId << fileName; qDebug() << Q_FUNC_INFO << editorId.name() << fileName;
EditorFactoryList factories; EditorFactoryList factories;
if (editorId.isEmpty()) { if (!editorId.isValid()) {
const QFileInfo fileInfo(fileName); const QFileInfo fileInfo(fileName);
// Find by mime type // Find by mime type
MimeType mimeType = d->m_core->mimeDatabase()->findByFile(fileInfo); MimeType mimeType = d->m_core->mimeDatabase()->findByFile(fileInfo);
if (!mimeType) { if (!mimeType) {
qWarning("%s unable to determine mime type of %s/%s. Falling back to text/plain", qWarning("%s unable to determine mime type of %s/%s. Falling back to text/plain",
Q_FUNC_INFO, fileName.toUtf8().constData(), editorId.toUtf8().constData()); Q_FUNC_INFO, fileName.toUtf8().constData(), editorId.name().constData());
mimeType = d->m_core->mimeDatabase()->findByType(QLatin1String("text/plain")); mimeType = d->m_core->mimeDatabase()->findByType(QLatin1String("text/plain"));
} }
// open text files > 48 MB in binary editor // open text files > 48 MB in binary editor
...@@ -1185,7 +1183,7 @@ IEditor *EditorManager::createEditor(const QString &editorId, ...@@ -1185,7 +1183,7 @@ IEditor *EditorManager::createEditor(const QString &editorId,
} }
if (factories.empty()) { if (factories.empty()) {
qWarning("%s: unable to find an editor factory for the file '%s', editor Id '%s'.", qWarning("%s: unable to find an editor factory for the file '%s', editor Id '%s'.",
Q_FUNC_INFO, fileName.toUtf8().constData(), editorId.toUtf8().constData()); Q_FUNC_INFO, fileName.toUtf8().constData(), editorId.name().constData());
return 0; return 0;
} }
...@@ -1217,7 +1215,7 @@ void EditorManager::addEditor(IEditor *editor, bool isDuplicate) ...@@ -1217,7 +1215,7 @@ void EditorManager::addEditor(IEditor *editor, bool isDuplicate)
// Run the OpenWithDialog and return the editor id // Run the OpenWithDialog and return the editor id
// selected by the user. // selected by the user.
QString EditorManager::getOpenWithEditorId(const QString &fileName, Core::Id EditorManager::getOpenWithEditorId(const QString &fileName,
bool *isExternalEditor) const bool *isExternalEditor) const
{ {
// Collect editors that can open the file // Collect editors that can open the file
...@@ -1230,14 +1228,14 @@ QString EditorManager::getOpenWithEditorId(const QString &fileName, ...@@ -1230,14 +1228,14 @@ QString EditorManager::getOpenWithEditorId(const QString &fileName,
const EditorFactoryList editors = editorFactories(mt, false); const EditorFactoryList editors = editorFactories(mt, false);
const int size = editors.size(); const int size = editors.size();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
allEditorIds.push_back(editors.at(i)->id()); allEditorIds.push_back(editors.at(i)->id().toString());
} }
// External editors // External editors
const ExternalEditorList exEditors = externalEditors(mt, false); const ExternalEditorList exEditors = externalEditors(mt, false);
const int esize = exEditors.size(); const int esize = exEditors.size();
for (int i = 0; i < esize; i++) { for (int i = 0; i < esize; i++) {
externalEditorIds.push_back(exEditors.at(i)->id()); externalEditorIds.push_back(exEditors.at(i)->id().toString());
allEditorIds.push_back(exEditors.at(i)->id()); allEditorIds.push_back(exEditors.at(i)->id().toString());
} }
if (allEditorIds.empty()) if (allEditorIds.empty())
return QString(); return QString();
...@@ -1253,7 +1251,7 @@ QString EditorManager::getOpenWithEditorId(const QString &fileName, ...@@ -1253,7 +1251,7 @@ QString EditorManager::getOpenWithEditorId(const QString &fileName,
return selectedId; return selectedId;
} }
IEditor *EditorManager::openEditor(const QString &fileName, const QString &editorId, IEditor *EditorManager::openEditor(const QString &fileName, const Id &editorId,
OpenEditorFlags flags, bool *newEditor) OpenEditorFlags flags, bool *newEditor)
{ {
return openEditor(currentEditorView(), fileName, editorId, flags, newEditor); return openEditor(currentEditorView(), fileName, editorId, flags, newEditor);
...@@ -1284,10 +1282,10 @@ static QString autoSaveName(const QString &fileName) ...@@ -1284,10 +1282,10 @@ static QString autoSaveName(const QString &fileName)
} }
IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QString &fileName, IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QString &fileName,
const QString &editorId, OpenEditorFlags flags, bool *newEditor) const Id &editorId, OpenEditorFlags flags, bool *newEditor)
{ {
if (debugEditorManager) if (debugEditorManager)
qDebug() << Q_FUNC_INFO << fileName << editorId; qDebug() << Q_FUNC_INFO << fileName << editorId.name();
QString fn = fileName; QString fn = fileName;
int lineNumber = -1; int lineNumber = -1;
...@@ -1350,7 +1348,7 @@ IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QStri ...@@ -1350,7 +1348,7 @@ IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QStri
return result; return result;
} }
bool EditorManager::openExternalEditor(const QString &fileName, const QString &editorId) bool EditorManager::openExternalEditor(const QString &fileName, const Core::Id &editorId)
{ {
IExternalEditor *ee = findById<IExternalEditor>(pluginManager(), editorId); IExternalEditor *ee = findById<IExternalEditor>(pluginManager(), editorId);
if (!ee) if (!ee)
...@@ -1389,12 +1387,12 @@ void EditorManager::switchToPreferedMode() ...@@ -1389,12 +1387,12 @@ void EditorManager::switchToPreferedMode()
ModeManager::instance()->activateModeType(preferedMode); ModeManager::instance()->activateModeType(preferedMode);
} }
IEditor *EditorManager::openEditorWithContents(const QString &editorId, IEditor *EditorManager::openEditorWithContents(const Id &editorId,
QString *titlePattern, QString *titlePattern,
const QString &contents) const QString &contents)
{ {
if (debugEditorManager) if (debugEditorManager)
qDebug() << Q_FUNC_INFO << editorId << titlePattern << contents; qDebug() << Q_FUNC_INFO << editorId.name() << titlePattern << contents;
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
...@@ -1905,7 +1903,7 @@ QByteArray EditorManager::saveState() const ...@@ -1905,7 +1903,7 @@ QByteArray EditorManager::saveState() const
foreach (const OpenEditorsModel::Entry &entry, entries) { foreach (const OpenEditorsModel::Entry &entry, entries) {
if (!entry.editor || !entry.editor->isTemporary()) if (!entry.editor || !entry.editor->isTemporary())
stream << entry.fileName() << entry.displayName() << entry.id().toUtf8(); stream << entry.fileName() << entry.displayName() << entry.id().name();
} }
stream << d->m_splitter->saveState(); stream << d->m_splitter->saveState();
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "../core_global.h" #include "../core_global.h"
#include <coreplugin/id.h>
#include <coreplugin/ifile.h> // enumerations #include <coreplugin/ifile.h> // enumerations
#include <QtCore/QList> #include <QtCore/QList>
...@@ -99,8 +100,8 @@ class CORE_EXPORT EditorManager : public QWidget ...@@ -99,8 +100,8 @@ class CORE_EXPORT EditorManager : public QWidget
Q_OBJECT Q_OBJECT
public: public:
typedef QList<IEditorFactory*> EditorFactoryList; typedef QList<IEditorFactory *> EditorFactoryList;
typedef QList<IExternalEditor*> ExternalEditorList; typedef QList<IExternalEditor *> ExternalEditorList;
explicit EditorManager(ICore *core, QWidget *parent); explicit EditorManager(ICore *core, QWidget *parent);
virtual ~EditorManager(); virtual ~EditorManager();
...@@ -117,18 +118,15 @@ public: ...@@ -117,18 +118,15 @@ public:
}; };
Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag) Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)
IEditor *openEditor(const QString &fileName, IEditor *openEditor(const QString &fileName, const Id &editorId = Id(),
const QString &editorId = QString(), OpenEditorFlags flags = 0, bool *newEditor = 0);
OpenEditorFlags flags = 0, IEditor *openEditorWithContents(const Id &editorId,
bool *newEditor = 0); QString *titlePattern = 0, const QString &contents = QString());
IEditor *openEditorWithContents(const QString &editorId,
QString *titlePattern = 0,
const QString &contents = QString());
bool openExternalEditor(const QString &fileName, const QString &editorId); bool openExternalEditor(const QString &fileName, const Id &editorId);
QStringList getOpenFileNames() const; QStringList getOpenFileNames() const;
QString getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0) const; Id getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0) const;
bool hasEditor(const QString &fileName) const; bool hasEditor(const QString &fileName) const;
QList<IEditor *> editorsForFileName(const QString &filename) const; QList<IEditor *> editorsForFileName(const QString &filename) const;
...@@ -241,8 +239,7 @@ public slots: ...@@ -241,8 +239,7 @@ public slots:
private: private:
QList<IFile *> filesForEditors(QList<IEditor *> editors) const; QList<IFile *> filesForEditors(QList<IEditor *> editors) const;
IEditor *createEditor(const QString &mimeType = QString(), IEditor *createEditor(const Id &id = Id(), const QString &fileName = QString());
const QString &fileName = QString());
void addEditor(IEditor *editor, bool isDuplicate = false); void addEditor(IEditor *editor, bool isDuplicate = false);
void removeEditor(IEditor *editor); void removeEditor(IEditor *editor);
...@@ -255,9 +252,7 @@ private: ...@@ -255,9 +252,7 @@ private:
IEditor *activateEditor(Internal::EditorView *view, IEditor *editor, OpenEditorFlags flags = 0); IEditor *activateEditor(Internal::EditorView *view, IEditor *editor, OpenEditorFlags flags = 0);
void activateEditorForIndex(Internal::EditorView *view, const QModelIndex &index, OpenEditorFlags = 0); void activateEditorForIndex(Internal::EditorView *view, const QModelIndex &index, OpenEditorFlags = 0);
IEditor *openEditor(Internal::EditorView *view, const QString &fileName, IEditor *openEditor(Internal::EditorView *view, const QString &fileName,
const QString &editorId = QString(), const Id &id = Id(), OpenEditorFlags flags = 0, bool *newEditor = 0);
OpenEditorFlags flags = 0,
bool *newEditor = 0);
Internal::SplitterOrView *currentSplitterOrView() const; Internal::SplitterOrView *currentSplitterOrView() const;
void closeEditor(IEditor *editor); void closeEditor(IEditor *editor);
......
...@@ -786,7 +786,7 @@ void SplitterOrView::restoreState(const QByteArray &state) ...@@ -786,7 +786,7 @@ void SplitterOrView::restoreState(const QByteArray &state)
stream >> fileName >> id >> editorState; stream >> fileName >> id >> editorState;
if (!QFile::exists(fileName)) if (!QFile::exists(fileName))
return; return;
IEditor *e = em->openEditor(view(), fileName, id, Core::EditorManager::IgnoreNavigationHistory IEditor *e = em->openEditor(view(), fileName, Id(QString(id)), Core::EditorManager::IgnoreNavigationHistory
| Core::EditorManager::NoActivate); | Core::EditorManager::NoActivate);
if (!e) { if (!e) {
......
...@@ -42,9 +42,9 @@ class IEditor; ...@@ -42,9 +42,9 @@ class IEditor;
class CORE_EXPORT IEditorFactory : public Core::IFileFactory class CORE_EXPORT IEditorFactory : public Core::IFileFactory
{ {
Q_OBJECT Q_OBJECT
public: public:
IEditorFactory(QObject *parent = 0) : IFileFactory(parent) {} IEditorFactory(QObject *parent = 0) : IFileFactory(parent) {}
virtual ~IEditorFactory() {}
virtual IEditor *createEditor(QWidget *parent) = 0; virtual IEditor *createEditor(QWidget *parent) = 0;
}; };
......
...@@ -39,17 +39,18 @@ ...@@ -39,17 +39,18 @@
namespace Core { namespace Core {
class Id;
class CORE_EXPORT IExternalEditor : public QObject class CORE_EXPORT IExternalEditor : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit IExternalEditor(QObject *parent = 0) : QObject(parent) {} explicit IExternalEditor(QObject *parent = 0) : QObject(parent) {}
virtual ~IExternalEditor() {}
virtual QStringList mimeTypes() const = 0; virtual QStringList mimeTypes() const = 0;
virtual QString id() const = 0; virtual Id id() const = 0;
virtual QString displayName() const = 0; virtual QString displayName() const = 0;
virtual bool startEditor(const QString &fileName, QString *errorMessage) = 0; virtual bool startEditor(const QString &fileName, QString *errorMessage) = 0;
}; };
......
...@@ -87,7 +87,7 @@ QString OpenEditorsModel::Entry::displayName() const { ...@@ -87,7 +87,7 @@ QString OpenEditorsModel::Entry::displayName() const {
return editor ? editor->displayName() : m_displayName; return editor ? editor->displayName() : m_displayName;
} }
QString OpenEditorsModel::Entry::id() const Id OpenEditorsModel::Entry::id() const
{ {
return editor ? editor->id() : m_id; return editor ? editor->id() : m_id;
} }
...@@ -319,7 +319,7 @@ QVariant OpenEditorsModel::data(const QModelIndex &index, int role) const ...@@ -319,7 +319,7 @@ QVariant OpenEditorsModel::data(const QModelIndex &index, int role) const
case Qt::UserRole + 1: case Qt::UserRole + 1:
return e.fileName(); return e.fileName();
case Qt::UserRole + 2: case Qt::UserRole + 2:
return e.editor ? e.editor->id() : e.id(); return QVariant::fromValue(e.editor ? e.editor->id() : e.id());
default: default:
return QVariant(); return QVariant();
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#define OPENEDITORSMODEL_H #define OPENEDITORSMODEL_H
#include "../core_global.h" #include "../core_global.h"
#include "../id.h"
#include <QtCore/QAbstractItemModel> #include <QtCore/QAbstractItemModel>
#include <QtCore/QScopedPointer> #include <QtCore/QScopedPointer>
...@@ -71,10 +72,10 @@ public: ...@@ -71,10 +72,10 @@ public:
IEditor *editor; IEditor *editor;
QString fileName() const; QString fileName() const;
QString displayName() const; QString displayName() const;
QString id() const; Id id() const;
QString m_fileName; QString m_fileName;
QString m_displayName; QString m_displayName;
QString m_id; Id m_id;
}; };
QList<Entry> entries() const; QList<Entry> entries() const;
......
...@@ -280,10 +280,10 @@ void OpenEditorsWindow::selectEditor(QTreeWidgetItem *item) ...@@ -280,10 +280,10 @@ void OpenEditorsWindow::selectEditor(QTreeWidgetItem *item)
return; return;
if (IFile *file = item->data(0, Qt::UserRole).value<IFile*>()) { if (IFile *file = item->data(0, Qt::UserRole).value<IFile*>()) {
EditorView *view = item->data(0, Qt::UserRole+1).value<EditorView*>(); EditorView *view = item->data(0, Qt::UserRole+1).value<EditorView*>();
EditorManager::instance()->activateEditorForFile(view, file, Core::EditorManager::ModeSwitch); EditorManager::instance()->activateEditorForFile(view, file, EditorManager::ModeSwitch);
} else { } else {
if (!EditorManager::instance()->openEditor( if (!EditorManager::instance()->openEditor(
item->toolTip(0), item->data(0, Qt::UserRole+2).toByteArray(), item->toolTip(0), item->data(0, Qt::UserRole+2).value<Core::Id>(),
Core::EditorManager::ModeSwitch)) { Core::EditorManager::ModeSwitch)) {
EditorManager::instance()->openedEditorsModel()->removeEditor(item->toolTip(0)); EditorManager::instance()->openedEditorsModel()->removeEditor(item->toolTip(0));
delete item; delete item;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
**************************************************************************/ **************************************************************************/
#include "systemeditor.h" #include "systemeditor.h"
#include "id.h"
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtCore/QUrl> #include <QtCore/QUrl>
...@@ -49,9 +50,9 @@ QStringList SystemEditor::mimeTypes() const ...@@ -49,9 +50,9 @@ QStringList SystemEditor::mimeTypes() const
return QStringList() << QLatin1String("application/octet-stream"); return QStringList() << QLatin1String("application/octet-stream");
} }
QString SystemEditor::id() const Id SystemEditor::id() const
{ {
return QLatin1String("CorePlugin.OpenWithSystemEditor"); return Id("CorePlugin.OpenWithSystemEditor");
} }