From 119a0920c119e1bf631b16babab72b5c71740495 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Sat, 21 Dec 2024 12:57:43 +0800 Subject: [PATCH] Keep pinned files in Open Documents list when closed, but remove editor This means that users can hit Ctrl+W out of habit and not have to worry about a pinned file closing. It will be out of their way but still easily accessible should they need it. Fixes: QTCREATORBUG-25964 Change-Id: Ic377cde021044cfc7f3ea1933293a81a6a8ac0fa Reviewed-by: Eike Ziller --- src/plugins/coreplugin/editormanager/editormanager.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index cf3f66f46b3..8e95d7bcf08 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -1616,7 +1616,10 @@ bool EditorManagerPrivate::closeEditors(const QList &editors, CloseFla QMultiHash editorsPerView; for (IEditor *editor : std::as_const(acceptedEditors)) { emit m_instance->editorAboutToClose(editor); - removeEditor(editor, flag != CloseFlag::Suspend); + const DocumentModel::Entry *entry = DocumentModel::entryForDocument(editor->document()); + // If the file is pinned, closing it should remove the editor but keep it in Open Documents. + const bool removeSuspendedEntry = !entry->pinned && flag != CloseFlag::Suspend; + removeEditor(editor, removeSuspendedEntry); if (EditorView *view = viewForEditor(editor)) { editorsPerView.insert(view, editor); if (QApplication::focusWidget() @@ -3074,7 +3077,8 @@ bool EditorManager::closeDocuments(const QList &entries) for (DocumentModel::Entry *entry : entries) { if (!entry) continue; - if (entry->isSuspended) + // Pinned files shouldn't be removed from Open Documents, even when pressing the "x" button. + if (!entry->pinned && entry->isSuspended) DocumentModelPrivate::removeEntry(entry); else documentsToClose << entry->document;