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

Add show method to webview view

Fixes #106085
上级 93a0c99f
......@@ -2095,6 +2095,15 @@ declare module 'vscode' {
* Note that hiding a view using the context menu instead disposes of the view and fires `onDidDispose`.
*/
readonly onDidChangeVisibility: Event<void>;
/**
* Reveal the view in the UI.
*
* If the view is collapsed, this will expand it.
*
* @param preserveFocus When `true` the view will not take focus.
*/
show(preserveFocus?: boolean): void;
}
interface WebviewViewResolveContext<T = unknown> {
......
......@@ -38,6 +38,11 @@ export class MainThreadWebviewsViews extends Disposable implements extHostProtoc
webviewView.description = value;
}
public $show(handle: extHostProtocol.WebviewHandle, preserveFocus: boolean): void {
const webviewView = this.getWebviewView(handle);
webviewView.show(preserveFocus);
}
public $registerWebviewViewProvider(viewType: string, options?: { retainContextWhenHidden?: boolean }): void {
if (this._webviewViewProviders.has(viewType)) {
throw new Error(`View provider for ${viewType} already registered`);
......
......@@ -641,6 +641,8 @@ export interface MainThreadWebviewViewsShape extends IDisposable {
$setWebviewViewTitle(handle: WebviewHandle, value: string | undefined): void;
$setWebviewViewDescription(handle: WebviewHandle, value: string | undefined): void;
$show(handle: WebviewHandle, preserveFocus: boolean): void;
}
export interface WebviewPanelViewStateData {
......
......@@ -99,6 +99,11 @@ class ExtHostWebviewView extends Disposable implements vscode.WebviewView {
this.#onDidChangeVisibility.fire();
}
public show(preserveFocus?: boolean): void {
this.assertNotDisposed();
this.#proxy.$show(this.#handle, !!preserveFocus);
}
private assertNotDisposed() {
if (this.#isDisposed) {
throw new Error('Webview is disposed');
......
......@@ -21,7 +21,7 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
import { ViewPane } from 'vs/workbench/browser/parts/views/viewPaneContainer';
import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewlet';
import { Memento, MementoObject } from 'vs/workbench/common/memento';
import { IViewDescriptorService } from 'vs/workbench/common/views';
import { IViewDescriptorService, IViewsService } from 'vs/workbench/common/views';
import { IWebviewService, WebviewOverlay } from 'vs/workbench/contrib/webview/browser/webview';
import { IWebviewViewService, WebviewView } from 'vs/workbench/contrib/webviewView/browser/webviewViewService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
......@@ -57,6 +57,7 @@ export class WebviewViewPane extends ViewPane {
@IProgressService private readonly progressService: IProgressService,
@IWebviewService private readonly webviewService: IWebviewService,
@IWebviewViewService private readonly webviewViewService: IWebviewViewService,
@IViewsService private readonly viewService: IViewsService,
) {
super({ ...options, titleMenuId: MenuId.ViewTitle }, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);
......@@ -168,6 +169,10 @@ export class WebviewViewPane extends ViewPane {
get description(): string | undefined { return self.titleDescription; },
set description(value: string | undefined) { self.updateTitleDescription(value); },
show: (preserveFocus) => {
this.viewService.openView(this.id, !preserveFocus);
}
};
await this.webviewViewService.resolve(this.id, webviewView, source.token);
......
......@@ -19,6 +19,8 @@ export interface WebviewView {
readonly onDidChangeVisibility: Event<boolean>;
readonly onDispose: Event<void>;
show(preserveFocus: boolean): void;
}
export interface IWebviewViewResolver {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册