Commit 7b1941c7 authored by Eike Ziller's avatar Eike Ziller

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: default avatarEike Ziller <eike.ziller@digia.com>
parent 39d99126
......@@ -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 \
......
......@@ -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",
......
......@@ -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<OpenEditorsModel::Entry *> m_documents;
QList<DocumentModel::Entry *> m_documents;
QMap<IDocument *, QList<IEditor *> > 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/*<no document>*/;
......@@ -114,7 +114,7 @@ int OpenEditorsModel::rowCount(const QModelIndex &parent) const
}
// TODO remove
QList<IEditor *> OpenEditorsModel::oneEditorForEachDocument() const
QList<IEditor *> DocumentModel::oneEditorForEachOpenedDocument() const
{
QList<IEditor *> result;
QMapIterator<IDocument *, QList<IEditor *> > it(d->m_editors);
......@@ -123,7 +123,7 @@ QList<IEditor *> 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<IEditor *> OpenEditorsModel::editorsForDocument(IDocument *document) const
QList<IEditor *> DocumentModel::editorsForDocument(IDocument *document) const
{
return d->m_editors.value(document);
}
QList<IEditor *> OpenEditorsModel::editorsForDocuments(const QList<IDocument *> &documents) const
QList<IEditor *> DocumentModel::editorsForDocuments(const QList<IDocument *> &documents) const
{
QList<IEditor *> result;
foreach (IDocument *document, documents)
......@@ -270,7 +270,7 @@ QList<IEditor *> OpenEditorsModel::editorsForDocuments(const QList<IDocument *>
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/*<no document>*/)
......@@ -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/*<no document>*/;
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 /*<no document>*/;
return indexOfDocument(document) + 1/*<no document>*/;
}
void OpenEditorsModel::itemChanged()
void DocumentModel::itemChanged()
{
IDocument *document = qobject_cast<IDocument *>(sender());
......@@ -361,7 +361,7 @@ void OpenEditorsModel::itemChanged()
emit dataChanged(mindex, mindex);
}
QList<OpenEditorsModel::Entry *> OpenEditorsModel::entries() const
QList<DocumentModel::Entry *> DocumentModel::documents() const
{
return d->m_documents;
}
......
......@@ -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<Entry *> entries() const;
int documentCount() const;
QList<Entry *> documents() const;
int indexOfDocument(IDocument *document) const;
QList<IEditor *> editorsForDocument(IDocument *document) const;
QList<IEditor *> editorsForDocuments(const QList<IDocument *> &documents) const;
QList<IEditor *> oneEditorForEachDocument() const;
int indexOfDocument(IDocument *document) const;
QList<IEditor *> 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
......@@ -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<QString, QVariant> 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<IEditor *> 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<IEditor *> 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<IEditor *>() << 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<IEditor*> &editorsToClose, bool askAboutModifiedEditors)
......@@ -1068,7 +1068,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &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<IEditor*> &editorsToClose, bool ask
if (!list.isEmpty()) {
closingFailed = true;
acceptedDocuments.subtract(list.toSet());
QSet<IEditor*> skipSet = d->m_editorModel->editorsForDocuments(list).toSet();
QSet<IEditor*> skipSet = d->m_documentModel->editorsForDocuments(list).toSet();
acceptedEditors = acceptedEditors.subtract(skipSet);
}
}
......@@ -1131,12 +1131,12 @@ bool EditorManager::closeEditors(const QList<IEditor*> &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<OpenEditorsModel::Entry *> documents = d->m_editorModel->entries();
const QList<DocumentModel::Entry *> 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);