vscode#WebviewViewResolveContext TypeScript Examples
The following examples show how to use
vscode#WebviewViewResolveContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: trivy_helpview.ts From trivy-vscode-extension with Apache License 2.0 | 5 votes |
resolveWebviewView(webviewView: WebviewView, _context: WebviewViewResolveContext<unknown>, _token: CancellationToken): void | Thenable<void> {
this.view = webviewView.webview;
this.update(null);
}
Example #2
Source File: webviewView.ts From vscode-todo-md with MIT License | 4 votes |
public resolveWebviewView(
webviewView: WebviewView,
context: WebviewViewResolveContext,
_token: CancellationToken,
) {
this._view = webviewView;
const localResourceRoots = [
this._extensionUri,
];
if ($config.webview.customCSSPath) {
localResourceRoots.push(Uri.file(path.dirname($config.webview.customCSSPath)));
}
webviewView.webview.options = {
enableScripts: true,
enableCommandUris: true,
localResourceRoots,
};
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
webviewView.webview.onDidReceiveMessage(async (message: MessageFromWebview) => {
switch (message.type) {
// ──── Needs to update everything ────────────────────────────
case 'webviewLoaded': {
this.sendEverything();
break;
}
case 'toggleDone': {
await toggleDoneAtLine(await getActiveOrDefaultDocument(), message.value);
await updateEverything();
break;
}
case 'toggleTaskCollapse': {
await toggleTaskCollapse(await getActiveOrDefaultDocument(), message.value);
await updateEverything();
break;
}
case 'editTask': {
await editTask(await getActiveOrDefaultDocument(), message.value);
await updateEverything();
break;
}
case 'startTask': {
await startTaskAtLine(message.value, await getActiveOrDefaultDocument());
await updateEverything();
break;
}
case 'toggleTaskCollapseRecursive': {
await toggleTaskCollapseRecursive(await getActiveOrDefaultDocument(), message.value);
await updateEverything();
break;
}
case 'incrementCount': {
await incrementCountForTask(await getActiveOrDefaultDocument(), message.value, getTaskAtLineExtension(message.value)!);
await updateEverything();
break;
}
case 'decrementCount': {
await decrementCountForTask(await getActiveOrDefaultDocument(), message.value, getTaskAtLineExtension(message.value)!);
await updateEverything();
break;
}
case 'deleteTask': {
await tryToDeleteTask(await getActiveOrDefaultDocument(), message.value);
await updateEverything();
break;
}
case 'editTaskRawText': {
await editTaskRawText(await getActiveOrDefaultDocument(), message.value.lineNumber, message.value.newRawText);
await updateEverything();
break;
}
// ──── No need to update everything ──────────────────────────
case 'showNotification': {
window.showInformationMessage(message.value);
break;
}
case 'goToTask': {
revealTask(message.value);
break;
}
case 'updateWebviewTitle': {
this.updateTitle(message.value);
break;
}
case 'followLink': {
followLink(message.value);
break;
}
case 'setDueDate': {
openSetDueDateInputbox(await getActiveOrDefaultDocument(), [message.value]);
break;
}
}
});
/**
* Update webview on it's visibility change (only when it becomes visible).
*/
webviewView.onDidChangeVisibility(e => {
if (webviewView.visible === true) {
this.sendEverything();
}
});
}