From 7b1941c792ca67a4760e461baaddb804d5d3993c Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Fri, 5 Jul 2013 16:08:38 +0200 Subject: [PATCH] OpenEditorsModel API: Use 'document' more where is about documents. Rename OpenEditorsModel to DocumentModel. In the DocumentModel also make the distinction between "restored" document (i.e. just info about file name, display name, id), "opened document" (i.e. document with IEditor and IDocument), and "document" (which refers to any). Change-Id: I01ebe10ec84aab5fe81e54be6bec14f653f28771 Reviewed-by: Eike Ziller --- src/plugins/coreplugin/coreplugin.pro | 4 +- src/plugins/coreplugin/coreplugin.qbs | 4 +- ...openeditorsmodel.cpp => documentmodel.cpp} | 78 +++++++++---------- .../{openeditorsmodel.h => documentmodel.h} | 35 ++++----- .../editormanager/editormanager.cpp | 74 +++++++++--------- .../coreplugin/editormanager/editormanager.h | 14 ++-- .../coreplugin/editormanager/editorview.cpp | 8 +- .../coreplugin/editormanager/editorview.h | 2 +- .../editormanager/openeditorsview.cpp | 12 +-- .../editormanager/openeditorswindow.cpp | 10 +-- .../editormanager/openeditorswindow.h | 6 +- src/plugins/coreplugin/editortoolbar.cpp | 12 +-- src/plugins/fakevim/fakevimplugin.cpp | 10 +-- src/plugins/locator/opendocumentsfilter.cpp | 6 +- src/plugins/locator/opendocumentsfilter.h | 4 +- src/plugins/qmldesigner/shortcutmanager.cpp | 4 +- src/plugins/texteditor/findinopenfiles.cpp | 6 +- 17 files changed, 144 insertions(+), 145 deletions(-) rename src/plugins/coreplugin/editormanager/{openeditorsmodel.cpp => documentmodel.cpp} (78%) rename src/plugins/coreplugin/editormanager/{openeditorsmodel.h => documentmodel.h} (83%) diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index 3e00ba333d9..25640dd63a4 100644 --- a/src/plugins/coreplugin/coreplugin.pro +++ b/src/plugins/coreplugin/coreplugin.pro @@ -33,7 +33,7 @@ SOURCES += mainwindow.cpp \ versiondialog.cpp \ editormanager/editormanager.cpp \ editormanager/editorview.cpp \ - editormanager/openeditorsmodel.cpp \ + editormanager/documentmodel.cpp \ editormanager/openeditorsview.cpp \ editormanager/openeditorswindow.cpp \ editormanager/ieditorfactory.cpp \ @@ -115,7 +115,7 @@ HEADERS += mainwindow.h \ statusbarmanager.h \ editormanager/editormanager.h \ editormanager/editorview.h \ - editormanager/openeditorsmodel.h \ + editormanager/documentmodel.h \ editormanager/openeditorsview.h \ editormanager/openeditorswindow.h \ editormanager/ieditor.h \ diff --git a/src/plugins/coreplugin/coreplugin.qbs b/src/plugins/coreplugin/coreplugin.qbs index 5fc009e4027..7b4abefae00 100644 --- a/src/plugins/coreplugin/coreplugin.qbs +++ b/src/plugins/coreplugin/coreplugin.qbs @@ -207,8 +207,8 @@ QtcPlugin { "editormanager/ieditorfactory.h", "editormanager/iexternaleditor.cpp", "editormanager/iexternaleditor.h", - "editormanager/openeditorsmodel.cpp", - "editormanager/openeditorsmodel.h", + "editormanager/documentmodel.cpp", + "editormanager/documentmodel.h", "editormanager/openeditorsview.cpp", "editormanager/openeditorsview.h", "editormanager/openeditorswindow.cpp", diff --git a/src/plugins/coreplugin/editormanager/openeditorsmodel.cpp b/src/plugins/coreplugin/editormanager/documentmodel.cpp similarity index 78% rename from src/plugins/coreplugin/editormanager/openeditorsmodel.cpp rename to src/plugins/coreplugin/editormanager/documentmodel.cpp index 859c3241be5..857d9164468 100644 --- a/src/plugins/coreplugin/editormanager/openeditorsmodel.cpp +++ b/src/plugins/coreplugin/editormanager/documentmodel.cpp @@ -27,7 +27,7 @@ ** ****************************************************************************/ -#include "openeditorsmodel.h" +#include "documentmodel.h" #include "ieditor.h" #include "idocument.h" @@ -38,75 +38,75 @@ namespace Core { -struct OpenEditorsModelPrivate +struct DocumentModelPrivate { - OpenEditorsModelPrivate(); - ~OpenEditorsModelPrivate(); + DocumentModelPrivate(); + ~DocumentModelPrivate(); const QIcon m_lockedIcon; const QIcon m_unlockedIcon; - QList m_documents; + QList m_documents; QMap > m_editors; }; -OpenEditorsModelPrivate::OpenEditorsModelPrivate() : +DocumentModelPrivate::DocumentModelPrivate() : m_lockedIcon(QLatin1String(":/core/images/locked.png")), m_unlockedIcon(QLatin1String(":/core/images/unlocked.png")) { } -OpenEditorsModelPrivate::~OpenEditorsModelPrivate() +DocumentModelPrivate::~DocumentModelPrivate() { qDeleteAll(m_documents); } -OpenEditorsModel::Entry::Entry() : +DocumentModel::Entry::Entry() : document(0) { } -OpenEditorsModel::OpenEditorsModel(QObject *parent) : - QAbstractItemModel(parent), d(new OpenEditorsModelPrivate) +DocumentModel::DocumentModel(QObject *parent) : + QAbstractItemModel(parent), d(new DocumentModelPrivate) { } -OpenEditorsModel::~OpenEditorsModel() +DocumentModel::~DocumentModel() { delete d; } -QIcon OpenEditorsModel::lockedIcon() const +QIcon DocumentModel::lockedIcon() const { return d->m_lockedIcon; } -QIcon OpenEditorsModel::unlockedIcon() const +QIcon DocumentModel::unlockedIcon() const { return d->m_unlockedIcon; } -QString OpenEditorsModel::Entry::fileName() const { +QString DocumentModel::Entry::fileName() const { return document ? document->filePath() : m_fileName; } -QString OpenEditorsModel::Entry::displayName() const { +QString DocumentModel::Entry::displayName() const { return document ? document->displayName() : m_displayName; } -Id OpenEditorsModel::Entry::id() const +Id DocumentModel::Entry::id() const { return m_id; } -int OpenEditorsModel::columnCount(const QModelIndex &parent) const +int DocumentModel::columnCount(const QModelIndex &parent) const { if (!parent.isValid()) return 2; return 0; } -int OpenEditorsModel::rowCount(const QModelIndex &parent) const +int DocumentModel::rowCount(const QModelIndex &parent) const { if (!parent.isValid()) return d->m_documents.count() + 1/**/; @@ -114,7 +114,7 @@ int OpenEditorsModel::rowCount(const QModelIndex &parent) const } // TODO remove -QList OpenEditorsModel::oneEditorForEachDocument() const +QList DocumentModel::oneEditorForEachOpenedDocument() const { QList result; QMapIterator > it(d->m_editors); @@ -123,7 +123,7 @@ QList OpenEditorsModel::oneEditorForEachDocument() const return result; } -void OpenEditorsModel::addEditor(IEditor *editor, bool *isNewDocument) +void DocumentModel::addEditor(IEditor *editor, bool *isNewDocument) { if (!editor) return; @@ -141,7 +141,7 @@ void OpenEditorsModel::addEditor(IEditor *editor, bool *isNewDocument) } } -void OpenEditorsModel::addRestoredEditor(const QString &fileName, const QString &displayName, const Id &id) +void DocumentModel::addRestoredDocument(const QString &fileName, const QString &displayName, const Id &id) { Entry *entry = new Entry; entry->m_fileName = fileName; @@ -150,7 +150,7 @@ void OpenEditorsModel::addRestoredEditor(const QString &fileName, const QString addEntry(entry); } -OpenEditorsModel::Entry *OpenEditorsModel::firstRestoredEditor() const +DocumentModel::Entry *DocumentModel::firstRestoredDocument() const { for (int i = 0; i < d->m_documents.count(); ++i) if (!d->m_documents.at(i)->document) @@ -158,7 +158,7 @@ OpenEditorsModel::Entry *OpenEditorsModel::firstRestoredEditor() const return 0; } -void OpenEditorsModel::addEntry(Entry *entry) +void DocumentModel::addEntry(Entry *entry) { QString fileName = entry->fileName(); @@ -190,7 +190,7 @@ void OpenEditorsModel::addEntry(Entry *entry) endInsertRows(); } -int OpenEditorsModel::indexofFileName(const QString &filename) const +int DocumentModel::indexofFileName(const QString &filename) const { if (filename.isEmpty()) return -1; @@ -201,14 +201,14 @@ int OpenEditorsModel::indexofFileName(const QString &filename) const return -1; } -void OpenEditorsModel::removeEntry(OpenEditorsModel::Entry *entry) +void DocumentModel::removeEntry(DocumentModel::Entry *entry) { QTC_ASSERT(!entry->document, return); // we wouldn't know what to do with the associated editors int index = d->m_documents.indexOf(entry); removeDocument(index); } -void OpenEditorsModel::removeEditor(IEditor *editor, bool *lastOneForDocument) +void DocumentModel::removeEditor(IEditor *editor, bool *lastOneForDocument) { if (lastOneForDocument) *lastOneForDocument = false; @@ -224,14 +224,14 @@ void OpenEditorsModel::removeEditor(IEditor *editor, bool *lastOneForDocument) } } -void OpenEditorsModel::removeDocument(const QString &fileName) +void DocumentModel::removeDocument(const QString &fileName) { int index = indexofFileName(fileName); QTC_ASSERT(!d->m_documents.at(index)->document, return); // we wouldn't know what to do with the associated editors removeDocument(index); } -void OpenEditorsModel::removeDocument(int idx) +void DocumentModel::removeDocument(int idx) { if (idx < 0) return; @@ -245,7 +245,7 @@ void OpenEditorsModel::removeDocument(int idx) disconnect(document, SIGNAL(changed()), this, SLOT(itemChanged())); } -void OpenEditorsModel::removeAllRestoredEditors() +void DocumentModel::removeAllRestoredDocuments() { for (int i = d->m_documents.count()-1; i >= 0; --i) { if (!d->m_documents.at(i)->document) { @@ -257,12 +257,12 @@ void OpenEditorsModel::removeAllRestoredEditors() } } -QList OpenEditorsModel::editorsForDocument(IDocument *document) const +QList DocumentModel::editorsForDocument(IDocument *document) const { return d->m_editors.value(document); } -QList OpenEditorsModel::editorsForDocuments(const QList &documents) const +QList DocumentModel::editorsForDocuments(const QList &documents) const { QList result; foreach (IDocument *document, documents) @@ -270,7 +270,7 @@ QList OpenEditorsModel::editorsForDocuments(const QList return result; } -int OpenEditorsModel::indexOfDocument(IDocument *document) const +int DocumentModel::indexOfDocument(IDocument *document) const { for (int i = 0; i < d->m_documents.count(); ++i) if (d->m_documents.at(i)->document == document) @@ -278,7 +278,7 @@ int OpenEditorsModel::indexOfDocument(IDocument *document) const return -1; } -QModelIndex OpenEditorsModel::index(int row, int column, const QModelIndex &parent) const +QModelIndex DocumentModel::index(int row, int column, const QModelIndex &parent) const { Q_UNUSED(parent) if (column < 0 || column > 1 || row < 0 || row >= d->m_documents.count() + 1/**/) @@ -286,7 +286,7 @@ QModelIndex OpenEditorsModel::index(int row, int column, const QModelIndex &pare return createIndex(row, column); } -OpenEditorsModel::Entry *OpenEditorsModel::entryAtRow(int row) const +DocumentModel::Entry *DocumentModel::documentAtRow(int row) const { int entryIndex = row - 1/**/; if (entryIndex < 0) @@ -294,12 +294,12 @@ OpenEditorsModel::Entry *OpenEditorsModel::entryAtRow(int row) const return d->m_documents[entryIndex]; } -int OpenEditorsModel::openDocumentCount() const +int DocumentModel::documentCount() const { return d->m_documents.count(); } -QVariant OpenEditorsModel::data(const QModelIndex &index, int role) const +QVariant DocumentModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || (index.column() != 0 && role < Qt::UserRole)) return QVariant(); @@ -343,14 +343,14 @@ QVariant OpenEditorsModel::data(const QModelIndex &index, int role) const return QVariant(); } -int OpenEditorsModel::rowOfDocument(IDocument *document) const +int DocumentModel::rowOfDocument(IDocument *document) const { if (!document) return 0 /**/; return indexOfDocument(document) + 1/**/; } -void OpenEditorsModel::itemChanged() +void DocumentModel::itemChanged() { IDocument *document = qobject_cast(sender()); @@ -361,7 +361,7 @@ void OpenEditorsModel::itemChanged() emit dataChanged(mindex, mindex); } -QList OpenEditorsModel::entries() const +QList DocumentModel::documents() const { return d->m_documents; } diff --git a/src/plugins/coreplugin/editormanager/openeditorsmodel.h b/src/plugins/coreplugin/editormanager/documentmodel.h similarity index 83% rename from src/plugins/coreplugin/editormanager/openeditorsmodel.h rename to src/plugins/coreplugin/editormanager/documentmodel.h index a3e7fff3bc5..5a8ccb3ab4a 100644 --- a/src/plugins/coreplugin/editormanager/openeditorsmodel.h +++ b/src/plugins/coreplugin/editormanager/documentmodel.h @@ -27,8 +27,8 @@ ** ****************************************************************************/ -#ifndef OPENEDITORSMODEL_H -#define OPENEDITORSMODEL_H +#ifndef DOCUMENTMODEL_H +#define DOCUMENTMODEL_H #include "../core_global.h" #include "../id.h" @@ -39,17 +39,17 @@ QT_FORWARD_DECLARE_CLASS(QIcon) namespace Core { -struct OpenEditorsModelPrivate; +struct DocumentModelPrivate; class IEditor; class IDocument; -class CORE_EXPORT OpenEditorsModel : public QAbstractItemModel +class CORE_EXPORT DocumentModel : public QAbstractItemModel { Q_OBJECT public: - explicit OpenEditorsModel(QObject *parent); - virtual ~OpenEditorsModel(); + explicit DocumentModel(QObject *parent); + virtual ~DocumentModel(); QIcon lockedIcon() const; QIcon unlockedIcon() const; @@ -71,26 +71,25 @@ public: Id m_id; }; - Entry *entryAtRow(int row) const; + Entry *documentAtRow(int row) const; int rowOfDocument(IDocument *document) const; - int openDocumentCount() const; - - QList entries() const; + int documentCount() const; + QList documents() const; + int indexOfDocument(IDocument *document) const; QList editorsForDocument(IDocument *document) const; QList editorsForDocuments(const QList &documents) const; - QList oneEditorForEachDocument() const; - int indexOfDocument(IDocument *document) const; + QList oneEditorForEachOpenedDocument() const; // editor manager related methods, nobody else should call it void addEditor(IEditor *editor, bool *isNewDocument); - void addRestoredEditor(const QString &fileName, const QString &displayName, const Id &id); - Entry *firstRestoredEditor() const; - void removeEntry(Entry *entry); + void addRestoredDocument(const QString &fileName, const QString &displayName, const Id &id); + Entry *firstRestoredDocument() const; void removeEditor(IEditor *editor, bool *lastOneForDocument); void removeDocument(const QString &fileName); - void removeAllRestoredEditors(); + void removeEntry(Entry *entry); + void removeAllRestoredDocuments(); private slots: void itemChanged(); @@ -100,9 +99,9 @@ private: int indexofFileName(const QString &filename) const; void removeDocument(int idx); - OpenEditorsModelPrivate *d; + DocumentModelPrivate *d; }; } // namespace Core -#endif // OPENEDITORSMODEL_H +#endif // DOCUMENTMODEL_H diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 65b38d7bc2d..5100d7b620f 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -32,7 +32,7 @@ #include "findplaceholder.h" #include "openeditorswindow.h" #include "openeditorsview.h" -#include "openeditorsmodel.h" +#include "documentmodel.h" #include "openwithdialog.h" #include "outputpane.h" #include "outputpanemanager.h" @@ -212,7 +212,7 @@ public: QAction *m_closeOtherEditorsContextAction; QAction *m_openGraphicalShellAction; QAction *m_openTerminalAction; - OpenEditorsModel::Entry *m_contextMenuEntry; + DocumentModel::Entry *m_contextMenuEntry; Internal::OpenEditorsWindow *m_windowPopup; Internal::EditorClosingCoreListener *m_coreListener; @@ -220,7 +220,7 @@ public: QMap m_editorStates; Internal::OpenEditorsViewFactory *m_openEditorsFactory; - OpenEditorsModel *m_editorModel; + DocumentModel *m_documentModel; IDocument::ReloadSetting m_reloadSetting; @@ -258,7 +258,7 @@ EditorManagerPrivate::EditorManagerPrivate(QWidget *parent) : m_autoSaveEnabled(true), m_autoSaveInterval(5) { - m_editorModel = new OpenEditorsModel(parent); + m_documentModel = new DocumentModel(parent); } EditorManagerPrivate::~EditorManagerPrivate() @@ -508,7 +508,7 @@ EditorToolBar *EditorManager::createToolBar(QWidget *parent) void EditorManager::removeEditor(IEditor *editor) { bool lastOneForDocument = false; - d->m_editorModel->removeEditor(editor, &lastOneForDocument); + d->m_documentModel->removeEditor(editor, &lastOneForDocument); if (lastOneForDocument) DocumentManager::removeDocument(editor->document()); ICore::removeContextObject(editor); @@ -660,7 +660,7 @@ void EditorManager::emptyView(Core::Internal::EditorView *view) QList editors = view->editors(); foreach (IEditor *editor, editors) { - if (d->m_editorModel->editorsForDocument(editor->document()).size() == 1) { + if (d->m_documentModel->editorsForDocument(editor->document()).size() == 1) { // it's the only editor for that file // so we need to keep it around (--> in the editor model) if (currentEditor() == editor) { @@ -741,7 +741,7 @@ void EditorManager::closeView(Core::Internal::EditorView *view) bool EditorManager::closeAllEditors(bool askAboutModifiedEditors) { - d->m_editorModel->removeAllRestoredEditors(); + d->m_documentModel->removeAllRestoredDocuments(); if (closeEditors(openedEditors(), askAboutModifiedEditors)) { // d->clearNavigationHistory(); return true; @@ -751,7 +751,7 @@ bool EditorManager::closeAllEditors(bool askAboutModifiedEditors) void EditorManager::closeOtherEditors(IDocument *document) { - d->m_editorModel->removeAllRestoredEditors(); + d->m_documentModel->removeAllRestoredDocuments(); QList editorsToClose; foreach (IEditor *editor, openedEditors()) if (editor->document() != document) @@ -784,7 +784,7 @@ static void assignAction(QAction *self, QAction *other) self->setIconVisibleInMenu(other->isIconVisibleInMenu()); } -void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, OpenEditorsModel::Entry *entry) +void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentModel::Entry *entry) { QTC_ASSERT(contextMenu, return); d->m_contextMenuEntry = entry; @@ -821,7 +821,7 @@ void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, OpenEditors contextMenu->addAction(d->m_closeOtherEditorsContextAction); } -void EditorManager::addNativeDirActions(QMenu *contextMenu, OpenEditorsModel::Entry *entry) +void EditorManager::addNativeDirActions(QMenu *contextMenu, DocumentModel::Entry *entry) { QTC_ASSERT(contextMenu, return); bool enabled = entry && !entry->fileName().isEmpty(); @@ -949,7 +949,7 @@ void EditorManager::closeEditorFromContextMenu() { IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : 0; if (document) - closeEditors(d->m_editorModel->editorsForDocument(document)); + closeEditors(d->m_documentModel->editorsForDocument(document)); } void EditorManager::closeOtherEditorsFromContextMenu() @@ -1035,14 +1035,14 @@ void EditorManager::closeEditor(Core::IEditor *editor) closeEditors(QList() << editor); } -void EditorManager::closeEditor(OpenEditorsModel::Entry *entry) +void EditorManager::closeEditor(DocumentModel::Entry *entry) { if (!entry) return; if (entry->document) - closeEditors(d->m_editorModel->editorsForDocument(entry->document)); + closeEditors(d->m_documentModel->editorsForDocument(entry->document)); else - d->m_editorModel->removeEntry(entry); + d->m_documentModel->removeEntry(entry); } bool EditorManager::closeEditors(const QList &editorsToClose, bool askAboutModifiedEditors) @@ -1068,7 +1068,7 @@ bool EditorManager::closeEditors(const QList &editorsToClose, bool ask } } if (editorAccepted) { - acceptedEditors += d->m_editorModel->editorsForDocument(editor->document()).toSet(); + acceptedEditors += d->m_documentModel->editorsForDocument(editor->document()).toSet(); acceptedDocuments.insert(editor->document()); } } @@ -1083,7 +1083,7 @@ bool EditorManager::closeEditors(const QList &editorsToClose, bool ask if (!list.isEmpty()) { closingFailed = true; acceptedDocuments.subtract(list.toSet()); - QSet skipSet = d->m_editorModel->editorsForDocuments(list).toSet(); + QSet skipSet = d->m_documentModel->editorsForDocuments(list).toSet(); acceptedEditors = acceptedEditors.subtract(skipSet); } } @@ -1131,12 +1131,12 @@ bool EditorManager::closeEditors(const QList &editorsToClose, bool ask if (newCurrent) { activateEditor(view, newCurrent, flags); } else { - OpenEditorsModel::Entry *entry = d->m_editorModel->firstRestoredEditor(); + DocumentModel::Entry *entry = d->m_documentModel->firstRestoredDocument(); if (entry) { activateEditorForEntry(view, entry, flags); } else { // no "restored" ones, so any entry left should have a document - const QList documents = d->m_editorModel->entries(); + const QList documents = d->m_documentModel->documents(); if (!documents.isEmpty()) { IDocument *document = documents.last()->document; if (document) @@ -1178,12 +1178,12 @@ Core::IEditor *EditorManager::pickUnusedEditor() const return 0; } -void EditorManager::activateEditorForEntry(OpenEditorsModel::Entry *entry, OpenEditorFlags flags) +void EditorManager::activateEditorForEntry(DocumentModel::Entry *entry, OpenEditorFlags flags) { activateEditorForEntry(currentEditorView(), entry, flags); } -void EditorManager::activateEditorForEntry(Internal::EditorView *view, OpenEditorsModel::Entry *entry, OpenEditorFlags flags) +void EditorManager::activateEditorForEntry(Internal::EditorView *view, DocumentModel::Entry *entry, OpenEditorFlags flags) { QTC_ASSERT(view, return); if (!entry) { // no document @@ -1199,7 +1199,7 @@ void EditorManager::activateEditorForEntry(Internal::EditorView *view, OpenEdito } if (!openEditor(view, entry->fileName(), entry->id(), flags)) - d->m_editorModel->removeEntry(entry); + d->m_documentModel->removeEntry(entry); } void EditorManager::activateView(EditorView *view) @@ -1409,7 +1409,7 @@ void EditorManager::addEditor(IEditor *editor) ICore::addContextObject(editor); bool isNewDocument = false; - d->m_editorModel->addEditor(editor, &isNewDocument); + d->m_documentModel->addEditor(editor, &isNewDocument); if (isNewDocument) { const bool isTemporary = editor->isTemporary(); const bool addWatcher = !isTemporary; @@ -1845,7 +1845,7 @@ void EditorManager::gotoNextDocHistory() dialog->selectNextEditor(); } else { EditorView *view = currentEditorView(); - dialog->setEditors(d->m_globalHistory, view, d->m_editorModel); + dialog->setEditors(d->m_globalHistory, view, d->m_documentModel); dialog->selectNextEditor(); showPopupOrSelectDocument(); } @@ -1858,7 +1858,7 @@ void EditorManager::gotoPreviousDocHistory() dialog->selectPreviousEditor(); } else { EditorView *view = currentEditorView(); - dialog->setEditors(d->m_globalHistory, view, d->m_editorModel); + dialog->setEditors(d->m_globalHistory, view, d->m_documentModel); dialog->selectPreviousEditor(); showPopupOrSelectDocument(); } @@ -1985,7 +1985,7 @@ void EditorManager::updateActions() { IEditor *curEditor = currentEditor(); IDocument *curDocument = curEditor ? curEditor->document() : 0; - int openedCount = d->m_editorModel->openDocumentCount(); + int openedCount = d->m_documentModel->documentCount(); if (curDocument) { if (HostOsInfo::isMacHost()) @@ -2009,8 +2009,8 @@ void EditorManager::updateActions() d->m_closeOtherEditorsAction->setEnabled(openedCount > 1); d->m_closeOtherEditorsAction->setText((openedCount > 1 ? tr("Close All Except %1").arg(quotedName) : tr("Close Others"))); - d->m_gotoNextDocHistoryAction->setEnabled(d->m_editorModel->rowCount() != 0); - d->m_gotoPreviousDocHistoryAction->setEnabled(d->m_editorModel->rowCount() != 0); + d->m_gotoNextDocHistoryAction->setEnabled(d->m_documentModel->rowCount() != 0); + d->m_gotoPreviousDocHistoryAction->setEnabled(d->m_documentModel->rowCount() != 0); EditorView *view = currentEditorView(); d->m_goBackAction->setEnabled(view ? view->canGoBack() : false); d->m_goForwardAction->setEnabled(view ? view->canGoForward() : false); @@ -2068,15 +2068,15 @@ QList EditorManager::visibleEditors() const return editors; } -// TODO code using this should probably better use OpenEditorsModel +// TODO code using this should probably better use DocumentModel QList EditorManager::openedEditors() const { - return d->m_editorModel->oneEditorForEachDocument(); + return d->m_documentModel->oneEditorForEachOpenedDocument(); } -OpenEditorsModel *EditorManager::openedEditorsModel() const +DocumentModel *EditorManager::documentModel() const { - return d->m_editorModel; + return d->m_documentModel; } void EditorManager::addCurrentPositionToNavigationHistory(IEditor *editor, const QByteArray &saveState) @@ -2159,12 +2159,12 @@ QByteArray EditorManager::saveState() const stream << d->m_editorStates; - QList entries = d->m_editorModel->entries(); + QList entries = d->m_documentModel->documents(); int entriesCount = 0; - foreach (OpenEditorsModel::Entry *entry, entries) { + foreach (DocumentModel::Entry *entry, entries) { // TODO: isTemporary should move to IDocument IEditor *editor = entry->document - ? d->m_editorModel->editorsForDocument(entry->document).first() + ? d->m_documentModel->editorsForDocument(entry->document).first() : 0; // The editor may be 0 if it was not loaded yet: In that case it is not temporary if (!editor || !editor->isTemporary()) @@ -2173,9 +2173,9 @@ QByteArray EditorManager::saveState() const stream << entriesCount; - foreach (OpenEditorsModel::Entry *entry, entries) { + foreach (DocumentModel::Entry *entry, entries) { IEditor *editor = entry->document - ? d->m_editorModel->editorsForDocument(entry->document).first() + ? d->m_documentModel->editorsForDocument(entry->document).first() : 0; if (!editor || !editor->isTemporary()) stream << entry->fileName() << entry->displayName() << entry->id(); @@ -2224,7 +2224,7 @@ bool EditorManager::restoreState(const QByteArray &state) if (rfi.exists() && fi.lastModified() < rfi.lastModified()) openEditor(fileName, id, DoNotMakeVisible); else - d->m_editorModel->addRestoredEditor(fileName, displayName, id); + d->m_documentModel->addRestoredDocument(fileName, displayName, id); } } diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h index 35c70bf62c3..b8a99ae1497 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.h +++ b/src/plugins/coreplugin/editormanager/editormanager.h @@ -32,7 +32,7 @@ #include "../core_global.h" -#include "openeditorsmodel.h" +#include "documentmodel.h" #include #include // enumerations @@ -131,11 +131,11 @@ public: QList openedEditors() const; static void activateEditor(IEditor *editor, OpenEditorFlags flags = 0); - void activateEditorForEntry(OpenEditorsModel::Entry *entry, OpenEditorFlags flags = 0); + void activateEditorForEntry(DocumentModel::Entry *entry, OpenEditorFlags flags = 0); IEditor *activateEditorForDocument(Internal::EditorView *view, IDocument *document, OpenEditorFlags flags = 0); - OpenEditorsModel *openedEditorsModel() const; - void closeEditor(OpenEditorsModel::Entry *entry); + DocumentModel *documentModel() const; + void closeEditor(DocumentModel::Entry *entry); void closeOtherEditors(IDocument *document); void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray()); @@ -185,8 +185,8 @@ public: static void setWindowTitleVcsTopic(const QString &topic); static QString windowTitleVcsTopic(); - void addSaveAndCloseEditorActions(QMenu *contextMenu, OpenEditorsModel::Entry *entry); - void addNativeDirActions(QMenu *contextMenu, OpenEditorsModel::Entry *entry); + void addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentModel::Entry *entry); + void addNativeDirActions(QMenu *contextMenu, DocumentModel::Entry *entry); signals: void currentEditorChanged(Core::IEditor *editor); @@ -259,7 +259,7 @@ private: IEditor *placeEditor(Internal::EditorView *view, IEditor *editor); IEditor *duplicateEditor(IEditor *editor); IEditor *activateEditor(Internal::EditorView *view, IEditor *editor, OpenEditorFlags flags = 0); - void activateEditorForEntry(Internal::EditorView *view, OpenEditorsModel::Entry *entry, OpenEditorFlags flags = 0); + void activateEditorForEntry(Internal::EditorView *view, DocumentModel::Entry *entry, OpenEditorFlags flags = 0); void activateView(Internal::EditorView *view); IEditor *openEditor(Internal::EditorView *view, const QString &fileName, const Id &id = Id(), OpenEditorFlags flags = 0, bool *newEditor = 0); diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp index ed34557d5c3..575cff41c55 100644 --- a/src/plugins/coreplugin/editormanager/editorview.cpp +++ b/src/plugins/coreplugin/editormanager/editorview.cpp @@ -31,7 +31,7 @@ #include "editormanager.h" #include "icore.h" #include "minisplitter.h" -#include "openeditorsmodel.h" +#include "documentmodel.h" #include #include @@ -303,8 +303,8 @@ IEditor *EditorView::currentEditor() const void EditorView::listSelectionActivated(int index) { - OpenEditorsModel *model = EditorManager::instance()->openedEditorsModel(); - EditorManager::instance()->activateEditorForEntry(this, model->entryAtRow(index)); + DocumentModel *model = EditorManager::instance()->documentModel(); + EditorManager::instance()->activateEditorForEntry(this, model->documentAtRow(index)); } void EditorView::splitHorizontally() @@ -786,7 +786,7 @@ void SplitterOrView::restoreState(const QByteArray &state) | Core::EditorManager::DoNotChangeCurrentEditor); if (!e) { - OpenEditorsModel::Entry *entry = em->openedEditorsModel()->firstRestoredEditor(); + DocumentModel::Entry *entry = em->documentModel()->firstRestoredDocument(); if (entry) em->activateEditorForEntry(view(), entry, Core::EditorManager::IgnoreNavigationHistory | Core::EditorManager::DoNotChangeCurrentEditor); diff --git a/src/plugins/coreplugin/editormanager/editorview.h b/src/plugins/coreplugin/editormanager/editorview.h index e34a68c0e1a..69f2cc25daf 100644 --- a/src/plugins/coreplugin/editormanager/editorview.h +++ b/src/plugins/coreplugin/editormanager/editorview.h @@ -57,7 +57,7 @@ class IContext; class IDocument; class IEditor; class InfoBarDisplay; -class OpenEditorsModel; +class DocumentModel; class EditorToolBar; namespace Internal { diff --git a/src/plugins/coreplugin/editormanager/openeditorsview.cpp b/src/plugins/coreplugin/editormanager/openeditorsview.cpp index cf9ce1c679d..b010aa25cdb 100644 --- a/src/plugins/coreplugin/editormanager/openeditorsview.cpp +++ b/src/plugins/coreplugin/editormanager/openeditorsview.cpp @@ -30,7 +30,7 @@ #include "openeditorsview.h" #include "editormanager.h" #include "ieditor.h" -#include "openeditorsmodel.h" +#include "documentmodel.h" #include #include @@ -98,7 +98,7 @@ OpenEditorsWidget::OpenEditorsWidget() setAttribute(Qt::WA_MacShowFocusRect, false); EditorManager *em = EditorManager::instance(); m_model = new ProxyModel(this); - m_model->setSourceModel(em->openedEditorsModel()); + m_model->setSourceModel(em->documentModel()); setModel(m_model); setSelectionMode(QAbstractItemView::SingleSelection); setSelectionBehavior(QAbstractItemView::SelectRows); @@ -129,7 +129,7 @@ void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor) { IDocument *document = editor ? editor->document() : 0; EditorManager *em = EditorManager::instance(); - QModelIndex index = m_model->index(em->openedEditorsModel()->indexOfDocument(document), 0); + QModelIndex index = m_model->index(em->documentModel()->indexOfDocument(document), 0); if (!index.isValid()) { clearSelection(); return; @@ -195,13 +195,13 @@ void OpenEditorsWidget::activateEditor(const QModelIndex &index) { selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); EditorManager *em = EditorManager::instance(); - em->activateEditorForEntry(em->openedEditorsModel()->entryAtRow(m_model->mapToSource(index).row())); + em->activateEditorForEntry(em->documentModel()->documentAtRow(m_model->mapToSource(index).row())); } void OpenEditorsWidget::closeEditor(const QModelIndex &index) { EditorManager *em = EditorManager::instance(); - em->closeEditor(em->openedEditorsModel()->entryAtRow(m_model->mapToSource(index).row())); + em->closeEditor(em->documentModel()->documentAtRow(m_model->mapToSource(index).row())); // work around selection changes updateCurrentItem(EditorManager::currentEditor()); } @@ -210,7 +210,7 @@ void OpenEditorsWidget::contextMenuRequested(QPoint pos) { QMenu contextMenu; QModelIndex editorIndex = indexAt(pos); - OpenEditorsModel::Entry *entry = EditorManager::instance()->openedEditorsModel()->entryAtRow( + DocumentModel::Entry *entry = EditorManager::instance()->documentModel()->documentAtRow( m_model->mapToSource(editorIndex).row()); EditorManager::instance()->addSaveAndCloseEditorActions(&contextMenu, entry); contextMenu.addSeparator(); diff --git a/src/plugins/coreplugin/editormanager/openeditorswindow.cpp b/src/plugins/coreplugin/editormanager/openeditorswindow.cpp index a43166e6d49..eb361925c95 100644 --- a/src/plugins/coreplugin/editormanager/openeditorswindow.cpp +++ b/src/plugins/coreplugin/editormanager/openeditorswindow.cpp @@ -28,7 +28,7 @@ ****************************************************************************/ #include "openeditorswindow.h" -#include "openeditorsmodel.h" +#include "documentmodel.h" #include "editormanager.h" #include "editorview.h" #include "idocument.h" @@ -193,7 +193,7 @@ void OpenEditorsWindow::centerOnItem(int selectedIndex) } } -void OpenEditorsWindow::setEditors(const QList &globalHistory, EditorView *view, OpenEditorsModel *model) +void OpenEditorsWindow::setEditors(const QList &globalHistory, EditorView *view, DocumentModel *model) { m_editorList->clear(); @@ -203,7 +203,7 @@ void OpenEditorsWindow::setEditors(const QList &globalHistory, Edi addHistoryItems(globalHistory, view, model, documentsDone); // add purely restored editors which are not initialised yet - foreach (OpenEditorsModel::Entry *entry, model->entries()) { + foreach (DocumentModel::Entry *entry, model->documents()) { if (entry->document) continue; QTreeWidgetItem *item = new QTreeWidgetItem(); @@ -229,7 +229,7 @@ void OpenEditorsWindow::selectEditor(QTreeWidgetItem *item) } else { if (!EditorManager::openEditor( item->toolTip(0), item->data(0, Qt::UserRole+2).value())) { - EditorManager::instance()->openedEditorsModel()->removeDocument(item->toolTip(0)); + EditorManager::instance()->documentModel()->removeDocument(item->toolTip(0)); delete item; } } @@ -249,7 +249,7 @@ void OpenEditorsWindow::ensureCurrentVisible() void OpenEditorsWindow::addHistoryItems(const QList &history, EditorView *view, - OpenEditorsModel *model, QSet &documentsDone) + DocumentModel *model, QSet &documentsDone) { foreach (const EditLocation &hi, history) { if (hi.document.isNull() || documentsDone.contains(hi.document)) diff --git a/src/plugins/coreplugin/editormanager/openeditorswindow.h b/src/plugins/coreplugin/editormanager/openeditorswindow.h index 93b5b38b9d7..33ea5640a00 100644 --- a/src/plugins/coreplugin/editormanager/openeditorswindow.h +++ b/src/plugins/coreplugin/editormanager/openeditorswindow.h @@ -45,7 +45,7 @@ namespace Core { class IDocument; class IEditor; -class OpenEditorsModel; +class DocumentModel; namespace Internal { @@ -60,7 +60,7 @@ public: explicit OpenEditorsWindow(QWidget *parent = 0); - void setEditors(const QList &globalHistory, EditorView *view, OpenEditorsModel *model); + void setEditors(const QList &globalHistory, EditorView *view, DocumentModel *model); bool eventFilter(QObject *src, QEvent *e); void focusInEvent(QFocusEvent *); @@ -78,7 +78,7 @@ private slots: private: static void updateItem(QTreeWidgetItem *item, IEditor *editor); void addHistoryItems(const QList &history, EditorView *view, - OpenEditorsModel *model, QSet &documentsDone); + DocumentModel *model, QSet &documentsDone); void ensureCurrentVisible(); bool isCentering(); void centerOnItem(int selectedIndex); diff --git a/src/plugins/coreplugin/editortoolbar.cpp b/src/plugins/coreplugin/editortoolbar.cpp index 3fb29a3a2e7..601023fdf21 100644 --- a/src/plugins/coreplugin/editortoolbar.cpp +++ b/src/plugins/coreplugin/editortoolbar.cpp @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include @@ -57,7 +57,7 @@ namespace Core { struct EditorToolBarPrivate { explicit EditorToolBarPrivate(QWidget *parent, EditorToolBar *q); - Core::OpenEditorsModel *m_editorsListModel; + Core::DocumentModel *m_editorsListModel; QComboBox *m_editorList; QToolButton *m_closeEditorButton; QToolButton *m_lockButton; @@ -115,7 +115,7 @@ EditorToolBar::EditorToolBar(QWidget *parent) : d->m_lockButton->setAutoRaise(true); d->m_lockButton->setEnabled(false); - d->m_editorsListModel = EditorManager::instance()->openedEditorsModel(); + d->m_editorsListModel = EditorManager::instance()->documentModel(); connect(d->m_goBackAction, SIGNAL(triggered()), this, SIGNAL(goBackClicked())); connect(d->m_goForwardAction, SIGNAL(triggered()), this, SIGNAL(goForwardClicked())); @@ -310,13 +310,13 @@ void EditorToolBar::updateEditorListSelection(IEditor *newSelection) void EditorToolBar::changeActiveEditor(int row) { EditorManager *em = EditorManager::instance(); - em->activateEditorForEntry(d->m_editorsListModel->entryAtRow(row)); + em->activateEditorForEntry(d->m_editorsListModel->documentAtRow(row)); } void EditorToolBar::listContextMenu(QPoint pos) { - OpenEditorsModel::Entry *entry = EditorManager::instance() - ->openedEditorsModel()->entryAtRow(d->m_editorList->currentIndex()); + DocumentModel::Entry *entry = EditorManager::instance() + ->documentModel()->documentAtRow(d->m_editorList->currentIndex()); QString fileName = entry ? entry->fileName() : QString(); if (fileName.isEmpty()) return; diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index 6261728c458..f3187d03ac6 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include #include @@ -1997,7 +1997,7 @@ void FakeVimPluginPrivate::highlightMatches(const QString &needle) int FakeVimPluginPrivate::currentFile() const { - OpenEditorsModel *model = EditorManager::instance()->openedEditorsModel(); + DocumentModel *model = EditorManager::instance()->documentModel(); IEditor *editor = EditorManager::currentEditor(); if (!editor) return -1; @@ -2007,13 +2007,13 @@ int FakeVimPluginPrivate::currentFile() const void FakeVimPluginPrivate::switchToFile(int n) { EditorManager *editorManager = ICore::editorManager(); - OpenEditorsModel *model = editorManager->openedEditorsModel(); - int size = model->openDocumentCount(); + DocumentModel *model = editorManager->documentModel(); + int size = model->documentCount(); QTC_ASSERT(size, return); n = n % size; if (n < 0) n += size; - editorManager->activateEditorForEntry(model->entries().at(n)); + editorManager->activateEditorForEntry(model->documents().at(n)); } ExCommandMap &FakeVimExCommandsPage::exCommandMap() diff --git a/src/plugins/locator/opendocumentsfilter.cpp b/src/plugins/locator/opendocumentsfilter.cpp index 0e2a91fc6b4..b5429bcf7fb 100644 --- a/src/plugins/locator/opendocumentsfilter.cpp +++ b/src/plugins/locator/opendocumentsfilter.cpp @@ -66,7 +66,7 @@ QList OpenDocumentsFilter::matchesFor(QFutureInterface OpenDocumentsFilter::matchesFor(QFutureInterfaceopenedEditorsModel()->entries()) { - OpenEditorsModel::Entry entry; + foreach (DocumentModel::Entry *e, EditorManager::instance()->documentModel()->documents()) { + DocumentModel::Entry entry; // create copy with only the information relevant to use // to avoid model deleting entries behind our back entry.m_displayName = e->displayName(); diff --git a/src/plugins/locator/opendocumentsfilter.h b/src/plugins/locator/opendocumentsfilter.h index 52e9ce208ae..9a861d3a543 100644 --- a/src/plugins/locator/opendocumentsfilter.h +++ b/src/plugins/locator/opendocumentsfilter.h @@ -32,7 +32,7 @@ #include "ilocatorfilter.h" -#include +#include #include #include @@ -61,7 +61,7 @@ public slots: private: Core::EditorManager *m_editorManager; - QList m_editors; + QList m_editors; }; } // namespace Internal diff --git a/src/plugins/qmldesigner/shortcutmanager.cpp b/src/plugins/qmldesigner/shortcutmanager.cpp index 518f905259e..518eba261ca 100644 --- a/src/plugins/qmldesigner/shortcutmanager.cpp +++ b/src/plugins/qmldesigner/shortcutmanager.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include @@ -172,7 +172,7 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex void ShortCutManager::updateActions(Core::IEditor* currentEditor) { - int openedCount = Core::ICore::editorManager()->openedEditorsModel()->openDocumentCount(); + int openedCount = Core::ICore::editorManager()->documentModel()->documentCount(); m_saveAction.setEnabled(currentEditor != 0 && currentEditor->document()->isModified()); m_saveAsAction.setEnabled(currentEditor != 0 && currentEditor->document()->isSaveAsAllowed()); diff --git a/src/plugins/texteditor/findinopenfiles.cpp b/src/plugins/texteditor/findinopenfiles.cpp index 2ef4414dec8..3e3a7f79528 100644 --- a/src/plugins/texteditor/findinopenfiles.cpp +++ b/src/plugins/texteditor/findinopenfiles.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include @@ -67,8 +67,8 @@ Utils::FileIterator *FindInOpenFiles::files(const QStringList &nameFilters, QMap openEditorEncodings = ITextEditor::openedTextEditorsEncodings(); QStringList fileNames; QList codecs; - foreach (Core::OpenEditorsModel::Entry *entry, - Core::EditorManager::instance()->openedEditorsModel()->entries()) { + foreach (Core::DocumentModel::Entry *entry, + Core::EditorManager::instance()->documentModel()->documents()) { QString fileName = entry->fileName(); if (!fileName.isEmpty()) { fileNames.append(fileName);