mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 03:54:24 +01:00
Make sidebar position a real setting (fixes #13338)
This commit is contained in:
@@ -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<any> {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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<any> {
|
||||
let hideSidebar = !this.partService.isSideBarHidden();
|
||||
const hideSidebar = !this.partService.isSideBarHidden();
|
||||
this.partService.setSideBarHidden(hideSidebar);
|
||||
|
||||
return TPromise.as(null);
|
||||
|
||||
@@ -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<any> {
|
||||
let hideStatusbar = !this.partService.isStatusBarHidden();
|
||||
const hideStatusbar = !this.partService.isStatusBarHidden();
|
||||
this.partService.setStatusBarHidden(hideStatusbar);
|
||||
|
||||
return TPromise.as(null);
|
||||
|
||||
@@ -881,7 +881,7 @@ export interface IWorkbenchEditorConfiguration {
|
||||
showIcons: boolean;
|
||||
enablePreview: boolean;
|
||||
enablePreviewFromQuickOpen: boolean;
|
||||
openPositioning: string;
|
||||
openPositioning: 'left' | 'right' | 'first' | 'last';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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<EditorInput>;
|
||||
private _onEditorOpened: Emitter<EditorInput>;
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.")
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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<string>(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((<WorkbenchMessageService>this.messageService).onMessagesShowing(() => this.messagesVisibleContext.set(true)));
|
||||
this.toDispose.push((<WorkbenchMessageService>this.messageService).onMessagesCleared(() => this.messagesVisibleContext.reset()));
|
||||
this.toDispose.push((<WorkbenchMessageService>this.messageService).onMessagesShowing(() => this.messagesVisibleContext.set(true)));
|
||||
this.toDispose.push((<WorkbenchMessageService>this.messageService).onMessagesCleared(() => this.messagesVisibleContext.reset()));
|
||||
|
||||
this.toDispose.push(this.quickOpen.onShow(() => (<WorkbenchMessageService>this.messageService).suspend())); // when quick open is open, don't show messages behind
|
||||
this.toDispose.push(this.quickOpen.onHide(() => (<WorkbenchMessageService>this.messageService).resume())); // resume messages once quick open is closed again
|
||||
}
|
||||
this.toDispose.push(this.quickOpen.onShow(() => (<WorkbenchMessageService>this.messageService).suspend())); // when quick open is open, don't show messages behind
|
||||
this.toDispose.push(this.quickOpen.onHide(() => (<WorkbenchMessageService>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<string>(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));
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user