forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
352 additions
and
438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
Oops, something went wrong.