From 697ef350c3410005ff04a41f0526045fabd01728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Wed, 30 Oct 2024 20:44:16 +0100 Subject: [PATCH 1/2] Keep closable state through pin/unpin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #14370 Contributed on behalf of STMicroelectronics Signed-off-by: Thomas Mäder --- packages/core/src/browser/widgets/widget.ts | 26 +++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/core/src/browser/widgets/widget.ts b/packages/core/src/browser/widgets/widget.ts index 9a71b96074208..f1524d7e5e653 100644 --- a/packages/core/src/browser/widgets/widget.ts +++ b/packages/core/src/browser/widgets/widget.ts @@ -24,6 +24,7 @@ import { KeyCode, KeysOrKeyCodes } from '../keyboard/keys'; import PerfectScrollbar from 'perfect-scrollbar'; import { PreviewableWidget } from '../widgets/previewable-widget'; +import { Slot } from '@phosphor/signaling'; decorate(injectable(), Widget); decorate(unmanaged(), Widget, 0); @@ -364,23 +365,38 @@ function waitForVisible(widget: Widget, visible: boolean, attached?: boolean): P }); } +const pinnedTitles = new Map, [boolean, Slot]>(); + export function isPinned(title: Title): boolean { const pinnedState = !title.closable && title.className.includes(PINNED_CLASS); return pinnedState; } -export function unpin(title: Title): void { - title.closable = true; - title.className = title.className.replace(PINNED_CLASS, '').trim(); -} - export function pin(title: Title): void { + const l = () => { + pinnedTitles.delete(title); + }; + pinnedTitles.set(title, [title.closable, l]); + title.owner.disposed.connect(l); title.closable = false; if (!title.className.includes(PINNED_CLASS)) { title.className += ` ${PINNED_CLASS}`; } } +export function unpin(title: Title): void { + const entry = pinnedTitles.get(title); + if (entry) { + title.owner.disposed.disconnect(entry[1]); + title.closable = entry[0]; + pinnedTitles.delete(title); + } else { + title.closable = true; + } + title.className = title.className.replace(PINNED_CLASS, '').trim(); +} + + export function isLocked(title: Title): boolean { return title.className.includes(LOCKED_CLASS); } From 5df6486867df2389bb1003c5b2b1c071756d2953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Thu, 31 Oct 2024 08:02:49 +0100 Subject: [PATCH 2/2] Fix linter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Mäder --- packages/core/src/browser/widgets/widget.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/src/browser/widgets/widget.ts b/packages/core/src/browser/widgets/widget.ts index f1524d7e5e653..db2b6f053b26d 100644 --- a/packages/core/src/browser/widgets/widget.ts +++ b/packages/core/src/browser/widgets/widget.ts @@ -396,7 +396,6 @@ export function unpin(title: Title): void { title.className = title.className.replace(PINNED_CLASS, '').trim(); } - export function isLocked(title: Title): boolean { return title.className.includes(LOCKED_CLASS); }