Skip to content

Commit

Permalink
Keep closable state through pin/unpin (#14377)
Browse files Browse the repository at this point in the history
Fixes #14370

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
  • Loading branch information
tsmaeder authored Nov 5, 2024
1 parent 0d58e3f commit 72b700d
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions packages/core/src/browser/widgets/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -364,23 +365,37 @@ function waitForVisible(widget: Widget, visible: boolean, attached?: boolean): P
});
}

const pinnedTitles = new Map<Title<Widget>, [boolean, Slot<Widget, void>]>();

export function isPinned(title: Title<Widget>): boolean {
const pinnedState = !title.closable && title.className.includes(PINNED_CLASS);
return pinnedState;
}

export function unpin(title: Title<Widget>): void {
title.closable = true;
title.className = title.className.replace(PINNED_CLASS, '').trim();
}

export function pin(title: Title<Widget>): 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<Widget>): 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<Widget>): boolean {
return title.className.includes(LOCKED_CLASS);
}
Expand Down

0 comments on commit 72b700d

Please sign in to comment.