refactor: optimize core engine and retrieval logic for v2.80.43
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { ApprovalQueue, Approval } from './approvalQueue';
|
||||
import { wrapPanelAsView } from '../../sidebarProvider';
|
||||
|
||||
/**
|
||||
* A small webview view that surfaces the currently pending approval, separate
|
||||
@@ -14,6 +15,7 @@ export class ApprovalPanelProvider implements vscode.WebviewViewProvider {
|
||||
public static readonly viewType = 'g1nation-approval-panel';
|
||||
|
||||
private _view?: vscode.WebviewView;
|
||||
private _panel?: vscode.WebviewPanel;
|
||||
private _subscription?: vscode.Disposable;
|
||||
|
||||
constructor(
|
||||
@@ -22,6 +24,32 @@ export class ApprovalPanelProvider implements vscode.WebviewViewProvider {
|
||||
) {}
|
||||
|
||||
public resolveWebviewView(view: vscode.WebviewView): void {
|
||||
this._initView(view);
|
||||
}
|
||||
|
||||
/** Open the approvals UI as an editor panel (Column 3 by default). */
|
||||
public openAsPanel(column: vscode.ViewColumn = vscode.ViewColumn.Three): vscode.WebviewPanel {
|
||||
if (this._panel) {
|
||||
this._panel.reveal(column);
|
||||
return this._panel;
|
||||
}
|
||||
const panel = vscode.window.createWebviewPanel(
|
||||
ApprovalPanelProvider.viewType,
|
||||
'Pending Approvals',
|
||||
column,
|
||||
{ enableScripts: true, localResourceRoots: [this._extensionUri], retainContextWhenHidden: true }
|
||||
);
|
||||
this._panel = panel;
|
||||
const adapter = wrapPanelAsView(panel);
|
||||
panel.onDidDispose(() => {
|
||||
if (this._panel === panel) this._panel = undefined;
|
||||
if (this._view === adapter) this._view = undefined;
|
||||
});
|
||||
this._initView(adapter);
|
||||
return panel;
|
||||
}
|
||||
|
||||
private _initView(view: vscode.WebviewView): void {
|
||||
this._view = view;
|
||||
view.webview.options = { enableScripts: true, localResourceRoots: [this._extensionUri] };
|
||||
view.webview.html = this._render(this._queue.current());
|
||||
@@ -40,13 +68,17 @@ export class ApprovalPanelProvider implements vscode.WebviewViewProvider {
|
||||
view.onDidDispose(() => {
|
||||
this._subscription?.dispose();
|
||||
this._subscription = undefined;
|
||||
this._view = undefined;
|
||||
if (this._view === view) this._view = undefined;
|
||||
});
|
||||
}
|
||||
|
||||
/** Bring the panel into focus; used by the status bar badge. */
|
||||
public focus(): void {
|
||||
void vscode.commands.executeCommand(`${ApprovalPanelProvider.viewType}.focus`);
|
||||
if (this._panel) {
|
||||
this._panel.reveal(this._panel.viewColumn ?? vscode.ViewColumn.Three);
|
||||
return;
|
||||
}
|
||||
this.openAsPanel();
|
||||
}
|
||||
|
||||
private _render(approval: Approval | null): string {
|
||||
|
||||
Reference in New Issue
Block a user