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
}
Core::IEditor *editor = m_core->editorManager()->openEditor(m_changeLog->fileName(),
QLatin1String(Constants::COMMIT_ID),
Constants::COMMIT_ID,
Core::EditorManager::ModeSwitch);
if (!editor) {
outputWindow->appendError(tr("Unable to create an editor for the commit."));
......
......@@ -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
......
......@@ -57,7 +57,6 @@ public:
namespace Internal {
class BinEditorFactory;
class BinEditorPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
......@@ -105,10 +104,9 @@ class BinEditorFactory : public Core::IEditorFactory
public:
explicit BinEditorFactory(BinEditorPlugin *owner);
virtual QStringList mimeTypes() const;
QStringList mimeTypes() const;
Core::IEditor *createEditor(QWidget *parent);
QString id() const;
Core::Id id() const;
QString displayName() const;
Core::IFile *open(const QString &fileName);
......
......@@ -48,13 +48,9 @@ CMakeEditorFactory::CMakeEditorFactory(CMakeManager *manager, TextEditor::TextEd
}
CMakeEditorFactory::~CMakeEditorFactory()
Core::Id CMakeEditorFactory::id() const
{
}
QString CMakeEditorFactory::id() const
{
return QLatin1String(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
return CMakeProjectManager::Constants::CMAKE_EDITOR_ID;
}
QString CMakeEditorFactory::displayName() const
......
......@@ -33,21 +33,17 @@
#ifndef CMAKEEDITORFACTORY_H
#define CMAKEEDITORFACTORY_H
#include <coreplugin/editormanager/ieditorfactory.h>
#include "cmakeprojectmanager.h"
#include <QtCore/QStringList>
#include <coreplugin/editormanager/ieditorfactory.h>
QT_BEGIN_NAMESPACE
class QAction;
QT_END_NAMESPACE
#include <QtCore/QStringList>
namespace TextEditor {
class TextEditorActionHandler;
}
namespace CMakeProjectManager {
namespace Internal {
class CMakeEditorFactory : public Core::IEditorFactory
......@@ -56,11 +52,11 @@ class CMakeEditorFactory : public Core::IEditorFactory
public:
CMakeEditorFactory(CMakeManager *parent, TextEditor::TextEditorActionHandler *handler);
~CMakeEditorFactory();
virtual QStringList mimeTypes() const;
virtual QString id() const;
virtual QString displayName() const;
// IEditorFactory
QStringList mimeTypes() const;
Core::Id id() const;
QString displayName() const;
Core::IFile *open(const QString &fileName);
Core::IEditor *createEditor(QWidget *parent);
......
......@@ -1148,8 +1148,7 @@ EditorManager::ExternalEditorList
/* For something that has a 'QString id' (IEditorFactory
* or IExternalEditor), find the one matching a id. */
template <class EditorFactoryLike>
inline EditorFactoryLike *findById(ExtensionSystem::PluginManager *pm,
const QString &id)
EditorFactoryLike *findById(ExtensionSystem::PluginManager *pm, const Core::Id &id)
{
const QList<EditorFactoryLike *> factories = pm->template getObjects<EditorFactoryLike>();
foreach(EditorFactoryLike *efl, factories)
......@@ -1158,20 +1157,19 @@ template <class EditorFactoryLike>
return 0;
}
IEditor *EditorManager::createEditor(const QString &editorId,
const QString &fileName)
IEditor *EditorManager::createEditor(const Id &editorId, const QString &fileName)
{
if (debugEditorManager)
qDebug() << Q_FUNC_INFO << editorId << fileName;
qDebug() << Q_FUNC_INFO << editorId.name() << fileName;
EditorFactoryList factories;
if (editorId.isEmpty()) {
if (!editorId.isValid()) {
const QFileInfo fileInfo(fileName);
// Find by mime type
MimeType mimeType = d->m_core->mimeDatabase()->findByFile(fileInfo);
if (!mimeType) {
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"));
}
// open text files > 48 MB in binary editor
......@@ -1185,7 +1183,7 @@ IEditor *EditorManager::createEditor(const QString &editorId,
}
if (factories.empty()) {
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;
}
......@@ -1217,7 +1215,7 @@ void EditorManager::addEditor(IEditor *editor, bool isDuplicate)
// Run the OpenWithDialog and return the editor id
// selected by the user.
QString EditorManager::getOpenWithEditorId(const QString &fileName,
Core::Id EditorManager::getOpenWithEditorId(const QString &fileName,
bool *isExternalEditor) const
{
// Collect editors that can open the file
......@@ -1230,14 +1228,14 @@ QString EditorManager::getOpenWithEditorId(const QString &fileName,
const EditorFactoryList editors = editorFactories(mt, false);
const int size = editors.size();
for (int i = 0; i < size; i++) {
allEditorIds.push_back(editors.at(i)->id());
allEditorIds.push_back(editors.at(i)->id().toString());
}
// External editors
const ExternalEditorList exEditors = externalEditors(mt, false);
const int esize = exEditors.size();
for (int i = 0; i < esize; i++) {
externalEditorIds.push_back(exEditors.at(i)->id());
allEditorIds.push_back(exEditors.at(i)->id());
externalEditorIds.push_back(exEditors.at(i)->id().toString());
allEditorIds.push_back(exEditors.at(i)->id().toString());
}
if (allEditorIds.empty())
return QString();
......@@ -1253,7 +1251,7 @@ QString EditorManager::getOpenWithEditorId(const QString &fileName,
return selectedId;
}
IEditor *EditorManager::openEditor(const QString &fileName, const QString &editorId,
IEditor *EditorManager::openEditor(const QString &fileName, const Id &editorId,
OpenEditorFlags flags, bool *newEditor)
{
return openEditor(currentEditorView(), fileName, editorId, flags, newEditor);
......@@ -1284,10 +1282,10 @@ static QString autoSaveName(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)
qDebug() << Q_FUNC_INFO << fileName << editorId;
qDebug() << Q_FUNC_INFO << fileName << editorId.name();
QString fn = fileName;
int lineNumber = -1;
......@@ -1350,7 +1348,7 @@ IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QStri
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);
if (!ee)
......@@ -1389,12 +1387,12 @@ void EditorManager::switchToPreferedMode()
ModeManager::instance()->activateModeType(preferedMode);
}
IEditor *EditorManager::openEditorWithContents(const QString &editorId,
IEditor *EditorManager::openEditorWithContents(const Id &editorId,
QString *titlePattern,
const QString &contents)
{
if (debugEditorManager)
qDebug() << Q_FUNC_INFO << editorId << titlePattern << contents;
qDebug() << Q_FUNC_INFO << editorId.name() << titlePattern << contents;
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
......@@ -1905,7 +1903,7 @@ QByteArray EditorManager::saveState() const
foreach (const OpenEditorsModel::Entry &entry, entries) {
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();
......
......@@ -35,6 +35,7 @@
#include "../core_global.h"
#include <coreplugin/id.h>
#include <coreplugin/ifile.h> // enumerations
#include <QtCore/QList>
......@@ -99,8 +100,8 @@ class CORE_EXPORT EditorManager : public QWidget
Q_OBJECT
public:
typedef QList<IEditorFactory*> EditorFactoryList;
typedef QList<IExternalEditor*> ExternalEditorList;
typedef QList<IEditorFactory *> EditorFactoryList;
typedef QList<IExternalEditor *> ExternalEditorList;
explicit EditorManager(ICore *core, QWidget *parent);
virtual ~EditorManager();
......@@ -117,18 +118,15 @@ public:
};
Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)
IEditor *openEditor(const QString &fileName,
const QString &editorId = QString(),
OpenEditorFlags flags = 0,
bool *newEditor = 0);
IEditor *openEditorWithContents(const QString &editorId,
QString *titlePattern = 0,
const QString &contents = QString());
IEditor *openEditor(const QString &fileName, const Id &editorId = Id(),
OpenEditorFlags flags = 0, bool *newEditor = 0);
IEditor *openEditorWithContents(const Id &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;
QString getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0) const;
Id getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0) const;
bool hasEditor(const QString &fileName) const;
QList<IEditor *> editorsForFileName(const QString &filename) const;
......@@ -241,8 +239,7 @@ public slots:
private:
QList<IFile *> filesForEditors(QList<IEditor *> editors) const;
IEditor *createEditor(const QString &mimeType = QString(),
const QString &fileName = QString());
IEditor *createEditor(const Id &id = Id(), const QString &fileName = QString());
void addEditor(IEditor *editor, bool isDuplicate = false);
void removeEditor(IEditor *editor);
......@@ -255,9 +252,7 @@ private:
IEditor *activateEditor(Internal::EditorView *view, IEditor *editor, OpenEditorFlags flags = 0);
void activateEditorForIndex(Internal::EditorView *view, const QModelIndex &index, OpenEditorFlags = 0);
IEditor *openEditor(Internal::EditorView *view, const QString &fileName,
const QString &editorId = QString(),
OpenEditorFlags flags = 0,
bool *newEditor = 0);
const Id &id = Id(), OpenEditorFlags flags = 0, bool *newEditor = 0);
Internal::SplitterOrView *currentSplitterOrView() const;
void closeEditor(IEditor *editor);
......
......@@ -786,7 +786,7 @@ void SplitterOrView::restoreState(const QByteArray &state)
stream >> fileName >> id >> editorState;
if (!QFile::exists(fileName))
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);
if (!e) {
......
......@@ -42,9 +42,9 @@ class IEditor;
class CORE_EXPORT IEditorFactory : public Core::IFileFactory
{
Q_OBJECT
public:
IEditorFactory(QObject *parent = 0) : IFileFactory(parent) {}
virtual ~IEditorFactory() {}
virtual IEditor *createEditor(QWidget *parent) = 0;
};
......
......@@ -39,17 +39,18 @@
namespace Core {
class Id;
class CORE_EXPORT IExternalEditor : public QObject
{
Q_OBJECT
public:
explicit IExternalEditor(QObject *parent = 0) : QObject(parent) {}
virtual ~IExternalEditor() {}
virtual QStringList mimeTypes() const = 0;
virtual QString id() const = 0;
virtual Id id() const = 0;
virtual QString displayName() const = 0;
virtual bool startEditor(const QString &fileName, QString *errorMessage) = 0;
};
......
......@@ -87,7 +87,7 @@ QString OpenEditorsModel::Entry::displayName() const {
return editor ? editor->displayName() : m_displayName;
}
QString OpenEditorsModel::Entry::id() const
Id OpenEditorsModel::Entry::id() const
{
return editor ? editor->id() : m_id;
}
......@@ -319,7 +319,7 @@ QVariant OpenEditorsModel::data(const QModelIndex &index, int role) const
case Qt::UserRole + 1:
return e.fileName();
case Qt::UserRole + 2:
return e.editor ? e.editor->id() : e.id();
return QVariant::fromValue(e.editor ? e.editor->id() : e.id());
default:
return QVariant();
}
......
......@@ -34,6 +34,7 @@
#define OPENEDITORSMODEL_H
#include "../core_global.h"
#include "../id.h"
#include <QtCore/QAbstractItemModel>
#include <QtCore/QScopedPointer>
......@@ -71,10 +72,10 @@ public:
IEditor *editor;
QString fileName() const;
QString displayName() const;
QString id() const;
Id id() const;
QString m_fileName;
QString m_displayName;
QString m_id;
Id m_id;
};
QList<Entry> entries() const;
......
......@@ -280,10 +280,10 @@ void OpenEditorsWindow::selectEditor(QTreeWidgetItem *item)
return;
if (IFile *file = item->data(0, Qt::UserRole).value<IFile*>()) {
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 {
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)) {
EditorManager::instance()->openedEditorsModel()->removeEditor(item->toolTip(0));
delete item;
......
......@@ -31,6 +31,7 @@
**************************************************************************/
#include "systemeditor.h"
#include "id.h"
#include <QtCore/QStringList>
#include <QtCore/QUrl>
......@@ -49,9 +50,9 @@ QStringList SystemEditor::mimeTypes() const
return QStringList() << QLatin1String("application/octet-stream");
}
QString SystemEditor::id() const
Id SystemEditor::id() const
{
return QLatin1String("CorePlugin.OpenWithSystemEditor");
return Id("CorePlugin.OpenWithSystemEditor");
}
QString SystemEditor::displayName() const
......
......@@ -40,18 +40,19 @@ namespace Internal {
class SystemEditor : public IExternalEditor
{
Q_OBJECT
Q_OBJECT
public:
explicit SystemEditor(QObject *parent = 0);
QStringList mimeTypes() const;
QString id() const;
Id id() const;
QString displayName() const;
bool startEditor(const QString &fileName, QString *errorMessage);
};
}
}
} // namespace Internal
} // namespace Core
#endif // SYSTEMEDITOR_H
......@@ -35,6 +35,7 @@
#include "core_global.h"
#include <QtCore/QMetaType>
#include <QtCore/QString>
namespace Core {
......@@ -65,4 +66,6 @@ CORE_EXPORT uint qHash(const Id &id);
} // namespace Core
Q_DECLARE_METATYPE(Core::Id);
#endif // CORE_ID_H
......@@ -44,20 +44,19 @@ QT_END_NAMESPACE
namespace Core {
class IFile;
class Id;
class CORE_EXPORT IFileFactory : public QObject
{
Q_OBJECT
public:
IFileFactory(QObject *parent = 0) : QObject(parent) {}
virtual ~IFileFactory() {}
virtual QStringList mimeTypes() const = 0;
virtual QString id() const = 0;
virtual Id id() const = 0;
virtual QString displayName() const = 0;
virtual Core::IFile *open(const QString &fileName) = 0;
virtual IFile *open(const QString &fileName) = 0;
};
} // namespace Core
......
......@@ -1003,8 +1003,8 @@ void MainWindow::openFileWith()
QStringList fileNames = editorManager()->getOpenFileNames();
foreach (const QString &fileName, fileNames) {
bool isExternal;
const QString editorId = editorManager()->getOpenWithEditorId(fileName, &isExternal);
if (editorId.isEmpty())
const Id editorId = editorManager()->getOpenWithEditorId(fileName, &isExternal);
if (!editorId.isValid())
continue;
if (isExternal) {
editorManager()->openExternalEditor(fileName, editorId);
......
......@@ -101,9 +101,9 @@ CppEditorFactory::CppEditorFactory(CppPlugin *owner) :
#endif
}
QString CppEditorFactory::id() const
Core::Id CppEditorFactory::id() const
{
return QLatin1String(CppEditor::Constants::CPPEDITOR_ID);
return CppEditor::Constants::CPPEDITOR_ID;
}
QString CppEditorFactory::displayName() const
......
......@@ -116,12 +116,11 @@ class CppEditorFactory : public Core::IEditorFactory
public:
CppEditorFactory(CppPlugin *owner);
virtual QStringList mimeTypes() const;
// IEditorFactory
QStringList mimeTypes() const;
Core::IEditor *createEditor(QWidget *parent);
virtual QString id() const;
virtual QString displayName() const;
Core::Id id() const;
QString displayName() const;
Core::IFile *open(const QString &fileName);
private:
......
......@@ -315,7 +315,7 @@ void CppFileSettingsWidget::slotEdit()
setLicenseTemplatePath(path);
}
// Edit (now) existing file with C++
Core::EditorManager::instance()->openEditor(path, QLatin1String(CppEditor::Constants::CPPEDITOR_ID),
Core::EditorManager::instance()->openEditor(path, CppEditor::Constants::CPPEDITOR_ID,
Core::EditorManager::ModeSwitch);
}
......
......@@ -631,7 +631,7 @@ void CVSPlugin::cvsDiff(const CvsDiffParameters &p)
CVSSubmitEditor *CVSPlugin::openCVSSubmitEditor(const QString &fileName)
{
Core::IEditor *editor = Core::EditorManager::instance()->openEditor(fileName, QLatin1String(Constants::CVSCOMMITEDITOR_ID),
Core::IEditor *editor = Core::EditorManager::instance()->openEditor(fileName, Constants::CVSCOMMITEDITOR_ID,
Core::EditorManager::ModeSwitch);
CVSSubmitEditor *submitEditor = qobject_cast<CVSSubmitEditor*>(editor);
QTC_CHECK(submitEditor);
......
......@@ -61,9 +61,9 @@ FormEditorFactory::FormEditorFactory()
QLatin1String("ui"));
}
QString FormEditorFactory::id() const
Core::Id FormEditorFactory::id() const
{
return QLatin1String(K_DESIGNER_XML_EDITOR_ID);
return K_DESIGNER_XML_EDITOR_ID;
}
QString FormEditorFactory::displayName() const
......
......@@ -37,25 +37,20 @@
#include <QtCore/QStringList>
namespace Core {
class IEditor;
class IFile;
}
namespace Designer {
namespace Internal {
class FormEditorFactory : public Core::IEditorFactory
{
Q_OBJECT
public:
FormEditorFactory();
virtual QStringList mimeTypes() const;
// IEditorFactory
virtual QString id() const;
virtual QString displayName() const;
QStringList mimeTypes() const;
Core::Id id() const;
QString displayName() const;
Core::IFile *open(const QString &fileName);
Core::IEditor *createEditor(QWidget *parent);
......
......@@ -75,9 +75,9 @@ QStringList ProjectFilesFactory::mimeTypes() const
return m_mimeTypes;
}
QString ProjectFilesFactory::id() const
Core::Id ProjectFilesFactory::id() const
{
return QLatin1String(Constants::FILES_EDITOR_ID);
return Constants::FILES_EDITOR_ID;
}
QString ProjectFilesFactory::displayName() const
......
......@@ -63,7 +63,7 @@ public:
virtual Core::IEditor *createEditor(QWidget *parent);
virtual QStringList mimeTypes() const;
virtual QString id() const;
virtual Core::Id id() const;
virtual QString displayName() const;
virtual Core::IFile *open(const QString &fileName);
......
......@@ -713,7 +713,7 @@ void GitPlugin::startCommit(bool amend)
Core::IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const CommitData &cd, bool amend)
{