提交 f1c6f2c2 编写于 作者: B Benjamin Pasero

text files - move save error handler into files model manager

上级 2d125bc3
......@@ -64,7 +64,7 @@ export class TextFileSaveErrorHandler extends Disposable implements ISaveErrorHa
this._register(textModelService.registerTextModelContentProvider(CONFLICT_RESOLUTION_SCHEME, provider));
// Set as save error handler to service for text files
this.textFileService.saveErrorHandler = this;
this.textFileService.files.saveErrorHandler = this;
this.registerListeners();
}
......
......@@ -33,8 +33,6 @@ import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel'
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { coalesce } from 'vs/base/common/arrays';
import { suggestFilename } from 'vs/base/common/mime';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
import { isValidBasename } from 'vs/base/common/extpath';
......@@ -59,16 +57,6 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
readonly untitled: IUntitledTextEditorModelManager = this.untitledTextEditorService;
saveErrorHandler = (() => {
const notificationService = this.notificationService;
return {
onSaveError(error: Error, model: ITextFileEditorModel): void {
notificationService.error(nls.localize('genericSaveError', "Failed to save '{0}': {1}", model.name, toErrorMessage(error, false)));
}
};
})();
abstract get encoding(): IResourceEncodings;
constructor(
......@@ -84,7 +72,6 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
@IFilesConfigurationService protected readonly filesConfigurationService: IFilesConfigurationService,
@ITextModelService private readonly textModelService: ITextModelService,
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
@INotificationService private readonly notificationService: INotificationService,
@IRemotePathService private readonly remotePathService: IRemotePathService
) {
super();
......
......@@ -738,7 +738,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
}
// Show to user
this.textFileService.saveErrorHandler.onSaveError(error, this);
this.textFileService.files.saveErrorHandler.onSaveError(error, this);
// Emit as event
this._onDidSaveError.fire();
......
......@@ -3,6 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { Emitter } from 'vs/base/common/event';
import { URI } from 'vs/base/common/uri';
import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel';
......@@ -18,6 +20,7 @@ import { onUnexpectedError } from 'vs/base/common/errors';
import { TextFileSaveParticipant } from 'vs/workbench/services/textfile/common/textFileSaveParticipant';
import { SaveReason } from 'vs/workbench/common/editor';
import { CancellationToken } from 'vs/base/common/cancellation';
import { INotificationService } from 'vs/platform/notification/common/notification';
export class TextFileEditorModelManager extends Disposable implements ITextFileEditorModelManager {
......@@ -42,6 +45,16 @@ export class TextFileEditorModelManager extends Disposable implements ITextFileE
private readonly _onDidChangeOrphaned = this._register(new Emitter<ITextFileEditorModel>());
readonly onDidChangeOrphaned = this._onDidChangeOrphaned.event;
saveErrorHandler = (() => {
const notificationService = this.notificationService;
return {
onSaveError(error: Error, model: ITextFileEditorModel): void {
notificationService.error(localize('genericSaveError', "Failed to save '{0}': {1}", model.name, toErrorMessage(error, false)));
}
};
})();
private readonly mapResourceToModel = new ResourceMap<ITextFileEditorModel>();
private readonly mapResourceToModelListeners = new ResourceMap<IDisposable>();
private readonly mapResourceToDisposeListener = new ResourceMap<IDisposable>();
......@@ -52,7 +65,8 @@ export class TextFileEditorModelManager extends Disposable implements ITextFileE
constructor(
@ILifecycleService private readonly lifecycleService: ILifecycleService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IFileService private readonly fileService: IFileService
@IFileService private readonly fileService: IFileService,
@INotificationService private readonly notificationService: INotificationService
) {
super();
......
......@@ -52,12 +52,6 @@ export interface ITextFileService extends IDisposable {
*/
readonly encoding: IResourceEncodings;
/**
* The handler that should be called when saving fails. Can be overridden
* to handle save errors in a custom way.
*/
saveErrorHandler: ISaveErrorHandler;
/**
* A resource is dirty if it has unsaved changes or is an untitled file not yet saved.
*
......@@ -377,6 +371,8 @@ export interface ITextFileEditorModelManager {
addSaveParticipant(participant: ITextFileSaveParticipant): IDisposable;
runSaveParticipants(model: IResolvedTextFileEditorModel, context: { reason: SaveReason; }, token: CancellationToken): Promise<void>
saveErrorHandler: ISaveErrorHandler;
disposeModel(model: ITextFileEditorModel): void;
}
......
......@@ -37,7 +37,6 @@ import { assign } from 'vs/base/common/objects';
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
export class NativeTextFileService extends AbstractTextFileService {
......@@ -56,10 +55,9 @@ export class NativeTextFileService extends AbstractTextFileService {
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService,
@ITextModelService textModelService: ITextModelService,
@ICodeEditorService codeEditorService: ICodeEditorService,
@INotificationService notificationService: INotificationService,
@IRemotePathService remotePathService: IRemotePathService
) {
super(fileService, untitledTextEditorService, lifecycleService, instantiationService, modelService, environmentService, dialogService, fileDialogService, textResourceConfigurationService, filesConfigurationService, textModelService, codeEditorService, notificationService, remotePathService);
super(fileService, untitledTextEditorService, lifecycleService, instantiationService, modelService, environmentService, dialogService, fileDialogService, textResourceConfigurationService, filesConfigurationService, textModelService, codeEditorService, remotePathService);
}
private _encoding: EncodingOracle | undefined;
......
......@@ -121,7 +121,6 @@ export class TestTextFileService extends BrowserTextFileService {
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService,
@ITextModelService textModelService: ITextModelService,
@ICodeEditorService codeEditorService: ICodeEditorService,
@INotificationService notificationService: INotificationService,
@IRemotePathService remotePathService: IRemotePathService
) {
super(
......@@ -137,7 +136,6 @@ export class TestTextFileService extends BrowserTextFileService {
filesConfigurationService,
textModelService,
codeEditorService,
notificationService,
remotePathService
);
}
......
......@@ -22,7 +22,6 @@ import { IProductService } from 'vs/platform/product/common/productService';
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { URI } from 'vs/base/common/uri';
import { IReadTextFileOptions, ITextFileStreamContent, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { createTextBufferFactoryFromStream } from 'vs/editor/common/model/textModel';
......@@ -62,7 +61,6 @@ export class TestTextFileService extends NativeTextFileService {
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService,
@ITextModelService textModelService: ITextModelService,
@ICodeEditorService codeEditorService: ICodeEditorService,
@INotificationService notificationService: INotificationService,
@IRemotePathService remotePathService: IRemotePathService
) {
super(
......@@ -79,7 +77,6 @@ export class TestTextFileService extends NativeTextFileService {
filesConfigurationService,
textModelService,
codeEditorService,
notificationService,
remotePathService
);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册