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

use more ITextFileEditorModel interface

上级 bf7a630d
......@@ -21,10 +21,9 @@ import {DiffEditorModel} from 'vs/workbench/common/editor/diffEditorModel';
import {FileEditorInput} from 'vs/workbench/parts/files/common/editors/fileEditorInput';
import {SaveFileAsAction, RevertFileAction, SaveFileAction} from 'vs/workbench/parts/files/browser/fileActions';
import {IFileService, IFileOperationResult, FileOperationResult} from 'vs/platform/files/common/files';
import {TextFileEditorModel, ISaveErrorHandler} from 'vs/workbench/parts/files/common/editors/textFileEditorModel';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IEventService} from 'vs/platform/event/common/event';
import {EventType as FileEventType, TextFileChangeEvent, ITextFileService} from 'vs/workbench/parts/files/common/files';
import {EventType as FileEventType, TextFileChangeEvent, ITextFileService, ISaveErrorHandler, ITextFileEditorModel} from 'vs/workbench/parts/files/common/files';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IMessageService, IMessageWithAction, Severity, CancelAction} from 'vs/platform/message/common/message';
import {IModeService} from 'vs/editor/common/services/modeService';
......@@ -57,7 +56,7 @@ export class SaveErrorHandler implements ISaveErrorHandler {
}
}
public onSaveError(error: any, model: TextFileEditorModel): void {
public onSaveError(error: any, model: ITextFileEditorModel): void {
let message: IMessageWithAction;
const resource = model.getResource();
......@@ -134,10 +133,10 @@ export class ConflictResolutionDiffEditorInput extends DiffEditorInput {
public static ID = 'workbench.editors.files.conflictResolutionDiffEditorInput';
private model: TextFileEditorModel;
private model: ITextFileEditorModel;
constructor(
model: TextFileEditorModel,
model: ITextFileEditorModel,
name: string,
description: string,
originalInput: FileOnDiskEditorInput,
......@@ -148,7 +147,7 @@ export class ConflictResolutionDiffEditorInput extends DiffEditorInput {
this.model = model;
}
public getModel(): TextFileEditorModel {
public getModel(): ITextFileEditorModel {
return this.model;
}
......@@ -227,10 +226,10 @@ class ResolveSaveConflictMessage implements IMessageWithAction {
public message: string;
public actions: Action[];
private model: TextFileEditorModel;
private model: ITextFileEditorModel;
constructor(
model: TextFileEditorModel,
model: ITextFileEditorModel,
message: string,
@IMessageService private messageService: IMessageService,
@IInstantiationService private instantiationService: IInstantiationService,
......
......@@ -16,7 +16,7 @@ import types = require('vs/base/common/types');
import {IModelContentChangedEvent} from 'vs/editor/common/editorCommon';
import {IMode} from 'vs/editor/common/modes';
import {EventType as WorkbenchEventType, ResourceEvent} from 'vs/workbench/common/events';
import {EventType as FileEventType, TextFileChangeEvent, ITextFileService, IAutoSaveConfiguration, ModelState, ITextFileEditorModel} from 'vs/workbench/parts/files/common/files';
import {EventType as FileEventType, TextFileChangeEvent, ITextFileService, IAutoSaveConfiguration, ModelState, ITextFileEditorModel, ISaveErrorHandler} from 'vs/workbench/parts/files/common/files';
import {EncodingMode, EditorModel} from 'vs/workbench/common/editor';
import {BaseTextEditorModel} from 'vs/workbench/common/editor/textEditorModel';
import {IFileService, IFileStat, IFileOperationResult, FileOperationResult} from 'vs/platform/files/common/files';
......@@ -27,34 +27,6 @@ import {IModeService} from 'vs/editor/common/services/modeService';
import {IModelService} from 'vs/editor/common/services/modelService';
import {ITelemetryService, anonymize} from 'vs/platform/telemetry/common/telemetry';
/**
* The save error handler can be installed on the text text file editor model to install code that executes when save errors occur.
*/
export interface ISaveErrorHandler {
/**
* Called whenever a save fails.
*/
onSaveError(error: any, model: TextFileEditorModel): void;
}
class DefaultSaveErrorHandler implements ISaveErrorHandler {
constructor( @IMessageService private messageService: IMessageService) { }
public onSaveError(error: any, model: TextFileEditorModel): void {
this.messageService.show(Severity.Error, nls.localize('genericSaveError', "Failed to save '{0}': {1}", paths.basename(model.getResource().fsPath), toErrorMessage(error, false)));
}
}
// Diagnostics support
let diag: (...args: any[]) => void;
if (!diag) {
diag = diagnostics.register('TextFileEditorModelDiagnostics', function (...args: any[]) {
console.log(args[1] + ' - ' + args[0] + ' (time: ' + args[2].getTime() + ' [' + args[2].toUTCString() + '])');
});
}
/**
* The text file editor model listens to changes to its underlying code editor model and saves these changes through the file service back to the disk.
*/
......@@ -720,4 +692,21 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
super.dispose();
}
}
class DefaultSaveErrorHandler implements ISaveErrorHandler {
constructor(@IMessageService private messageService: IMessageService) { }
public onSaveError(error: any, model: TextFileEditorModel): void {
this.messageService.show(Severity.Error, nls.localize('genericSaveError', "Failed to save '{0}': {1}", paths.basename(model.getResource().fsPath), toErrorMessage(error, false)));
}
}
// Diagnostics support
let diag: (...args: any[]) => void;
if (!diag) {
diag = diagnostics.register('TextFileEditorModelDiagnostics', function (...args: any[]) {
console.log(args[1] + ' - ' + args[0] + ' (time: ' + args[2].getTime() + ' [' + args[2].toUTCString() + '])');
});
}
\ No newline at end of file
......@@ -96,6 +96,17 @@ export function asFileResource(obj: any): IFileResource {
return null;
}
/**
* The save error handler can be installed on the text text file editor model to install code that executes when save errors occur.
*/
export interface ISaveErrorHandler {
/**
* Called whenever a save fails.
*/
onSaveError(error: any, model: ITextFileEditorModel): void;
}
/**
* List of event types from files.
*/
......@@ -294,6 +305,14 @@ export interface ITextFileEditorModel extends ITextEditorModel, IEncodingSupport
getState(): ModelState;
save(overwriteReadonly?: boolean, overwriteEncoding?: boolean): TPromise<void>;
revert(): TPromise<void>;
setConflictResolutionMode();
getValue(): string;
isDirty(): boolean;
isResolved(): boolean;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册