diff --git a/packages/core/src/browser/common-frontend-contribution.ts b/packages/core/src/browser/common-frontend-contribution.ts index c0346336f5acc..a9dcc71927eeb 100644 --- a/packages/core/src/browser/common-frontend-contribution.ts +++ b/packages/core/src/browser/common-frontend-contribution.ts @@ -59,7 +59,7 @@ import { ConfirmDialog, confirmExit, Dialog } from './dialogs'; import { WindowService } from './window/window-service'; import { FrontendApplicationConfigProvider } from './frontend-application-config-provider'; import { DecorationStyle } from './decoration-style'; -import { Title, Widget } from './widgets'; +import { PINNED_CLASS, Title, Widget } from './widgets'; export namespace CommonMenus { @@ -327,8 +327,6 @@ export const supportPaste = browser.isNative || (!browser.isChrome && document.q export const RECENT_COMMANDS_STORAGE_KEY = 'commands'; -export const PINNED_CLASS = 'theia-mod-pinned'; - @injectable() export class CommonFrontendContribution implements FrontendApplicationContribution, MenuContribution, CommandContribution, KeybindingContribution, ColorContribution { @@ -912,11 +910,11 @@ export class CommonFrontendContribution implements FrontendApplicationContributi execute: () => this.selectIconTheme() }); commandRegistry.registerCommand(CommonCommands.PIN_TAB, new CurrentWidgetCommandAdapter(this.shell, { - isEnabled: title => !!title && title.closable && title.className.indexOf(PINNED_CLASS) === -1, + isEnabled: title => !!title && title.closable && !title.className.includes(PINNED_CLASS), execute: title => this.togglePinned(title), })); commandRegistry.registerCommand(CommonCommands.UNPIN_TAB, new CurrentWidgetCommandAdapter(this.shell, { - isEnabled: title => !!title && title.className.indexOf(PINNED_CLASS) >= 0, + isEnabled: title => !!title && !title.closable && title.className.includes(PINNED_CLASS), execute: title => this.togglePinned(title), })); commandRegistry.registerCommand(CommonCommands.CONFIGURE_DISPLAY_LANGUAGE, { diff --git a/packages/core/src/browser/shell/tab-bars.ts b/packages/core/src/browser/shell/tab-bars.ts index 644dc3b76beda..4deefd625736b 100644 --- a/packages/core/src/browser/shell/tab-bars.ts +++ b/packages/core/src/browser/shell/tab-bars.ts @@ -31,6 +31,7 @@ import { IconThemeService } from '../icon-theme-service'; import { BreadcrumbsRenderer, BreadcrumbsRendererFactory } from '../breadcrumbs/breadcrumbs-renderer'; import { NavigatableWidget } from '../navigatable-types'; import { IDragEvent } from '@phosphor/dragdrop'; +import { PINNED_CLASS } from '../widgets/widget'; /** The class name added to hidden content nodes, which are required to render vertical side bars. */ const HIDDEN_CONTENT_CLASS = 'theia-TabBar-hidden-content'; @@ -475,7 +476,7 @@ export class TabBarRenderer extends TabBar.Renderer { if (this.tabBar && event.currentTarget instanceof HTMLElement) { const id = event.currentTarget.parentElement!.id; const title = this.tabBar.titles.find(t => this.createTabId(t) === id); - if (title && title.className.indexOf('theia-mod-pinned') >= 0 && this.commandService) { + if (title?.closable === false && title?.className.includes(PINNED_CLASS) && this.commandService) { this.commandService.executeCommand('workbench.action.unpinEditor', event); } } diff --git a/packages/core/src/browser/view-container.ts b/packages/core/src/browser/view-container.ts index 573df31413340..fdd3a7b95b522 100644 --- a/packages/core/src/browser/view-container.ts +++ b/packages/core/src/browser/view-container.ts @@ -18,7 +18,7 @@ import { interfaces, injectable, inject, postConstruct } from 'inversify'; import { IIterator, toArray, find, some, every, map, ArrayExt } from '@phosphor/algorithm'; import { Widget, EXPANSION_TOGGLE_CLASS, COLLAPSED_CLASS, CODICON_TREE_ITEM_CLASSES, MessageLoop, Message, SplitPanel, - BaseWidget, addEventListener, SplitLayout, LayoutItem, PanelLayout, addKeyListener, waitForRevealed, UnsafeWidgetUtilities, DockPanel + BaseWidget, addEventListener, SplitLayout, LayoutItem, PanelLayout, addKeyListener, waitForRevealed, UnsafeWidgetUtilities, DockPanel, PINNED_CLASS } from './widgets'; import { Event as CommonEvent, Emitter } from '../common/event'; import { Disposable, DisposableCollection } from '../common/disposable'; @@ -276,7 +276,9 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica if (title.iconClass) { this.title.iconClass = title.iconClass; } - if (title.closeable !== undefined) { + if (this.title.className.includes(PINNED_CLASS)) { + this.title.closable &&= false; + } else if (title.closeable !== undefined) { this.title.closable = title.closeable; } } diff --git a/packages/core/src/browser/widgets/widget.ts b/packages/core/src/browser/widgets/widget.ts index d15a52b538ac1..7a0c46f9bb737 100644 --- a/packages/core/src/browser/widgets/widget.ts +++ b/packages/core/src/browser/widgets/widget.ts @@ -52,6 +52,7 @@ export const BUSY_CLASS = 'theia-mod-busy'; export const CODICON_LOADING_CLASSES = codiconArray('loading'); export const SELECTED_CLASS = 'theia-mod-selected'; export const FOCUS_CLASS = 'theia-mod-focus'; +export const PINNED_CLASS = 'theia-mod-pinned'; export const DEFAULT_SCROLL_OPTIONS: PerfectScrollbar.Options = { suppressScrollX: true, minScrollbarLength: 35,