Fix ordering of items in open documents popup

When the document history was updated, it was cleaned of any items which
no longer had a document open for them. This worked fine when that only
happened when user closed documents. Nowadays this also happens when
suspending documents without user interaction.

Only remove items from the document history if they are no longer
available even as a suspended document.

Task-number: QTCREATORBUG-19758
Change-Id: I131a24823b5c456879b67a35b039768a15bd7716
Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2018-02-14 12:34:14 +01:00
parent 3060ddbcf3
commit 324de13b4e
3 changed files with 9 additions and 4 deletions

View File

@@ -517,6 +517,11 @@ Utils::optional<int> DocumentModel::indexOfDocument(IDocument *document)
return d->indexOfDocument(document); return d->indexOfDocument(document);
} }
Utils::optional<int> DocumentModel::indexOfFilePath(const Utils::FileName &filePath)
{
return d->indexOfFilePath(filePath);
}
DocumentModel::Entry *DocumentModel::entryForDocument(IDocument *document) DocumentModel::Entry *DocumentModel::entryForDocument(IDocument *document)
{ {
return Utils::findOrDefault(d->m_entries, return Utils::findOrDefault(d->m_entries,

View File

@@ -69,6 +69,7 @@ public:
static int entryCount(); static int entryCount();
static QList<Entry *> entries(); static QList<Entry *> entries();
static Utils::optional<int> indexOfDocument(IDocument *document); static Utils::optional<int> indexOfDocument(IDocument *document);
static Utils::optional<int> indexOfFilePath(const Utils::FileName &filePath);
static Entry *entryForDocument(IDocument *document); static Entry *entryForDocument(IDocument *document);
static Entry *entryForFilePath(const Utils::FileName &filePath); static Entry *entryForFilePath(const Utils::FileName &filePath);
static QList<IDocument *> openedDocuments(); static QList<IDocument *> openedDocuments();

View File

@@ -268,11 +268,10 @@ void EditorView::updateEditorHistory(IEditor *editor, QList<EditLocation> &histo
location.state = QVariant(state); location.state = QVariant(state);
for (int i = 0; i < history.size(); ++i) { for (int i = 0; i < history.size(); ++i) {
if (history.at(i).document == 0 const EditLocation &item = history.at(i);
|| history.at(i).document == document if (item.document == document
){ || !DocumentModel::indexOfFilePath(FileName::fromString(item.fileName))) {
history.removeAt(i--); history.removeAt(i--);
continue;
} }
} }
history.prepend(location); history.prepend(location);