提交 c9b48d56 编写于 作者: M Matt Bierner

Fixing save of untitled text based custom editors

上级 1264510b
...@@ -752,18 +752,23 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod ...@@ -752,18 +752,23 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod
}); });
} }
public async save(_options?: ISaveOptions): Promise<boolean> { public async save(options?: ISaveOptions): Promise<boolean> {
return !!await this.saveCustomEditor(options);
}
public async saveCustomEditor(_options?: ISaveOptions): Promise<URI | undefined> {
if (!this._editable) { if (!this._editable) {
return false; return undefined;
} }
// TODO: handle save untitled case
await createCancelablePromise(token => this._proxy.$onSave(this._editorResource, this.viewType, token)); await createCancelablePromise(token => this._proxy.$onSave(this._editorResource, this.viewType, token));
this.change(() => { this.change(() => {
this._savePoint = this._currentEditIndex; this._savePoint = this._currentEditIndex;
}); });
return true; return this._editorResource;
} }
public async saveAs(resource: URI, targetResource: URI, _options?: ISaveOptions): Promise<boolean> { public async saveCustomEditorAs(resource: URI, targetResource: URI, _options?: ISaveOptions): Promise<boolean> {
if (this._editable) { if (this._editable) {
await this._proxy.$onSaveAs(this._editorResource, this.viewType, targetResource); await this._proxy.$onSaveAs(this._editorResource, this.viewType, targetResource);
this.change(() => { this.change(() => {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import { memoize } from 'vs/base/common/decorators'; import { memoize } from 'vs/base/common/decorators';
import { Lazy } from 'vs/base/common/lazy'; import { Lazy } from 'vs/base/common/lazy';
import { IReference } from 'vs/base/common/lifecycle'; import { IReference } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { basename } from 'vs/base/common/path'; import { basename } from 'vs/base/common/path';
import { isEqual } from 'vs/base/common/resources'; import { isEqual } from 'vs/base/common/resources';
import { assertIsDefined } from 'vs/base/common/types'; import { assertIsDefined } from 'vs/base/common/types';
...@@ -99,6 +100,10 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput { ...@@ -99,6 +100,10 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
return this._modelRef ? this._modelRef.object.isReadonly() : false; return this._modelRef ? this._modelRef.object.isReadonly() : false;
} }
public isUntitled(): boolean {
return this.resource.scheme === Schemas.untitled;
}
public isDirty(): boolean { public isDirty(): boolean {
if (!this._modelRef) { if (!this._modelRef) {
return false; return false;
...@@ -120,8 +125,16 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput { ...@@ -120,8 +125,16 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
public async save(groupId: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> { public async save(groupId: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
const modelRef = assertIsDefined(this._modelRef); const modelRef = assertIsDefined(this._modelRef);
const result = await modelRef.object.save(options); const target = await modelRef.object.saveCustomEditor(options);
return result ? this : undefined; if (!target) {
return undefined; // save cancelled
}
if (!isEqual(target, this.resource)) {
return this.customEditorService.createInput(target, this.viewType, groupId);
}
return this;
} }
public async saveAs(groupId: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> { public async saveAs(groupId: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
...@@ -133,7 +146,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput { ...@@ -133,7 +146,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
return undefined; // save cancelled return undefined; // save cancelled
} }
if (!await modelRef.object.saveAs(this._editorResource, target, options)) { if (!await modelRef.object.saveCustomEditorAs(this._editorResource, target, options)) {
return undefined; return undefined;
} }
......
...@@ -57,8 +57,8 @@ export interface ICustomEditorModel extends IDisposable { ...@@ -57,8 +57,8 @@ export interface ICustomEditorModel extends IDisposable {
revert(options?: IRevertOptions): Promise<void>; revert(options?: IRevertOptions): Promise<void>;
save(options?: ISaveOptions): Promise<boolean>; saveCustomEditor(options?: ISaveOptions): Promise<URI | undefined>;
saveAs(resource: URI, targetResource: URI, currentOptions?: ISaveOptions): Promise<boolean>; saveCustomEditorAs(resource: URI, targetResource: URI, currentOptions?: ISaveOptions): Promise<boolean>;
} }
export const enum CustomEditorPriority { export const enum CustomEditorPriority {
......
...@@ -68,11 +68,11 @@ export class CustomTextEditorModel extends Disposable implements ICustomEditorMo ...@@ -68,11 +68,11 @@ export class CustomTextEditorModel extends Disposable implements ICustomEditorMo
return this.textFileService.revert(this.resource, options); return this.textFileService.revert(this.resource, options);
} }
public async save(options?: ISaveOptions): Promise<boolean> { public saveCustomEditor(options?: ISaveOptions): Promise<URI | undefined> {
return !!await this.textFileService.save(this.resource, options); return this.textFileService.save(this.resource, options);
} }
public async saveAs(resource: URI, targetResource: URI, options?: ISaveOptions): Promise<boolean> { public async saveCustomEditorAs(resource: URI, targetResource: URI, options?: ISaveOptions): Promise<boolean> {
return !!await this.textFileService.saveAs(resource, targetResource, options); return !!await this.textFileService.saveAs(resource, targetResource, options);
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册