forked from qt-creator/qt-creator
use Core::Id for IEditorFactory::id
Change-Id: Iefd67a0461d9016b8ba0f3371df7ec6d42e188c5 Reviewed-on: http://codereview.qt-project.org/4321 Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user