提交 4c7071e9 编写于 作者: M Matt Bierner

Add WebviewView.description

Allow configuring the description for webview views.

This is rendered next to the title in a less prominently in the title
上级 1fbd1733
......@@ -2062,6 +2062,11 @@ declare module 'vscode' {
*/
title?: string;
/**
* Human-readable string which is rendered less prominently in the title.
*/
description?: string;
/**
* Event fired when the view is disposed.
*
......
......@@ -29,13 +29,15 @@ export class MainThreadWebviewsViews extends Disposable implements extHostProtoc
}
public $setWebviewViewTitle(handle: extHostProtocol.WebviewHandle, value: string | undefined): void {
const webviewView = this._webviewViews.get(handle);
if (!webviewView) {
throw new Error('unknown webview view');
}
const webviewView = this.getWebviewView(handle);
webviewView.title = value;
}
public $setWebviewViewDescription(handle: extHostProtocol.WebviewHandle, value: string | undefined): void {
const webviewView = this.getWebviewView(handle);
webviewView.description = value;
}
public $registerWebviewViewProvider(viewType: string, options?: { retainContextWhenHidden?: boolean }): void {
if (this._webviewViewProviders.has(viewType)) {
throw new Error(`View provider for ${viewType} already registered`);
......@@ -89,5 +91,13 @@ export class MainThreadWebviewsViews extends Disposable implements extHostProtoc
provider.dispose();
this._webviewViewProviders.delete(viewType);
}
private getWebviewView(handle: string): WebviewView {
const webviewView = this._webviewViews.get(handle);
if (!webviewView) {
throw new Error('unknown webview view');
}
return webviewView;
}
}
......@@ -640,6 +640,7 @@ export interface MainThreadWebviewViewsShape extends IDisposable {
$unregisterWebviewViewProvider(viewType: string): void;
$setWebviewViewTitle(handle: WebviewHandle, value: string | undefined): void;
$setWebviewViewDescription(handle: WebviewHandle, value: string | undefined): void;
}
export interface WebviewPanelViewStateData {
......
......@@ -23,6 +23,7 @@ class ExtHostWebviewView extends Disposable implements vscode.WebviewView {
#isDisposed = false;
#isVisible: boolean;
#title: string | undefined;
#description: string | undefined;
constructor(
handle: extHostProtocol.WebviewHandle,
......@@ -70,6 +71,19 @@ class ExtHostWebviewView extends Disposable implements vscode.WebviewView {
}
}
public get description(): string | undefined {
this.assertNotDisposed();
return this.#description;
}
public set description(value: string | undefined) {
this.assertNotDisposed();
if (this.#description !== value) {
this.#description = value;
this.#proxy.$setWebviewViewDescription(this.#handle, value);
}
}
public get visible(): boolean { return this.#isVisible; }
public get webview(): vscode.Webview { return this.#webview; }
......
......@@ -23,7 +23,7 @@ import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewl
import { Memento, MementoObject } from 'vs/workbench/common/memento';
import { IViewDescriptorService } from 'vs/workbench/common/views';
import { IWebviewService, WebviewOverlay } from 'vs/workbench/contrib/webview/browser/webview';
import { IWebviewViewService } from 'vs/workbench/contrib/webviewView/browser/webviewViewService';
import { IWebviewViewService, WebviewView } from 'vs/workbench/contrib/webviewView/browser/webviewViewService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
declare const ResizeObserver: any;
......@@ -158,13 +158,19 @@ export class WebviewViewPane extends ViewPane {
await this.extensionService.activateByEvent(`onView:${this.id}`);
let self = this;
await this.webviewViewService.resolve(this.id, {
const webviewView: WebviewView = {
webview,
onDidChangeVisibility: this.onDidChangeBodyVisibility,
onDispose: this.onDispose,
get title() { return self.title; },
set title(value: string) { self.updateTitle(value); }
}, source.token);
set title(value: string) { self.updateTitle(value); },
get description(): string | undefined { return self.titleDescription; },
set description(value: string | undefined) { self.updateTitleDescription(value); },
};
await this.webviewViewService.resolve(this.id, webviewView, source.token);
});
}
}
......
......@@ -13,6 +13,7 @@ export const IWebviewViewService = createDecorator<IWebviewViewService>('webview
export interface WebviewView {
title?: string;
description?: string;
readonly webview: WebviewOverlay;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册