Wha*_*ion 7 view visual-studio-code vscode-extensions
根据此页面,网络视图可以“在侧边栏或面板区域中呈现”。这些示例展示了如何呈现为编辑器面板......
vscode.window.createWebviewPanel(
'catCoding', // Identifies the type of the webview. Used internally
'Cat Coding', // Title of the panel displayed to the user
vscode.ViewColumn.One, // Editor column to show the new webview panel in.
{} // Webview options..
);
Run Code Online (Sandbox Code Playgroud)
我正在尝试将网络视图渲染为资源管理器下侧边栏中的附加面板。
我假设对第三个参数进行某种更改vscode.ViewColumn.One?
Gam*_*a11 11
看起来createWebviewPanel()实际上只适用于编辑器中显示的网络视图。对于侧边栏,您必须使用该页面上链接registerWebviewViewProvider()中所示的内容:webview-view-sample
vscode.window.registerWebviewViewProvider('calicoColors.colorsView', provider));
Run Code Online (Sandbox Code Playgroud)
然后指定通过哪个视图显示它package.json- 该示例使用资源管理器:
{
"contributes": {
"views": {
"explorer": [
{
"type": "webview",
"id": "calicoColors.colorsView",
"name": "Calico Colors"
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
Wha*_*ion 11
@Gamma11,感谢您的回答。绝对有助于解决“定义迷宫”
稍微阐述一下(也许可以使用更严格的 JS(而不是 TS)版本来简化/澄清webview-view-sample ):
1 - 在 package.json 中,您有以下条目将视图定义为位于侧边栏资源管理器中的 Web 视图:
"views": {
"explorer": [
{
"type": "webview",
"id": "calicoColors.colorsView",
"name": "Trillion Files"
}
]
}
Run Code Online (Sandbox Code Playgroud)
2 - 同样在 package.json 中发送到 JS 的激活
"activationEvents": [
"onView:calicoColors.colorsView"
]
Run Code Online (Sandbox Code Playgroud)
3 - 在 JS 中,事件由 vscode.commands.registerCommand 拾取
function activate(context){
var thisProvider={
resolveWebviewView:function(thisWebview, thisWebviewContext, thisToken){
thisWebviewView.webview.options={enableScripts:true}
thisWebviewView.webview.html="<!doctype><html>[etc etc]";
}
};
context.subscriptions.push(
vscode.commands.registerWebviewViewProvider("calicoColors.colorView", thisProvider);
);
}
function deactivate() { }
module.exports = {
activate,
deactivate
}
Run Code Online (Sandbox Code Playgroud)
还有很多属性可以进入 thisProvider,但是这个最少的代码可以在侧边栏中启动并运行面板。
| 归档时间: |
|
| 查看次数: |
11056 次 |
| 最近记录: |