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

Context Menu Enables Pinned Tabs On Seperate Row #193813

Merged
merged 8 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 43 additions & 8 deletions src/vs/workbench/browser/actions/layoutActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,25 @@ export class ToggleStatusbarVisibilityAction extends Action2 {

registerAction2(ToggleStatusbarVisibilityAction);

// --- Toggle Tabs Visibility
// --- Bse Class Toggle Boolean Setting Action

abstract class BaseToggleBooleanSettingAction extends Action2 {

protected abstract get settingId(): string;

override run(accessor: ServicesAccessor): Promise<void> {
const configurationService = accessor.get(IConfigurationService);

const oldettingValue = configurationService.getValue<string>(this.settingId);
const newSettingValue = !oldettingValue;

return configurationService.updateValue(this.settingId, newSettingValue);
}
}

export class ToggleTabsVisibilityAction extends Action2 {
// --- Toggle Tabs Visibility

export class ToggleTabsVisibilityAction extends BaseToggleBooleanSettingAction {
static readonly ID = 'workbench.action.toggleTabsVisibility';

constructor() {
Expand All @@ -503,16 +518,36 @@ export class ToggleTabsVisibilityAction extends Action2 {
});
}

run(accessor: ServicesAccessor): Promise<void> {
const configurationService = accessor.get(IConfigurationService);
protected override get settingId(): string {
return 'workbench.editor.showTabs';
}
}
registerAction2(ToggleTabsVisibilityAction);

const visibility = configurationService.getValue<string>('workbench.editor.showTabs');
const newVisibilityValue = !visibility;
// --- Toggle Pinned Tabs On Separate Row

export class ToggleSeparatePinnedTabsAction extends BaseToggleBooleanSettingAction {

static readonly ID = 'workbench.action.toggleSeparatePinnedTabs';

constructor() {
super({
id: ToggleSeparatePinnedTabsAction.ID,
title: {
value: localize('toggleSeparatePinnedTabs', "Separate Pinned Tabs"),
original: 'Separate Pinned Tabs'
},
category: Categories.View,
benibenj marked this conversation as resolved.
Show resolved Hide resolved
precondition: ContextKeyExpr.has('config.workbench.editor.showTabs'),
f1: true
});
}

return configurationService.updateValue('workbench.editor.showTabs', newVisibilityValue);
protected override get settingId(): string {
return 'workbench.editor.pinnedTabsOnSeparateRow';
}
}
registerAction2(ToggleTabsVisibilityAction);
registerAction2(ToggleSeparatePinnedTabsAction);

// --- Toggle Zen Mode

Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/browser/parts/editor/editor.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IEditorFactoryRegistry, EditorExtensions } from 'vs/workbench/common/ed
import {
TextCompareEditorActiveContext, ActiveEditorPinnedContext, EditorGroupEditorsCountContext, ActiveEditorStickyContext, ActiveEditorAvailableEditorIdsContext,
MultipleEditorGroupsContext, ActiveEditorDirtyContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, SideBySideEditorActiveContext,
EditorTabsVisibleContext, ActiveEditorLastInGroupContext
EditorTabsVisibleContext, ActiveEditorLastInGroupContext, EditorPinnedAndUnpinnedTabsContext
} from 'vs/workbench/common/contextkeys';
import { SideBySideEditorInput, SideBySideEditorInputSerializer } from 'vs/workbench/common/editor/sideBySideEditorInput';
import { TextResourceEditor } from 'vs/workbench/browser/parts/editor/textResourceEditor';
Expand Down Expand Up @@ -66,7 +66,7 @@ import { Codicon } from 'vs/base/common/codicons';
import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
import { UntitledTextEditorInputSerializer, UntitledTextEditorWorkingCopyEditorHandler } from 'vs/workbench/services/untitled/common/untitledTextEditorHandler';
import { DynamicEditorConfigurations } from 'vs/workbench/browser/parts/editor/editorConfiguration';
import { ToggleTabsVisibilityAction } from 'vs/workbench/browser/actions/layoutActions';
import { ToggleSeparatePinnedTabsAction, ToggleTabsVisibilityAction } from 'vs/workbench/browser/actions/layoutActions';

//#region Editor Registrations

Expand Down Expand Up @@ -352,6 +352,7 @@ MenuRegistry.appendMenuItem(MenuId.EditorTabsBarContext, { command: { id: SPLIT_
MenuRegistry.appendMenuItem(MenuId.EditorTabsBarContext, { command: { id: SPLIT_EDITOR_LEFT, title: localize('splitLeft', "Split Left") }, group: '2_split', order: 30 });
MenuRegistry.appendMenuItem(MenuId.EditorTabsBarContext, { command: { id: SPLIT_EDITOR_RIGHT, title: localize('splitRight', "Split Right") }, group: '2_split', order: 40 });
MenuRegistry.appendMenuItem(MenuId.EditorTabsBarContext, { command: { id: ToggleTabsVisibilityAction.ID, title: localize('toggleTabs', "Enable Tabs"), toggled: ContextKeyExpr.has('config.workbench.editor.showTabs') }, group: '3_config', order: 10 });
MenuRegistry.appendMenuItem(MenuId.EditorTabsBarContext, { command: { id: ToggleSeparatePinnedTabsAction.ID, title: localize('separatePinnedTabs', "Separate Pinned Tabs"), toggled: ContextKeyExpr.has('config.workbench.editor.pinnedTabsOnSeparateRow') }, when: EditorPinnedAndUnpinnedTabsContext, group: '3_config', order: 20 });

// Editor Title Context Menu
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: CLOSE_EDITOR_COMMAND_ID, title: localize('close', "Close") }, group: '1_close', order: 10 });
Expand Down
13 changes: 11 additions & 2 deletions src/vs/workbench/browser/parts/editor/editorGroupView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import 'vs/css!./media/editorgroupview';
import { EditorGroupModel, IEditorOpenOptions, IGroupModelChangeEvent, ISerializedEditorGroupModel, isGroupEditorCloseEvent, isGroupEditorOpenEvent, isSerializedEditorGroupModel } from 'vs/workbench/common/editor/editorGroupModel';
import { GroupIdentifier, CloseDirection, IEditorCloseEvent, IEditorPane, SaveReason, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditorPane, EditorResourceAccessor, EditorInputCapabilities, IUntypedEditorInput, DEFAULT_EDITOR_ASSOCIATION, SideBySideEditor, EditorCloseContext, IEditorWillMoveEvent, IEditorWillOpenEvent, IMatchEditorOptions, GroupModelChangeKind, IActiveEditorChangeEvent, IFindEditorOptions } from 'vs/workbench/common/editor';
import { ActiveEditorGroupLockedContext, ActiveEditorDirtyContext, EditorGroupEditorsCountContext, ActiveEditorStickyContext, ActiveEditorPinnedContext, ActiveEditorLastInGroupContext, ActiveEditorFirstInGroupContext } from 'vs/workbench/common/contextkeys';
import { ActiveEditorGroupLockedContext, ActiveEditorDirtyContext, EditorGroupEditorsCountContext, ActiveEditorStickyContext, ActiveEditorPinnedContext, ActiveEditorLastInGroupContext, ActiveEditorFirstInGroupContext, EditorPinnedAndUnpinnedTabsContext } from 'vs/workbench/common/contextkeys';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';
import { Emitter, Relay } from 'vs/base/common/event';
Expand Down Expand Up @@ -241,6 +241,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
const groupActiveEditorStickyContext = ActiveEditorStickyContext.bindTo(this.scopedContextKeyService);
const groupEditorsCountContext = EditorGroupEditorsCountContext.bindTo(this.scopedContextKeyService);
const groupLockedContext = ActiveEditorGroupLockedContext.bindTo(this.scopedContextKeyService);
const groupHasPinnedAndUnpinnedContext = EditorPinnedAndUnpinnedTabsContext.bindTo(this.scopedContextKeyService);

const activeEditorListener = this._register(new MutableDisposable());

Expand All @@ -264,9 +265,10 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
case GroupModelChangeKind.GROUP_LOCKED:
groupLockedContext.set(this.isLocked);
break;
case GroupModelChangeKind.EDITOR_ACTIVE:
case GroupModelChangeKind.EDITOR_CLOSE:
case GroupModelChangeKind.EDITOR_OPEN:
groupHasPinnedAndUnpinnedContext.set(this.hasPinnedAndUnpinnedEditors());
case GroupModelChangeKind.EDITOR_ACTIVE:
case GroupModelChangeKind.EDITOR_MOVE:
groupActiveEditorFirstContext.set(this.model.isFirst(this.model.activeEditor));
groupActiveEditorLastContext.set(this.model.isLast(this.model.activeEditor));
Expand All @@ -280,6 +282,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
if (e.editor && e.editor === this.model.activeEditor) {
groupActiveEditorStickyContext.set(this.model.isSticky(this.model.activeEditor));
}
groupHasPinnedAndUnpinnedContext.set(this.hasPinnedAndUnpinnedEditors());
break;
}

Expand All @@ -293,7 +296,13 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
observeActiveEditor();
}));

// Update context keys on startup
observeActiveEditor();
groupHasPinnedAndUnpinnedContext.set(this.hasPinnedAndUnpinnedEditors());
}

private hasPinnedAndUnpinnedEditors(): boolean {
return this.model.stickyCount > 0 && this.model.stickyCount < this.model.count;
}

private registerContainerListeners(): void {
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/common/contextkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const IsCenteredLayoutContext = new RawContextKey<boolean>('isCenteredLay
export const SplitEditorsVertically = new RawContextKey<boolean>('splitEditorsVertically', false, localize('splitEditorsVertically', "Whether editors split vertically"));
export const EditorAreaVisibleContext = new RawContextKey<boolean>('editorAreaVisible', true, localize('editorAreaVisible', "Whether the editor area is visible"));
export const EditorTabsVisibleContext = new RawContextKey<boolean>('editorTabsVisible', true, localize('editorTabsVisible', "Whether editor tabs are visible"));
export const EditorPinnedAndUnpinnedTabsContext = new RawContextKey<boolean>('editorPinnedAndUnpinnedTabsVisible', false, true);

//#endregion

Expand Down