提交 7e71822a 编写于 作者: M Matt Bierner

Hook up CustomEditorModel to workingCopyService

上级 0fcc0aa8
......@@ -12,6 +12,7 @@ import { URI, UriComponents } from 'vs/base/common/uri';
import * as modes from 'vs/editor/common/modes';
import { localize } from 'vs/nls';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IProductService } from 'vs/platform/product/common/productService';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
......@@ -20,6 +21,7 @@ import { editorGroupToViewColumn, EditorViewColumn, viewColumnToEditorGroup } fr
import { IEditorInput } from 'vs/workbench/common/editor';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { CustomFileEditorInput } from 'vs/workbench/contrib/customEditor/browser/customEditorInput';
import { CustomEditorModel } from 'vs/workbench/contrib/customEditor/browser/customEditorModel';
import { WebviewExtensionDescription } from 'vs/workbench/contrib/webview/browser/webview';
import { WebviewInput } from 'vs/workbench/contrib/webview/browser/webviewEditorInput';
import { ICreateWebViewShowOptions, IWebviewWorkbenchService, WebviewInputOptions } from 'vs/workbench/contrib/webview/browser/webviewWorkbenchService';
......@@ -27,7 +29,6 @@ import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { extHostNamedCustomer } from '../common/extHostCustomers';
import { CustomEditorModel } from 'vs/workbench/contrib/customEditor/browser/customEditorModel';
/**
* Bi-directional map between webview handles and inputs.
......@@ -102,6 +103,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
@IExtensionService extensionService: IExtensionService,
@IEditorGroupsService private readonly _editorGroupService: IEditorGroupsService,
@IEditorService private readonly _editorService: IEditorService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IOpenerService private readonly _openerService: IOpenerService,
@IProductService private readonly _productService: IProductService,
@ITelemetryService private readonly _telemetryService: ITelemetryService,
......@@ -271,7 +273,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
webviewInput.webview.options = options;
webviewInput.webview.extension = extension;
const model = new CustomEditorModel();
const model = this._instantiationService.createInstance(CustomEditorModel, webviewInput.getResource());
webviewInput.setModel(model);
this._models.set(handle, model);
......
......@@ -5,18 +5,44 @@
import { Emitter, Event } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { IWorkingCopy, IWorkingCopyService, WorkingCopyCapabilities } from 'vs/workbench/services/workingCopy/common/workingCopyService';
type Edit = string;
export class CustomEditorModel extends Disposable {
export class CustomEditorModel extends Disposable implements IWorkingCopy {
private _currentEditIndex: number = 0;
private _savePoint: number = -1;
private _edits: Array<Edit> = [];
constructor(
private readonly _resource: URI,
@IWorkingCopyService private readonly _workingCopyService: IWorkingCopyService,
) {
super();
this._register(this._workingCopyService.registerWorkingCopy(this));
}
//#region IWorkingCopy
public get resource() {
return this._resource;
}
public get capabilities(): WorkingCopyCapabilities {
return 0;
}
public isDirty(): boolean {
return this._edits.length > 0 && this._savePoint !== this._edits.length;
}
protected readonly _onDidChangeDirty: Emitter<void> = this._register(new Emitter<void>());
readonly onDidChangeDirty: Event<void> = this._onDidChangeDirty.event;
//#endregion
protected readonly _onUndo: Emitter<Edit> = this._register(new Emitter<Edit>());
readonly onUndo: Event<Edit> = this._onUndo.event;
......@@ -26,10 +52,6 @@ export class CustomEditorModel extends Disposable {
this.updateDirty();
}
public isDirty(): boolean {
return this._edits.length > 0 && this._savePoint !== this._edits.length;
}
private updateDirty() {
this._onDidChangeDirty.fire();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册