Skip to content

Commit

Permalink
Updated Path & toggle CLArg shortcuts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BeardyKing committed Dec 5, 2023
1 parent 16a559d commit 836ccf6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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));
Expand Down Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit 836ccf6

Please sign in to comment.