提交 761b992c 编写于 作者: B Benjamin Pasero

config change handling 💄

上级 2186c66c
......@@ -588,6 +588,8 @@ export const HotExitConfiguration = {
export const CONTENT_CHANGE_EVENT_BUFFER_DELAY = 1000;
export const FILES_ASSOCIATIONS_CONFIG = 'files.associations';
export interface IFilesConfiguration {
files: {
associations: { [filepattern: string]: string };
......
......@@ -22,7 +22,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IDecorationsService, IResourceDecorationChangeEvent } from 'vs/workbench/services/decorations/browser/decorations';
import { Schemas } from 'vs/base/common/network';
import { FileKind } from 'vs/platform/files/common/files';
import { FileKind, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/files';
import { IModel } from 'vs/editor/common/editorCommon';
import { IThemeService } from 'vs/platform/theme/common/themeService';
......@@ -64,11 +64,25 @@ export class ResourceLabel extends IconLabel {
}
private registerListeners(): void {
this.extensionService.onReady().then(() => this.render(true /* clear cache */)); // update when extensions are loaded with potentially new languages
this.toDispose.push(this.configurationService.onDidChangeConfiguration(() => this.render(true /* clear cache */))); // update when file.associations change
this.toDispose.push(this.modelService.onModelModeChanged(e => this.onModelModeChanged(e))); // react to model mode changes
this.toDispose.push(this.decorationsService.onDidChangeDecorations(this.onFileDecorationsChanges, this)); // react to file decoration changes
// update when extensions are loaded with potentially new languages
this.extensionService.onReady().then(() => this.render(true /* clear cache */));
// react to model mode changes
this.toDispose.push(this.modelService.onModelModeChanged(e => this.onModelModeChanged(e)));
// react to file decoration changes
this.toDispose.push(this.decorationsService.onDidChangeDecorations(this.onFileDecorationsChanges, this));
// react to theme changes
this.toDispose.push(this.themeService.onThemeChange(() => this.render(false)));
// react to files.associations changes
this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(FILES_ASSOCIATIONS_CONFIG)) {
this.render(true /* clear cache */);
}
}));
}
private onModelModeChanged(e: { model: IModel; oldModeId: string; }): void {
......
......@@ -218,7 +218,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
if (configuration && configuration.workbench && configuration.workbench.editor) {
const editorConfig = configuration.workbench.editor;
// Pin all preview editors of the user chose to disable preview
const newPreviewEditors = editorConfig.enablePreview;
if (this.tabOptions.previewEditors !== newPreviewEditors && !newPreviewEditors) {
......
......@@ -33,7 +33,7 @@ import { IEditor as IBaseEditor, IEditorInput } from 'vs/platform/editor/common/
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IQuickOpenService, IPickOpenEntry, IFilePickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen';
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { SUPPORTED_ENCODINGS, IFileService, IFilesConfiguration } from 'vs/platform/files/common/files';
import { SUPPORTED_ENCODINGS, IFileService, IFilesConfiguration, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IModelService } from 'vs/editor/common/services/modelService';
......@@ -785,8 +785,6 @@ export class ChangeModeAction extends Action {
public static ID = 'workbench.action.editor.changeLanguageMode';
public static LABEL = nls.localize('changeMode', "Change Language Mode");
private static FILE_ASSOCIATION_KEY = 'files.associations';
constructor(
actionId: string,
actionLabel: string,
......@@ -964,7 +962,7 @@ export class ChangeModeAction extends Action {
TPromise.timeout(50 /* quick open is sensitive to being opened so soon after another */).done(() => {
this.quickOpenService.pick(picks, { placeHolder: nls.localize('pickLanguageToConfigure', "Select Language Mode to Associate with '{0}'", extension || basename) }).done(language => {
if (language) {
const fileAssociationsConfig = this.configurationService.inspect(ChangeModeAction.FILE_ASSOCIATION_KEY);
const fileAssociationsConfig = this.configurationService.inspect(FILES_ASSOCIATIONS_CONFIG);
let associationKey: string;
if (extension && basename[0] !== '.') {
......@@ -987,7 +985,7 @@ export class ChangeModeAction extends Action {
currentAssociations[associationKey] = language.id;
this.configurationService.updateValue(ChangeModeAction.FILE_ASSOCIATION_KEY, currentAssociations, target);
this.configurationService.updateValue(FILES_ASSOCIATIONS_CONFIG, currentAssociations, target);
}
});
});
......
......@@ -36,7 +36,7 @@ import { Component } from 'vs/workbench/common/component';
import Event, { Emitter } from 'vs/base/common/event';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { KeyMod } from 'vs/base/common/keyCodes';
import { QuickOpenHandler, QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions, EditorQuickOpenEntry, IWorkbenchQuickOpenConfiguration } from 'vs/workbench/browser/quickopen';
import { QuickOpenHandler, QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions, EditorQuickOpenEntry, CLOSE_ON_FOCUS_LOST_CONFIG } from 'vs/workbench/browser/quickopen';
import errors = require('vs/base/common/errors');
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
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
this._onShow = new Emitter<void>();
this._onHide = new Emitter<void>();
this.updateConfiguration(<IWorkbenchQuickOpenConfiguration>this.configurationService.getConfiguration());
this.updateConfiguration();
this.registerListeners();
}
private registerListeners(): void {
this.toUnbind.push(this.configurationService.onDidChangeConfiguration(e => this.updateConfiguration(this.configurationService.getConfiguration<IWorkbenchQuickOpenConfiguration>())));
this.toUnbind.push(this.configurationService.onDidChangeConfiguration(e => this.updateConfiguration()));
this.toUnbind.push(this.partService.onTitleBarVisibilityChange(() => this.positionQuickOpenWidget()));
this.toUnbind.push(browser.onDidChangeZoomLevel(() => this.positionQuickOpenWidget()));
}
private updateConfiguration(settings: IWorkbenchQuickOpenConfiguration): void {
private updateConfiguration(): void {
if (this.environmentService.args['sticky-quickopen']) {
this.closeOnFocusLost = false;
} else {
this.closeOnFocusLost = settings.workbench && settings.workbench.quickOpen && settings.workbench.quickOpen.closeOnFocusLost;
this.closeOnFocusLost = this.configurationService.getValue(CLOSE_ON_FOCUS_LOST_CONFIG);
}
}
......
......@@ -22,11 +22,10 @@ import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/edi
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
import { IConstructorSignature0, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
export const CLOSE_ON_FOCUS_LOST_CONFIG = 'workbench.quickOpen.closeOnFocusLost';
export interface IWorkbenchQuickOpenConfiguration {
workbench: {
quickOpen: {
closeOnFocusLost: boolean;
},
commandPalette: {
history: number;
preserveInput: boolean;
......
......@@ -804,6 +804,8 @@ export const EditorOpenPositioning = {
LAST: 'last'
};
export const OPEN_POSITIONING_CONFIG = 'workbench.editor.openPositioning';
export interface IWorkbenchEditorConfiguration {
/* __GDPR__FRAGMENT__
"IWorkbenchEditorConfiguration" : {
......
......@@ -6,11 +6,11 @@
'use strict';
import Event, { Emitter, once } from 'vs/base/common/event';
import { Extensions, IEditorInputFactoryRegistry, EditorInput, toResource, IEditorStacksModel, IEditorGroup, IEditorIdentifier, IEditorCloseEvent, GroupIdentifier, IStacksModelChangeEvent, IWorkbenchEditorConfiguration, EditorOpenPositioning, SideBySideEditorInput } from 'vs/workbench/common/editor';
import { Extensions, IEditorInputFactoryRegistry, EditorInput, toResource, IEditorStacksModel, IEditorGroup, IEditorIdentifier, IEditorCloseEvent, GroupIdentifier, IStacksModelChangeEvent, EditorOpenPositioning, SideBySideEditorInput, OPEN_POSITIONING_CONFIG } from 'vs/workbench/common/editor';
import URI from 'vs/base/common/uri';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { Registry } from 'vs/platform/registry/common/platform';
......@@ -84,7 +84,7 @@ export class EditorGroup implements IEditorGroup {
this.mru = [];
this.toDispose = [];
this.mapResourceToEditorCount = new ResourceMap<number>();
this.onConfigurationUpdated(configurationService.getConfiguration<IWorkbenchEditorConfiguration>());
this.onConfigurationUpdated();
this._onEditorActivated = new Emitter<EditorInput>();
this._onEditorOpened = new Emitter<EditorInput>();
......@@ -110,13 +110,11 @@ export class EditorGroup implements IEditorGroup {
}
private registerListeners(): void {
this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationUpdated(this.configurationService.getConfiguration<IWorkbenchEditorConfiguration>())));
this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationUpdated(e)));
}
private onConfigurationUpdated(config: IWorkbenchEditorConfiguration): void {
if (config && config.workbench && config.workbench.editor) {
this.editorOpenPositioning = config.workbench.editor.openPositioning;
}
private onConfigurationUpdated(event?: IConfigurationChangeEvent): void {
this.editorOpenPositioning = this.configurationService.getValue(OPEN_POSITIONING_CONFIG);
}
public get id(): GroupIdentifier {
......
......@@ -46,7 +46,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem';
import { RunOnceScheduler } from 'vs/base/common/async';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { ConfigurationTarget, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
const TextInputActions: IAction[] = [
new Action('undo', nls.localize('undo', "Undo"), null, true, () => document.execCommand('undo') && TPromise.as(true)),
......@@ -261,7 +261,11 @@ export class ElectronWindow extends Themable {
}
}
private onDidUpdateConfiguration(e): void {
private onDidUpdateConfiguration(event: IConfigurationChangeEvent): void {
if (!event.affectsConfiguration('window.zoomLevel')) {
return;
}
const windowConfig: IWindowsConfiguration = this.configurationService.getConfiguration<IWindowsConfiguration>();
let newZoomLevel = 0;
......
......@@ -15,7 +15,6 @@ import DOM = require('vs/base/browser/dom');
import { Builder, $ } from 'vs/base/browser/builder';
import { Delayer, RunOnceScheduler } from 'vs/base/common/async';
import * as browser from 'vs/base/browser/browser';
import assert = require('vs/base/common/assert');
import { StopWatch } from 'vs/base/common/stopwatch';
import { startTimer } from 'vs/base/node/startupTimers';
import errors = require('vs/base/common/errors');
......@@ -267,9 +266,6 @@ export class Workbench implements IPartService {
* once. Use the shutdown function to free up resources created by the workbench on startup.
*/
public startup(callbacks?: IWorkbenchCallbacks): void {
assert.ok(!this.workbenchStarted, 'Can not start a workbench that was already started');
assert.ok(!this.workbenchShutdown, 'Can not start a workbench that was shutdown');
try {
this.workbenchStarted = true;
this.callbacks = callbacks;
......@@ -1224,26 +1220,18 @@ export class Workbench implements IPartService {
}
public getEditorPart(): EditorPart {
assert.ok(this.workbenchStarted, 'Workbench is not started. Call startup() first.');
return this.editorPart;
}
public getSidebarPart(): SidebarPart {
assert.ok(this.workbenchStarted, 'Workbench is not started. Call startup() first.');
return this.sidebarPart;
}
public getPanelPart(): PanelPart {
assert.ok(this.workbenchStarted, 'Workbench is not started. Call startup() first.');
return this.panelPart;
}
public getInstantiationService(): IInstantiationService {
assert.ok(this.workbenchStarted, 'Workbench is not started. Call startup() first.');
return this.instantiationService;
}
......@@ -1265,6 +1253,7 @@ export class Workbench implements IPartService {
public toggleZenMode(skipLayout?: boolean): void {
this.zenMode.active = !this.zenMode.active;
// 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
let toggleFullScreen = false;
if (this.zenMode.active) {
......@@ -1279,9 +1268,11 @@ export class Workbench implements IPartService {
if (config.hideActivityBar) {
this.setActivityBarHidden(true, true);
}
if (config.hideStatusBar) {
this.setStatusBarHidden(true, true);
}
if (config.hideTabs) {
this.editorPart.hideTabs(true);
}
......@@ -1289,9 +1280,11 @@ export class Workbench implements IPartService {
if (this.zenMode.wasPanelVisible) {
this.setPanelHidden(false, true).done(undefined, errors.onUnexpectedError);
}
if (this.zenMode.wasSideBarVisible) {
this.setSideBarHidden(false, true).done(undefined, errors.onUnexpectedError);
}
// Status bar and activity bar visibility come from settings -> update their visibility.
this.onDidUpdateConfiguration(true);
this.editorPart.hideTabs(false);
......@@ -1299,13 +1292,16 @@ export class Workbench implements IPartService {
if (activeEditor) {
activeEditor.focus();
}
toggleFullScreen = this.zenMode.transitionedToFullScreen && browser.isFullscreen();
}
this.inZenMode.set(this.zenMode.active);
if (!skipLayout) {
this.layout();
}
if (toggleFullScreen) {
this.windowService.toggleFullScreen().done(undefined, errors.onUnexpectedError);
}
......
......@@ -9,7 +9,7 @@ import { onUnexpectedError } from 'vs/base/common/errors';
import * as paths from 'vs/base/common/paths';
import { TPromise } from 'vs/base/common/winjs.base';
import mime = require('vs/base/common/mime');
import { IFilesConfiguration } from 'vs/platform/files/common/files';
import { IFilesConfiguration, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/files';
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
import { IExtensionPointUser, ExtensionMessageCollector, IExtensionPoint, ExtensionsRegistry } from 'vs/platform/extensions/common/extensionsRegistry';
import { ModesRegistry } from 'vs/editor/common/modes/modesRegistry';
......@@ -124,7 +124,7 @@ export class WorkbenchModeServiceImpl extends ModeServiceImpl {
});
this._configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('files.associations')) {
if (e.affectsConfiguration(FILES_ASSOCIATIONS_CONFIG)) {
this.updateMime();
}
});
......
......@@ -85,7 +85,7 @@ export abstract class TextFileService implements ITextFileService {
const configuration = this.configurationService.getConfiguration<IFilesConfiguration>();
this.currentFilesAssociationConfig = configuration && configuration.files && configuration.files.associations;
this.onConfigurationChange(configuration);
this.onFilesConfigurationChange(configuration);
/* __GDPR__
"autoSave" : {
......@@ -123,8 +123,12 @@ export abstract class TextFileService implements ITextFileService {
this.lifecycleService.onWillShutdown(event => event.veto(this.beforeShutdown(event.reason)));
this.lifecycleService.onShutdown(this.dispose, this);
// Configuration changes
this.toUnbind.push(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationChange(this.configurationService.getConfiguration<IFilesConfiguration>())));
// Files configuration changes
this.toUnbind.push(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('files')) {
this.onFilesConfigurationChange(this.configurationService.getConfiguration<IFilesConfiguration>());
}
}));
}
private beforeShutdown(reason: ShutdownReason): boolean | TPromise<boolean> {
......@@ -316,7 +320,7 @@ export abstract class TextFileService implements ITextFileService {
return this.backupFileService.discardAllWorkspaceBackups();
}
protected onConfigurationChange(configuration: IFilesConfiguration): void {
protected onFilesConfigurationChange(configuration: IFilesConfiguration): void {
const wasAutoSaveEnabled = (this.getAutoSaveMode() !== AutoSaveMode.OFF);
const autoSaveMode = (configuration && configuration.files && configuration.files.autoSave) || AutoSaveConfiguration.OFF;
......
......@@ -104,7 +104,7 @@ suite('Files - TextFileService', () => {
const service = accessor.textFileService;
service.setConfirmResult(ConfirmResult.DONT_SAVE);
service.onConfigurationChange({ files: { hotExit: 'off' } });
service.onFilesConfigurationChange({ files: { hotExit: 'off' } });
model.load().done(() => {
model.textEditorModel.setValue('foo');
......@@ -137,7 +137,7 @@ suite('Files - TextFileService', () => {
const service = accessor.textFileService;
service.setConfirmResult(ConfirmResult.SAVE);
service.onConfigurationChange({ files: { hotExit: 'off' } });
service.onFilesConfigurationChange({ files: { hotExit: 'off' } });
model.load().done(() => {
model.textEditorModel.setValue('foo');
......@@ -377,7 +377,7 @@ suite('Files - TextFileService', () => {
const service = accessor.textFileService;
// Set hot exit config
service.onConfigurationChange({ files: { hotExit: setting } });
service.onFilesConfigurationChange({ files: { hotExit: setting } });
// Set empty workspace if required
if (!workspace) {
accessor.contextService.setWorkspace(new Workspace('empty:1508317022751'));
......
......@@ -233,8 +233,8 @@ export class TestTextFileService extends TextFileService {
return this.confirmResult;
}
public onConfigurationChange(configuration: any): void {
super.onConfigurationChange(configuration);
public onFilesConfigurationChange(configuration: any): void {
super.onFilesConfigurationChange(configuration);
}
protected cleanupBackupsBeforeShutdown(): TPromise<void> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册