DocumentModel: Make interface static

Move item model implementation to private, adjust user code.

Change-Id: Ifbe94e7c7b9b1e8be1b4c531958dbd7a9413af13
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
hjk
2014-05-07 16:25:04 +02:00
parent 226c1abc89
commit 6e584b5b49
41 changed files with 259 additions and 246 deletions

View File

@@ -716,7 +716,7 @@ void IndexerPrivate::runCore(const QHash<QString, FileData> & /*headers*/,
QHash<ProjectPart::Ptr, QList<IndexerPrivate::FileData> > parts; QHash<ProjectPart::Ptr, QList<IndexerPrivate::FileData> > parts;
typedef QHash<ProjectPart::Ptr, QList<IndexerPrivate::FileData> >::Iterator PartIter; typedef QHash<ProjectPart::Ptr, QList<IndexerPrivate::FileData> >::Iterator PartIter;
QList<Core::IDocument *> docs = Core::EditorManager::documentModel()->openedDocuments(); QList<Core::IDocument *> docs = Core::DocumentModel::openedDocuments();
QSet<QString> openDocs; QSet<QString> openDocs;
foreach (Core::IDocument *doc, docs) foreach (Core::IDocument *doc, docs)
openDocs.insert(doc->filePath()); openDocs.insert(doc->filePath());

View File

@@ -197,7 +197,7 @@ bool CMakeProject::parseCMakeLists()
} }
CMakeBuildConfiguration *activeBC = static_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration()); CMakeBuildConfiguration *activeBC = static_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
foreach (Core::IDocument *document, Core::EditorManager::documentModel()->openedDocuments()) foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments())
if (isProjectFile(document->filePath())) if (isProjectFile(document->filePath()))
document->infoBar()->removeInfo("CMakeEditor.RunCMake"); document->infoBar()->removeInfo("CMakeEditor.RunCMake");

View File

@@ -1434,7 +1434,7 @@ void DocumentManager::executeOpenWithMenuAction(QAction *action)
if (entry.editorFactory) { if (entry.editorFactory) {
// close any open editors that have this file open, but have a different type. // close any open editors that have this file open, but have a different type.
QList<IEditor *> editorsOpenForFile QList<IEditor *> editorsOpenForFile
= EditorManager::documentModel()->editorsForFilePath(entry.fileName); = DocumentModel::editorsForFilePath(entry.fileName);
if (!editorsOpenForFile.isEmpty()) { if (!editorsOpenForFile.isEmpty()) {
foreach (IEditor *openEditor, editorsOpenForFile) { foreach (IEditor *openEditor, editorsOpenForFile) {
if (entry.editorFactory->id() == openEditor->document()->id()) if (entry.editorFactory->id() == openEditor->document()->id())

View File

@@ -39,11 +39,31 @@
namespace Core { namespace Core {
struct DocumentModelPrivate class DocumentModelPrivate : public QAbstractItemModel
{ {
Q_OBJECT
public:
DocumentModelPrivate(); DocumentModelPrivate();
~DocumentModelPrivate(); ~DocumentModelPrivate();
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QModelIndex parent(const QModelIndex &/*index*/) const { return QModelIndex(); }
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
void addEntry(DocumentModel::Entry *entry);
void removeDocument(int idx);
int indexOfFilePath(const QString &filePath) const;
int indexOfDocument(IDocument *document) const;
private slots:
friend class DocumentModel;
void itemChanged();
private:
const QIcon m_lockedIcon; const QIcon m_lockedIcon;
const QIcon m_unlockedIcon; const QIcon m_unlockedIcon;
@@ -62,36 +82,49 @@ DocumentModelPrivate::~DocumentModelPrivate()
qDeleteAll(m_documents); qDeleteAll(m_documents);
} }
static DocumentModelPrivate *d;
DocumentModel::Entry::Entry() : DocumentModel::Entry::Entry() :
document(0) document(0)
{ {
} }
DocumentModel::DocumentModel(QObject *parent) : DocumentModel::DocumentModel()
QAbstractItemModel(parent), d(new DocumentModelPrivate)
{ {
} }
DocumentModel::~DocumentModel() void DocumentModel::init()
{
d = new DocumentModelPrivate;
}
void DocumentModel::destroy()
{ {
delete d; delete d;
} }
QIcon DocumentModel::lockedIcon() const QIcon DocumentModel::lockedIcon()
{ {
return d->m_lockedIcon; return d->m_lockedIcon;
} }
QIcon DocumentModel::unlockedIcon() const QIcon DocumentModel::unlockedIcon()
{ {
return d->m_unlockedIcon; return d->m_unlockedIcon;
} }
QString DocumentModel::Entry::fileName() const { QAbstractItemModel *DocumentModel::model()
{
return d;
}
QString DocumentModel::Entry::fileName() const
{
return document ? document->filePath() : m_fileName; return document ? document->filePath() : m_fileName;
} }
QString DocumentModel::Entry::displayName() const { QString DocumentModel::Entry::displayName() const
{
return document ? document->displayName() : m_displayName; return document ? document->displayName() : m_displayName;
} }
@@ -100,22 +133,22 @@ Id DocumentModel::Entry::id() const
return m_id; return m_id;
} }
int DocumentModel::columnCount(const QModelIndex &parent) const int DocumentModelPrivate::columnCount(const QModelIndex &parent) const
{ {
if (!parent.isValid()) if (!parent.isValid())
return 2; return 2;
return 0; return 0;
} }
int DocumentModel::rowCount(const QModelIndex &parent) const int DocumentModelPrivate::rowCount(const QModelIndex &parent) const
{ {
if (!parent.isValid()) if (!parent.isValid())
return d->m_documents.count() + 1/*<no document>*/; return m_documents.count() + 1/*<no document>*/;
return 0; return 0;
} }
// TODO remove // TODO remove
QList<IEditor *> DocumentModel::oneEditorForEachOpenedDocument() const QList<IEditor *> DocumentModel::oneEditorForEachOpenedDocument()
{ {
QList<IEditor *> result; QList<IEditor *> result;
QMapIterator<IDocument *, QList<IEditor *> > it(d->m_editors); QMapIterator<IDocument *, QList<IEditor *> > it(d->m_editors);
@@ -138,7 +171,7 @@ void DocumentModel::addEditor(IEditor *editor, bool *isNewDocument)
Entry *entry = new Entry; Entry *entry = new Entry;
entry->document = editor->document(); entry->document = editor->document();
entry->m_id = editor->document()->id(); entry->m_id = editor->document()->id();
addEntry(entry); d->addEntry(entry);
} }
} }
@@ -148,10 +181,10 @@ void DocumentModel::addRestoredDocument(const QString &fileName, const QString &
entry->m_fileName = fileName; entry->m_fileName = fileName;
entry->m_displayName = displayName; entry->m_displayName = displayName;
entry->m_id = id; entry->m_id = id;
addEntry(entry); d->addEntry(entry);
} }
DocumentModel::Entry *DocumentModel::firstRestoredDocument() const DocumentModel::Entry *DocumentModel::firstRestoredDocument()
{ {
for (int i = 0; i < d->m_documents.count(); ++i) for (int i = 0; i < d->m_documents.count(); ++i)
if (!d->m_documents.at(i)->document) if (!d->m_documents.at(i)->document)
@@ -159,16 +192,16 @@ DocumentModel::Entry *DocumentModel::firstRestoredDocument() const
return 0; return 0;
} }
void DocumentModel::addEntry(Entry *entry) void DocumentModelPrivate::addEntry(DocumentModel::Entry *entry)
{ {
QString fileName = entry->fileName(); QString fileName = entry->fileName();
// replace a non-loaded entry (aka 'restored') if possible // replace a non-loaded entry (aka 'restored') if possible
int previousIndex = indexOfFilePath(fileName); int previousIndex = indexOfFilePath(fileName);
if (previousIndex >= 0) { if (previousIndex >= 0) {
if (entry->document && d->m_documents.at(previousIndex)->document == 0) { if (entry->document && m_documents.at(previousIndex)->document == 0) {
Entry *previousEntry = d->m_documents.at(previousIndex); DocumentModel::Entry *previousEntry = m_documents.at(previousIndex);
d->m_documents[previousIndex] = entry; m_documents[previousIndex] = entry;
delete previousEntry; delete previousEntry;
connect(entry->document, SIGNAL(changed()), this, SLOT(itemChanged())); connect(entry->document, SIGNAL(changed()), this, SLOT(itemChanged()));
} else { } else {
@@ -179,19 +212,24 @@ void DocumentModel::addEntry(Entry *entry)
int index; int index;
QString displayName = entry->displayName(); QString displayName = entry->displayName();
for (index = 0; index < d->m_documents.count(); ++index) { for (index = 0; index < m_documents.count(); ++index) {
if (displayName < d->m_documents.at(index)->displayName()) if (displayName < m_documents.at(index)->displayName())
break; break;
} }
int row = index + 1/*<no document>*/; int row = index + 1/*<no document>*/;
beginInsertRows(QModelIndex(), row, row); beginInsertRows(QModelIndex(), row, row);
d->m_documents.insert(index, entry); m_documents.insert(index, entry);
if (entry->document) if (entry->document)
connect(entry->document, SIGNAL(changed()), this, SLOT(itemChanged())); connect(entry->document, SIGNAL(changed()), this, SLOT(itemChanged()));
endInsertRows(); endInsertRows();
} }
int DocumentModel::indexOfFilePath(const QString &filePath) const int DocumentModel::indexOfFilePath(const QString &filePath)
{
return d->indexOfFilePath(filePath);
}
int DocumentModelPrivate::indexOfFilePath(const QString &filePath) const
{ {
if (filePath.isEmpty()) if (filePath.isEmpty())
return -1; return -1;
@@ -207,7 +245,7 @@ void DocumentModel::removeEntry(DocumentModel::Entry *entry)
{ {
QTC_ASSERT(!entry->document, return); // we wouldn't know what to do with the associated editors QTC_ASSERT(!entry->document, return); // we wouldn't know what to do with the associated editors
int index = d->m_documents.indexOf(entry); int index = d->m_documents.indexOf(entry);
removeDocument(index); d->removeDocument(index);
} }
void DocumentModel::removeEditor(IEditor *editor, bool *lastOneForDocument) void DocumentModel::removeEditor(IEditor *editor, bool *lastOneForDocument)
@@ -222,7 +260,7 @@ void DocumentModel::removeEditor(IEditor *editor, bool *lastOneForDocument)
if (lastOneForDocument) if (lastOneForDocument)
*lastOneForDocument = true; *lastOneForDocument = true;
d->m_editors.remove(document); d->m_editors.remove(document);
removeDocument(indexOfDocument(document)); d->removeDocument(indexOfDocument(document));
} }
} }
@@ -230,10 +268,10 @@ void DocumentModel::removeDocument(const QString &fileName)
{ {
int index = indexOfFilePath(fileName); int index = indexOfFilePath(fileName);
QTC_ASSERT(!d->m_documents.at(index)->document, return); // we wouldn't know what to do with the associated editors QTC_ASSERT(!d->m_documents.at(index)->document, return); // we wouldn't know what to do with the associated editors
removeDocument(index); d->removeDocument(index);
} }
void DocumentModel::removeDocument(int idx) void DocumentModelPrivate::removeDocument(int idx)
{ {
if (idx < 0) if (idx < 0)
return; return;
@@ -252,19 +290,24 @@ void DocumentModel::removeAllRestoredDocuments()
for (int i = d->m_documents.count()-1; i >= 0; --i) { for (int i = d->m_documents.count()-1; i >= 0; --i) {
if (!d->m_documents.at(i)->document) { if (!d->m_documents.at(i)->document) {
int row = i + 1/*<no document>*/; int row = i + 1/*<no document>*/;
beginRemoveRows(QModelIndex(), row, row); d->beginRemoveRows(QModelIndex(), row, row);
delete d->m_documents.takeAt(i); delete d->m_documents.takeAt(i);
endRemoveRows(); d->endRemoveRows();
} }
} }
} }
QList<IEditor *> DocumentModel::editorsForDocument(IDocument *document) const QList<IEditor *> DocumentModel::editorsForDocument(IDocument *document)
{ {
return d->m_editors.value(document); return d->m_editors.value(document);
} }
QList<IEditor *> DocumentModel::editorsForDocuments(const QList<IDocument *> &documents) const QList<IEditor *> DocumentModel::editorsForOpenedDocuments()
{
return editorsForDocuments(openedDocuments());
}
QList<IEditor *> DocumentModel::editorsForDocuments(const QList<IDocument *> &documents)
{ {
QList<IEditor *> result; QList<IEditor *> result;
foreach (IDocument *document, documents) foreach (IDocument *document, documents)
@@ -272,15 +315,20 @@ QList<IEditor *> DocumentModel::editorsForDocuments(const QList<IDocument *> &do
return result; return result;
} }
int DocumentModel::indexOfDocument(IDocument *document) const int DocumentModel::indexOfDocument(IDocument *document)
{ {
for (int i = 0; i < d->m_documents.count(); ++i) return d->indexOfDocument(document);
if (d->m_documents.at(i)->document == document) }
int DocumentModelPrivate::indexOfDocument(IDocument *document) const
{
for (int i = 0; i < m_documents.count(); ++i)
if (m_documents.at(i)->document == document)
return i; return i;
return -1; return -1;
} }
DocumentModel::Entry *DocumentModel::entryForDocument(IDocument *document) const DocumentModel::Entry *DocumentModel::entryForDocument(IDocument *document)
{ {
int index = indexOfDocument(document); int index = indexOfDocument(document);
if (index < 0) if (index < 0)
@@ -288,12 +336,12 @@ DocumentModel::Entry *DocumentModel::entryForDocument(IDocument *document) const
return d->m_documents.at(index); return d->m_documents.at(index);
} }
QList<IDocument *> DocumentModel::openedDocuments() const QList<IDocument *> DocumentModel::openedDocuments()
{ {
return d->m_editors.keys(); return d->m_editors.keys();
} }
IDocument *DocumentModel::documentForFilePath(const QString &filePath) const IDocument *DocumentModel::documentForFilePath(const QString &filePath)
{ {
int index = indexOfFilePath(filePath); int index = indexOfFilePath(filePath);
if (index < 0) if (index < 0)
@@ -301,7 +349,7 @@ IDocument *DocumentModel::documentForFilePath(const QString &filePath) const
return d->m_documents.at(index)->document; return d->m_documents.at(index)->document;
} }
QList<IEditor *> DocumentModel::editorsForFilePath(const QString &filePath) const QList<IEditor *> DocumentModel::editorsForFilePath(const QString &filePath)
{ {
IDocument *document = documentForFilePath(filePath); IDocument *document = documentForFilePath(filePath);
if (document) if (document)
@@ -309,15 +357,15 @@ QList<IEditor *> DocumentModel::editorsForFilePath(const QString &filePath) cons
return QList<IEditor *>(); return QList<IEditor *>();
} }
QModelIndex DocumentModel::index(int row, int column, const QModelIndex &parent) const QModelIndex DocumentModelPrivate::index(int row, int column, const QModelIndex &parent) const
{ {
Q_UNUSED(parent) Q_UNUSED(parent)
if (column < 0 || column > 1 || row < 0 || row >= d->m_documents.count() + 1/*<no document>*/) if (column < 0 || column > 1 || row < 0 || row >= m_documents.count() + 1/*<no document>*/)
return QModelIndex(); return QModelIndex();
return createIndex(row, column); return createIndex(row, column);
} }
DocumentModel::Entry *DocumentModel::documentAtRow(int row) const DocumentModel::Entry *DocumentModel::documentAtRow(int row)
{ {
int entryIndex = row - 1/*<no document>*/; int entryIndex = row - 1/*<no document>*/;
if (entryIndex < 0) if (entryIndex < 0)
@@ -325,12 +373,12 @@ DocumentModel::Entry *DocumentModel::documentAtRow(int row) const
return d->m_documents[entryIndex]; return d->m_documents[entryIndex];
} }
int DocumentModel::documentCount() const int DocumentModel::documentCount()
{ {
return d->m_documents.count(); return d->m_documents.count();
} }
QVariant DocumentModel::data(const QModelIndex &index, int role) const QVariant DocumentModelPrivate::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid() || (index.column() != 0 && role < Qt::UserRole)) if (!index.isValid() || (index.column() != 0 && role < Qt::UserRole))
return QVariant(); return QVariant();
@@ -346,7 +394,7 @@ QVariant DocumentModel::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
} }
} }
const Entry *e = d->m_documents.at(entryIndex); const DocumentModel::Entry *e = m_documents.at(entryIndex);
switch (role) { switch (role) {
case Qt::DisplayRole: case Qt::DisplayRole:
return (e->document && e->document->isModified()) return (e->document && e->document->isModified())
@@ -362,7 +410,7 @@ QVariant DocumentModel::data(const QModelIndex &index, int role) const
} else { } else {
showLock = !QFileInfo(e->m_fileName).isWritable(); showLock = !QFileInfo(e->m_fileName).isWritable();
} }
return showLock ? d->m_lockedIcon : QIcon(); return showLock ? m_lockedIcon : QIcon();
} }
case Qt::ToolTipRole: case Qt::ToolTipRole:
return e->fileName().isEmpty() return e->fileName().isEmpty()
@@ -374,14 +422,14 @@ QVariant DocumentModel::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
} }
int DocumentModel::rowOfDocument(IDocument *document) const int DocumentModel::rowOfDocument(IDocument *document)
{ {
if (!document) if (!document)
return 0 /*<no document>*/; return 0 /*<no document>*/;
return indexOfDocument(document) + 1/*<no document>*/; return indexOfDocument(document) + 1/*<no document>*/;
} }
void DocumentModel::itemChanged() void DocumentModelPrivate::itemChanged()
{ {
IDocument *document = qobject_cast<IDocument *>(sender()); IDocument *document = qobject_cast<IDocument *>(sender());
@@ -392,9 +440,11 @@ void DocumentModel::itemChanged()
emit dataChanged(mindex, mindex); emit dataChanged(mindex, mindex);
} }
QList<DocumentModel::Entry *> DocumentModel::documents() const QList<DocumentModel::Entry *> DocumentModel::documents()
{ {
return d->m_documents; return d->m_documents;
} }
} // namespace Core } // namespace Core
#include "documentmodel.moc"

View File

@@ -39,26 +39,19 @@ QT_FORWARD_DECLARE_CLASS(QIcon)
namespace Core { namespace Core {
struct DocumentModelPrivate;
class IEditor; class IEditor;
class IDocument; class IDocument;
class CORE_EXPORT DocumentModel : public QAbstractItemModel class CORE_EXPORT DocumentModel
{ {
Q_OBJECT
public: public:
explicit DocumentModel(QObject *parent); static void init();
virtual ~DocumentModel(); static void destroy();
QIcon lockedIcon() const; static QIcon lockedIcon();
QIcon unlockedIcon() const; static QIcon unlockedIcon();
int columnCount(const QModelIndex &parent = QModelIndex()) const; static QAbstractItemModel *model();
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QModelIndex parent(const QModelIndex &/*index*/) const { return QModelIndex(); }
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
struct CORE_EXPORT Entry { struct CORE_EXPORT Entry {
Entry(); Entry();
@@ -71,39 +64,34 @@ public:
Id m_id; Id m_id;
}; };
Entry *documentAtRow(int row) const; static Entry *documentAtRow(int row);
int rowOfDocument(IDocument *document) const; static int rowOfDocument(IDocument *document);
int documentCount() const; static int documentCount();
QList<Entry *> documents() const; static QList<Entry *> documents();
int indexOfDocument(IDocument *document) const; static int indexOfDocument(IDocument *document);
int indexOfFilePath(const QString &filePath) const; static int indexOfFilePath(const QString &filePath);
Entry *entryForDocument(IDocument *document) const; static Entry *entryForDocument(IDocument *document);
QList<IDocument *> openedDocuments() const; static QList<IDocument *> openedDocuments();
IDocument *documentForFilePath(const QString &filePath) const; static IDocument *documentForFilePath(const QString &filePath);
QList<IEditor *> editorsForFilePath(const QString &filePath) const; static QList<IEditor *> editorsForFilePath(const QString &filePath);
QList<IEditor *> editorsForDocument(IDocument *document) const; static QList<IEditor *> editorsForDocument(IDocument *document);
QList<IEditor *> editorsForDocuments(const QList<IDocument *> &documents) const; static QList<IEditor *> editorsForDocuments(const QList<IDocument *> &documents);
QList<IEditor *> oneEditorForEachOpenedDocument() const; static QList<IEditor *> oneEditorForEachOpenedDocument();
static QList<IEditor *> editorsForOpenedDocuments();
// editor manager related functions, nobody else should call it // editor manager related functions, nobody else should call it
void addEditor(IEditor *editor, bool *isNewDocument); static void addEditor(IEditor *editor, bool *isNewDocument);
void addRestoredDocument(const QString &fileName, const QString &displayName, const Id &id); static void addRestoredDocument(const QString &fileName, const QString &displayName, const Id &id);
Entry *firstRestoredDocument() const; static Entry *firstRestoredDocument();
void removeEditor(IEditor *editor, bool *lastOneForDocument); static void removeEditor(IEditor *editor, bool *lastOneForDocument);
void removeDocument(const QString &fileName); static void removeDocument(const QString &fileName);
void removeEntry(Entry *entry); static void removeEntry(Entry *entry);
void removeAllRestoredDocuments(); static void removeAllRestoredDocuments();
private slots:
void itemChanged();
private: private:
void addEntry(Entry *entry); DocumentModel();
void removeDocument(int idx);
DocumentModelPrivate *d;
}; };
} // namespace Core } // namespace Core

View File

@@ -203,8 +203,6 @@ public:
QMap<QString, QVariant> m_editorStates; QMap<QString, QVariant> m_editorStates;
Internal::OpenEditorsViewFactory *m_openEditorsFactory; Internal::OpenEditorsViewFactory *m_openEditorsFactory;
DocumentModel *m_documentModel;
IDocument::ReloadSetting m_reloadSetting; IDocument::ReloadSetting m_reloadSetting;
QString m_titleAddition; QString m_titleAddition;
@@ -244,12 +242,13 @@ EditorManagerPrivate::EditorManagerPrivate(QWidget *parent) :
m_autoSaveEnabled(true), m_autoSaveEnabled(true),
m_autoSaveInterval(5) m_autoSaveInterval(5)
{ {
m_documentModel = new DocumentModel(parent); DocumentModel::init();
} }
EditorManagerPrivate::~EditorManagerPrivate() EditorManagerPrivate::~EditorManagerPrivate()
{ {
// clearNavigationHistory(); // clearNavigationHistory();
DocumentModel::destroy();
} }
static EditorManager *m_instance = 0; static EditorManager *m_instance = 0;
@@ -503,7 +502,7 @@ EditorToolBar *EditorManager::createToolBar(QWidget *parent)
void EditorManager::removeEditor(IEditor *editor) void EditorManager::removeEditor(IEditor *editor)
{ {
bool lastOneForDocument = false; bool lastOneForDocument = false;
d->m_documentModel->removeEditor(editor, &lastOneForDocument); DocumentModel::removeEditor(editor, &lastOneForDocument);
if (lastOneForDocument) if (lastOneForDocument)
DocumentManager::removeDocument(editor->document()); DocumentManager::removeDocument(editor->document());
ICore::removeContextObject(editor); ICore::removeContextObject(editor);
@@ -639,7 +638,7 @@ void EditorManager::emptyView(Core::Internal::EditorView *view)
QList<IEditor *> editors = view->editors(); QList<IEditor *> editors = view->editors();
foreach (IEditor *editor, editors) { foreach (IEditor *editor, editors) {
if (d->m_documentModel->editorsForDocument(editor->document()).size() == 1) { if (DocumentModel::editorsForDocument(editor->document()).size() == 1) {
// it's the only editor for that file // it's the only editor for that file
// so we need to keep it around (--> in the editor model) // so we need to keep it around (--> in the editor model)
if (currentEditor() == editor) { if (currentEditor() == editor) {
@@ -720,16 +719,16 @@ void EditorManager::closeView(Core::Internal::EditorView *view)
bool EditorManager::closeAllEditors(bool askAboutModifiedEditors) bool EditorManager::closeAllEditors(bool askAboutModifiedEditors)
{ {
d->m_documentModel->removeAllRestoredDocuments(); DocumentModel::removeAllRestoredDocuments();
if (closeDocuments(d->m_documentModel->openedDocuments(), askAboutModifiedEditors)) if (closeDocuments(DocumentModel::openedDocuments(), askAboutModifiedEditors))
return true; return true;
return false; return false;
} }
void EditorManager::closeAllEditorsExceptVisible() void EditorManager::closeAllEditorsExceptVisible()
{ {
d->m_documentModel->removeAllRestoredDocuments(); DocumentModel::removeAllRestoredDocuments();
QList<IDocument *> documentsToClose = d->m_documentModel->openedDocuments(); QList<IDocument *> documentsToClose = DocumentModel::openedDocuments();
foreach (IEditor *editor, visibleEditors()) foreach (IEditor *editor, visibleEditors())
documentsToClose.removeAll(editor->document()); documentsToClose.removeAll(editor->document());
closeDocuments(documentsToClose, true); closeDocuments(documentsToClose, true);
@@ -737,8 +736,8 @@ void EditorManager::closeAllEditorsExceptVisible()
void EditorManager::closeOtherEditors(IDocument *document) void EditorManager::closeOtherEditors(IDocument *document)
{ {
d->m_documentModel->removeAllRestoredDocuments(); DocumentModel::removeAllRestoredDocuments();
QList<IDocument *> documentsToClose = d->m_documentModel->openedDocuments(); QList<IDocument *> documentsToClose = DocumentModel::openedDocuments();
documentsToClose.removeAll(document); documentsToClose.removeAll(document);
closeDocuments(documentsToClose, true); closeDocuments(documentsToClose, true);
} }
@@ -799,8 +798,8 @@ void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentMod
: tr("Close Other Editors")); : tr("Close Other Editors"));
d->m_closeCurrentEditorContextAction->setEnabled(entry != 0); d->m_closeCurrentEditorContextAction->setEnabled(entry != 0);
d->m_closeOtherEditorsContextAction->setEnabled(entry != 0); d->m_closeOtherEditorsContextAction->setEnabled(entry != 0);
d->m_closeAllEditorsContextAction->setEnabled(!d->m_documentModel->documents().isEmpty()); d->m_closeAllEditorsContextAction->setEnabled(!DocumentModel::documents().isEmpty());
d->m_closeAllEditorsExceptVisibleContextAction->setEnabled(visibleDocumentsCount() < d->m_documentModel->documents().count()); d->m_closeAllEditorsExceptVisibleContextAction->setEnabled(visibleDocumentsCount() < DocumentModel::documents().count());
contextMenu->addAction(d->m_closeCurrentEditorContextAction); contextMenu->addAction(d->m_closeCurrentEditorContextAction);
contextMenu->addAction(d->m_closeAllEditorsContextAction); contextMenu->addAction(d->m_closeAllEditorsContextAction);
contextMenu->addAction(d->m_closeOtherEditorsContextAction); contextMenu->addAction(d->m_closeOtherEditorsContextAction);
@@ -944,7 +943,7 @@ void EditorManager::closeEditorFromContextMenu()
{ {
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : 0; IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : 0;
if (document) if (document)
closeEditors(d->m_documentModel->editorsForDocument(document)); closeEditors(DocumentModel::editorsForDocument(document));
} }
void EditorManager::closeOtherEditorsFromContextMenu() void EditorManager::closeOtherEditorsFromContextMenu()
@@ -1042,9 +1041,9 @@ void EditorManager::closeEditor(DocumentModel::Entry *entry)
if (!entry) if (!entry)
return; return;
if (entry->document) if (entry->document)
closeEditors(d->m_documentModel->editorsForDocument(entry->document)); closeEditors(DocumentModel::editorsForDocument(entry->document));
else else
d->m_documentModel->removeEntry(entry); DocumentModel::removeEntry(entry);
} }
bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool askAboutModifiedEditors) bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool askAboutModifiedEditors)
@@ -1070,7 +1069,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
} }
} }
if (editorAccepted) { if (editorAccepted) {
acceptedEditors += d->m_documentModel->editorsForDocument(editor->document()).toSet(); acceptedEditors += DocumentModel::editorsForDocument(editor->document()).toSet();
acceptedDocuments.insert(editor->document()); acceptedDocuments.insert(editor->document());
} }
} }
@@ -1087,7 +1086,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
if (!list.isEmpty()) { if (!list.isEmpty()) {
closingFailed = true; closingFailed = true;
acceptedDocuments.subtract(list.toSet()); acceptedDocuments.subtract(list.toSet());
QSet<IEditor*> skipSet = d->m_documentModel->editorsForDocuments(list).toSet(); QSet<IEditor*> skipSet = DocumentModel::editorsForDocuments(list).toSet();
acceptedEditors = acceptedEditors.subtract(skipSet); acceptedEditors = acceptedEditors.subtract(skipSet);
} }
} }
@@ -1135,12 +1134,12 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
if (newCurrent) { if (newCurrent) {
activateEditor(view, newCurrent, flags); activateEditor(view, newCurrent, flags);
} else { } else {
DocumentModel::Entry *entry = d->m_documentModel->firstRestoredDocument(); DocumentModel::Entry *entry = DocumentModel::firstRestoredDocument();
if (entry) { if (entry) {
activateEditorForEntry(view, entry, flags); activateEditorForEntry(view, entry, flags);
} else { } else {
// no "restored" ones, so any entry left should have a document // no "restored" ones, so any entry left should have a document
const QList<DocumentModel::Entry *> documents = d->m_documentModel->documents(); const QList<DocumentModel::Entry *> documents = DocumentModel::documents();
if (!documents.isEmpty()) { if (!documents.isEmpty()) {
IDocument *document = documents.last()->document; IDocument *document = documents.last()->document;
if (document) if (document)
@@ -1173,8 +1172,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
Core::IEditor *EditorManager::pickUnusedEditor(EditorView **foundView) Core::IEditor *EditorManager::pickUnusedEditor(EditorView **foundView)
{ {
foreach (IEditor *editor, foreach (IEditor *editor, DocumentModel::editorsForOpenedDocuments()) {
d->m_documentModel->editorsForDocuments(d->m_documentModel->openedDocuments())) {
EditorView *view = viewForEditor(editor); EditorView *view = viewForEditor(editor);
if (!view || view->currentEditor() != editor) { if (!view || view->currentEditor() != editor) {
if (foundView) if (foundView)
@@ -1206,7 +1204,7 @@ void EditorManager::activateEditorForEntry(Internal::EditorView *view, DocumentM
} }
if (!openEditor(view, entry->fileName(), entry->id(), flags)) if (!openEditor(view, entry->fileName(), entry->id(), flags))
d->m_documentModel->removeEntry(entry); DocumentModel::removeEntry(entry);
} }
void EditorManager::activateView(EditorView *view) void EditorManager::activateView(EditorView *view)
@@ -1312,7 +1310,7 @@ Core::IEditor *EditorManager::activateEditorForDocument(Core::Internal::EditorVi
Q_ASSERT(view); Q_ASSERT(view);
IEditor *editor = view->editorForDocument(document); IEditor *editor = view->editorForDocument(document);
if (!editor) { if (!editor) {
const QList<IEditor*> editors = d->m_documentModel->editorsForDocument(document); const QList<IEditor*> editors = DocumentModel::editorsForDocument(document);
if (editors.isEmpty()) if (editors.isEmpty())
return 0; return 0;
editor = editors.first(); editor = editors.first();
@@ -1433,7 +1431,7 @@ void EditorManager::addEditor(IEditor *editor)
ICore::addContextObject(editor); ICore::addContextObject(editor);
bool isNewDocument = false; bool isNewDocument = false;
d->m_documentModel->addEditor(editor, &isNewDocument); DocumentModel::addEditor(editor, &isNewDocument);
if (isNewDocument) { if (isNewDocument) {
const bool isTemporary = editor->document()->isTemporary(); const bool isTemporary = editor->document()->isTemporary();
const bool addWatcher = !isTemporary; const bool addWatcher = !isTemporary;
@@ -1591,7 +1589,7 @@ IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QStri
if (newEditor) if (newEditor)
*newEditor = false; *newEditor = false;
const QList<IEditor *> editors = d->m_documentModel->editorsForFilePath(fn); const QList<IEditor *> editors = DocumentModel::editorsForFilePath(fn);
if (!editors.isEmpty()) { if (!editors.isEmpty()) {
IEditor *editor = editors.first(); IEditor *editor = editors.first();
editor = activateEditor(view, editor, flags); editor = activateEditor(view, editor, flags);
@@ -1688,7 +1686,7 @@ IEditor *EditorManager::openEditorWithContents(const Id &editorId,
if (base.contains(dollar)) { if (base.contains(dollar)) {
int i = 1; int i = 1;
QSet<QString> docnames; QSet<QString> docnames;
foreach (DocumentModel::Entry *entry, d->m_documentModel->documents()) { foreach (DocumentModel::Entry *entry, DocumentModel::documents()) {
QString name = entry->fileName(); QString name = entry->fileName();
if (name.isEmpty()) if (name.isEmpty())
name = entry->displayName(); name = entry->displayName();
@@ -1786,7 +1784,7 @@ void EditorManager::autoSave()
{ {
QStringList errors; QStringList errors;
// FIXME: the saving should be staggered // FIXME: the saving should be staggered
foreach (IDocument *document, d->m_documentModel->openedDocuments()) { foreach (IDocument *document, DocumentModel::openedDocuments()) {
if (!document->isModified() || !document->shouldAutoSave()) if (!document->isModified() || !document->shouldAutoSave())
continue; continue;
if (document->filePath().isEmpty()) // FIXME: save them to a dedicated directory if (document->filePath().isEmpty()) // FIXME: save them to a dedicated directory
@@ -1836,7 +1834,7 @@ bool EditorManager::saveDocumentAs(IDocument *documentParam)
if (absoluteFilePath != document->filePath()) { if (absoluteFilePath != document->filePath()) {
// close existing editors for the new file name // close existing editors for the new file name
IDocument *otherDocument = d->m_documentModel->documentForFilePath(absoluteFilePath); IDocument *otherDocument = DocumentModel::documentForFilePath(absoluteFilePath);
if (otherDocument) if (otherDocument)
closeDocuments(QList<IDocument *>() << otherDocument, false); closeDocuments(QList<IDocument *>() << otherDocument, false);
} }
@@ -1862,7 +1860,7 @@ void EditorManager::addDocumentToRecentFiles(IDocument *document)
{ {
if (document->isTemporary()) if (document->isTemporary())
return; return;
DocumentModel::Entry *entry = d->m_documentModel->entryForDocument(document); DocumentModel::Entry *entry = DocumentModel::entryForDocument(document);
if (!entry) if (!entry)
return; return;
DocumentManager::addToRecentFiles(document->filePath(), entry->id()); DocumentManager::addToRecentFiles(document->filePath(), entry->id());
@@ -1875,7 +1873,7 @@ void EditorManager::gotoNextDocHistory()
dialog->selectNextEditor(); dialog->selectNextEditor();
} else { } else {
EditorView *view = currentEditorView(); EditorView *view = currentEditorView();
dialog->setEditors(d->m_globalHistory, view, d->m_documentModel); dialog->setEditors(d->m_globalHistory, view);
dialog->selectNextEditor(); dialog->selectNextEditor();
showPopupOrSelectDocument(); showPopupOrSelectDocument();
} }
@@ -1888,7 +1886,7 @@ void EditorManager::gotoPreviousDocHistory()
dialog->selectPreviousEditor(); dialog->selectPreviousEditor();
} else { } else {
EditorView *view = currentEditorView(); EditorView *view = currentEditorView();
dialog->setEditors(d->m_globalHistory, view, d->m_documentModel); dialog->setEditors(d->m_globalHistory, view);
dialog->selectPreviousEditor(); dialog->selectPreviousEditor();
showPopupOrSelectDocument(); showPopupOrSelectDocument();
} }
@@ -2021,7 +2019,7 @@ void EditorManager::setupSaveActions(IDocument *document, QAction *saveAction, Q
void EditorManager::updateActions() void EditorManager::updateActions()
{ {
IDocument *curDocument = currentDocument(); IDocument *curDocument = currentDocument();
int openedCount = d->m_documentModel->documentCount(); const int openedCount = DocumentModel::documentCount();
if (curDocument) { if (curDocument) {
if (HostOsInfo::isMacHost()) if (HostOsInfo::isMacHost())
@@ -2045,10 +2043,10 @@ void EditorManager::updateActions()
d->m_closeOtherEditorsAction->setEnabled(openedCount > 1); d->m_closeOtherEditorsAction->setEnabled(openedCount > 1);
d->m_closeOtherEditorsAction->setText((openedCount > 1 ? tr("Close All Except %1").arg(quotedName) : tr("Close Others"))); d->m_closeOtherEditorsAction->setText((openedCount > 1 ? tr("Close All Except %1").arg(quotedName) : tr("Close Others")));
d->m_closeAllEditorsExceptVisibleAction->setEnabled(visibleDocumentsCount() < d->m_documentModel->documents().count()); d->m_closeAllEditorsExceptVisibleAction->setEnabled(visibleDocumentsCount() < openedCount);
d->m_gotoNextDocHistoryAction->setEnabled(d->m_documentModel->rowCount() != 0); d->m_gotoNextDocHistoryAction->setEnabled(openedCount != 0);
d->m_gotoPreviousDocHistoryAction->setEnabled(d->m_documentModel->rowCount() != 0); d->m_gotoPreviousDocHistoryAction->setEnabled(openedCount != 0);
EditorView *view = currentEditorView(); EditorView *view = currentEditorView();
d->m_goBackAction->setEnabled(view ? view->canGoBack() : false); d->m_goBackAction->setEnabled(view ? view->canGoBack() : false);
d->m_goForwardAction->setEnabled(view ? view->canGoForward() : false); d->m_goForwardAction->setEnabled(view ? view->canGoForward() : false);
@@ -2121,14 +2119,9 @@ int EditorManager::visibleDocumentsCount()
return visibleDocuments.count(); return visibleDocuments.count();
} }
DocumentModel *EditorManager::documentModel()
{
return d->m_documentModel;
}
bool EditorManager::closeDocuments(const QList<IDocument *> &document, bool askAboutModifiedEditors) bool EditorManager::closeDocuments(const QList<IDocument *> &document, bool askAboutModifiedEditors)
{ {
return m_instance->closeEditors(d->m_documentModel->editorsForDocuments(document), askAboutModifiedEditors); return m_instance->closeEditors(DocumentModel::editorsForDocuments(document), askAboutModifiedEditors);
} }
void EditorManager::addCurrentPositionToNavigationHistory(IEditor *editor, const QByteArray &saveState) void EditorManager::addCurrentPositionToNavigationHistory(IEditor *editor, const QByteArray &saveState)
@@ -2200,10 +2193,10 @@ QByteArray EditorManager::saveState()
stream << QByteArray("EditorManagerV4"); stream << QByteArray("EditorManagerV4");
// TODO: In case of split views it's not possible to restore these for all correctly with this // TODO: In case of split views it's not possible to restore these for all correctly with this
QList<IDocument *> documents = d->m_documentModel->openedDocuments(); QList<IDocument *> documents = DocumentModel::openedDocuments();
foreach (IDocument *document, documents) { foreach (IDocument *document, documents) {
if (!document->filePath().isEmpty() && !document->isTemporary()) { if (!document->filePath().isEmpty() && !document->isTemporary()) {
IEditor *editor = d->m_documentModel->editorsForDocument(document).first(); IEditor *editor = DocumentModel::editorsForDocument(document).first();
QByteArray state = editor->saveState(); QByteArray state = editor->saveState();
if (!state.isEmpty()) if (!state.isEmpty())
d->m_editorStates.insert(document->filePath(), QVariant(state)); d->m_editorStates.insert(document->filePath(), QVariant(state));
@@ -2212,7 +2205,7 @@ QByteArray EditorManager::saveState()
stream << d->m_editorStates; stream << d->m_editorStates;
QList<DocumentModel::Entry *> entries = d->m_documentModel->documents(); QList<DocumentModel::Entry *> entries = DocumentModel::documents();
int entriesCount = 0; int entriesCount = 0;
foreach (DocumentModel::Entry *entry, entries) { foreach (DocumentModel::Entry *entry, entries) {
// The editor may be 0 if it was not loaded yet: In that case it is not temporary // The editor may be 0 if it was not loaded yet: In that case it is not temporary
@@ -2270,7 +2263,7 @@ bool EditorManager::restoreState(const QByteArray &state)
if (rfi.exists() && fi.lastModified() < rfi.lastModified()) if (rfi.exists() && fi.lastModified() < rfi.lastModified())
openEditor(fileName, id, DoNotMakeVisible); openEditor(fileName, id, DoNotMakeVisible);
else else
d->m_documentModel->addRestoredDocument(fileName, displayName, id); DocumentModel::addRestoredDocument(fileName, displayName, id);
} }
} }

View File

@@ -132,7 +132,6 @@ public:
static IEditor *activateEditorForDocument(IDocument *document, OpenEditorFlags flags = 0); static IEditor *activateEditorForDocument(IDocument *document, OpenEditorFlags flags = 0);
static IEditor *activateEditorForDocument(Internal::EditorView *view, IDocument *document, OpenEditorFlags flags = 0); static IEditor *activateEditorForDocument(Internal::EditorView *view, IDocument *document, OpenEditorFlags flags = 0);
static DocumentModel *documentModel();
static bool closeDocuments(const QList<IDocument *> &documents, bool askAboutModifiedEditors = true); static bool closeDocuments(const QList<IDocument *> &documents, bool askAboutModifiedEditors = true);
static void closeEditor(DocumentModel::Entry *entry); static void closeEditor(DocumentModel::Entry *entry);
static void closeOtherEditors(IDocument *document); static void closeOtherEditors(IDocument *document);

View File

@@ -302,8 +302,7 @@ IEditor *EditorView::currentEditor() const
void EditorView::listSelectionActivated(int index) void EditorView::listSelectionActivated(int index)
{ {
EditorManager::activateEditorForEntry( EditorManager::activateEditorForEntry(this, DocumentModel::documentAtRow(index));
this, EditorManager::documentModel()->documentAtRow(index));
} }
void EditorView::splitHorizontally() void EditorView::splitHorizontally()
@@ -802,7 +801,7 @@ void SplitterOrView::restoreState(const QByteArray &state)
| Core::EditorManager::DoNotChangeCurrentEditor); | Core::EditorManager::DoNotChangeCurrentEditor);
if (!e) { if (!e) {
DocumentModel::Entry *entry = EditorManager::documentModel()->firstRestoredDocument(); DocumentModel::Entry *entry = DocumentModel::firstRestoredDocument();
if (entry) if (entry)
EditorManager::activateEditorForEntry(view(), entry, Core::EditorManager::IgnoreNavigationHistory EditorManager::activateEditorForEntry(view(), entry, Core::EditorManager::IgnoreNavigationHistory
| Core::EditorManager::DoNotChangeCurrentEditor); | Core::EditorManager::DoNotChangeCurrentEditor);

View File

@@ -97,7 +97,7 @@ OpenEditorsWidget::OpenEditorsWidget()
setFrameStyle(QFrame::NoFrame); setFrameStyle(QFrame::NoFrame);
setAttribute(Qt::WA_MacShowFocusRect, false); setAttribute(Qt::WA_MacShowFocusRect, false);
m_model = new ProxyModel(this); m_model = new ProxyModel(this);
m_model->setSourceModel(EditorManager::documentModel()); m_model->setSourceModel(DocumentModel::model());
setModel(m_model); setModel(m_model);
setSelectionMode(QAbstractItemView::SingleSelection); setSelectionMode(QAbstractItemView::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionBehavior(QAbstractItemView::SelectRows);
@@ -128,7 +128,7 @@ OpenEditorsWidget::~OpenEditorsWidget()
void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor) void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor)
{ {
IDocument *document = editor ? editor->document() : 0; IDocument *document = editor ? editor->document() : 0;
QModelIndex index = m_model->index(EditorManager::documentModel()->indexOfDocument(document), 0); QModelIndex index = m_model->index(DocumentModel::indexOfDocument(document), 0);
if (!index.isValid()) { if (!index.isValid()) {
clearSelection(); clearSelection();
return; return;
@@ -189,13 +189,13 @@ void OpenEditorsWidget::activateEditor(const QModelIndex &index)
{ {
selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
EditorManager::activateEditorForEntry( EditorManager::activateEditorForEntry(
EditorManager::documentModel()->documentAtRow(m_model->mapToSource(index).row())); DocumentModel::documentAtRow(m_model->mapToSource(index).row()));
} }
void OpenEditorsWidget::closeEditor(const QModelIndex &index) void OpenEditorsWidget::closeEditor(const QModelIndex &index)
{ {
EditorManager::closeEditor( EditorManager::closeEditor(
EditorManager::documentModel()->documentAtRow(m_model->mapToSource(index).row())); DocumentModel::documentAtRow(m_model->mapToSource(index).row()));
// work around selection changes // work around selection changes
updateCurrentItem(EditorManager::currentEditor()); updateCurrentItem(EditorManager::currentEditor());
} }
@@ -204,7 +204,7 @@ void OpenEditorsWidget::contextMenuRequested(QPoint pos)
{ {
QMenu contextMenu; QMenu contextMenu;
QModelIndex editorIndex = indexAt(pos); QModelIndex editorIndex = indexAt(pos);
DocumentModel::Entry *entry = EditorManager::documentModel()->documentAtRow( DocumentModel::Entry *entry = DocumentModel::documentAtRow(
m_model->mapToSource(editorIndex).row()); m_model->mapToSource(editorIndex).row());
EditorManager::addSaveAndCloseEditorActions(&contextMenu, entry); EditorManager::addSaveAndCloseEditorActions(&contextMenu, entry);
contextMenu.addSeparator(); contextMenu.addSeparator();

View File

@@ -194,18 +194,18 @@ void OpenEditorsWindow::centerOnItem(int selectedIndex)
} }
} }
void OpenEditorsWindow::setEditors(const QList<EditLocation> &globalHistory, EditorView *view, DocumentModel *model) void OpenEditorsWindow::setEditors(const QList<EditLocation> &globalHistory, EditorView *view)
{ {
m_editorList->clear(); m_editorList->clear();
QSet<IDocument*> documentsDone; QSet<IDocument*> documentsDone;
addHistoryItems(view->editorHistory(), view, model, documentsDone); addHistoryItems(view->editorHistory(), view, documentsDone);
// add missing editors from the global history // add missing editors from the global history
addHistoryItems(globalHistory, view, model, documentsDone); addHistoryItems(globalHistory, view, documentsDone);
// add purely restored editors which are not initialised yet // add purely restored editors which are not initialised yet
addRestoredItems(model); addRestoredItems();
} }
@@ -219,7 +219,7 @@ void OpenEditorsWindow::selectEditor(QTreeWidgetItem *item)
} else { } else {
if (!EditorManager::openEditor( if (!EditorManager::openEditor(
item->toolTip(0), item->data(0, Qt::UserRole+2).value<Core::Id>())) { item->toolTip(0), item->data(0, Qt::UserRole+2).value<Core::Id>())) {
EditorManager::documentModel()->removeDocument(item->toolTip(0)); DocumentModel::removeDocument(item->toolTip(0));
delete item; delete item;
} }
} }
@@ -239,7 +239,7 @@ void OpenEditorsWindow::ensureCurrentVisible()
void OpenEditorsWindow::addHistoryItems(const QList<EditLocation> &history, EditorView *view, void OpenEditorsWindow::addHistoryItems(const QList<EditLocation> &history, EditorView *view,
DocumentModel *model, QSet<IDocument *> &documentsDone) QSet<IDocument *> &documentsDone)
{ {
foreach (const EditLocation &hi, history) { foreach (const EditLocation &hi, history) {
if (hi.document.isNull() || documentsDone.contains(hi.document)) if (hi.document.isNull() || documentsDone.contains(hi.document))
@@ -251,7 +251,7 @@ void OpenEditorsWindow::addHistoryItems(const QList<EditLocation> &history, Edit
if (hi.document->isModified()) if (hi.document->isModified())
title += tr("*"); title += tr("*");
item->setIcon(0, !hi.document->filePath().isEmpty() && hi.document->isFileReadOnly() item->setIcon(0, !hi.document->filePath().isEmpty() && hi.document->isFileReadOnly()
? model->lockedIcon() : m_emptyIcon); ? DocumentModel::lockedIcon() : m_emptyIcon);
item->setText(0, title); item->setText(0, title);
item->setToolTip(0, hi.document->filePath()); item->setToolTip(0, hi.document->filePath());
item->setData(0, Qt::UserRole, QVariant::fromValue(hi.document.data())); item->setData(0, Qt::UserRole, QVariant::fromValue(hi.document.data()));
@@ -265,9 +265,9 @@ void OpenEditorsWindow::addHistoryItems(const QList<EditLocation> &history, Edit
} }
} }
void OpenEditorsWindow::addRestoredItems(DocumentModel *model) void OpenEditorsWindow::addRestoredItems()
{ {
foreach (DocumentModel::Entry *entry, model->documents()) { foreach (DocumentModel::Entry *entry, DocumentModel::documents()) {
if (entry->document) if (entry->document)
continue; continue;
QTreeWidgetItem *item = new QTreeWidgetItem(); QTreeWidgetItem *item = new QTreeWidgetItem();

View File

@@ -45,7 +45,6 @@ namespace Core {
class IDocument; class IDocument;
class IEditor; class IEditor;
class DocumentModel;
namespace Internal { namespace Internal {
@@ -60,7 +59,7 @@ public:
explicit OpenEditorsWindow(QWidget *parent = 0); explicit OpenEditorsWindow(QWidget *parent = 0);
void setEditors(const QList<EditLocation> &globalHistory, EditorView *view, DocumentModel *model); void setEditors(const QList<EditLocation> &globalHistory, EditorView *view);
bool eventFilter(QObject *src, QEvent *e); bool eventFilter(QObject *src, QEvent *e);
void focusInEvent(QFocusEvent *); void focusInEvent(QFocusEvent *);
@@ -76,9 +75,8 @@ private slots:
void selectEditor(QTreeWidgetItem *item); void selectEditor(QTreeWidgetItem *item);
private: private:
void addHistoryItems(const QList<EditLocation> &history, EditorView *view, void addHistoryItems(const QList<EditLocation> &history, EditorView *view, QSet<IDocument*> &documentsDone);
DocumentModel *model, QSet<IDocument*> &documentsDone); void addRestoredItems();
void addRestoredItems(DocumentModel *model);
void ensureCurrentVisible(); void ensureCurrentVisible();
bool isCentering(); bool isCentering();
void centerOnItem(int selectedIndex); void centerOnItem(int selectedIndex);

View File

@@ -54,10 +54,10 @@ enum {
namespace Core { namespace Core {
struct EditorToolBarPrivate { struct EditorToolBarPrivate
{
explicit EditorToolBarPrivate(QWidget *parent, EditorToolBar *q); explicit EditorToolBarPrivate(QWidget *parent, EditorToolBar *q);
Core::DocumentModel *m_editorsListModel;
QComboBox *m_editorList; QComboBox *m_editorList;
QToolButton *m_closeEditorButton; QToolButton *m_closeEditorButton;
QToolButton *m_lockButton; QToolButton *m_lockButton;
@@ -115,7 +115,6 @@ EditorToolBar::EditorToolBar(QWidget *parent) :
d->m_lockButton->setAutoRaise(true); d->m_lockButton->setAutoRaise(true);
d->m_lockButton->setEnabled(false); d->m_lockButton->setEnabled(false);
d->m_editorsListModel = EditorManager::documentModel();
connect(d->m_goBackAction, SIGNAL(triggered()), this, SIGNAL(goBackClicked())); connect(d->m_goBackAction, SIGNAL(triggered()), this, SIGNAL(goBackClicked()));
connect(d->m_goForwardAction, SIGNAL(triggered()), this, SIGNAL(goForwardClicked())); connect(d->m_goForwardAction, SIGNAL(triggered()), this, SIGNAL(goForwardClicked()));
@@ -123,7 +122,7 @@ EditorToolBar::EditorToolBar(QWidget *parent) :
d->m_editorList->setProperty("notelideasterisk", true); d->m_editorList->setProperty("notelideasterisk", true);
d->m_editorList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); d->m_editorList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
d->m_editorList->setMinimumContentsLength(20); d->m_editorList->setMinimumContentsLength(20);
d->m_editorList->setModel(d->m_editorsListModel); d->m_editorList->setModel(DocumentModel::model());
d->m_editorList->setMaxVisibleItems(40); d->m_editorList->setMaxVisibleItems(40);
d->m_editorList->setContextMenuPolicy(Qt::CustomContextMenu); d->m_editorList->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -291,7 +290,7 @@ void EditorToolBar::setToolbarCreationFlags(ToolbarCreationFlags flags)
void EditorToolBar::setCurrentEditor(IEditor *editor) void EditorToolBar::setCurrentEditor(IEditor *editor)
{ {
IDocument *document = editor ? editor->document() : 0; IDocument *document = editor ? editor->document() : 0;
d->m_editorList->setCurrentIndex(d->m_editorsListModel->rowOfDocument(document)); d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(document));
// If we never added the toolbar from the editor, we will never change // If we never added the toolbar from the editor, we will never change
// the editor, so there's no need to update the toolbar either. // the editor, so there's no need to update the toolbar either.
@@ -304,17 +303,17 @@ void EditorToolBar::setCurrentEditor(IEditor *editor)
void EditorToolBar::updateEditorListSelection(IEditor *newSelection) void EditorToolBar::updateEditorListSelection(IEditor *newSelection)
{ {
if (newSelection) if (newSelection)
d->m_editorList->setCurrentIndex(d->m_editorsListModel->rowOfDocument(newSelection->document())); d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(newSelection->document()));
} }
void EditorToolBar::changeActiveEditor(int row) void EditorToolBar::changeActiveEditor(int row)
{ {
EditorManager::activateEditorForEntry(d->m_editorsListModel->documentAtRow(row)); EditorManager::activateEditorForEntry(DocumentModel::documentAtRow(row));
} }
void EditorToolBar::listContextMenu(QPoint pos) void EditorToolBar::listContextMenu(QPoint pos)
{ {
DocumentModel::Entry *entry = EditorManager::documentModel()->documentAtRow( DocumentModel::Entry *entry = DocumentModel::documentAtRow(
d->m_editorList->currentIndex()); d->m_editorList->currentIndex());
QString fileName = entry ? entry->fileName() : QString(); QString fileName = entry ? entry->fileName() : QString();
QString shortFileName = entry ? QFileInfo(fileName).fileName() : QString(); QString shortFileName = entry ? QFileInfo(fileName).fileName() : QString();
@@ -362,7 +361,7 @@ void EditorToolBar::checkDocumentStatus()
{ {
IDocument *document = qobject_cast<IDocument *>(sender()); IDocument *document = qobject_cast<IDocument *>(sender());
QTC_ASSERT(document, return); QTC_ASSERT(document, return);
DocumentModel::Entry *entry = EditorManager::documentModel()->documentAtRow( DocumentModel::Entry *entry = DocumentModel::documentAtRow(
d->m_editorList->currentIndex()); d->m_editorList->currentIndex());
if (entry && entry->document && entry->document == document) if (entry && entry->document && entry->document == document)
@@ -381,18 +380,18 @@ void EditorToolBar::updateDocumentStatus(IDocument *document)
return; return;
} }
d->m_editorList->setCurrentIndex(d->m_editorsListModel->rowOfDocument(document)); d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(document));
if (document->filePath().isEmpty()) { if (document->filePath().isEmpty()) {
d->m_lockButton->setIcon(QIcon()); d->m_lockButton->setIcon(QIcon());
d->m_lockButton->setEnabled(false); d->m_lockButton->setEnabled(false);
d->m_lockButton->setToolTip(QString()); d->m_lockButton->setToolTip(QString());
} else if (document->isFileReadOnly()) { } else if (document->isFileReadOnly()) {
d->m_lockButton->setIcon(QIcon(d->m_editorsListModel->lockedIcon())); d->m_lockButton->setIcon(DocumentModel::lockedIcon());
d->m_lockButton->setEnabled(true); d->m_lockButton->setEnabled(true);
d->m_lockButton->setToolTip(tr("Make Writable")); d->m_lockButton->setToolTip(tr("Make Writable"));
} else { } else {
d->m_lockButton->setIcon(QIcon(d->m_editorsListModel->unlockedIcon())); d->m_lockButton->setIcon(DocumentModel::unlockedIcon());
d->m_lockButton->setEnabled(false); d->m_lockButton->setEnabled(false);
d->m_lockButton->setToolTip(tr("File is writable")); d->m_lockButton->setToolTip(tr("File is writable"));
} }

View File

@@ -91,7 +91,7 @@ QList<LocatorFilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<Core:
void OpenDocumentsFilter::refreshInternally() void OpenDocumentsFilter::refreshInternally()
{ {
m_editors.clear(); m_editors.clear();
foreach (DocumentModel::Entry *e, EditorManager::documentModel()->documents()) { foreach (DocumentModel::Entry *e, DocumentModel::documents()) {
DocumentModel::Entry entry; DocumentModel::Entry entry;
// create copy with only the information relevant to use // create copy with only the information relevant to use
// to avoid model deleting entries behind our back // to avoid model deleting entries behind our back

View File

@@ -1700,7 +1700,7 @@ void CPPEditorWidget::onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefL
{ {
abortDeclDefLink(); abortDeclDefLink();
m_declDefLink = link; m_declDefLink = link;
Core::IDocument *targetDocument = Core::EditorManager::documentModel()->documentForFilePath( Core::IDocument *targetDocument = Core::DocumentModel::documentForFilePath(
m_declDefLink->targetFile->fileName()); m_declDefLink->targetFile->fileName());
if (baseTextDocument() != targetDocument) { if (baseTextDocument() != targetDocument) {
if (TextEditor::ITextEditorDocument *textEditorDocument = qobject_cast<TextEditor::ITextEditorDocument *>(targetDocument)) if (TextEditor::ITextEditorDocument *textEditorDocument = qobject_cast<TextEditor::ITextEditorDocument *>(targetDocument))
@@ -1749,7 +1749,7 @@ void CPPEditorWidget::abortDeclDefLink()
if (!m_declDefLink) if (!m_declDefLink)
return; return;
Core::IDocument *targetDocument = Core::EditorManager::documentModel()->documentForFilePath( Core::IDocument *targetDocument = Core::DocumentModel::documentForFilePath(
m_declDefLink->targetFile->fileName()); m_declDefLink->targetFile->fileName());
if (baseTextDocument() != targetDocument) { if (baseTextDocument() != targetDocument) {
if (TextEditor::ITextEditorDocument *textEditorDocument = qobject_cast<TextEditor::ITextEditorDocument *>(targetDocument)) if (TextEditor::ITextEditorDocument *textEditorDocument = qobject_cast<TextEditor::ITextEditorDocument *>(targetDocument))

View File

@@ -183,12 +183,12 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti
undoAllChangesAndCloseAllEditors(); undoAllChangesAndCloseAllEditors();
// Open editor // Open editor
QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), 0); QCOMPARE(DocumentModel::openedDocuments().size(), 0);
CPPEditor *editor; CPPEditor *editor;
CPPEditorWidget *editorWidget; CPPEditorWidget *editorWidget;
QVERIFY(openCppEditor(filePath, &editor, &editorWidget)); QVERIFY(openCppEditor(filePath, &editor, &editorWidget));
QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), 1); QCOMPARE(DocumentModel::openedDocuments().size(), 1);
QVERIFY(m_modelManager->isCppEditor(editor)); QVERIFY(m_modelManager->isCppEditor(editor));
QVERIFY(m_modelManager->workingCopy().contains(filePath)); QVERIFY(m_modelManager->workingCopy().contains(filePath));
@@ -268,7 +268,7 @@ void TestActionsTestCase::undoChangesInDocument(BaseTextDocument *editorDocument
void TestActionsTestCase::undoChangesInAllEditorWidgets() void TestActionsTestCase::undoChangesInAllEditorWidgets()
{ {
foreach (IDocument *document, EditorManager::documentModel()->openedDocuments()) { foreach (IDocument *document, DocumentModel::openedDocuments()) {
BaseTextDocument *baseTextDocument = qobject_cast<BaseTextDocument *>(document); BaseTextDocument *baseTextDocument = qobject_cast<BaseTextDocument *>(document);
undoChangesInDocument(baseTextDocument); undoChangesInDocument(baseTextDocument);
} }
@@ -309,7 +309,7 @@ void TestActionsTestCase::undoAllChangesAndCloseAllEditors()
undoChangesInAllEditorWidgets(); undoChangesInAllEditorWidgets();
EditorManager::closeAllEditors(/*askAboutModifiedEditors =*/ false); EditorManager::closeAllEditors(/*askAboutModifiedEditors =*/ false);
QApplication::processEvents(); QApplication::processEvents();
QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), 0); QCOMPARE(DocumentModel::openedDocuments().size(), 0);
} }
void TestActionsTestCase::configureAllProjects(const QList<QPointer<ProjectExplorer::Project> > void TestActionsTestCase::configureAllProjects(const QList<QPointer<ProjectExplorer::Project> >

View File

@@ -113,7 +113,7 @@ public:
private: private:
void doBeforeLocatorRun() void doBeforeLocatorRun()
{ {
QVERIFY(EditorManager::documentModel()->openedDocuments().isEmpty()); QVERIFY(DocumentModel::openedDocuments().isEmpty());
QVERIFY(garbageCollectGlobalSnapshot()); QVERIFY(garbageCollectGlobalSnapshot());
m_editor = EditorManager::openEditor(m_fileName); m_editor = EditorManager::openEditor(m_fileName);
@@ -126,7 +126,7 @@ private:
{ {
QVERIFY(closeEditorWithoutGarbageCollectorInvocation(m_editor)); QVERIFY(closeEditorWithoutGarbageCollectorInvocation(m_editor));
QCoreApplication::processEvents(); QCoreApplication::processEvents();
QVERIFY(EditorManager::documentModel()->openedDocuments().isEmpty()); QVERIFY(DocumentModel::openedDocuments().isEmpty());
QVERIFY(garbageCollectGlobalSnapshot()); QVERIFY(garbageCollectGlobalSnapshot());
} }

View File

@@ -710,10 +710,10 @@ void CppToolsPlugin::test_modelmanager_gc_if_last_cppeditor_closed()
helper.resetRefreshedSourceFiles(); helper.resetRefreshedSourceFiles();
// Open a file in the editor // Open a file in the editor
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 0); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0);
Core::IEditor *editor = Core::EditorManager::openEditor(file); Core::IEditor *editor = Core::EditorManager::openEditor(file);
QVERIFY(editor); QVERIFY(editor);
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 1); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
QVERIFY(mm->isCppEditor(editor)); QVERIFY(mm->isCppEditor(editor));
QVERIFY(mm->workingCopy().contains(file)); QVERIFY(mm->workingCopy().contains(file));
@@ -741,10 +741,10 @@ void CppToolsPlugin::test_modelmanager_dont_gc_opened_files()
helper.resetRefreshedSourceFiles(); helper.resetRefreshedSourceFiles();
// Open a file in the editor // Open a file in the editor
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 0); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0);
Core::IEditor *editor = Core::EditorManager::openEditor(file); Core::IEditor *editor = Core::EditorManager::openEditor(file);
QVERIFY(editor); QVERIFY(editor);
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 1); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
QVERIFY(mm->isCppEditor(editor)); QVERIFY(mm->isCppEditor(editor));
// Wait until the file is refreshed and check whether it is in the working copy // Wait until the file is refreshed and check whether it is in the working copy
@@ -832,7 +832,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project()
QCOMPARE(mm->snapshot().size(), 4); QCOMPARE(mm->snapshot().size(), 4);
// Open a file in the editor // Open a file in the editor
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 0); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0);
struct Data { struct Data {
QString firstDeclarationName; QString firstDeclarationName;
@@ -849,7 +849,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project()
Core::IEditor *editor = Core::EditorManager::openEditor(fileName); Core::IEditor *editor = Core::EditorManager::openEditor(fileName);
EditorCloser closer(editor); EditorCloser closer(editor);
QVERIFY(editor); QVERIFY(editor);
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 1); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
QVERIFY(mm->isCppEditor(editor)); QVERIFY(mm->isCppEditor(editor));
CppEditorSupport *sup = mm->cppEditorSupport( CppEditorSupport *sup = mm->cppEditorSupport(
@@ -903,7 +903,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project_pch()
QCOMPARE(mm->snapshot().size(), 4); QCOMPARE(mm->snapshot().size(), 4);
// Open a file in the editor // Open a file in the editor
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 0); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0);
struct Data { struct Data {
QString firstDeclarationName; QString firstDeclarationName;
@@ -920,7 +920,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project_pch()
Core::IEditor *editor = Core::EditorManager::openEditor(fileName); Core::IEditor *editor = Core::EditorManager::openEditor(fileName);
EditorCloser closer(editor); EditorCloser closer(editor);
QVERIFY(editor); QVERIFY(editor);
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 1); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
QVERIFY(mm->isCppEditor(editor)); QVERIFY(mm->isCppEditor(editor));
CppEditorSupport *sup = mm->cppEditorSupport( CppEditorSupport *sup = mm->cppEditorSupport(
@@ -972,7 +972,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor()
QCOMPARE(mm->snapshot().size(), 4); QCOMPARE(mm->snapshot().size(), 4);
// Open a file in the editor // Open a file in the editor
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 0); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0);
struct Data { struct Data {
QString editorDefines; QString editorDefines;
@@ -989,7 +989,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor()
Core::IEditor *editor = Core::EditorManager::openEditor(main1File); Core::IEditor *editor = Core::EditorManager::openEditor(main1File);
EditorCloser closer(editor); EditorCloser closer(editor);
QVERIFY(editor); QVERIFY(editor);
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 1); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
QVERIFY(mm->isCppEditor(editor)); QVERIFY(mm->isCppEditor(editor));
CppEditorSupport *sup = mm->cppEditorSupport( CppEditorSupport *sup = mm->cppEditorSupport(

View File

@@ -2144,7 +2144,7 @@ void DebuggerPluginPrivate::cleanupViews()
return; return;
QList<IDocument *> toClose; QList<IDocument *> toClose;
foreach (IDocument *document, EditorManager::documentModel()->openedDocuments()) { foreach (IDocument *document, DocumentModel::openedDocuments()) {
if (document->property(Constants::OPENED_BY_DEBUGGER).toBool()) { if (document->property(Constants::OPENED_BY_DEBUGGER).toBool()) {
bool keepIt = true; bool keepIt = true;
if (document->property(Constants::OPENED_WITH_DISASSEMBLY).toBool()) if (document->property(Constants::OPENED_WITH_DISASSEMBLY).toBool())

View File

@@ -1380,8 +1380,7 @@ void DebuggerToolTipManager::debugModeEntered()
this, SLOT(slotUpdateVisibleToolTips())); this, SLOT(slotUpdateVisibleToolTips()));
connect(em, SIGNAL(editorOpened(Core::IEditor*)), connect(em, SIGNAL(editorOpened(Core::IEditor*)),
this, SLOT(slotEditorOpened(Core::IEditor*))); this, SLOT(slotEditorOpened(Core::IEditor*)));
DocumentModel *documentModel = EditorManager::documentModel(); foreach (IEditor *e, DocumentModel::editorsForOpenedDocuments())
foreach (IEditor *e, documentModel->editorsForDocuments(documentModel->openedDocuments()))
slotEditorOpened(e); slotEditorOpened(e);
// Position tooltips delayed once all the editor placeholder layouting is done. // Position tooltips delayed once all the editor placeholder layouting is done.
if (!d->m_tooltips.isEmpty()) if (!d->m_tooltips.isEmpty())
@@ -1400,8 +1399,7 @@ void DebuggerToolTipManager::leavingDebugMode()
hide(); hide();
if (QWidget *topLevel = ICore::mainWindow()->topLevelWidget()) if (QWidget *topLevel = ICore::mainWindow()->topLevelWidget())
topLevel->removeEventFilter(this); topLevel->removeEventFilter(this);
DocumentModel *documentModel = EditorManager::documentModel(); foreach (IEditor *e, DocumentModel::editorsForOpenedDocuments()) {
foreach (IEditor *e, documentModel->editorsForDocuments(documentModel->openedDocuments())) {
DebuggerToolTipEditor toolTipEditor = DebuggerToolTipEditor(e); DebuggerToolTipEditor toolTipEditor = DebuggerToolTipEditor(e);
if (toolTipEditor.isValid()) { if (toolTipEditor.isValid()) {
toolTipEditor.widget->verticalScrollBar()->disconnect(this); toolTipEditor.widget->verticalScrollBar()->disconnect(this);

View File

@@ -249,7 +249,7 @@ void DisassemblerAgentPrivate::configureMimeType()
MimeType mtype = MimeDatabase::findByType(mimeType); MimeType mtype = MimeDatabase::findByType(mimeType);
if (mtype) { if (mtype) {
foreach (IEditor *editor, EditorManager::documentModel()->editorsForDocument(document)) foreach (IEditor *editor, DocumentModel::editorsForDocument(document))
if (PlainTextEditorWidget *widget = qobject_cast<PlainTextEditorWidget *>(editor->widget())) if (PlainTextEditorWidget *widget = qobject_cast<PlainTextEditorWidget *>(editor->widget()))
widget->configure(mtype); widget->configure(mtype);
} else { } else {

View File

@@ -542,7 +542,7 @@ void QmlEngine::gotoLocation(const Location &location)
QString titlePattern = tr("JS Source for %1").arg(fileName); QString titlePattern = tr("JS Source for %1").arg(fileName);
//Check if there are open documents with the same title //Check if there are open documents with the same title
foreach (Core::IDocument *document, Core::EditorManager::documentModel()->openedDocuments()) { foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments()) {
if (document->displayName() == titlePattern) { if (document->displayName() == titlePattern) {
Core::EditorManager::activateEditorForDocument(document); Core::EditorManager::activateEditorForDocument(document);
return; return;
@@ -1310,7 +1310,7 @@ void QmlEngine::updateScriptSource(const QString &fileName, int lineOffset, int
//update open editors //update open editors
QString titlePattern = tr("JS Source for %1").arg(fileName); QString titlePattern = tr("JS Source for %1").arg(fileName);
//Check if there are open editors with the same title //Check if there are open editors with the same title
foreach (Core::IDocument *doc, Core::EditorManager::documentModel()->openedDocuments()) { foreach (Core::IDocument *doc, Core::DocumentModel::openedDocuments()) {
if (doc->displayName() == titlePattern) { if (doc->displayName() == titlePattern) {
updateDocument(doc, document); updateDocument(doc, document);
break; break;

View File

@@ -354,7 +354,7 @@ void QmlInspectorAdapter::updatePendingPreviewDocuments(QmlJS::Document::Ptr doc
return; return;
QList<Core::IEditor *> editors QList<Core::IEditor *> editors
= Core::EditorManager::documentModel()->editorsForFilePath(doc->fileName()); = Core::DocumentModel::editorsForFilePath(doc->fileName());
if (editors.isEmpty()) if (editors.isEmpty())
return; return;
@@ -456,9 +456,8 @@ void QmlInspectorAdapter::initializePreviews()
} }
// initial update // initial update
Core::DocumentModel *documentModel = Core::EditorManager::documentModel(); foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments()) {
foreach (Core::IDocument *document, documentModel->openedDocuments()) { QList<Core::IEditor *> editors = Core::DocumentModel::editorsForDocument(document);
QList<Core::IEditor *> editors = documentModel->editorsForDocument(document);
createPreviewForEditor(editors.takeFirst()); createPreviewForEditor(editors.takeFirst());
QmlLiveTextPreview *preview QmlLiveTextPreview *preview
= m_textPreviews.value(document->filePath()); = m_textPreviews.value(document->filePath());

View File

@@ -1777,7 +1777,7 @@ void QmlV8DebuggerClient::highlightExceptionCode(int lineNumber,
const QString &filePath, const QString &filePath,
const QString &errorMessage) const QString &errorMessage)
{ {
QList<IEditor *> editors = EditorManager::documentModel()->editorsForFilePath(filePath); QList<IEditor *> editors = DocumentModel::editorsForFilePath(filePath);
// set up the format for the errors // set up the format for the errors
QTextCharFormat errorFormat; QTextCharFormat errorFormat;
@@ -1816,11 +1816,9 @@ void QmlV8DebuggerClient::highlightExceptionCode(int lineNumber,
void QmlV8DebuggerClient::clearExceptionSelection() void QmlV8DebuggerClient::clearExceptionSelection()
{ {
DocumentModel *documentModel = EditorManager::documentModel();
QList<IEditor *> openedEditors = documentModel->editorsForDocuments(documentModel->openedDocuments());
QList<QTextEdit::ExtraSelection> selections; QList<QTextEdit::ExtraSelection> selections;
foreach (IEditor *editor, openedEditors) { foreach (IEditor *editor, DocumentModel::editorsForOpenedDocuments()) {
TextEditor::BaseTextEditorWidget *ed = qobject_cast<TextEditor::BaseTextEditorWidget *>(editor->widget()); TextEditor::BaseTextEditorWidget *ed = qobject_cast<TextEditor::BaseTextEditorWidget *>(editor->widget());
if (!ed) if (!ed)
continue; continue;

View File

@@ -172,7 +172,7 @@ public:
const QString cppFile = files.at(0); const QString cppFile = files.at(0);
const QString hFile = files.at(1); const QString hFile = files.at(1);
QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), files.size()); QCOMPARE(DocumentModel::openedDocuments().size(), files.size());
waitForFilesInGlobalSnapshot(QStringList() << cppFile << hFile); waitForFilesInGlobalSnapshot(QStringList() << cppFile << hFile);
// Execute "Go To Slot" // Execute "Go To Slot"

View File

@@ -32,6 +32,7 @@
#include "diffeditorconstants.h" #include "diffeditorconstants.h"
#include "diffeditordocument.h" #include "diffeditordocument.h"
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/documentmodel.h>
#include <coreplugin/id.h> #include <coreplugin/id.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -70,11 +71,10 @@ void DiffEditorManager::slotEditorsClosed(const QList<Core::IEditor *> &editors)
editorsForDocument[document]++; editorsForDocument[document]++;
} }
} }
Core::DocumentModel *documentModel = Core::EditorManager::documentModel();
QMapIterator<Core::IDocument *, int> it(editorsForDocument); QMapIterator<Core::IDocument *, int> it(editorsForDocument);
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
if (documentModel->editorsForDocument(it.key()).count() == 0) { // no other editors use that document if (Core::DocumentModel::editorsForDocument(it.key()).count() == 0) { // no other editors use that document
DiffEditorDocument *document DiffEditorDocument *document
= qobject_cast<DiffEditorDocument *>(it.key()); = qobject_cast<DiffEditorDocument *>(it.key());
if (document) { if (document) {

View File

@@ -2149,17 +2149,17 @@ int FakeVimPluginPrivate::currentFile() const
IEditor *editor = EditorManager::currentEditor(); IEditor *editor = EditorManager::currentEditor();
if (!editor) if (!editor)
return -1; return -1;
return EditorManager::documentModel()->indexOfDocument(editor->document()); return DocumentModel::indexOfDocument(editor->document());
} }
void FakeVimPluginPrivate::switchToFile(int n) void FakeVimPluginPrivate::switchToFile(int n)
{ {
int size = EditorManager::documentModel()->documentCount(); int size = DocumentModel::documentCount();
QTC_ASSERT(size, return); QTC_ASSERT(size, return);
n = n % size; n = n % size;
if (n < 0) if (n < 0)
n += size; n += size;
EditorManager::activateEditorForEntry(EditorManager::documentModel()->documents().at(n)); EditorManager::activateEditorForEntry(DocumentModel::documents().at(n));
} }
ExCommandMap &FakeVimExCommandsPage::exCommandMap() ExCommandMap &FakeVimExCommandsPage::exCommandMap()

View File

@@ -157,8 +157,7 @@ GitDiffSwitcher::GitDiffSwitcher(Core::IDocument *parentDocument, GitClient *git
m_gitClient(gitClient), m_gitClient(gitClient),
m_signalMapper(new QSignalMapper(this)) m_signalMapper(new QSignalMapper(this))
{ {
Core::DocumentModel *documentModel = Core::EditorManager::documentModel(); QList<Core::IEditor *> editors = Core::DocumentModel::editorsForDocument(m_document);
QList<Core::IEditor *> editors = documentModel->editorsForDocument(m_document);
for (int i = 0; i < editors.count(); i++) for (int i = 0; i < editors.count(); i++)
attachAction(editors.at(i)); attachAction(editors.at(i));
@@ -938,9 +937,9 @@ private:
Core::IEditor *locateEditor(const char *property, const QString &entry) Core::IEditor *locateEditor(const char *property, const QString &entry)
{ {
foreach (Core::IDocument *document, Core::EditorManager::documentModel()->openedDocuments()) foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments())
if (document->property(property).toString() == entry) if (document->property(property).toString() == entry)
return Core::EditorManager::documentModel()->editorsForDocument(document).first(); return Core::DocumentModel::editorsForDocument(document).first();
return 0; return 0;
} }

View File

@@ -1275,7 +1275,7 @@ void GitPlugin::updateSubmodules()
// If the file is modified in an editor, make sure it is saved. // If the file is modified in an editor, make sure it is saved.
static bool ensureFileSaved(const QString &fileName) static bool ensureFileSaved(const QString &fileName)
{ {
Core::IDocument *document = Core::EditorManager::documentModel()->documentForFilePath(fileName); Core::IDocument *document = Core::DocumentModel::documentForFilePath(fileName);
return Core::DocumentManager::saveModifiedDocument(document); return Core::DocumentManager::saveModifiedDocument(document);
} }

View File

@@ -272,9 +272,7 @@ void EditorConfiguration::setUseGlobalSettings(bool use)
d->m_useGlobal = use; d->m_useGlobal = use;
d->m_defaultCodeStyle->setCurrentDelegate(d->m_useGlobal d->m_defaultCodeStyle->setCurrentDelegate(d->m_useGlobal
? TextEditorSettings::codeStyle() : 0); ? TextEditorSettings::codeStyle() : 0);
QList<Core::IEditor *> opened = Core::EditorManager::documentModel()->editorsForDocuments( foreach (Core::IEditor *editor, Core::DocumentModel::editorsForOpenedDocuments()) {
Core::EditorManager::documentModel()->openedDocuments());
foreach (Core::IEditor *editor, opened) {
if (BaseTextEditorWidget *baseTextEditor = qobject_cast<BaseTextEditorWidget *>(editor->widget())) { if (BaseTextEditorWidget *baseTextEditor = qobject_cast<BaseTextEditorWidget *>(editor->widget())) {
Project *project = SessionManager::projectForFile(editor->document()->filePath()); Project *project = SessionManager::projectForFile(editor->document()->filePath());
if (project && project->editorConfiguration() == this) if (project && project->editorConfiguration() == this)
@@ -386,9 +384,7 @@ void EditorConfiguration::slotAboutToRemoveProject(ProjectExplorer::Project *pro
if (project->editorConfiguration() != this) if (project->editorConfiguration() != this)
return; return;
Core::DocumentModel *model = Core::EditorManager::documentModel(); foreach (Core::IEditor *editor, Core::DocumentModel::editorsForOpenedDocuments()) {
QList<Core::IEditor *> editors = model->editorsForDocuments(model->openedDocuments());
foreach (Core::IEditor *editor, editors) {
if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor)) { if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor)) {
Core::IDocument *document = editor->document(); Core::IDocument *document = editor->document();
if (document) { if (document) {

View File

@@ -1083,7 +1083,7 @@ bool QmakePriFileNode::priFileWritable(const QString &path)
bool QmakePriFileNode::saveModifiedEditors() bool QmakePriFileNode::saveModifiedEditors()
{ {
Core::IDocument *document Core::IDocument *document
= Core::EditorManager::documentModel()->documentForFilePath(m_projectFilePath); = Core::DocumentModel::documentForFilePath(m_projectFilePath);
if (!document || !document->isModified()) if (!document || !document->isModified())
return true; return true;
@@ -1250,7 +1250,7 @@ void QmakePriFileNode::save(const QStringList &lines)
// We manually tell each editor to reload it's file. // We manually tell each editor to reload it's file.
// (The .pro files are notified by the file system watcher.) // (The .pro files are notified by the file system watcher.)
QStringList errorStrings; QStringList errorStrings;
Core::IDocument *document = Core::EditorManager::documentModel()->documentForFilePath(m_projectFilePath); Core::IDocument *document = Core::DocumentModel::documentForFilePath(m_projectFilePath);
if (document) { if (document) {
QString errorString; QString errorString;
if (!document->reload(&errorString, Core::IDocument::FlagReload, Core::IDocument::TypeContents)) if (!document->reload(&errorString, Core::IDocument::FlagReload, Core::IDocument::TypeContents))

View File

@@ -171,7 +171,7 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex
void ShortCutManager::updateActions(Core::IEditor* currentEditor) void ShortCutManager::updateActions(Core::IEditor* currentEditor)
{ {
int openedCount = Core::EditorManager::documentModel()->documentCount(); int openedCount = Core::DocumentModel::documentCount();
m_saveAction.setEnabled(currentEditor != 0 && currentEditor->document()->isModified()); m_saveAction.setEnabled(currentEditor != 0 && currentEditor->document()->isModified());
m_saveAsAction.setEnabled(currentEditor != 0 && currentEditor->document()->isSaveAsAllowed()); m_saveAsAction.setEnabled(currentEditor != 0 && currentEditor->document()->isSaveAsAllowed());

View File

@@ -999,9 +999,8 @@ void FindReferences::onReplaceButtonClicked(const QString &text, const QList<Cor
// files that are opened in an editor are changed, but not saved // files that are opened in an editor are changed, but not saved
QStringList changedOnDisk; QStringList changedOnDisk;
QStringList changedUnsavedEditors; QStringList changedUnsavedEditors;
DocumentModel *documentModel = EditorManager::documentModel();
foreach (const QString &fileName, fileNames) { foreach (const QString &fileName, fileNames) {
if (documentModel->documentForFilePath(fileName)) if (DocumentModel::documentForFilePath(fileName))
changedOnDisk += fileName; changedOnDisk += fileName;
else else
changedUnsavedEditors += fileName; changedUnsavedEditors += fileName;

View File

@@ -249,12 +249,11 @@ void ModelManager::writeMessageInternal(const QString &msg) const
ModelManagerInterface::WorkingCopy ModelManager::workingCopyInternal() const ModelManagerInterface::WorkingCopy ModelManager::workingCopyInternal() const
{ {
WorkingCopy workingCopy; WorkingCopy workingCopy;
DocumentModel *documentModel = EditorManager::documentModel(); foreach (IDocument *document, DocumentModel::openedDocuments()) {
foreach (IDocument *document, documentModel->openedDocuments()) {
const QString key = document->filePath(); const QString key = document->filePath();
if (TextEditor::BaseTextDocument *textDocument = qobject_cast<TextEditor::BaseTextDocument *>(document)) { if (TextEditor::BaseTextDocument *textDocument = qobject_cast<TextEditor::BaseTextDocument *>(document)) {
// TODO the language should be a property on the document, not the editor // TODO the language should be a property on the document, not the editor
if (documentModel->editorsForDocument(document).first()->context().contains(ProjectExplorer::Constants::LANG_QMLJS)) if (DocumentModel::editorsForDocument(document).first()->context().contains(ProjectExplorer::Constants::LANG_QMLJS))
workingCopy.insert(key, textDocument->plainText(), textDocument->document()->revision()); workingCopy.insert(key, textDocument->plainText(), textDocument->document()->revision());
} }
} }

View File

@@ -143,7 +143,7 @@ void BarDescriptorFileNodeManager::updateBarDescriptorNodes(ProjectExplorer::Pro
if (existingNode) { if (existingNode) {
if (existingNode->path() != package.appDescriptorPath()) { if (existingNode->path() != package.appDescriptorPath()) {
// Reload the new bar-descriptor document in the existing editor (if there is one) // Reload the new bar-descriptor document in the existing editor (if there is one)
Core::IDocument *oldDocument = Core::EditorManager::documentModel()->documentForFilePath(existingNode->path()); Core::IDocument *oldDocument = Core::DocumentModel::documentForFilePath(existingNode->path());
if (oldDocument) { if (oldDocument) {
QString errorMessage; QString errorMessage;

View File

@@ -59,9 +59,8 @@ BaseTextMarkRegistry::BaseTextMarkRegistry(QObject *parent)
void BaseTextMarkRegistry::add(BaseTextMark *mark) void BaseTextMarkRegistry::add(BaseTextMark *mark)
{ {
m_marks[FileName::fromString(mark->fileName())].insert(mark); m_marks[FileName::fromString(mark->fileName())].insert(mark);
DocumentModel *documentModel = EditorManager::documentModel();
ITextEditorDocument *document ITextEditorDocument *document
= qobject_cast<ITextEditorDocument*>(documentModel->documentForFilePath(mark->fileName())); = qobject_cast<ITextEditorDocument*>(DocumentModel::documentForFilePath(mark->fileName()));
if (!document) if (!document)
return; return;
document->markableInterface()->addMark(mark); document->markableInterface()->addMark(mark);

View File

@@ -68,7 +68,7 @@ Utils::FileIterator *FindInOpenFiles::files(const QStringList &nameFilters,
QStringList fileNames; QStringList fileNames;
QList<QTextCodec *> codecs; QList<QTextCodec *> codecs;
foreach (Core::DocumentModel::Entry *entry, foreach (Core::DocumentModel::Entry *entry,
Core::EditorManager::documentModel()->documents()) { Core::DocumentModel::documents()) {
QString fileName = entry->fileName(); QString fileName = entry->fileName();
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
fileNames.append(fileName); fileNames.append(fileName);
@@ -100,7 +100,7 @@ QString FindInOpenFiles::toolTip() const
bool FindInOpenFiles::isEnabled() const bool FindInOpenFiles::isEnabled() const
{ {
return Core::EditorManager::documentModel()->documentCount() > 0; return Core::DocumentModel::documentCount() > 0;
} }
void FindInOpenFiles::writeSettings(QSettings *settings) void FindInOpenFiles::writeSettings(QSettings *settings)

View File

@@ -58,7 +58,7 @@ ITextEditorDocument::ITextEditorDocument(QObject *parent)
QMap<QString, QString> ITextEditorDocument::openedTextDocumentContents() QMap<QString, QString> ITextEditorDocument::openedTextDocumentContents()
{ {
QMap<QString, QString> workingCopy; QMap<QString, QString> workingCopy;
foreach (Core::IDocument *document, Core::EditorManager::documentModel()->openedDocuments()) { foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments()) {
ITextEditorDocument *textEditorDocument = qobject_cast<ITextEditorDocument *>(document); ITextEditorDocument *textEditorDocument = qobject_cast<ITextEditorDocument *>(document);
if (!textEditorDocument) if (!textEditorDocument)
continue; continue;
@@ -71,7 +71,7 @@ QMap<QString, QString> ITextEditorDocument::openedTextDocumentContents()
QMap<QString, QTextCodec *> ITextEditorDocument::openedTextDocumentEncodings() QMap<QString, QTextCodec *> ITextEditorDocument::openedTextDocumentEncodings()
{ {
QMap<QString, QTextCodec *> workingCopy; QMap<QString, QTextCodec *> workingCopy;
foreach (Core::IDocument *document, Core::EditorManager::documentModel()->openedDocuments()) { foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments()) {
ITextEditorDocument *textEditorDocument = qobject_cast<ITextEditorDocument *>(document); ITextEditorDocument *textEditorDocument = qobject_cast<ITextEditorDocument *>(document);
if (!textEditorDocument) if (!textEditorDocument)
continue; continue;

View File

@@ -177,7 +177,7 @@ RefactoringFile::RefactoringFile(const QString &fileName, const QSharedPointer<R
, m_editorCursorPosition(-1) , m_editorCursorPosition(-1)
, m_appliedOnce(false) , m_appliedOnce(false)
{ {
QList<Core::IEditor *> editors = Core::EditorManager::documentModel()->editorsForFilePath(fileName); QList<Core::IEditor *> editors = Core::DocumentModel::editorsForFilePath(fileName);
if (!editors.isEmpty()) if (!editors.isEmpty())
m_editor = qobject_cast<TextEditor::BaseTextEditorWidget *>(editors.first()->widget()); m_editor = qobject_cast<TextEditor::BaseTextEditorWidget *>(editors.first()->widget());
} }

View File

@@ -67,9 +67,9 @@ Q_DECLARE_METATYPE(QVariant)
inline Core::IEditor *locateEditor(const char *property, const QString &entry) inline Core::IEditor *locateEditor(const char *property, const QString &entry)
{ {
foreach (Core::IDocument *document, Core::EditorManager::documentModel()->openedDocuments()) foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments())
if (document->property(property).toString() == entry) if (document->property(property).toString() == entry)
return Core::EditorManager::documentModel()->editorsForDocument(document).first(); return Core::DocumentModel::editorsForDocument(document).first();
return 0; return 0;
} }

View File

@@ -1201,7 +1201,7 @@ const VcsBaseEditorParameters *VcsBaseEditorWidget::findType(const VcsBaseEditor
// Find the codec used for a file querying the editor. // Find the codec used for a file querying the editor.
static QTextCodec *findFileCodec(const QString &source) static QTextCodec *findFileCodec(const QString &source)
{ {
Core::IDocument *document = Core::EditorManager::documentModel()->documentForFilePath(source); Core::IDocument *document = Core::DocumentModel::documentForFilePath(source);
if (Core::TextDocument *textDocument = qobject_cast<Core::TextDocument *>(document)) if (Core::TextDocument *textDocument = qobject_cast<Core::TextDocument *>(document))
return const_cast<QTextCodec *>(textDocument->codec()); return const_cast<QTextCodec *>(textDocument->codec());
return 0; return 0;
@@ -1555,10 +1555,10 @@ void VcsBaseEditorWidget::tagEditor(Core::IEditor *e, const QString &tag)
Core::IEditor* VcsBaseEditorWidget::locateEditorByTag(const QString &tag) Core::IEditor* VcsBaseEditorWidget::locateEditorByTag(const QString &tag)
{ {
foreach (Core::IDocument *document, Core::EditorManager::documentModel()->openedDocuments()) { foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments()) {
const QVariant tagPropertyValue = document->property(tagPropertyC); const QVariant tagPropertyValue = document->property(tagPropertyC);
if (tagPropertyValue.type() == QVariant::String && tagPropertyValue.toString() == tag) if (tagPropertyValue.type() == QVariant::String && tagPropertyValue.toString() == tag)
return Core::EditorManager::documentModel()->editorsForDocument(document).first(); return Core::DocumentModel::editorsForDocument(document).first();
} }
return 0; return 0;
} }

View File

@@ -220,7 +220,7 @@ StateListener::StateListener(QObject *parent) :
static inline QString displayNameOfEditor(const QString &fileName) static inline QString displayNameOfEditor(const QString &fileName)
{ {
Core::IDocument *document = Core::EditorManager::documentModel()->documentForFilePath(fileName); Core::IDocument *document = Core::DocumentModel::documentForFilePath(fileName);
if (document) if (document)
return document->displayName(); return document->displayName();
return QString(); return QString();