提交 904e4260 编写于 作者: M Matt Bierner

Introduce RevivedWebviewEditorInput

上级 98c084ff
......@@ -11,7 +11,7 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
import { ExtHostContext, ExtHostWebviewsShape, IExtHostContext, MainContext, MainThreadWebviewsShape, WebviewPanelHandle, WebviewPanelShowOptions, WebviewInsetHandle } from 'vs/workbench/api/node/extHost.protocol';
import { editorGroupToViewColumn, EditorViewColumn, viewColumnToEditorGroup } from 'vs/workbench/api/shared/editor';
import { WebviewEditor } from 'vs/workbench/contrib/webview/electron-browser/webviewEditor';
import { WebviewEditorInput } from 'vs/workbench/contrib/webview/electron-browser/webviewEditorInput';
import { WebviewEditorInput, RevivedWebviewEditorInput } from 'vs/workbench/contrib/webview/electron-browser/webviewEditorInput';
import { ICreateWebViewShowOptions, IWebviewEditorService, WebviewInputOptions, WebviewReviver } from 'vs/workbench/contrib/webview/electron-browser/webviewEditorService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
......@@ -246,7 +246,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
return false;
}
return this._revivers.has(webview.state.viewType) || !!webview.reviver;
return this._revivers.has(webview.state.viewType) || !!(webview as RevivedWebviewEditorInput).reviver;
}
private _onBeforeShutdown(): boolean {
......
......@@ -64,8 +64,6 @@ export class WebviewEditorInput extends EditorInput {
private _scrollYPercentage: number = 0;
private _state: any;
private _revived: boolean = false;
public readonly extensionLocation: URI | undefined;
private readonly _id: number;
......@@ -77,7 +75,6 @@ export class WebviewEditorInput extends EditorInput {
state: any,
events: WebviewEvents,
extensionLocation: URI | undefined,
public readonly reviver: (input: WebviewEditorInput) => Promise<void> | undefined,
@IPartService private readonly _partService: IPartService,
) {
super();
......@@ -213,10 +210,6 @@ export class WebviewEditorInput extends EditorInput {
}
public resolve(): Promise<IEditorModel> {
if (this.reviver && !this._revived) {
this._revived = true;
return this.reviver(this).then(() => new EditorModel());
}
return Promise.resolve(new EditorModel());
}
......@@ -310,3 +303,30 @@ export class WebviewEditorInput extends EditorInput {
this._group = group;
}
}
export class RevivedWebviewEditorInput extends WebviewEditorInput {
private _revived: boolean = false;
constructor(
viewType: string,
id: number | undefined,
name: string,
options: WebviewInputOptions,
state: any,
events: WebviewEvents,
extensionLocation: URI | undefined,
public readonly reviver: (input: WebviewEditorInput) => Promise<void>,
@IPartService partService: IPartService,
) {
super(viewType, id, name, options, state, events, extensionLocation, partService);
}
public async resolve(): Promise<IEditorModel> {
if (!this._revived) {
this._revived = true;
await this.reviver(this);
}
return super.resolve();
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IEditorInputFactory } from 'vs/workbench/common/editor';
import { WebviewEditorInput } from './webviewEditorInput';
import { WebviewEditorInput, RevivedWebviewEditorInput } from './webviewEditorInput';
import { IWebviewEditorService, WebviewInputOptions } from './webviewEditorService';
import { URI, UriComponents } from 'vs/base/common/uri';
......@@ -41,7 +41,7 @@ export class WebviewEditorInputFactory implements IEditorInputFactory {
}
// Only attempt revival if we may have a reviver
if (!this._webviewService.canRevive(input) && !input.reviver) {
if (!this._webviewService.canRevive(input) && !(input instanceof RevivedWebviewEditorInput)) {
return null;
}
......
......@@ -9,7 +9,7 @@ import { IInstantiationService, createDecorator } from 'vs/platform/instantiatio
import { IEditorService, ACTIVE_GROUP_TYPE, SIDE_GROUP_TYPE } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import * as vscode from 'vscode';
import { WebviewEditorInput } from './webviewEditorInput';
import { WebviewEditorInput, RevivedWebviewEditorInput } from './webviewEditorInput';
import { GroupIdentifier } from 'vs/workbench/common/editor';
import { equals } from 'vs/base/common/arrays';
......@@ -132,18 +132,17 @@ export class WebviewEditorService implements IWebviewEditorService {
options: WebviewInputOptions,
extensionLocation: URI
): WebviewEditorInput {
const webviewInput = this._instantiationService.createInstance(WebviewEditorInput, viewType, id, title, options, state, {}, extensionLocation, (webview: WebviewEditorInput): Promise<void> => {
return this.tryRevive(webview).then(didRevive => {
if (didRevive) {
return Promise.resolve(undefined);
}
// A reviver may not be registered yet. Put into queue and resolve promise when we can revive
let resolve: (value: void) => void;
const promise = new Promise<void>(r => { resolve = r; });
this._awaitingRevival.push({ input: webview, resolve: resolve! });
return promise;
});
const webviewInput = this._instantiationService.createInstance(RevivedWebviewEditorInput, viewType, id, title, options, state, {}, extensionLocation, async (webview: WebviewEditorInput): Promise<void> => {
const didRevive = await this.tryRevive(webview);
if (didRevive) {
return Promise.resolve(undefined);
}
// A reviver may not be registered yet. Put into queue and resolve promise when we can revive
let resolve: () => void;
const promise = new Promise<void>(r => { resolve = r; });
this._awaitingRevival.push({ input: webview, resolve: resolve! });
return promise;
});
webviewInput.iconPath = iconPath;
return webviewInput;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册