Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep closable state through pin/unpin #14377

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>]>();
sgraband marked this conversation as resolved.
Show resolved Hide resolved

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
Loading