]> Git Repo - pico-vscode.git/commitdiff
Only have one panel open at a time
authorWilliam Vinnicombe <[email protected]>
Wed, 17 Jan 2024 18:09:06 +0000 (18:09 +0000)
committerWilliam Vinnicombe <[email protected]>
Mon, 12 Feb 2024 11:34:37 +0000 (11:34 +0000)
Signed-off-by: William Vinnicombe <[email protected]>
src/commands/openSdkDocumentation.mts

index ed58692fc16342d0dcbd63fc5123f12b66b659f7..601b50f01029d1663fa313e36f6af77ed4f603c3 100644 (file)
@@ -38,6 +38,7 @@ export default class OpenSdkDocumentationCommand extends CommandWithArgs {
   private _logger: Logger = new Logger("OpenSdkDocumentationCommand");
 
   public static readonly id = "openSdkDocumentation";
+  private _panel: WebviewPanel|undefined = undefined;
 
   constructor(private readonly _extensionUri: Uri) {
     super(OpenSdkDocumentationCommand.id);
@@ -72,18 +73,23 @@ export default class OpenSdkDocumentationCommand extends CommandWithArgs {
 
     // show webview
     this._logger.info("Opening SDK documentation in browser...");
-    const panel = window.createWebviewPanel(
-      "pico-sdk-documentation",
-      "Pico SDK Documentation",
-      { viewColumn: ViewColumn.Two, preserveFocus: false },
-      {
-        enableScripts: true,
-        retainContextWhenHidden: true,
-        enableFindWidget: true,
-        localResourceRoots: [Uri.joinPath(this._extensionUri, "web", "docs")],
-        enableCommandUris: true,
-      }
-    );
+    if (this._panel === undefined){
+      Logger.log("New panel");
+      this._panel = window.createWebviewPanel(
+        "pico-sdk-documentation",
+        "Pico SDK Documentation",
+        { viewColumn: ViewColumn.Two, preserveFocus: false },
+        {
+          enableScripts: true,
+          retainContextWhenHidden: true,
+          enableFindWidget: true,
+          localResourceRoots: [Uri.joinPath(this._extensionUri, "web", "docs")],
+          enableCommandUris: true,
+        }
+      );
+    }
+
+    const panel = this._panel;
 
     panel.webview.html = this._getHtmlForWebview(
       Uri.joinPath(this._extensionUri, "web", "docs", url).fsPath,
@@ -97,6 +103,13 @@ export default class OpenSdkDocumentationCommand extends CommandWithArgs {
       this._extensionUri
     );
     panel.reveal();
+
+    // dispose when hidden
+    panel.onDidDispose(
+      event => {
+        this._panel = undefined;
+      }, this
+    );
   }
 
   private _getHtmlForWebview(
This page took 0.033918 seconds and 4 git commands to generate.