From 836ccf64096fdde35783e22bf7e3b16498e3c760 Mon Sep 17 00:00:00 2001 From: BeardyKing <39307332+BeardyKing@users.noreply.github.com> Date: Tue, 5 Dec 2023 19:06:58 +0000 Subject: [PATCH] Updated Path & toggle CLArg shortcuts Updated spacebar & middle mouse click toggle to correctly update the tree Updated the saving location of CLArgs.json to a per project .idea folder, prior to this the CLArgs.json was global to all project which is not ideal --- .../beardyking/simpleclargs/ui/CLArgumentTree.java | 13 +++++++++++-- .../beardyking/simpleclargs/utils/CLArgUtils.java | 9 +++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/beardyking/simpleclargs/ui/CLArgumentTree.java b/src/main/java/com/github/beardyking/simpleclargs/ui/CLArgumentTree.java index 395df83..129bb0e 100644 --- a/src/main/java/com/github/beardyking/simpleclargs/ui/CLArgumentTree.java +++ b/src/main/java/com/github/beardyking/simpleclargs/ui/CLArgumentTree.java @@ -48,7 +48,7 @@ import static java.util.Arrays.sort; public class CLArgumentTree { - public static String filePath = "CLArgs.json"; + public static String saveFileName = "CLArgs.json"; public final JPanel frame = new JPanel(new BorderLayout()); static Dimension squareButtonSize = new Dimension(32, 32); @@ -146,6 +146,9 @@ public void mouseClicked(MouseEvent e) { Rectangle checkBoxBounds = tree.getPathBounds(clickedPath); if (checkBoxBounds != null && checkBoxBounds.contains(e.getPoint())) { toggleSelectedNodes(tree); + updatePreviewNodeText(); + CLArgUtils.saveCommandTreeToFile(); + updateClargData(updateNodeTexts(rootNode)); tree.repaint(); } } @@ -157,7 +160,10 @@ public void mouseClicked(MouseEvent e) { private JPanel createTreeTab() { JPanel frame = new JBPanel<>(new BorderLayout()); NodeDataJsonParser jsonParser = new NodeDataJsonParser(); - rootNode = jsonParser.loadNodeDataTreeFromJson(filePath); + Project project = ProjectManager.getInstance().getOpenProjects()[0]; + String basePath = project.getBasePath(); + String saveFilePath = basePath + "/.idea/" + saveFileName; + rootNode = jsonParser.loadNodeDataTreeFromJson(saveFilePath); if (rootNode == null) { rootNode = new DefaultMutableTreeNode(new NodeData(true, "CL Args", false)); @@ -292,6 +298,9 @@ public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { toggleSelectedNodes(tree); + updatePreviewNodeText(); + CLArgUtils.saveCommandTreeToFile(); + updateClargData(updateNodeTexts(rootNode)); tree.repaint(); } } diff --git a/src/main/java/com/github/beardyking/simpleclargs/utils/CLArgUtils.java b/src/main/java/com/github/beardyking/simpleclargs/utils/CLArgUtils.java index a87f83d..0eff3b7 100644 --- a/src/main/java/com/github/beardyking/simpleclargs/utils/CLArgUtils.java +++ b/src/main/java/com/github/beardyking/simpleclargs/utils/CLArgUtils.java @@ -1,6 +1,8 @@ package com.github.beardyking.simpleclargs.utils; import com.github.beardyking.simpleclargs.serialization.NodeDataJsonParser; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; @@ -9,13 +11,16 @@ import javax.swing.tree.TreePath; import java.util.Enumeration; -import static com.github.beardyking.simpleclargs.ui.CLArgumentTree.filePath; +import static com.github.beardyking.simpleclargs.ui.CLArgumentTree.saveFileName; import static com.github.beardyking.simpleclargs.ui.CLArgumentTree.rootNode; public class CLArgUtils { public static void saveCommandTreeToFile() { NodeDataJsonParser jsonParser = new NodeDataJsonParser(); - jsonParser.saveNodeDataTreeToJson(rootNode, filePath); + Project project = ProjectManager.getInstance().getOpenProjects()[0]; + String basePath = project.getBasePath(); + String saveFilePath = basePath + "/.idea/" + saveFileName; + jsonParser.saveNodeDataTreeToJson(rootNode, saveFilePath); } public static void expandAllNodes(JTree tree, TreePath parentPath) {