From 084891cee10c3f7ef8e4eece1860ff808d5f5894 Mon Sep 17 00:00:00 2001 From: Mossy1022 Date: Wed, 11 Sep 2024 10:17:20 -0400 Subject: [PATCH] Fix for no nodes bug + only allowed one view at a time --- main.ts | 32 +++++++++++++++++++------------- manifest.json | 2 +- package.json | 2 +- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/main.ts b/main.ts index d484f63..057953c 100644 --- a/main.ts +++ b/main.ts @@ -2057,22 +2057,28 @@ export default class ScGraphView extends Plugin { // Register the new view this.registerView("smart-connections-visualizer", (leaf: WorkspaceLeaf) => new ScGraphItemView(leaf, this)); - // Register hover link source - this.registerHoverLinkSource('smart-connections-visualizer', { - display: 'Smart connections visualizer hover link source', - defaultMod: true - }); + // Register hover link source + this.registerHoverLinkSource('smart-connections-visualizer', { + display: 'Smart connections visualizer hover link source', + defaultMod: true + }); // This creates an icon in the left ribbon. this.addRibbonIcon('git-fork', 'Open smart connections visualizer', (evt: MouseEvent) => { - // Create a new leaf in the current workspace - let leaf = this.app.workspace.getLeaf(true); - - // Set the new leaf's view to your custom view - leaf.setViewState({ - type: "smart-connections-visualizer", - active: true, - }); + // Check if the view is already open + const existingLeaf = this.app.workspace.getLeavesOfType("smart-connections-visualizer")[0]; + if (existingLeaf) { + // If it exists, focus on it + this.app.workspace.setActiveLeaf(existingLeaf); + } else { + // Create a new leaf in the current workspace + let leaf = this.app.workspace.getLeaf(true); + // Set the new leaf's view to your custom view + leaf.setViewState({ + type: "smart-connections-visualizer", + active: true, + }); + } }) diff --git a/manifest.json b/manifest.json index 6126694..ce76b42 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "smart-connections-visualizer", "name": "Smart Connections Visualizer", - "version": "1.0.17", + "version": "1.0.18", "minAppVersion": "0.15.0", "description": "View your Smart Connections in a visualized format.", "author": "Evan Moscoso", diff --git a/package.json b/package.json index 558e15f..5aa3ef2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "smart-connections-visualizer", - "version": "1.0.17", + "version": "1.0.18", "description": "A plugin that allows you to view your Smart Connections in a visualized format.", "main": "main.js", "scripts": {