本文整理汇总了TypeScript中vscode.window.createWebviewPanel方法的典型用法代码示例。如果您正苦于以下问题:TypeScript window.createWebviewPanel方法的具体用法?TypeScript window.createWebviewPanel怎么用?TypeScript window.createWebviewPanel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode.window
的用法示例。
在下文中一共展示了window.createWebviewPanel方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('webviews should allow overriding allowed resource paths using localResourceRoots', async () => {
const webview = _register(vscode.window.createWebviewPanel(webviewId, 'title', { viewColumn: vscode.ViewColumn.One }, {
enableScripts: true,
localResourceRoots: [vscode.Uri.file(join(vscode.workspace.rootPath!, 'sub'))]
}));
webview.webview.html = createHtmlDocumentWithBody(/*html*/`
<script>
const vscode = acquireVsCodeApi();
window.addEventListener('message', (message) => {
const img = document.createElement('img');
img.addEventListener('load', () => { vscode.postMessage({ value: true }); });
img.addEventListener('error', () => { vscode.postMessage({ value: false }); });
img.src = message.data.src;
document.body.appendChild(img);
});
</script>`);
const workspaceRootUri = vscode.Uri.file(vscode.workspace.rootPath!).with({ scheme: 'vscode-resource' });
{
const response = sendRecieveMessage(webview, { src: workspaceRootUri.toString() + '/sub/image.png' });
assert.strictEqual((await response).value, true);
}
{
const response = sendRecieveMessage(webview, { src: workspaceRootUri.toString() + '/image.png' });
assert.strictEqual((await response).value, false);
}
});
示例2: test
test('webviews should have real view column after they are created, #56097', async () => {
const webview = _register(vscode.window.createWebviewPanel(webviewId, 'title', { viewColumn: vscode.ViewColumn.Active }, { enableScripts: true }));
// Since we used a symbolic column, we don't know what view column the webview will actually show in at first
assert.strictEqual(webview.viewColumn, undefined);
let changed = false;
const viewStateChanged = new Promise<vscode.WebviewPanelOnDidChangeViewStateEvent>((resolve) => {
webview.onDidChangeViewState(e => {
if (changed) {
throw new Error('Only expected a single view state change');
}
changed = true;
resolve(e);
}, undefined, disposables);
});
assert.strictEqual((await viewStateChanged).webviewPanel.viewColumn, vscode.ViewColumn.One);
const firstResponse = getMesssage(webview);
webview.webview.html = createHtmlDocumentWithBody(/*html*/`
<script>
const vscode = acquireVsCodeApi();
vscode.postMessage({ });
</script>`);
webview.webview.postMessage({ value: 1 });
await firstResponse;
assert.strictEqual(webview.viewColumn, vscode.ViewColumn.One);
});
示例3: show
async show(): Promise<void> {
const html = await this.getHtml();
if (this._panel === undefined) {
this._panel = window.createWebviewPanel(
this.id,
this.title,
{ viewColumn: ViewColumn.Active, preserveFocus: false },
{
retainContextWhenHidden: true,
enableFindWidget: true,
enableCommandUris: true,
enableScripts: true
}
);
this._panel.iconPath = Uri.file(Container.context.asAbsolutePath('images/gitlens-icon.png'));
this._disposablePanel = Disposable.from(
this._panel,
this._panel.onDidDispose(this.onPanelDisposed, this),
this._panel.onDidChangeViewState(this.onViewStateChanged, this),
this._panel.webview.onDidReceiveMessage(this.onMessageReceivedCore, this)
);
this._panel.webview.html = html;
}
else {
// Reset the html to get the webview to reload
this._panel.webview.html = '';
this._panel.webview.html = html;
this._panel.reveal(ViewColumn.Active, false);
}
}
示例4: conditionalTest
conditionalTest('webviews with retainContextWhenHidden should be able to recive messages while hidden', async () => {
const webview = _register(vscode.window.createWebviewPanel(webviewId, 'title', { viewColumn: vscode.ViewColumn.One }, { enableScripts: true, retainContextWhenHidden: true }));
const ready = getMesssage(webview);
webview.webview.html = statefulWebviewHtml;
await ready;
const firstResponse = await sendRecieveMessage(webview, { type: 'add' });
assert.strictEqual((await firstResponse).value, 1);
// Swap away from the webview
const doc = await vscode.workspace.openTextDocument(testDocument);
await vscode.window.showTextDocument(doc);
// Try posting a message to our hidden webview
const secondResponse = await sendRecieveMessage(webview, { type: 'add' });
assert.strictEqual((await secondResponse).value, 2);
// Now show webview again
webview.reveal(vscode.ViewColumn.One);
// We should still have old state
const thirdResponse = await sendRecieveMessage(webview, { type: 'get' });
assert.strictEqual(thirdResponse.value, 2);
});
示例5: showReleaseNotes
export async function showReleaseNotes(): Promise<void> {
if (releaseNotesPanel) {
releaseNotesPanel.reveal();
} else {
releaseNotesPanel = vscode.window.createWebviewPanel('releaseNotes', "C/C++ Extension Release Notes", vscode.ViewColumn.One);
releaseNotesPanel.webview.html = await readFileText(getExtensionFilePath("ReleaseNotes.html"));
releaseNotesPanel.onDidDispose(() => releaseNotesPanel = undefined, null, extensionContext.subscriptions);
}
}
示例6: updateWebview
let previewCommand = vscode.commands.registerCommand('shader-toy.showGlslPreview', () => {
if (webviewPanel) {
webviewPanel.dispose();
}
let options: vscode.WebviewOptions = {
enableScripts: true,
localResourceRoots: undefined
};
webviewPanel = vscode.window.createWebviewPanel(
'shadertoy',
'GLSL Preview',
vscode.ViewColumn.Two,
options
);
updateWebview();
});
示例7: async
return async ()=>
{
let conf:configure = new configure();
let local_path:string = conf.localPath;
let remote_path:string = conf.remotePath;
let r = new remote({
host: conf.ipv4addr,
port: conf.port,
username: conf.username,
password: conf.password
});
let l = new local();
let f = new fileops();
const panel = vscode.window.createWebviewPanel('uploadList','upload list',vscode.ViewColumn.One,{enableScripts: true});
panel.webview.html = "loading";
let diffInfos = await f.get_file_diff_infos(r,l,remote_path,local_path);
panel.webview.html = ui.read_panel(diffInfos);
let message:any = await new Promise((resolve)=>
{
panel.webview.onDidReceiveMessage((message)=>
{
resolve(message);
});
});
let localFiles = new Array<string>();
let remoteFiles = new Array<string>();
switch(message.command)
{
case 'upload':
for(let i = 0; i < message.selected_list.length; ++i)
{
let index:number = message.selected_list[i];
localFiles.push(diffInfos[index].local_name);
remoteFiles.push(diffInfos[index].remote_name);
}
await f.sync_files_to_remote(r, localFiles, remoteFiles);
panel.webview.html = "upload complete";
}
};