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 <eike.ziller@qt.io>
This commit is contained in:
Mitch Curtis
2024-12-21 12:57:43 +08:00
parent 216170653f
commit 119a0920c1

View File

@@ -1616,7 +1616,10 @@ bool EditorManagerPrivate::closeEditors(const QList<IEditor*> &editors, CloseFla
QMultiHash<EditorView *, IEditor *> editorsPerView; QMultiHash<EditorView *, IEditor *> editorsPerView;
for (IEditor *editor : std::as_const(acceptedEditors)) { for (IEditor *editor : std::as_const(acceptedEditors)) {
emit m_instance->editorAboutToClose(editor); 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)) { if (EditorView *view = viewForEditor(editor)) {
editorsPerView.insert(view, editor); editorsPerView.insert(view, editor);
if (QApplication::focusWidget() if (QApplication::focusWidget()
@@ -3074,7 +3077,8 @@ bool EditorManager::closeDocuments(const QList<DocumentModel::Entry *> &entries)
for (DocumentModel::Entry *entry : entries) { for (DocumentModel::Entry *entry : entries) {
if (!entry) if (!entry)
continue; 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); DocumentModelPrivate::removeEntry(entry);
else else
documentsToClose << entry->document; documentsToClose << entry->document;