forked from qt-creator/qt-creator
EditorManager: Rename "restored" to "suspended" documents
For documents that were "restored" from a session, without actually opening them. The new naming differentiates them from documents that were "restored" from auto-save files, and also fits better if we later "suspend" documents that have not been visible for a while. Change-Id: I7727344299eb2b395fc94cd1ab401ceb489111aa Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -108,7 +108,7 @@ private:
|
||||
QHash<QString, DocumentModel::Entry *> m_entryByFixedPath;
|
||||
};
|
||||
|
||||
class RestoredDocument : public IDocument
|
||||
class SuspendedDocument : public IDocument
|
||||
{
|
||||
public:
|
||||
bool save(QString *, const QString &, bool) override { return false; }
|
||||
@@ -132,13 +132,13 @@ static DocumentModelPrivate *d;
|
||||
|
||||
DocumentModel::Entry::Entry() :
|
||||
document(0),
|
||||
isRestored(false)
|
||||
isSuspended(false)
|
||||
{
|
||||
}
|
||||
|
||||
DocumentModel::Entry::~Entry()
|
||||
{
|
||||
if (isRestored)
|
||||
if (isSuspended)
|
||||
delete document;
|
||||
}
|
||||
|
||||
@@ -222,20 +222,20 @@ void DocumentModel::addEditor(IEditor *editor, bool *isNewDocument)
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentModel::addRestoredDocument(const QString &fileName, const QString &displayName, Id id)
|
||||
void DocumentModel::addSuspendedDocument(const QString &fileName, const QString &displayName, Id id)
|
||||
{
|
||||
Entry *entry = new Entry;
|
||||
entry->document = new RestoredDocument;
|
||||
entry->document = new SuspendedDocument;
|
||||
entry->document->setFilePath(Utils::FileName::fromString(fileName));
|
||||
entry->document->setPreferredDisplayName(displayName);
|
||||
entry->document->setId(id);
|
||||
entry->isRestored = true;
|
||||
entry->isSuspended = true;
|
||||
d->addEntry(entry);
|
||||
}
|
||||
|
||||
DocumentModel::Entry *DocumentModel::firstRestoredEntry()
|
||||
DocumentModel::Entry *DocumentModel::firstSuspendedEntry()
|
||||
{
|
||||
return Utils::findOrDefault(d->m_entries, [](Entry *entry) { return entry->isRestored; });
|
||||
return Utils::findOrDefault(d->m_entries, [](Entry *entry) { return entry->isSuspended; });
|
||||
}
|
||||
|
||||
void DocumentModelPrivate::addEntry(DocumentModel::Entry *entry)
|
||||
@@ -245,11 +245,11 @@ void DocumentModelPrivate::addEntry(DocumentModel::Entry *entry)
|
||||
if (!fileName.isEmpty())
|
||||
fixedPath = DocumentManager::fixFileName(fileName.toString(), DocumentManager::ResolveLinks);
|
||||
|
||||
// replace a non-loaded entry (aka 'restored') if possible
|
||||
// replace a non-loaded entry (aka 'suspended') if possible
|
||||
int previousIndex = indexOfFilePath(fileName);
|
||||
if (previousIndex >= 0) {
|
||||
DocumentModel::Entry *previousEntry = m_entries.at(previousIndex);
|
||||
const bool replace = !entry->isRestored && previousEntry->isRestored;
|
||||
const bool replace = !entry->isSuspended && previousEntry->isSuspended;
|
||||
if (replace) {
|
||||
delete previousEntry;
|
||||
m_entries[previousIndex] = entry;
|
||||
@@ -359,8 +359,8 @@ int DocumentModelPrivate::indexOfFilePath(const Utils::FileName &filePath) const
|
||||
|
||||
void DocumentModel::removeEntry(DocumentModel::Entry *entry)
|
||||
{
|
||||
// For non restored entries, we wouldn't know what to do with the associated editors
|
||||
QTC_ASSERT(entry->isRestored, return);
|
||||
// For non suspended entries, we wouldn't know what to do with the associated editors
|
||||
QTC_ASSERT(entry->isSuspended, return);
|
||||
int index = d->m_entries.indexOf(entry);
|
||||
d->removeDocument(index);
|
||||
}
|
||||
@@ -384,8 +384,8 @@ void DocumentModel::removeEditor(IEditor *editor, bool *lastOneForDocument)
|
||||
void DocumentModel::removeDocument(const QString &fileName)
|
||||
{
|
||||
int index = d->indexOfFilePath(Utils::FileName::fromString(fileName));
|
||||
// For non restored entries, we wouldn't know what to do with the associated editors
|
||||
QTC_ASSERT(d->m_entries.at(index)->isRestored, return);
|
||||
// For non suspended entries, we wouldn't know what to do with the associated editors
|
||||
QTC_ASSERT(d->m_entries.at(index)->isSuspended, return);
|
||||
d->removeDocument(index);
|
||||
}
|
||||
|
||||
@@ -410,10 +410,10 @@ void DocumentModelPrivate::removeDocument(int idx)
|
||||
delete entry;
|
||||
}
|
||||
|
||||
void DocumentModel::removeAllRestoredEntries()
|
||||
void DocumentModel::removeAllSuspendedEntries()
|
||||
{
|
||||
for (int i = d->m_entries.count()-1; i >= 0; --i) {
|
||||
if (d->m_entries.at(i)->isRestored) {
|
||||
if (d->m_entries.at(i)->isSuspended) {
|
||||
int row = i + 1/*<no document>*/;
|
||||
d->beginRemoveRows(QModelIndex(), row, row);
|
||||
delete d->m_entries.takeAt(i);
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
Id id() const;
|
||||
|
||||
IDocument *document;
|
||||
bool isRestored;
|
||||
bool isSuspended;
|
||||
};
|
||||
|
||||
static Entry *entryAtRow(int row);
|
||||
@@ -82,12 +82,12 @@ public:
|
||||
|
||||
// editor manager related functions, nobody else should call it
|
||||
static void addEditor(IEditor *editor, bool *isNewDocument);
|
||||
static void addRestoredDocument(const QString &fileName, const QString &displayName, Id id);
|
||||
static Entry *firstRestoredEntry();
|
||||
static void addSuspendedDocument(const QString &fileName, const QString &displayName, Id id);
|
||||
static Entry *firstSuspendedEntry();
|
||||
static void removeEditor(IEditor *editor, bool *lastOneForDocument);
|
||||
static void removeDocument(const QString &fileName);
|
||||
static void removeEntry(Entry *entry);
|
||||
static void removeAllRestoredEntries();
|
||||
static void removeAllSuspendedEntries();
|
||||
|
||||
private:
|
||||
DocumentModel();
|
||||
|
||||
@@ -1255,7 +1255,7 @@ void EditorManagerPrivate::activateEditorForEntry(EditorView *view, DocumentMode
|
||||
return;
|
||||
}
|
||||
IDocument *document = entry->document;
|
||||
if (!entry->isRestored) {
|
||||
if (!entry->isSuspended) {
|
||||
activateEditorForDocument(view, document, flags);
|
||||
return;
|
||||
}
|
||||
@@ -1977,7 +1977,7 @@ bool EditorManagerPrivate::saveDocumentAs(IDocument *document)
|
||||
|
||||
void EditorManagerPrivate::closeAllEditorsExceptVisible()
|
||||
{
|
||||
DocumentModel::removeAllRestoredEntries();
|
||||
DocumentModel::removeAllSuspendedEntries();
|
||||
QList<IDocument *> documentsToClose = DocumentModel::openedDocuments();
|
||||
foreach (IEditor *editor, EditorManager::visibleEditors())
|
||||
documentsToClose.removeAll(editor->document());
|
||||
@@ -2120,7 +2120,7 @@ IEditor *EditorManager::currentEditor()
|
||||
|
||||
bool EditorManager::closeAllEditors(bool askAboutModifiedEditors)
|
||||
{
|
||||
DocumentModel::removeAllRestoredEntries();
|
||||
DocumentModel::removeAllSuspendedEntries();
|
||||
if (closeDocuments(DocumentModel::openedDocuments(), askAboutModifiedEditors))
|
||||
return true;
|
||||
return false;
|
||||
@@ -2128,7 +2128,7 @@ bool EditorManager::closeAllEditors(bool askAboutModifiedEditors)
|
||||
|
||||
void EditorManager::closeOtherDocuments(IDocument *document)
|
||||
{
|
||||
DocumentModel::removeAllRestoredEntries();
|
||||
DocumentModel::removeAllSuspendedEntries();
|
||||
QList<IDocument *> documentsToClose = DocumentModel::openedDocuments();
|
||||
documentsToClose.removeAll(document);
|
||||
closeDocuments(documentsToClose, true);
|
||||
@@ -2311,7 +2311,7 @@ void EditorManager::closeDocument(DocumentModel::Entry *entry)
|
||||
{
|
||||
if (!entry)
|
||||
return;
|
||||
if (entry->isRestored)
|
||||
if (entry->isSuspended)
|
||||
DocumentModel::removeEntry(entry);
|
||||
else
|
||||
closeDocuments(QList<IDocument *>() << entry->document);
|
||||
@@ -2423,10 +2423,10 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
|
||||
if (newCurrent) {
|
||||
EditorManagerPrivate::activateEditor(view, newCurrent, DoNotChangeCurrentEditor);
|
||||
} else if (forceViewToShowEditor == view) {
|
||||
DocumentModel::Entry *entry = DocumentModel::firstRestoredEntry();
|
||||
DocumentModel::Entry *entry = DocumentModel::firstSuspendedEntry();
|
||||
if (entry) {
|
||||
EditorManagerPrivate::activateEditorForEntry(view, entry, DoNotChangeCurrentEditor);
|
||||
} else { // no "restored" ones, so any entry left should have a document
|
||||
} else { // no "suspended" ones, so any entry left should have a document
|
||||
const QList<DocumentModel::Entry *> documents = DocumentModel::entries();
|
||||
if (!documents.isEmpty()) {
|
||||
if (IDocument *document = documents.last()->document) {
|
||||
@@ -2888,7 +2888,7 @@ bool EditorManager::restoreState(const QByteArray &state)
|
||||
if (rfi.exists() && fi.lastModified() < rfi.lastModified())
|
||||
openEditor(fileName, id, DoNotMakeVisible);
|
||||
else
|
||||
DocumentModel::addRestoredDocument(fileName, displayName, id);
|
||||
DocumentModel::addSuspendedDocument(fileName, displayName, id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -920,7 +920,7 @@ void SplitterOrView::restoreState(const QByteArray &state)
|
||||
| EditorManager::DoNotChangeCurrentEditor);
|
||||
|
||||
if (!e) {
|
||||
DocumentModel::Entry *entry = DocumentModel::firstRestoredEntry();
|
||||
DocumentModel::Entry *entry = DocumentModel::firstSuspendedEntry();
|
||||
if (entry) {
|
||||
EditorManagerPrivate::activateEditorForEntry(view(), entry,
|
||||
EditorManager::IgnoreNavigationHistory | EditorManager::DoNotChangeCurrentEditor);
|
||||
|
||||
@@ -179,8 +179,8 @@ void OpenEditorsWindow::setEditors(const QList<EditLocation> &globalHistory, Edi
|
||||
// add missing editors from the global history
|
||||
addHistoryItems(globalHistory, view, documentsDone);
|
||||
|
||||
// add purely restored editors which are not initialised yet
|
||||
addRestoredItems();
|
||||
// add purely suspended editors which are not initialised yet
|
||||
addSuspendedItems();
|
||||
}
|
||||
|
||||
|
||||
@@ -241,10 +241,10 @@ void OpenEditorsWindow::addHistoryItems(const QList<EditLocation> &history, Edit
|
||||
}
|
||||
}
|
||||
|
||||
void OpenEditorsWindow::addRestoredItems()
|
||||
void OpenEditorsWindow::addSuspendedItems()
|
||||
{
|
||||
foreach (DocumentModel::Entry *entry, DocumentModel::entries()) {
|
||||
if (!entry->isRestored)
|
||||
if (!entry->isSuspended)
|
||||
continue;
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||
QString title = entry->displayName();
|
||||
|
||||
@@ -79,7 +79,7 @@ private:
|
||||
void selectEditor(QTreeWidgetItem *item);
|
||||
|
||||
void addHistoryItems(const QList<EditLocation> &history, EditorView *view, QSet<IDocument*> &documentsDone);
|
||||
void addRestoredItems();
|
||||
void addSuspendedItems();
|
||||
void ensureCurrentVisible();
|
||||
void selectUpDown(bool up);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user