提交 2d3727b3 编写于 作者: M Matt Bierner

Push `editorResource` concept back into `CustomFileEditorInput`

上级 6f459807
......@@ -99,7 +99,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
// This should trigger the real reviver to be registered from the extension host side.
this._register(_webviewEditorService.registerResolver({
canResolve: (webview: WebviewEditorInput) => {
if (!webview.webview.state && !webview.editorResource) {
if (!webview.webview.state && webview.getTypeId() === WebviewEditorInput.typeId) { // TODO: The typeid check is a workaround for the CustomFileEditorInput case
return false;
}
......@@ -252,16 +252,16 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
this._editorProviders.set(viewType, this._webviewEditorService.registerResolver({
canResolve: (webviewEditorInput) => {
return !!webviewEditorInput.editorResource && webviewEditorInput.viewType === viewType;
return webviewEditorInput.getTypeId() !== WebviewEditorInput.typeId && webviewEditorInput.viewType === viewType;
},
resolveWebview: async (webview: WebviewEditorInput) => {
resolveWebview: async (webview) => {
const handle = `resolved-${MainThreadWebviews.revivalPool++}`;
this._webviewEditorInputs.add(handle, webview);
this.hookupWebviewEventDelegate(handle, webview);
try {
await this._proxy.$resolveWebviewEditor(
webview.editorResource,
webview.getResource(),
handle,
viewType,
webview.getTitle(),
......
......@@ -20,6 +20,7 @@ export class CustomFileEditorInput extends WebviewEditorInput {
private name?: string;
private _hasResolved = false;
private readonly _editorResource: URI;
constructor(
resource: URI,
......@@ -33,12 +34,21 @@ export class CustomFileEditorInput extends WebviewEditorInput {
@IExtensionService
private readonly _extensionService: IExtensionService
) {
super(id, viewType, '', undefined, webview, resource);
super(id, viewType, '', undefined, webview);
this._editorResource = resource;
}
public getTypeId(): string {
return CustomFileEditorInput.typeId;
}
public getResource(): URI {
return this._editorResource;
}
getName(): string {
if (!this.name) {
this.name = basename(this.labelService.getUriLabel(this.editorResource));
this.name = basename(this.labelService.getUriLabel(this.getResource()));
}
return this.name;
}
......@@ -46,7 +56,7 @@ export class CustomFileEditorInput extends WebviewEditorInput {
matches(other: IEditorInput): boolean {
return this === other || (other instanceof CustomFileEditorInput
&& this.viewType === other.viewType
&& this.editorResource.toString() === other.editorResource.toString());
&& this.getResource().toString() === other.getResource().toString());
}
@memoize
......@@ -56,15 +66,15 @@ export class CustomFileEditorInput extends WebviewEditorInput {
@memoize
private get mediumTitle(): string {
return this.labelService.getUriLabel(this.editorResource, { relative: true });
return this.labelService.getUriLabel(this.getResource(), { relative: true });
}
@memoize
private get longTitle(): string {
return this.labelService.getUriLabel(this.editorResource);
return this.labelService.getUriLabel(this.getResource());
}
getTitle(verbosity: Verbosity): string {
getTitle(verbosity?: Verbosity): string {
switch (verbosity) {
case Verbosity.SHORT:
return this.shortTitle;
......
......@@ -25,7 +25,7 @@ export class CustomEditoInputFactory extends WebviewEditorInputFactory {
public serialize(input: CustomFileEditorInput): string | undefined {
const data = {
...this.toJson(input),
editorResource: input.editorResource.toJSON()
editorResource: input.getResource().toJSON()
};
try {
......
......@@ -157,7 +157,7 @@ export class CustomEditorContribution implements IWorkbenchContribution {
}
for (const input of group.editors) {
if (input instanceof CustomFileEditorInput && input.editorResource.toString() === resource.toString()) {
if (input instanceof CustomFileEditorInput && input.getResource().toString() === resource.toString()) {
return {
override: group.openEditor(input, options).then(withNullAsUndefined)
};
......
......@@ -71,8 +71,7 @@ export class WebviewEditorInput extends EditorInput {
readonly location: URI;
readonly id: ExtensionIdentifier;
},
webview: Unowned<WebviewEditorOverlay>,
public readonly editorResource: URI,
webview: Unowned<WebviewEditorOverlay>
) {
super();
......@@ -89,8 +88,7 @@ export class WebviewEditorInput extends EditorInput {
public getResource(): URI {
return URI.from({
scheme: WebviewPanelResourceScheme,
path: `webview-panel/webview-${this.id}`,
query: this.editorResource ? encodeURIComponent(this.editorResource.toString(true)) : ''
path: `webview-panel/webview-${this.id}`
});
}
......@@ -157,10 +155,9 @@ export class RevivedWebviewEditorInput extends WebviewEditorInput {
readonly id: ExtensionIdentifier
},
private readonly reviver: (input: WebviewEditorInput) => Promise<void>,
webview: Unowned<WebviewEditorOverlay>,
public readonly editorResource: URI,
webview: Unowned<WebviewEditorOverlay>
) {
super(id, viewType, name, extension, webview, editorResource);
super(id, viewType, name, extension, webview);
}
public async resolve(): Promise<IEditorModel> {
......
......@@ -208,7 +208,7 @@ export class WebviewEditorService implements IWebviewEditorService {
const promise = new Promise<void>(r => { resolve = r; });
this._revivalPool.add(webview, resolve!);
return promise;
}, new UnownedDisposable(webview), null!/*TODO*/);
}, new UnownedDisposable(webview));
webviewInput.iconPath = iconPath;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册