提交 4d1b09fc 编写于 作者: B Benjamin Pasero

move shutdown handling into base text file service

上级 92158fe2
......@@ -30,7 +30,6 @@ import {ServiceCollection} from 'vs/platform/instantiation/common/serviceCollect
import {InstantiationService} from 'vs/platform/instantiation/common/instantiationService';
import {IEditorGroupService, GroupArrangement} from 'vs/workbench/services/group/common/groupService';
import {TextFileService} from 'vs/workbench/parts/files/common/textFileServices';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IFileService, IResolveContentOptions} from 'vs/platform/files/common/files';
import {IModelService} from 'vs/editor/common/services/modelService';
import {ModelServiceImpl} from 'vs/editor/common/services/modelServiceImpl';
......@@ -96,17 +95,14 @@ export abstract class TestTextFileService extends TextFileService {
constructor(
@ILifecycleService lifecycleService: ILifecycleService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IInstantiationService instantiationService: IInstantiationService,
@IConfigurationService configurationService: IConfigurationService,
@ITelemetryService telemetryService: ITelemetryService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IEditorGroupService editorGroupService: IEditorGroupService,
@IEventService eventService: IEventService,
@IFileService fileService: IFileService,
@IModelService modelService: IModelService,
@IUntitledEditorService untitledEditorService: IUntitledEditorService
) {
super(lifecycleService, contextService, instantiationService, configurationService, telemetryService, editorGroupService, editorService, eventService, fileService, modelService, untitledEditorService);
super(lifecycleService, contextService, configurationService, telemetryService, editorGroupService, editorService, fileService, untitledEditorService);
}
public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent> {
......
......@@ -16,13 +16,10 @@ import {ConfirmResult} from 'vs/workbench/common/editor';
import {ILifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IFileService, IResolveContentOptions, IFilesConfiguration, IFileOperationResult, FileOperationResult, AutoSaveConfiguration} from 'vs/platform/files/common/files';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IEventService} from 'vs/platform/event/common/event';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {UntitledEditorModel} from 'vs/workbench/common/editor/untitledEditorModel';
......@@ -46,17 +43,14 @@ export abstract class TextFileService implements ITextFileService {
protected configuredAutoSaveOnWindowChange: boolean;
constructor(
@ILifecycleService protected lifecycleService: ILifecycleService,
@IWorkspaceContextService protected contextService: IWorkspaceContextService,
@IInstantiationService private instantiationService: IInstantiationService,
@ILifecycleService private lifecycleService: ILifecycleService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IConfigurationService private configurationService: IConfigurationService,
@ITelemetryService private telemetryService: ITelemetryService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@IWorkbenchEditorService protected editorService: IWorkbenchEditorService,
@IEventService private eventService: IEventService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IFileService protected fileService: IFileService,
@IModelService protected modelService: IModelService,
@IUntitledEditorService protected untitledEditorService: IUntitledEditorService
@IUntitledEditorService private untitledEditorService: IUntitledEditorService
) {
this.listenerToUnbind = [];
this._onAutoSaveConfigurationChange = new Emitter<IAutoSaveConfiguration>();
......@@ -73,12 +67,18 @@ export abstract class TextFileService implements ITextFileService {
public abstract promptForPath(defaultPath?: string): string;
public abstract confirmBeforeShutdown(): boolean | TPromise<boolean>;
public get onAutoSaveConfigurationChange(): Event<IAutoSaveConfiguration> {
return this._onAutoSaveConfigurationChange.event;
}
protected registerListeners(): void {
// Lifecycle
this.lifecycleService.onWillShutdown(event => event.veto(this.beforeShutdown()));
this.lifecycleService.onShutdown(this.dispose, this);
// Configuration changes
this.listenerToUnbind.push(this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationChange(e.config)));
......@@ -88,6 +88,29 @@ export abstract class TextFileService implements ITextFileService {
this.listenerToUnbind.push(this.editorGroupService.onEditorsChanged(() => this.onEditorFocusChanged()));
}
private beforeShutdown(): boolean | TPromise<boolean> {
// Dirty files need treatment on shutdown
if (this.getDirty().length) {
// If auto save is enabled, save all files and then check again for dirty files
if (this.getAutoSaveMode() !== AutoSaveMode.OFF) {
return this.saveAll(false /* files only */).then(() => {
if (this.getDirty().length) {
return this.confirmBeforeShutdown(); // we still have dirty files around, so confirm normally
}
return false; // all good, no veto
});
}
// Otherwise just confirm what to do
return this.confirmBeforeShutdown();
}
return false; // no veto
}
private onWindowFocusLost(): void {
if (this.configuredAutoSaveOnWindowChange && this.isDirty()) {
this.saveAll().done(null, errors.onUnexpectedError);
......
......@@ -12,12 +12,10 @@ import strings = require('vs/base/common/strings');
import {isWindows, isLinux} from 'vs/base/common/platform';
import URI from 'vs/base/common/uri';
import {ConfirmResult} from 'vs/workbench/common/editor';
import {IEventService} from 'vs/platform/event/common/event';
import {TextFileService as AbstractTextFileService} from 'vs/workbench/parts/files/common/textFileServices';
import {AutoSaveMode, IRawTextContent} from 'vs/workbench/parts/files/common/files';
import {IRawTextContent} from 'vs/workbench/parts/files/common/files';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IFileService, IResolveContentOptions} from 'vs/platform/files/common/files';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {ILifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
......@@ -37,29 +35,19 @@ export class TextFileService extends AbstractTextFileService {
constructor(
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IInstantiationService instantiationService: IInstantiationService,
@IFileService fileService: IFileService,
@IUntitledEditorService untitledEditorService: IUntitledEditorService,
@ILifecycleService lifecycleService: ILifecycleService,
@ITelemetryService telemetryService: ITelemetryService,
@IConfigurationService configurationService: IConfigurationService,
@IEventService eventService: IEventService,
@IModeService private modeService: IModeService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IEditorGroupService editorGroupService: IEditorGroupService,
@IWindowService private windowService: IWindowService,
@IModelService modelService: IModelService,
@IModelService private modelService: IModelService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
super(lifecycleService, contextService, instantiationService, configurationService, telemetryService, editorGroupService, editorService, eventService, fileService, modelService, untitledEditorService);
}
protected registerListeners(): void {
super.registerListeners();
// Lifecycle
this.lifecycleService.onWillShutdown(event => event.veto(this.beforeShutdown()));
this.lifecycleService.onShutdown(this.onShutdown, this);
super(lifecycleService, contextService, configurationService, telemetryService, editorGroupService, editorService, fileService, untitledEditorService);
}
public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent> {
......@@ -80,30 +68,7 @@ export class TextFileService extends AbstractTextFileService {
});
}
public beforeShutdown(): boolean | TPromise<boolean> {
// Dirty files need treatment on shutdown
if (this.getDirty().length) {
// If auto save is enabled, save all files and then check again for dirty files
if (this.getAutoSaveMode() !== AutoSaveMode.OFF) {
return this.saveAll(false /* files only */).then(() => {
if (this.getDirty().length) {
return this.confirmBeforeShutdown(); // we still have dirty files around, so confirm normally
}
return false; // all good, no veto
});
}
// Otherwise just confirm what to do
return this.confirmBeforeShutdown();
}
return false; // no veto
}
private confirmBeforeShutdown(): boolean | TPromise<boolean> {
public confirmBeforeShutdown(): boolean | TPromise<boolean> {
const confirm = this.confirmSave();
// Save
......@@ -128,10 +93,6 @@ export class TextFileService extends AbstractTextFileService {
}
}
private onShutdown(): void {
super.dispose();
}
public confirmSave(resources?: URI[]): ConfirmResult {
if (!!this.environmentService.extensionDevelopmentPath) {
return ConfirmResult.DONT_SAVE; // no veto when we are in extension dev mode because we cannot assum we run interactive (e.g. tests)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册