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

Push `editorResource` concept back into `CustomFileEditorInput`

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