From c2899c4b17c5da4ee1ee70bd56badaefa8d284e4 Mon Sep 17 00:00:00 2001 From: flosch62 Date: Sun, 26 Jan 2025 10:55:44 +0100 Subject: [PATCH] Add command to open lab folder in a new window --- package.json | 10 ++++++++++ src/commands/index.ts | 3 ++- src/commands/openFolderInNewWindow.ts | 19 +++++++++++++++++++ src/extension.ts | 4 +++- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/commands/openFolderInNewWindow.ts diff --git a/package.json b/package.json index dcde392..8d2452d 100644 --- a/package.json +++ b/package.json @@ -132,6 +132,11 @@ "category": "Containerlab", "icon": "$(folder-opened)" }, + { + "command": "containerlab.lab.openFolderInNewWindow", + "title": "Open Folder in New Window", + "icon": "$(folder-opened)" + }, { "command": "containerlab.node.start", "title": "Start node" @@ -239,6 +244,11 @@ "when": "viewItem == containerlabLabDeployed", "group": "labFile@2" }, + { + "command": "containerlab.lab.openFolderInNewWindow", + "when": "viewItem =~ /containerlabLab/", + "group": "labFile@3" + }, { "command": "containerlab.lab.deploy", "when": "viewItem == containerlabLabUndeployed", diff --git a/src/commands/index.ts b/src/commands/index.ts index 7c8c4a3..ba5f7f7 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -10,4 +10,5 @@ export * from "./ssh"; export * from "./showLogs"; export * from "./graph"; export * from "./copyLabPath"; -export * from "./addToWorkspace"; \ No newline at end of file +export * from "./addToWorkspace"; +export * from "./openFolderInNewWindow"; \ No newline at end of file diff --git a/src/commands/openFolderInNewWindow.ts b/src/commands/openFolderInNewWindow.ts new file mode 100644 index 0000000..afcabcb --- /dev/null +++ b/src/commands/openFolderInNewWindow.ts @@ -0,0 +1,19 @@ +import * as vscode from "vscode"; +import * as path from "path"; +import { ContainerlabNode } from "../containerlabTreeDataProvider"; + +export async function openFolderInNewWindow(node: ContainerlabNode) { + if (!node.details?.labPath) { + vscode.window.showErrorMessage("No lab path found for this lab."); + return; + } + + // The folder that contains the .clab.(yml|yaml) + const folderPath = path.dirname(node.details.labPath); + const uri = vscode.Uri.file(folderPath); + + // Force opening that folder in a brand-new window + await vscode.commands.executeCommand("vscode.openFolder", uri, { + forceNewWindow: true + }); +} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index e7c6069..c20ab4b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -11,6 +11,7 @@ import { redeploy, redeployCleanup, openLabFile, + openFolderInNewWindow, startNode, stopNode, attachShell, @@ -58,7 +59,8 @@ export async function activate(context: vscode.ExtensionContext) { })); context.subscriptions.push(vscode.commands.registerCommand('containerlab.lab.openFile', openLabFile)); - context.subscriptions.push(vscode.commands.registerCommand('containerlab.lab.addToWorkspace',addLabFolderToWorkspace)); + context.subscriptions.push(vscode.commands.registerCommand('containerlab.lab.addToWorkspace', addLabFolderToWorkspace)); + context.subscriptions.push(vscode.commands.registerCommand('containerlab.lab.openFolderInNewWindow', openFolderInNewWindow)); context.subscriptions.push(vscode.commands.registerCommand('containerlab.lab.copyPath', copyLabPath)); context.subscriptions.push(vscode.commands.registerCommand('containerlab.lab.deploy', deploy));