You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2022/03/28 19:57:40 UTC

[camel-karavan] branch main updated: Fix desugner reopen (#242)

This is an automated email from the ASF dual-hosted git repository.

marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git


The following commit(s) were added to refs/heads/main by this push:
     new b4b621c  Fix desugner reopen (#242)
b4b621c is described below

commit b4b621ce832a5f1855dcbf0b85301a101467df6e
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Mon Mar 28 15:57:35 2022 -0400

    Fix desugner reopen (#242)
---
 karavan-vscode/src/designerView.ts | 82 +++++++++++++++++++++-----------------
 1 file changed, 46 insertions(+), 36 deletions(-)

diff --git a/karavan-vscode/src/designerView.ts b/karavan-vscode/src/designerView.ts
index 80a7677..acdecf8 100644
--- a/karavan-vscode/src/designerView.ts
+++ b/karavan-vscode/src/designerView.ts
@@ -84,7 +84,6 @@ export class DesignerView {
                     const yaml = CamelDefinitionYaml.integrationToYaml(i);
                     const filename = name.toLocaleLowerCase().endsWith('.yaml') ? name : name + '.yaml';
                     const relativePath = (this.rootPath ? fullPath?.replace(this.rootPath, "") : fullPath) + path.sep + filename;
-                    console.log(relativePath);
                     utils.save(relativePath, yaml);
                     this.openKaravanWebView(filename, filename, yaml);
                     vscode.commands.executeCommand('integrations.refresh');
@@ -93,43 +92,54 @@ export class DesignerView {
     }
 
     openKaravanWebView(filename: string, relativePath: string, yaml?: string) {
-        // Karavan webview
-        const panel = vscode.window.createWebviewPanel(
-            "karavan",
-            filename,
-            vscode.ViewColumn.One,
-            {
-                enableScripts: true,
-                retainContextWhenHidden: true,
-                localResourceRoots: [
-                    vscode.Uri.joinPath(this.context.extensionUri, "dist"),
-                ],
-            }
-        );
-        panel.webview.html = this.webviewContent;
-        panel.iconPath = vscode.Uri.joinPath(
-            this.context.extensionUri,
-            "icons/karavan.svg"
-        );
-
-        // Handle messages from the webview
-        panel.webview.onDidReceiveMessage(
-            message => {
-                switch (message.command) {
-                    case 'save':
-                        utils.save(message.relativePath, message.yaml);
-                        break;
-                    case 'getData':
-                        this.sendData(panel, filename, relativePath, yaml);
-                        break;
+        if (!KARAVAN_PANELS.has(relativePath)) {
+            // Karavan webview
+            const panel = vscode.window.createWebviewPanel(
+                "karavan",
+                filename,
+                vscode.ViewColumn.One,
+                {
+                    enableScripts: true,
+                    retainContextWhenHidden: true,
+                    localResourceRoots: [
+                        vscode.Uri.joinPath(this.context.extensionUri, "dist"),
+                    ],
                 }
-            },
-            undefined,
-            this.context.subscriptions
-        );
-        KARAVAN_PANELS.set(relativePath, panel);
-        vscode.commands.executeCommand("setContext", KARAVAN_LOADED, true);
+            );
+            panel.webview.html = this.webviewContent;
+            panel.iconPath = vscode.Uri.joinPath(
+                this.context.extensionUri,
+                "icons/karavan.svg"
+            );
+
+            // Handle messages from the webview
+            panel.webview.onDidReceiveMessage(
+                message => {
+                    switch (message.command) {
+                        case 'save':
+                            utils.save(message.relativePath, message.yaml);
+                            break;
+                        case 'getData':
+                            this.sendData(panel, filename, relativePath, yaml);
+                            break;
+                    }
+                },
+                undefined,
+                this.context.subscriptions
+            );
+            // Handle close event
+            panel.onDidDispose(() => {
+                console.log("close panel", relativePath)
+                KARAVAN_PANELS.delete(relativePath);
+            }, null, this.context.subscriptions);
+
+            KARAVAN_PANELS.set(relativePath, panel);
+            vscode.commands.executeCommand("setContext", KARAVAN_LOADED, true);
+        } else {
+            KARAVAN_PANELS.get(relativePath)?.reveal(undefined, true);
+        }
     }
+
     sendData(panel: vscode.WebviewPanel, filename: string, relativePath: string, yaml?: string) {
 
         // Read and send Kamelets