提交 961ff966 编写于 作者: B Benjamin Pasero

fixes #17430

上级 c90d64ac
......@@ -32,7 +32,6 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
/**
......@@ -53,10 +52,9 @@ export class TextDiffEditor extends BaseTextEditor {
@IConfigurationService configurationService: IConfigurationService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IThemeService themeService: IThemeService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@ITextFileService textFileService: ITextFileService
@IEditorGroupService private editorGroupService: IEditorGroupService
) {
super(TextDiffEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService);
super(TextDiffEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService);
}
public getTitle(): string {
......
......@@ -8,21 +8,17 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { Dimension, Builder } from 'vs/base/browser/builder';
import objects = require('vs/base/common/objects');
import errors = require('vs/base/common/errors');
import types = require('vs/base/common/types');
import DOM = require('vs/base/browser/dom');
import { CodeEditor } from 'vs/editor/browser/codeEditor';
import { EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { IEditorViewState, IEditor, IEditorOptions, EventType as EditorEventType } from 'vs/editor/common/editorCommon';
import { IEditorViewState, IEditor, IEditorOptions } from 'vs/editor/common/editorCommon';
import { Position } from 'vs/platform/editor/common/editor';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { ITextFileService, SaveReason, AutoSaveMode } from 'vs/workbench/services/textfile/common/textfiles';
import { EventEmitter } from 'vs/base/common/eventEmitter';
import { Scope } from 'vs/workbench/common/memento';
const TEXT_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'textEditorViewState';
......@@ -46,7 +42,6 @@ export abstract class BaseTextEditor extends BaseEditor {
private editorControl: IEditor;
private _editorContainer: Builder;
private hasPendingConfigurationChange: boolean;
private pendingAutoSave: TPromise<void>;
constructor(
id: string,
......@@ -54,8 +49,7 @@ export abstract class BaseTextEditor extends BaseEditor {
@IInstantiationService private _instantiationService: IInstantiationService,
@IStorageService private storageService: IStorageService,
@IConfigurationService private configurationService: IConfigurationService,
@IThemeService private themeService: IThemeService,
@ITextFileService private textFileService: ITextFileService
@IThemeService private themeService: IThemeService
) {
super(id, telemetryService);
......@@ -116,12 +110,6 @@ export abstract class BaseTextEditor extends BaseEditor {
// Editor for Text
this._editorContainer = parent;
this.editorControl = this.createEditorControl(parent, this.computeConfiguration(this.configurationService.getConfiguration<IEditorConfiguration>()));
// Application & Editor focus change
if (this.editorControl instanceof EventEmitter) {
this.toUnbind.push(this.editorControl.addListener2(EditorEventType.EditorBlur, () => this.onEditorFocusLost()));
}
this.toUnbind.push(DOM.addDisposableListener(window, DOM.EventType.BLUR, () => this.onWindowFocusLost()));
}
/**
......@@ -136,39 +124,6 @@ export abstract class BaseTextEditor extends BaseEditor {
return this.instantiationService.createInstance(CodeEditor, parent.getHTMLElement(), configuration);
}
private onEditorFocusLost(): void {
if (this.pendingAutoSave) {
return; // save is already triggered
}
if (this.textFileService.getAutoSaveMode() === AutoSaveMode.ON_FOCUS_CHANGE && this.textFileService.isDirty()) {
this.saveAll(SaveReason.FOCUS_CHANGE);
}
}
private onWindowFocusLost(): void {
if (this.pendingAutoSave) {
return; // save is already triggered
}
if (this.textFileService.getAutoSaveMode() === AutoSaveMode.ON_WINDOW_CHANGE && this.textFileService.isDirty()) {
this.saveAll(SaveReason.WINDOW_CHANGE);
}
}
private saveAll(reason: SaveReason): void {
this.pendingAutoSave = this.textFileService.saveAll(void 0, reason).then(() => {
this.pendingAutoSave = void 0;
return void 0;
}, error => {
this.pendingAutoSave = void 0;
errors.onUnexpectedError(error);
return void 0;
});
}
public setInput(input: EditorInput, options?: EditorOptions): TPromise<void> {
return super.setInput(input, options).then(() => {
......
......@@ -20,7 +20,6 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
/**
......@@ -38,10 +37,9 @@ export class TextResourceEditor extends BaseTextEditor {
@IConfigurationService configurationService: IConfigurationService,
@IThemeService themeService: IThemeService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@ITextFileService textFileService: ITextFileService
@IEditorGroupService private editorGroupService: IEditorGroupService
) {
super(TextResourceEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService);
super(TextResourceEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService);
this.toUnbind.push(this.untitledEditorService.onDidChangeDirty(e => this.onUntitledDirtyChange(e)));
}
......
......@@ -13,7 +13,7 @@ import paths = require('vs/base/common/paths');
import { IEditorOptions } from 'vs/editor/common/editorCommon';
import { Action } from 'vs/base/common/actions';
import { VIEWLET_ID, TEXT_FILE_EDITOR_ID } from 'vs/workbench/parts/files/common/files';
import { ITextFileEditorModel, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { ITextFileEditorModel } from 'vs/workbench/services/textfile/common/textfiles';
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
import { EditorOptions, TextEditorOptions } from 'vs/workbench/common/editor';
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
......@@ -50,10 +50,9 @@ export class TextFileEditor extends BaseTextEditor {
@IConfigurationService configurationService: IConfigurationService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IThemeService themeService: IThemeService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@ITextFileService textFileService: ITextFileService
@IEditorGroupService private editorGroupService: IEditorGroupService
) {
super(TextFileEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService);
super(TextFileEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService);
// Clear view state for deleted files
this.toUnbind.push(this.fileService.onFileChanges(e => this.onFilesChanged(e)));
......
......@@ -22,7 +22,6 @@ import { OutputEditors, OUTPUT_PANEL_ID, IOutputService, CONTEXT_IN_OUTPUT } fro
import { SwitchOutputAction, SwitchOutputActionItem, ClearOutputAction } from 'vs/workbench/parts/output/browser/outputActions';
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
export class OutputPanel extends TextResourceEditor {
......@@ -39,10 +38,9 @@ export class OutputPanel extends TextResourceEditor {
@IOutputService private outputService: IOutputService,
@IUntitledEditorService untitledEditorService: IUntitledEditorService,
@IContextKeyService private contextKeyService: IContextKeyService,
@IEditorGroupService editorGroupService: IEditorGroupService,
@ITextFileService textFileService: ITextFileService
@IEditorGroupService editorGroupService: IEditorGroupService
) {
super(telemetryService, instantiationService, storageService, configurationService, themeService, untitledEditorService, editorGroupService, textFileService);
super(telemetryService, instantiationService, storageService, configurationService, themeService, untitledEditorService, editorGroupService);
this.scopedInstantiationService = instantiationService;
this.toDispose = [];
......
......@@ -43,7 +43,6 @@ import { IThemeService } from 'vs/workbench/services/themes/common/themeService'
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
......@@ -113,10 +112,9 @@ export class DefaultPreferencesEditor extends BaseTextEditor {
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IPreferencesService private preferencesService: IPreferencesService,
@IModelService private modelService: IModelService,
@IModeService private modeService: IModeService,
@ITextFileService textFileService: ITextFileService
@IModeService private modeService: IModeService
) {
super(DefaultPreferencesEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService);
super(DefaultPreferencesEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService);
this.delayedFilterLogging = new Delayer<void>(1000);
}
......
......@@ -36,6 +36,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IMessageService } from 'vs/platform/message/common/message';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { IWindowsService } from 'vs/platform/windows/common/windows';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
class SettingsTestEnvironmentService extends EnvironmentService {
......@@ -60,9 +61,10 @@ class TestDirtyTextFileService extends TestTextFileService {
@IInstantiationService instantiationService: IInstantiationService,
@IMessageService messageService: IMessageService,
@IBackupFileService backupFileService: IBackupFileService,
@IWindowsService windowsService: IWindowsService
@IWindowsService windowsService: IWindowsService,
@IEditorGroupService editorGroupService: IEditorGroupService
) {
super(lifecycleService, contextService, configurationService, telemetryService, editorService, fileService, untitledEditorService, instantiationService, messageService, backupFileService, windowsService);
super(lifecycleService, contextService, configurationService, telemetryService, editorService, fileService, untitledEditorService, instantiationService, messageService, backupFileService, windowsService, editorGroupService);
}
public isDirty(resource?: URI): boolean {
......
......@@ -10,12 +10,14 @@ import URI from 'vs/base/common/uri';
import paths = require('vs/base/common/paths');
import errors = require('vs/base/common/errors');
import objects = require('vs/base/common/objects');
import DOM = require('vs/base/browser/dom');
import Event, { Emitter } from 'vs/base/common/event';
import platform = require('vs/base/common/platform');
import { IWindowsService } from 'vs/platform/windows/common/windows';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { IRevertOptions, IResult, ITextFileOperationResult, ITextFileService, IRawTextContent, IAutoSaveConfiguration, AutoSaveMode, SaveReason, ITextFileEditorModelManager, ITextFileEditorModel, ISaveOptions } from 'vs/workbench/services/textfile/common/textfiles';
import { ConfirmResult } from 'vs/workbench/common/editor';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { ILifecycleService, ShutdownReason } 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';
......@@ -66,6 +68,7 @@ export abstract class TextFileService implements ITextFileService {
@IMessageService private messageService: IMessageService,
@IEnvironmentService protected environmentService: IEnvironmentService,
@IBackupFileService private backupFileService: IBackupFileService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@IWindowsService private windowsService: IWindowsService
) {
this.toUnbind = [];
......@@ -116,6 +119,11 @@ export abstract class TextFileService implements ITextFileService {
// Configuration changes
this.toUnbind.push(this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationChange(e.config)));
// Application & Editor focus change
this.toUnbind.push(DOM.addDisposableListener(window, DOM.EventType.BLUR, () => this.onWindowFocusLost()));
this.toUnbind.push(DOM.addDisposableListener(window, DOM.EventType.BLUR, () => this.onEditorFocusChanged(), true));
this.toUnbind.push(this.editorGroupService.onEditorsChanged(() => this.onEditorFocusChanged()));
}
private beforeShutdown(reason: ShutdownReason): boolean | TPromise<boolean> {
......@@ -287,6 +295,18 @@ export abstract class TextFileService implements ITextFileService {
return this.backupFileService.discardAllWorkspaceBackups();
}
private onWindowFocusLost(): void {
if (this.configuredAutoSaveOnWindowChange && this.isDirty()) {
this.saveAll(void 0, SaveReason.WINDOW_CHANGE).done(null, errors.onUnexpectedError);
}
}
private onEditorFocusChanged(): void {
if (this.configuredAutoSaveOnFocusChange && this.isDirty()) {
this.saveAll(void 0, SaveReason.FOCUS_CHANGE).done(null, errors.onUnexpectedError);
}
}
private onConfigurationChange(configuration: IFilesConfiguration): void {
const wasAutoSaveEnabled = (this.getAutoSaveMode() !== AutoSaveMode.OFF);
......
......@@ -261,8 +261,8 @@ export interface ITextFileService extends IDisposable {
* @param resources can be null to save all.
* @param includeUntitled to save all resources and optionally exclude untitled ones.
*/
saveAll(includeUntitled?: boolean, reason?: SaveReason): TPromise<ITextFileOperationResult>;
saveAll(resources: URI[], reason?: SaveReason): TPromise<ITextFileOperationResult>;
saveAll(includeUntitled?: boolean): TPromise<ITextFileOperationResult>;
saveAll(resources: URI[]): TPromise<ITextFileOperationResult>;
/**
* Reverts the provided resource.
......
......@@ -24,6 +24,7 @@ import { IModeService } from 'vs/editor/common/services/modeService';
import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ModelBuilder } from 'vs/editor/node/model/modelBuilder';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import product from 'vs/platform/node/product';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......@@ -51,9 +52,10 @@ export class TextFileService extends AbstractTextFileService {
@IMessageService messageService: IMessageService,
@IBackupFileService backupFileService: IBackupFileService,
@IStorageService private storageService: IStorageService,
@IWindowsService windowsService: IWindowsService
@IWindowsService windowsService: IWindowsService,
@IEditorGroupService editorGroupService: IEditorGroupService
) {
super(lifecycleService, contextService, configurationService, telemetryService, fileService, untitledEditorService, instantiationService, messageService, environmentService, backupFileService, windowsService);
super(lifecycleService, contextService, configurationService, telemetryService, fileService, untitledEditorService, instantiationService, messageService, environmentService, backupFileService, editorGroupService, windowsService);
}
public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent> {
......
......@@ -115,9 +115,10 @@ export class TestTextFileService extends TextFileService {
@IInstantiationService instantiationService: IInstantiationService,
@IMessageService messageService: IMessageService,
@IBackupFileService backupFileService: IBackupFileService,
@IWindowsService windowsService: IWindowsService
@IWindowsService windowsService: IWindowsService,
@IEditorGroupService editorGroupService: IEditorGroupService
) {
super(lifecycleService, contextService, configurationService, telemetryService, fileService, untitledEditorService, instantiationService, messageService, TestEnvironmentService, backupFileService, windowsService);
super(lifecycleService, contextService, configurationService, telemetryService, fileService, untitledEditorService, instantiationService, messageService, TestEnvironmentService, backupFileService, editorGroupService, windowsService);
}
public setPromptPath(path: string): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册