Skip to content

Commit 761b992

Browse files
author
Benjamin Pasero
committed
config change handling 💄
1 parent 2186c66 commit 761b992

14 files changed

Lines changed: 68 additions & 52 deletions

File tree

src/vs/platform/files/common/files.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ export const HotExitConfiguration = {
588588

589589
export const CONTENT_CHANGE_EVENT_BUFFER_DELAY = 1000;
590590

591+
export const FILES_ASSOCIATIONS_CONFIG = 'files.associations';
592+
591593
export interface IFilesConfiguration {
592594
files: {
593595
associations: { [filepattern: string]: string };

src/vs/workbench/browser/labels.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
2222
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
2323
import { IDecorationsService, IResourceDecorationChangeEvent } from 'vs/workbench/services/decorations/browser/decorations';
2424
import { Schemas } from 'vs/base/common/network';
25-
import { FileKind } from 'vs/platform/files/common/files';
25+
import { FileKind, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/files';
2626
import { IModel } from 'vs/editor/common/editorCommon';
2727
import { IThemeService } from 'vs/platform/theme/common/themeService';
2828

@@ -64,11 +64,25 @@ export class ResourceLabel extends IconLabel {
6464
}
6565

6666
private registerListeners(): void {
67-
this.extensionService.onReady().then(() => this.render(true /* clear cache */)); // update when extensions are loaded with potentially new languages
68-
this.toDispose.push(this.configurationService.onDidChangeConfiguration(() => this.render(true /* clear cache */))); // update when file.associations change
69-
this.toDispose.push(this.modelService.onModelModeChanged(e => this.onModelModeChanged(e))); // react to model mode changes
70-
this.toDispose.push(this.decorationsService.onDidChangeDecorations(this.onFileDecorationsChanges, this)); // react to file decoration changes
67+
68+
// update when extensions are loaded with potentially new languages
69+
this.extensionService.onReady().then(() => this.render(true /* clear cache */));
70+
71+
// react to model mode changes
72+
this.toDispose.push(this.modelService.onModelModeChanged(e => this.onModelModeChanged(e)));
73+
74+
// react to file decoration changes
75+
this.toDispose.push(this.decorationsService.onDidChangeDecorations(this.onFileDecorationsChanges, this));
76+
77+
// react to theme changes
7178
this.toDispose.push(this.themeService.onThemeChange(() => this.render(false)));
79+
80+
// react to files.associations changes
81+
this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => {
82+
if (e.affectsConfiguration(FILES_ASSOCIATIONS_CONFIG)) {
83+
this.render(true /* clear cache */);
84+
}
85+
}));
7286
}
7387

7488
private onModelModeChanged(e: { model: IModel; oldModeId: string; }): void {

src/vs/workbench/browser/parts/editor/editorPart.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
218218
if (configuration && configuration.workbench && configuration.workbench.editor) {
219219
const editorConfig = configuration.workbench.editor;
220220

221-
222221
// Pin all preview editors of the user chose to disable preview
223222
const newPreviewEditors = editorConfig.enablePreview;
224223
if (this.tabOptions.previewEditors !== newPreviewEditors && !newPreviewEditors) {

src/vs/workbench/browser/parts/editor/editorStatus.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { IEditor as IBaseEditor, IEditorInput } from 'vs/platform/editor/common/
3333
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
3434
import { IQuickOpenService, IPickOpenEntry, IFilePickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen';
3535
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
36-
import { SUPPORTED_ENCODINGS, IFileService, IFilesConfiguration } from 'vs/platform/files/common/files';
36+
import { SUPPORTED_ENCODINGS, IFileService, IFilesConfiguration, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/files';
3737
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
3838
import { IModeService } from 'vs/editor/common/services/modeService';
3939
import { IModelService } from 'vs/editor/common/services/modelService';
@@ -785,8 +785,6 @@ export class ChangeModeAction extends Action {
785785
public static ID = 'workbench.action.editor.changeLanguageMode';
786786
public static LABEL = nls.localize('changeMode', "Change Language Mode");
787787

788-
private static FILE_ASSOCIATION_KEY = 'files.associations';
789-
790788
constructor(
791789
actionId: string,
792790
actionLabel: string,
@@ -964,7 +962,7 @@ export class ChangeModeAction extends Action {
964962
TPromise.timeout(50 /* quick open is sensitive to being opened so soon after another */).done(() => {
965963
this.quickOpenService.pick(picks, { placeHolder: nls.localize('pickLanguageToConfigure', "Select Language Mode to Associate with '{0}'", extension || basename) }).done(language => {
966964
if (language) {
967-
const fileAssociationsConfig = this.configurationService.inspect(ChangeModeAction.FILE_ASSOCIATION_KEY);
965+
const fileAssociationsConfig = this.configurationService.inspect(FILES_ASSOCIATIONS_CONFIG);
968966

969967
let associationKey: string;
970968
if (extension && basename[0] !== '.') {
@@ -987,7 +985,7 @@ export class ChangeModeAction extends Action {
987985

988986
currentAssociations[associationKey] = language.id;
989987

990-
this.configurationService.updateValue(ChangeModeAction.FILE_ASSOCIATION_KEY, currentAssociations, target);
988+
this.configurationService.updateValue(FILES_ASSOCIATIONS_CONFIG, currentAssociations, target);
991989
}
992990
});
993991
});

src/vs/workbench/browser/parts/quickopen/quickOpenController.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { Component } from 'vs/workbench/common/component';
3636
import Event, { Emitter } from 'vs/base/common/event';
3737
import { IPartService } from 'vs/workbench/services/part/common/partService';
3838
import { KeyMod } from 'vs/base/common/keyCodes';
39-
import { QuickOpenHandler, QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions, EditorQuickOpenEntry, IWorkbenchQuickOpenConfiguration } from 'vs/workbench/browser/quickopen';
39+
import { QuickOpenHandler, QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions, EditorQuickOpenEntry, CLOSE_ON_FOCUS_LOST_CONFIG } from 'vs/workbench/browser/quickopen';
4040
import errors = require('vs/base/common/errors');
4141
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
4242
import { IPickOpenEntry, IFilePickOpenEntry, IInputOptions, IQuickOpenService, IPickOptions, IShowOptions, IPickOpenItem } from 'vs/platform/quickOpen/common/quickOpen';
@@ -131,22 +131,22 @@ export class QuickOpenController extends Component implements IQuickOpenService
131131
this._onShow = new Emitter<void>();
132132
this._onHide = new Emitter<void>();
133133

134-
this.updateConfiguration(<IWorkbenchQuickOpenConfiguration>this.configurationService.getConfiguration());
134+
this.updateConfiguration();
135135

136136
this.registerListeners();
137137
}
138138

139139
private registerListeners(): void {
140-
this.toUnbind.push(this.configurationService.onDidChangeConfiguration(e => this.updateConfiguration(this.configurationService.getConfiguration<IWorkbenchQuickOpenConfiguration>())));
140+
this.toUnbind.push(this.configurationService.onDidChangeConfiguration(e => this.updateConfiguration()));
141141
this.toUnbind.push(this.partService.onTitleBarVisibilityChange(() => this.positionQuickOpenWidget()));
142142
this.toUnbind.push(browser.onDidChangeZoomLevel(() => this.positionQuickOpenWidget()));
143143
}
144144

145-
private updateConfiguration(settings: IWorkbenchQuickOpenConfiguration): void {
145+
private updateConfiguration(): void {
146146
if (this.environmentService.args['sticky-quickopen']) {
147147
this.closeOnFocusLost = false;
148148
} else {
149-
this.closeOnFocusLost = settings.workbench && settings.workbench.quickOpen && settings.workbench.quickOpen.closeOnFocusLost;
149+
this.closeOnFocusLost = this.configurationService.getValue(CLOSE_ON_FOCUS_LOST_CONFIG);
150150
}
151151
}
152152

src/vs/workbench/browser/quickopen.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/edi
2222
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
2323
import { IConstructorSignature0, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2424

25+
export const CLOSE_ON_FOCUS_LOST_CONFIG = 'workbench.quickOpen.closeOnFocusLost';
26+
2527
export interface IWorkbenchQuickOpenConfiguration {
2628
workbench: {
27-
quickOpen: {
28-
closeOnFocusLost: boolean;
29-
},
3029
commandPalette: {
3130
history: number;
3231
preserveInput: boolean;

src/vs/workbench/common/editor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,8 @@ export const EditorOpenPositioning = {
804804
LAST: 'last'
805805
};
806806

807+
export const OPEN_POSITIONING_CONFIG = 'workbench.editor.openPositioning';
808+
807809
export interface IWorkbenchEditorConfiguration {
808810
/* __GDPR__FRAGMENT__
809811
"IWorkbenchEditorConfiguration" : {

src/vs/workbench/common/editor/editorStacksModel.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
'use strict';
77

88
import Event, { Emitter, once } from 'vs/base/common/event';
9-
import { Extensions, IEditorInputFactoryRegistry, EditorInput, toResource, IEditorStacksModel, IEditorGroup, IEditorIdentifier, IEditorCloseEvent, GroupIdentifier, IStacksModelChangeEvent, IWorkbenchEditorConfiguration, EditorOpenPositioning, SideBySideEditorInput } from 'vs/workbench/common/editor';
9+
import { Extensions, IEditorInputFactoryRegistry, EditorInput, toResource, IEditorStacksModel, IEditorGroup, IEditorIdentifier, IEditorCloseEvent, GroupIdentifier, IStacksModelChangeEvent, EditorOpenPositioning, SideBySideEditorInput, OPEN_POSITIONING_CONFIG } from 'vs/workbench/common/editor';
1010
import URI from 'vs/base/common/uri';
1111
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
1212
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
13-
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
13+
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
1414
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
1515
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
1616
import { Registry } from 'vs/platform/registry/common/platform';
@@ -84,7 +84,7 @@ export class EditorGroup implements IEditorGroup {
8484
this.mru = [];
8585
this.toDispose = [];
8686
this.mapResourceToEditorCount = new ResourceMap<number>();
87-
this.onConfigurationUpdated(configurationService.getConfiguration<IWorkbenchEditorConfiguration>());
87+
this.onConfigurationUpdated();
8888

8989
this._onEditorActivated = new Emitter<EditorInput>();
9090
this._onEditorOpened = new Emitter<EditorInput>();
@@ -110,13 +110,11 @@ export class EditorGroup implements IEditorGroup {
110110
}
111111

112112
private registerListeners(): void {
113-
this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationUpdated(this.configurationService.getConfiguration<IWorkbenchEditorConfiguration>())));
113+
this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationUpdated(e)));
114114
}
115115

116-
private onConfigurationUpdated(config: IWorkbenchEditorConfiguration): void {
117-
if (config && config.workbench && config.workbench.editor) {
118-
this.editorOpenPositioning = config.workbench.editor.openPositioning;
119-
}
116+
private onConfigurationUpdated(event?: IConfigurationChangeEvent): void {
117+
this.editorOpenPositioning = this.configurationService.getValue(OPEN_POSITIONING_CONFIG);
120118
}
121119

122120
public get id(): GroupIdentifier {

src/vs/workbench/electron-browser/window.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
4646
import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem';
4747
import { RunOnceScheduler } from 'vs/base/common/async';
4848
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
49-
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
49+
import { ConfigurationTarget, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
5050

5151
const TextInputActions: IAction[] = [
5252
new Action('undo', nls.localize('undo', "Undo"), null, true, () => document.execCommand('undo') && TPromise.as(true)),
@@ -261,7 +261,11 @@ export class ElectronWindow extends Themable {
261261
}
262262
}
263263

264-
private onDidUpdateConfiguration(e): void {
264+
private onDidUpdateConfiguration(event: IConfigurationChangeEvent): void {
265+
if (!event.affectsConfiguration('window.zoomLevel')) {
266+
return;
267+
}
268+
265269
const windowConfig: IWindowsConfiguration = this.configurationService.getConfiguration<IWindowsConfiguration>();
266270

267271
let newZoomLevel = 0;

src/vs/workbench/electron-browser/workbench.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import DOM = require('vs/base/browser/dom');
1515
import { Builder, $ } from 'vs/base/browser/builder';
1616
import { Delayer, RunOnceScheduler } from 'vs/base/common/async';
1717
import * as browser from 'vs/base/browser/browser';
18-
import assert = require('vs/base/common/assert');
1918
import { StopWatch } from 'vs/base/common/stopwatch';
2019
import { startTimer } from 'vs/base/node/startupTimers';
2120
import errors = require('vs/base/common/errors');
@@ -267,9 +266,6 @@ export class Workbench implements IPartService {
267266
* once. Use the shutdown function to free up resources created by the workbench on startup.
268267
*/
269268
public startup(callbacks?: IWorkbenchCallbacks): void {
270-
assert.ok(!this.workbenchStarted, 'Can not start a workbench that was already started');
271-
assert.ok(!this.workbenchShutdown, 'Can not start a workbench that was shutdown');
272-
273269
try {
274270
this.workbenchStarted = true;
275271
this.callbacks = callbacks;
@@ -1224,26 +1220,18 @@ export class Workbench implements IPartService {
12241220
}
12251221

12261222
public getEditorPart(): EditorPart {
1227-
assert.ok(this.workbenchStarted, 'Workbench is not started. Call startup() first.');
1228-
12291223
return this.editorPart;
12301224
}
12311225

12321226
public getSidebarPart(): SidebarPart {
1233-
assert.ok(this.workbenchStarted, 'Workbench is not started. Call startup() first.');
1234-
12351227
return this.sidebarPart;
12361228
}
12371229

12381230
public getPanelPart(): PanelPart {
1239-
assert.ok(this.workbenchStarted, 'Workbench is not started. Call startup() first.');
1240-
12411231
return this.panelPart;
12421232
}
12431233

12441234
public getInstantiationService(): IInstantiationService {
1245-
assert.ok(this.workbenchStarted, 'Workbench is not started. Call startup() first.');
1246-
12471235
return this.instantiationService;
12481236
}
12491237

@@ -1265,6 +1253,7 @@ export class Workbench implements IPartService {
12651253

12661254
public toggleZenMode(skipLayout?: boolean): void {
12671255
this.zenMode.active = !this.zenMode.active;
1256+
12681257
// Check if zen mode transitioned to full screen and if now we are out of zen mode -> we need to go out of full screen
12691258
let toggleFullScreen = false;
12701259
if (this.zenMode.active) {
@@ -1279,33 +1268,40 @@ export class Workbench implements IPartService {
12791268
if (config.hideActivityBar) {
12801269
this.setActivityBarHidden(true, true);
12811270
}
1271+
12821272
if (config.hideStatusBar) {
12831273
this.setStatusBarHidden(true, true);
12841274
}
1275+
12851276
if (config.hideTabs) {
12861277
this.editorPart.hideTabs(true);
12871278
}
12881279
} else {
12891280
if (this.zenMode.wasPanelVisible) {
12901281
this.setPanelHidden(false, true).done(undefined, errors.onUnexpectedError);
12911282
}
1283+
12921284
if (this.zenMode.wasSideBarVisible) {
12931285
this.setSideBarHidden(false, true).done(undefined, errors.onUnexpectedError);
12941286
}
1287+
12951288
// Status bar and activity bar visibility come from settings -> update their visibility.
12961289
this.onDidUpdateConfiguration(true);
12971290
this.editorPart.hideTabs(false);
12981291
const activeEditor = this.editorPart.getActiveEditor();
12991292
if (activeEditor) {
13001293
activeEditor.focus();
13011294
}
1295+
13021296
toggleFullScreen = this.zenMode.transitionedToFullScreen && browser.isFullscreen();
13031297
}
1298+
13041299
this.inZenMode.set(this.zenMode.active);
13051300

13061301
if (!skipLayout) {
13071302
this.layout();
13081303
}
1304+
13091305
if (toggleFullScreen) {
13101306
this.windowService.toggleFullScreen().done(undefined, errors.onUnexpectedError);
13111307
}

0 commit comments

Comments
 (0)