Skip to content

Commit

Permalink
Adapt context menu and commands
Browse files Browse the repository at this point in the history
  • Loading branch information
benibenj committed Oct 18, 2023
1 parent e859dc6 commit e47adcb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 20 deletions.
79 changes: 61 additions & 18 deletions src/vs/workbench/browser/actions/layoutActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,49 +470,87 @@ export class ToggleStatusbarVisibilityAction extends Action2 {

registerAction2(ToggleStatusbarVisibilityAction);

// --- Base Class Toggle Boolean Setting Action
// --- Hide Editor Tabs

abstract class BaseToggleBooleanSettingAction extends Action2 {
export class HideEditorTabsAction extends Action2 {

protected abstract get settingId(): string;
static readonly ID = 'workbench.action.hideEditorTabs';

constructor() {
super({
id: HideEditorTabsAction.ID,
title: {
value: localize('hideEditorTabs', "Hide Editor Tabs"),
original: 'Hide Editor Tabs'
},
category: Categories.View,
precondition: ContextKeyExpr.equals('config.workbench.editor.showTabs', 'none').negate(),
f1: true
});
}

override run(accessor: ServicesAccessor): Promise<void> {
const configurationService = accessor.get(IConfigurationService);
return configurationService.updateValue('workbench.editor.showTabs', 'none');
}
}
registerAction2(HideEditorTabsAction);

const oldettingValue = configurationService.getValue<string>(this.settingId);
const newSettingValue = !oldettingValue;
// --- Show Multiple Editor Tabs

export class ShowMultipleEditorTabsAction extends Action2 {

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

constructor() {
super({
id: ShowMultipleEditorTabsAction.ID,
title: {
value: localize('showMultipleEditorTabs', "Show Multiple Editor Tabs"),
original: 'Show Multiple Editor Tabs'
},
category: Categories.View,
precondition: ContextKeyExpr.equals('config.workbench.editor.showTabs', 'multiple').negate(),
f1: true
});
}

return configurationService.updateValue(this.settingId, newSettingValue);
override run(accessor: ServicesAccessor): Promise<void> {
const configurationService = accessor.get(IConfigurationService);
return configurationService.updateValue('workbench.editor.showTabs', 'multiple');
}
}
registerAction2(ShowMultipleEditorTabsAction);

// --- Toggle Tabs Visibility
// --- Show Single Editor Tab

export class ToggleTabsVisibilityAction extends BaseToggleBooleanSettingAction {
export class ShowSingleEditorTabAction extends Action2 {

static readonly ID = 'workbench.action.toggleTabsVisibility';
static readonly ID = 'workbench.action.showEditorTab';

constructor() {
super({
id: ToggleTabsVisibilityAction.ID,
id: ShowSingleEditorTabAction.ID,
title: {
value: localize('toggleTabs', "Toggle Editor Tab Visibility"),
original: 'Toggle Editor Tab Visibility'
value: localize('showSingleEditorTab', "Show Single Editor Tab"),
original: 'Show Single Editor Tab'
},
category: Categories.View,
precondition: ContextKeyExpr.equals('config.workbench.editor.showTabs', 'single').negate(),
f1: true
});
}

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

// --- Toggle Pinned Tabs On Separate Row

export class ToggleSeparatePinnedTabsAction extends BaseToggleBooleanSettingAction {
export class ToggleSeparatePinnedTabsAction extends Action2 {

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

Expand All @@ -529,8 +567,13 @@ export class ToggleSeparatePinnedTabsAction extends BaseToggleBooleanSettingActi
});
}

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

const oldettingValue = configurationService.getValue<string>('workbench.editor.pinnedTabsOnSeparateRow');
const newSettingValue = !oldettingValue;

return configurationService.updateValue('workbench.editor.pinnedTabsOnSeparateRow', newSettingValue);
}
}
registerAction2(ToggleSeparatePinnedTabsAction);
Expand Down
7 changes: 5 additions & 2 deletions src/vs/workbench/browser/parts/editor/editor.contribution.ts
Original file line number Diff line number Diff line change
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 { ToggleSeparatePinnedTabsAction, ToggleTabsVisibilityAction } from 'vs/workbench/browser/actions/layoutActions';
import { HideEditorTabsAction, ShowMultipleEditorTabsAction, ShowSingleEditorTabAction, ToggleSeparatePinnedTabsAction } from 'vs/workbench/browser/actions/layoutActions';
import product from 'vs/platform/product/common/product';

//#region Editor Registrations
Expand Down Expand Up @@ -355,7 +355,8 @@ MenuRegistry.appendMenuItem(MenuId.EditorTabsBarContext, { command: { id: SPLIT_
MenuRegistry.appendMenuItem(MenuId.EditorTabsBarContext, { command: { id: SPLIT_EDITOR_DOWN, title: localize('splitDown', "Split Down") }, group: '2_split', order: 20 });
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', "Editor Tabs"), toggled: ContextKeyExpr.equals('config.workbench.editor.showTabs', 'multiple') }, group: '3_config', order: 10 });
MenuRegistry.appendMenuItem(MenuId.EditorTabsBarContext, { command: { id: ShowSingleEditorTabAction.ID, title: localize('showSingleTab', "Show Single Tab") }, group: '3_config', order: 10, when: ContextKeyExpr.equals('config.workbench.editor.showTabs', 'multiple') });
MenuRegistry.appendMenuItem(MenuId.EditorTabsBarContext, { command: { id: HideEditorTabsAction.ID, title: localize('hideTabBar', "Hide Tab Bar") }, group: '3_config', order: 15, when: ContextKeyExpr.equals('config.workbench.editor.showTabs', 'none').negate() });
MenuRegistry.appendMenuItem(MenuId.EditorTabsBarContext, { command: { id: ToggleSeparatePinnedTabsAction.ID, title: localize('toggleSeparatePinnedEditorTabs', "Separate Pinned Editor Tabs"), toggled: ContextKeyExpr.has('config.workbench.editor.pinnedTabsOnSeparateRow') }, when: EditorPinnedAndUnpinnedTabsContext, group: '3_config', order: 20 });

// Editor Title Context Menu
Expand All @@ -374,6 +375,8 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: SPLIT_ED
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: SPLIT_EDITOR_RIGHT, title: localize('splitRight', "Split Right") }, group: '5_split', order: 40 });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: SPLIT_EDITOR_IN_GROUP, title: localize('splitInGroup', "Split in Group") }, group: '6_split_in_group', order: 10, when: ActiveEditorCanSplitInGroupContext });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: JOIN_EDITOR_IN_GROUP, title: localize('joinInGroup', "Join in Group") }, group: '6_split_in_group', order: 10, when: SideBySideEditorActiveContext });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: ShowMultipleEditorTabsAction.ID, title: localize('showMultipleTabs', "Show Multiple Tabs") }, group: '7_config', order: 10, when: ContextKeyExpr.equals('config.workbench.editor.showTabs', 'single') });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: HideEditorTabsAction.ID, title: localize('hideTabBar', "Hide Tab Bar") }, group: '7_config', order: 20, when: ContextKeyExpr.equals('config.workbench.editor.showTabs', 'none').negate() });

// Editor Title Menu
MenuRegistry.appendMenuItem(MenuId.EditorTitle, { command: { id: TOGGLE_DIFF_SIDE_BY_SIDE, title: localize('inlineView', "Inline View"), toggled: ContextKeyExpr.equals('config.diffEditor.renderSideBySide', false) }, group: '1_diff', order: 10, when: ContextKeyExpr.has('isInDiffEditor') });
Expand Down

0 comments on commit e47adcb

Please sign in to comment.