From 069984e003cc9d35fbe68ded04acafc796545a8a Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 7 Oct 2016 11:09:59 +0200 Subject: [PATCH] Make sidebar position a real setting (fixes #13338) --- src/vs/test/utils/servicesTestUtils.ts | 1 - .../browser/actions/toggleSidebarPosition.ts | 22 ++++++++-- .../actions/toggleSidebarVisibility.ts | 8 +++- .../actions/toggleStatusbarVisibility.ts | 8 +++- src/vs/workbench/common/editor.ts | 2 +- .../common/editor/editorStacksModel.ts | 6 ++- .../electron-browser/main.contribution.ts | 8 +++- .../workbench/electron-browser/workbench.ts | 40 ++++++++++++------- .../services/part/common/partService.ts | 6 --- 9 files changed, 68 insertions(+), 33 deletions(-) diff --git a/src/vs/test/utils/servicesTestUtils.ts b/src/vs/test/utils/servicesTestUtils.ts index b39619fe14ec4..6941fd3af0d96 100644 --- a/src/vs/test/utils/servicesTestUtils.ts +++ b/src/vs/test/utils/servicesTestUtils.ts @@ -256,7 +256,6 @@ export class TestPartService implements IPartService { return 0; } - public setSideBarPosition(position): void { } public addClass(clazz: string): void { } public removeClass(clazz: string): void { } public getWorkbenchElementId(): string { return ''; } diff --git a/src/vs/workbench/browser/actions/toggleSidebarPosition.ts b/src/vs/workbench/browser/actions/toggleSidebarPosition.ts index e8b69ff814caa..ce54051829c4a 100644 --- a/src/vs/workbench/browser/actions/toggleSidebarPosition.ts +++ b/src/vs/workbench/browser/actions/toggleSidebarPosition.ts @@ -9,7 +9,9 @@ import nls = require('vs/nls'); import {Registry} from 'vs/platform/platform'; import {Action} from 'vs/base/common/actions'; import {SyncActionDescriptor} from 'vs/platform/actions/common/actions'; +import {IMessageService, Severity} from 'vs/platform/message/common/message'; import {IWorkbenchActionRegistry, Extensions} from 'vs/workbench/common/actionRegistry'; +import {IConfigurationEditingService, ConfigurationTarget} from 'vs/workbench/services/configuration/common/configurationEditing'; import {IPartService, Position} from 'vs/workbench/services/part/common/partService'; export class ToggleSidebarPositionAction extends Action { @@ -17,15 +19,27 @@ export class ToggleSidebarPositionAction extends Action { public static ID = 'workbench.action.toggleSidebarPosition'; public static LABEL = nls.localize('togglePosition', "Toggle Side Bar Position"); - constructor(id: string, label: string, @IPartService private partService: IPartService) { + private static sidebarPositionConfigurationKey = 'workbench.sideBar.location'; + + constructor( + id: string, + label: string, + @IPartService private partService: IPartService, + @IMessageService private messageService: IMessageService, + @IConfigurationEditingService private configurationEditingService: IConfigurationEditingService + ) { super(id, label); - this.enabled = !!this.partService; + this.enabled = !!this.partService && !!this.configurationEditingService; } public run(): TPromise { - let position = this.partService.getSideBarPosition(); - this.partService.setSideBarPosition(position === Position.LEFT ? Position.RIGHT : Position.LEFT); + const position = this.partService.getSideBarPosition(); + const newPositionValue = (position === Position.LEFT) ? 'right' : 'left'; + + this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: ToggleSidebarPositionAction.sidebarPositionConfigurationKey, value: newPositionValue }).then(null, error => { + this.messageService.show(Severity.Error, error); + }); return TPromise.as(null); } diff --git a/src/vs/workbench/browser/actions/toggleSidebarVisibility.ts b/src/vs/workbench/browser/actions/toggleSidebarVisibility.ts index 91f62b6c5c82f..c1fc13314e52c 100644 --- a/src/vs/workbench/browser/actions/toggleSidebarVisibility.ts +++ b/src/vs/workbench/browser/actions/toggleSidebarVisibility.ts @@ -18,14 +18,18 @@ export class ToggleSidebarVisibilityAction extends Action { public static ID = 'workbench.action.toggleSidebarVisibility'; public static LABEL = nls.localize('toggleSidebar', "Toggle Side Bar Visibility"); - constructor(id: string, label: string, @IPartService private partService: IPartService) { + constructor( + id: string, + label: string, + @IPartService private partService: IPartService + ) { super(id, label); this.enabled = !!this.partService; } public run(): TPromise { - let hideSidebar = !this.partService.isSideBarHidden(); + const hideSidebar = !this.partService.isSideBarHidden(); this.partService.setSideBarHidden(hideSidebar); return TPromise.as(null); diff --git a/src/vs/workbench/browser/actions/toggleStatusbarVisibility.ts b/src/vs/workbench/browser/actions/toggleStatusbarVisibility.ts index b0fd30585ae3f..245f7795c8f68 100644 --- a/src/vs/workbench/browser/actions/toggleStatusbarVisibility.ts +++ b/src/vs/workbench/browser/actions/toggleStatusbarVisibility.ts @@ -17,14 +17,18 @@ export class ToggleStatusbarVisibilityAction extends Action { public static ID = 'workbench.action.toggleStatusbarVisibility'; public static LABEL = nls.localize('toggleStatusbar', "Toggle Status Bar Visibility"); - constructor(id: string, label: string, @IPartService private partService: IPartService) { + constructor( + id: string, + label: string, + @IPartService private partService: IPartService + ) { super(id, label); this.enabled = !!this.partService; } public run(): TPromise { - let hideStatusbar = !this.partService.isStatusBarHidden(); + const hideStatusbar = !this.partService.isStatusBarHidden(); this.partService.setStatusBarHidden(hideStatusbar); return TPromise.as(null); diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index a8ee5aa293097..818f05f257ae3 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -881,7 +881,7 @@ export interface IWorkbenchEditorConfiguration { showIcons: boolean; enablePreview: boolean; enablePreviewFromQuickOpen: boolean; - openPositioning: string; + openPositioning: 'left' | 'right' | 'first' | 'last'; } }; } diff --git a/src/vs/workbench/common/editor/editorStacksModel.ts b/src/vs/workbench/common/editor/editorStacksModel.ts index 7242b49b89860..bdaedda577b8d 100644 --- a/src/vs/workbench/common/editor/editorStacksModel.ts +++ b/src/vs/workbench/common/editor/editorStacksModel.ts @@ -59,7 +59,7 @@ export class EditorGroup implements IEditorGroup { private active: EditorInput; // editor in active state private toDispose: IDisposable[]; - private editorOpenPositioning: string; + private editorOpenPositioning: 'left' | 'right' | 'first' | 'last'; private _onEditorActivated: Emitter; private _onEditorOpened: Emitter; @@ -114,7 +114,9 @@ export class EditorGroup implements IEditorGroup { } private onConfigurationUpdated(config: IWorkbenchEditorConfiguration): void { - this.editorOpenPositioning = config && config.workbench && config.workbench.editor && config.workbench.editor.openPositioning; + if (config && config.workbench && config.workbench.editor) { + this.editorOpenPositioning = config.workbench.editor.openPositioning; + } } public get id(): GroupIdentifier { diff --git a/src/vs/workbench/electron-browser/main.contribution.ts b/src/vs/workbench/electron-browser/main.contribution.ts index 57379719433f4..849cddc7f524b 100644 --- a/src/vs/workbench/electron-browser/main.contribution.ts +++ b/src/vs/workbench/electron-browser/main.contribution.ts @@ -109,7 +109,13 @@ configurationRegistry.registerConfiguration({ 'type': 'boolean', 'description': nls.localize('openDefaultSettings', "Controls if opening settings also opens an editor showing all default settings."), 'default': true - } + }, + 'workbench.sideBar.location': { + 'type': 'string', + 'enum': ['left', 'right'], + 'default': 'left', + 'description': nls.localize('sideBarLocation', "Controls the location of the sidebar. It can either show on the left or right of the workbench.") + }, } }); diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index 312f556882909..02030b9be2c1a 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -43,6 +43,7 @@ import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace'; import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage'; import {ContextMenuService} from 'vs/workbench/services/contextview/electron-browser/contextmenuService'; import {WorkbenchKeybindingService} from 'vs/workbench/services/keybinding/electron-browser/keybindingService'; +import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; import {IConfigurationEditingService} from 'vs/workbench/services/configuration/common/configurationEditing'; import {ConfigurationEditingService} from 'vs/workbench/services/configuration/node/configurationEditingService'; import {ContextKeyService} from 'vs/platform/contextkey/browser/contextKeyService'; @@ -104,12 +105,13 @@ const Identifiers = { */ export class Workbench implements IPartService { - private static sidebarPositionSettingKey = 'workbench.sidebar.position'; private static statusbarHiddenSettingKey = 'workbench.statusbar.hidden'; private static sidebarHiddenSettingKey = 'workbench.sidebar.hidden'; private static sidebarRestoreSettingKey = 'workbench.sidebar.restore'; private static panelHiddenSettingKey = 'workbench.panel.hidden'; + private static sidebarPositionConfigurationKey = 'workbench.sideBar.location'; + public _serviceBrand: any; private container: HTMLElement; @@ -122,6 +124,7 @@ export class Workbench implements IPartService { private editorService: WorkbenchEditorService; private contextKeyService: IContextKeyService; private keybindingService: IKeybindingService; + private configurationEditingService: IConfigurationEditingService; private activitybarPart: ActivitybarPart; private sidebarPart: SidebarPart; private panelPart: PanelPart; @@ -154,6 +157,7 @@ export class Workbench implements IPartService { @IStorageService private storageService: IStorageService, @ILifecycleService private lifecycleService: ILifecycleService, @IMessageService private messageService: IMessageService, + @IConfigurationService private configurationService: IConfigurationService, @ITelemetryService private telemetryService: ITelemetryService, @IEnvironmentService private environmentService: IEnvironmentService ) { @@ -392,7 +396,8 @@ export class Workbench implements IPartService { serviceCollection.set(ITextFileService, this.instantiationService.createInstance(TextFileService)); // Configuration Editing - serviceCollection.set(IConfigurationEditingService, this.instantiationService.createInstance(ConfigurationEditingService)); + this.configurationEditingService = this.instantiationService.createInstance(ConfigurationEditingService); + serviceCollection.set(IConfigurationEditingService, this.configurationEditingService); // Configuration Resolver const workspace = this.contextService.getWorkspace(); @@ -438,8 +443,8 @@ export class Workbench implements IPartService { } // Sidebar position - const rawPosition = this.storageService.get(Workbench.sidebarPositionSettingKey, StorageScope.GLOBAL, 'left'); - this.sideBarPosition = (rawPosition === 'left') ? Position.LEFT : Position.RIGHT; + const sideBarPosition = this.configurationService.lookup(Workbench.sidebarPositionConfigurationKey).value; + this.sideBarPosition = (sideBarPosition === 'right') ? Position.RIGHT : Position.LEFT; // Statusbar visibility this.statusBarHidden = this.storageService.getBoolean(Workbench.statusbarHiddenSettingKey, StorageScope.GLOBAL, false); @@ -613,7 +618,7 @@ export class Workbench implements IPartService { return this.sideBarPosition; } - public setSideBarPosition(position: Position): void { + private setSideBarPosition(position: Position): void { if (this.sideBarHidden) { this.setSideBarHidden(false, true /* Skip Layout */); } @@ -630,9 +635,6 @@ export class Workbench implements IPartService { // Layout this.workbenchLayout.layout(true); - - // Remember in settings - this.storageService.store(Workbench.sidebarPositionSettingKey, position === Position.LEFT ? 'left' : 'right', StorageScope.GLOBAL); } public dispose(): void { @@ -666,13 +668,14 @@ export class Workbench implements IPartService { this.toDispose.push(this.editorPart.onEditorsChanged(() => this.onEditorsChanged())); // Handle message service and quick open events - if (this.messageService instanceof WorkbenchMessageService) { - this.toDispose.push((this.messageService).onMessagesShowing(() => this.messagesVisibleContext.set(true))); - this.toDispose.push((this.messageService).onMessagesCleared(() => this.messagesVisibleContext.reset())); + this.toDispose.push((this.messageService).onMessagesShowing(() => this.messagesVisibleContext.set(true))); + this.toDispose.push((this.messageService).onMessagesCleared(() => this.messagesVisibleContext.reset())); - this.toDispose.push(this.quickOpen.onShow(() => (this.messageService).suspend())); // when quick open is open, don't show messages behind - this.toDispose.push(this.quickOpen.onHide(() => (this.messageService).resume())); // resume messages once quick open is closed again - } + this.toDispose.push(this.quickOpen.onShow(() => (this.messageService).suspend())); // when quick open is open, don't show messages behind + this.toDispose.push(this.quickOpen.onHide(() => (this.messageService).resume())); // resume messages once quick open is closed again + + // Configuration changes + this.toDispose.push(this.configurationService.onDidUpdateConfiguration(() => this.onDidUpdateConfiguration())); } private onEditorsChanged(): void { @@ -691,6 +694,15 @@ export class Workbench implements IPartService { } } + private onDidUpdateConfiguration(): void { + const newSidebarPositionValue = this.configurationService.lookup(Workbench.sidebarPositionConfigurationKey).value; + const newSidebarPosition = newSidebarPositionValue === 'right' ? Position.RIGHT : Position.LEFT; + + if (newSidebarPosition !== this.getSideBarPosition()) { + this.setSideBarPosition(newSidebarPosition); + } + } + private createWorkbenchLayout(): void { const options = new LayoutOptions(); options.setMargin(new Box(0, 0, 0, 0)); diff --git a/src/vs/workbench/services/part/common/partService.ts b/src/vs/workbench/services/part/common/partService.ts index 4c935db776c3a..be54d9fa15cb5 100644 --- a/src/vs/workbench/services/part/common/partService.ts +++ b/src/vs/workbench/services/part/common/partService.ts @@ -90,12 +90,6 @@ export interface IPartService { */ getSideBarPosition(): Position; - /** - * Sets the side bar position. If the side bar is hidden, the side bar will - * also be made visible. - */ - setSideBarPosition(position: Position): void; - /** * Adds a class to the workbench part. */