Skip to content

Commit

Permalink
debt - inline layout actions
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Jan 24, 2019
1 parent 0ea5880 commit a4b18cb
Show file tree
Hide file tree
Showing 16 changed files with 352 additions and 438 deletions.
9 changes: 1 addition & 8 deletions src/tsconfig.strictNullChecks.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,7 @@
"./vs/workbench/api/shared/editor.ts",
"./vs/workbench/api/shared/tasks.ts",
"./vs/workbench/browser/actions.ts",
"./vs/workbench/browser/actions/toggleActivityBarVisibility.ts",
"./vs/workbench/browser/actions/toggleCenteredLayout.ts",
"./vs/workbench/browser/actions/toggleEditorLayout.ts",
"./vs/workbench/browser/actions/toggleSidebarPosition.ts",
"./vs/workbench/browser/actions/toggleSidebarVisibility.ts",
"./vs/workbench/browser/actions/toggleStatusbarVisibility.ts",
"./vs/workbench/browser/actions/toggleTabsVisibility.ts",
"./vs/workbench/browser/actions/toggleZenMode.ts",
"./vs/workbench/browser/actions/layoutActions.ts",
"./vs/workbench/browser/actions/workspaceActions.ts",
"./vs/workbench/browser/actions/workspaceCommands.ts",
"./vs/workbench/browser/composite.ts",
Expand Down
339 changes: 339 additions & 0 deletions src/vs/workbench/browser/actions/layoutActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,339 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as nls from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform';
import { Action } from 'vs/base/common/actions';
import { SyncActionDescriptor, MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { IPartService, Parts, Position } from 'vs/workbench/services/part/common/partService';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IEditorGroupsService, GroupOrientation } from 'vs/workbench/services/group/common/editorGroupsService';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { KeyMod, KeyCode, KeyChord } from 'vs/base/common/keyCodes';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';

const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);

// --- Toggle Activity Bar

export class ToggleActivityBarVisibilityAction extends Action {

static readonly ID = 'workbench.action.toggleActivityBarVisibility';
static readonly LABEL = nls.localize('toggleActivityBar', "Toggle Activity Bar Visibility");

private static readonly activityBarVisibleKey = 'workbench.activityBar.visible';

constructor(
id: string,
label: string,
@IPartService private readonly partService: IPartService,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
super(id, label);

this.enabled = !!this.partService;
}

run(): Promise<any> {
const visibility = this.partService.isVisible(Parts.ACTIVITYBAR_PART);
const newVisibilityValue = !visibility;

return this.configurationService.updateValue(ToggleActivityBarVisibilityAction.activityBarVisibleKey, newVisibilityValue, ConfigurationTarget.USER);
}
}

registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleActivityBarVisibilityAction, ToggleActivityBarVisibilityAction.ID, ToggleActivityBarVisibilityAction.LABEL), 'View: Toggle Activity Bar Visibility', nls.localize('view', "View"));

MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
group: '2_workbench_layout',
command: {
id: ToggleActivityBarVisibilityAction.ID,
title: nls.localize({ key: 'miToggleActivityBar', comment: ['&& denotes a mnemonic'] }, "Toggle &&Activity Bar")
},
order: 4
});

// --- Toggle Centered Layout

class ToggleCenteredLayout extends Action {

static readonly ID = 'workbench.action.toggleCenteredLayout';
static readonly LABEL = nls.localize('toggleCenteredLayout', "Toggle Centered Layout");

constructor(
id: string,
label: string,
@IPartService private readonly partService: IPartService
) {
super(id, label);
this.enabled = !!this.partService;
}

run(): Promise<any> {
this.partService.centerEditorLayout(!this.partService.isEditorLayoutCentered());

return Promise.resolve(null);
}
}

registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleCenteredLayout, ToggleCenteredLayout.ID, ToggleCenteredLayout.LABEL), 'View: Toggle Centered Layout', nls.localize('view', "View"));

MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
group: '1_toggle_view',
command: {
id: ToggleCenteredLayout.ID,
title: nls.localize('miToggleCenteredLayout', "Toggle Centered Layout")
},
order: 3
});

// --- Toggle Editor Layout

export class ToggleEditorLayoutAction extends Action {

static readonly ID = 'workbench.action.toggleEditorGroupLayout';
static readonly LABEL = nls.localize('flipLayout', "Toggle Vertical/Horizontal Editor Layout");

private toDispose: IDisposable[];

constructor(
id: string,
label: string,
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService
) {
super(id, label);

this.toDispose = [];

this.class = 'flip-editor-layout';
this.updateEnablement();

this.registerListeners();
}

private registerListeners(): void {
this.toDispose.push(this.editorGroupService.onDidAddGroup(() => this.updateEnablement()));
this.toDispose.push(this.editorGroupService.onDidRemoveGroup(() => this.updateEnablement()));
}

private updateEnablement(): void {
this.enabled = this.editorGroupService.count > 1;
}

run(): Promise<any> {
const newOrientation = (this.editorGroupService.orientation === GroupOrientation.VERTICAL) ? GroupOrientation.HORIZONTAL : GroupOrientation.VERTICAL;
this.editorGroupService.setGroupOrientation(newOrientation);

return Promise.resolve(null);
}

dispose(): void {
this.toDispose = dispose(this.toDispose);

super.dispose();
}
}

CommandsRegistry.registerCommand('_workbench.editor.setGroupOrientation', function (accessor: ServicesAccessor, args: [GroupOrientation]) {
const editorGroupService = accessor.get(IEditorGroupsService);
const [orientation] = args;

editorGroupService.setGroupOrientation(orientation);

return Promise.resolve(null);
});

const group = nls.localize('view', "View");
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleEditorLayoutAction, ToggleEditorLayoutAction.ID, ToggleEditorLayoutAction.LABEL, { primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_0, mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_0 } }), 'View: Flip Editor Group Layout', group);

MenuRegistry.appendMenuItem(MenuId.MenubarLayoutMenu, {
group: 'z_flip',
command: {
id: ToggleEditorLayoutAction.ID,
title: nls.localize({ key: 'miToggleEditorLayout', comment: ['&& denotes a mnemonic'] }, "Flip &&Layout")
},
order: 1
});

// --- Toggle Sidebar Position

export class ToggleSidebarPositionAction extends Action {

static readonly ID = 'workbench.action.toggleSidebarPosition';
static readonly LABEL = nls.localize('toggleSidebarPosition', "Toggle Side Bar Position");

private static readonly sidebarPositionConfigurationKey = 'workbench.sideBar.location';

constructor(
id: string,
label: string,
@IPartService private readonly partService: IPartService,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
super(id, label);

this.enabled = !!this.partService && !!this.configurationService;
}

run(): Promise<any> {
const position = this.partService.getSideBarPosition();
const newPositionValue = (position === Position.LEFT) ? 'right' : 'left';

return this.configurationService.updateValue(ToggleSidebarPositionAction.sidebarPositionConfigurationKey, newPositionValue, ConfigurationTarget.USER);
}

static getLabel(partService: IPartService): string {
return partService.getSideBarPosition() === Position.LEFT ? nls.localize('moveSidebarRight', "Move Side Bar Right") : nls.localize('moveSidebarLeft', "Move Side Bar Left");
}
}

registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleSidebarPositionAction, ToggleSidebarPositionAction.ID, ToggleSidebarPositionAction.LABEL), 'View: Toggle Side Bar Position', nls.localize('view', "View"));

MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
group: '2_workbench_layout',
command: {
id: ToggleSidebarPositionAction.ID,
title: nls.localize({ key: 'miMoveSidebarLeftRight', comment: ['&& denotes a mnemonic'] }, "&&Move Side Bar Left/Right")
},
order: 2
});

// --- Toggle Sidebar Visibility

export class ToggleSidebarVisibilityAction extends Action {

static readonly ID = 'workbench.action.toggleSidebarVisibility';
static readonly LABEL = nls.localize('toggleSidebar', "Toggle Side Bar Visibility");

constructor(
id: string,
label: string,
@IPartService private readonly partService: IPartService
) {
super(id, label);

this.enabled = !!this.partService;
}

run(): Promise<any> {
const hideSidebar = this.partService.isVisible(Parts.SIDEBAR_PART);
this.partService.setSideBarHidden(hideSidebar);

return Promise.resolve(null);
}
}

registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleSidebarVisibilityAction, ToggleSidebarVisibilityAction.ID, ToggleSidebarVisibilityAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_B }), 'View: Toggle Side Bar Visibility', nls.localize('view', "View"));

MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
group: '2_workbench_layout',
command: {
id: ToggleSidebarVisibilityAction.ID,
title: nls.localize({ key: 'miToggleSidebar', comment: ['&& denotes a mnemonic'] }, "&&Toggle Side Bar")
},
order: 1
});

// --- Toggle Statusbar Visibility

class ToggleStatusbarVisibilityAction extends Action {

static readonly ID = 'workbench.action.toggleStatusbarVisibility';
static readonly LABEL = nls.localize('toggleStatusbar', "Toggle Status Bar Visibility");

private static readonly statusbarVisibleKey = 'workbench.statusBar.visible';

constructor(
id: string,
label: string,
@IPartService private readonly partService: IPartService,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
super(id, label);

this.enabled = !!this.partService;
}

run(): Promise<any> {
const visibility = this.partService.isVisible(Parts.STATUSBAR_PART);
const newVisibilityValue = !visibility;

return this.configurationService.updateValue(ToggleStatusbarVisibilityAction.statusbarVisibleKey, newVisibilityValue, ConfigurationTarget.USER);
}
}

registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleStatusbarVisibilityAction, ToggleStatusbarVisibilityAction.ID, ToggleStatusbarVisibilityAction.LABEL), 'View: Toggle Status Bar Visibility', nls.localize('view', "View"));

MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
group: '2_workbench_layout',
command: {
id: ToggleStatusbarVisibilityAction.ID,
title: nls.localize({ key: 'miToggleStatusbar', comment: ['&& denotes a mnemonic'] }, "&&Toggle Status Bar")
},
order: 3
});

// --- Toggle Tabs Visibility

class ToggleTabsVisibilityAction extends Action {

static readonly ID = 'workbench.action.toggleTabsVisibility';
static readonly LABEL = nls.localize('toggleTabs', "Toggle Tab Visibility");

private static readonly tabsVisibleKey = 'workbench.editor.showTabs';

constructor(
id: string,
label: string,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
super(id, label);
}

run(): Promise<any> {
const visibility = this.configurationService.getValue<string>(ToggleTabsVisibilityAction.tabsVisibleKey);
const newVisibilityValue = !visibility;

return this.configurationService.updateValue(ToggleTabsVisibilityAction.tabsVisibleKey, newVisibilityValue);
}
}

registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleTabsVisibilityAction, ToggleTabsVisibilityAction.ID, ToggleTabsVisibilityAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.KEY_W }), 'View: Toggle Tab Visibility', nls.localize('view', "View"));

// --- Toggle Zen Mode

class ToggleZenMode extends Action {

static readonly ID = 'workbench.action.toggleZenMode';
static readonly LABEL = nls.localize('toggleZenMode', "Toggle Zen Mode");

constructor(
id: string,
label: string,
@IPartService private readonly partService: IPartService
) {
super(id, label);
this.enabled = !!this.partService;
}

run(): Promise<any> {
this.partService.toggleZenMode();

return Promise.resolve(null);
}
}

registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleZenMode, ToggleZenMode.ID, ToggleZenMode.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_Z) }), 'View: Toggle Zen Mode', nls.localize('view', "View"));

MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
group: '1_toggle_view',
command: {
id: ToggleZenMode.ID,
title: nls.localize('miToggleZenMode', "Toggle Zen Mode")
},
order: 2
});
Loading

0 comments on commit a4b18cb

Please sign in to comment.