From 17a46f6be70d8757a1ae9ad8338cb02b1216d9c7 Mon Sep 17 00:00:00 2001 From: Steve Hannah Date: Wed, 1 Jan 2025 16:59:43 -0800 Subject: [PATCH] feat: add menu item to open project directory --- .../weblite/jdeploy/gui/JDeployProjectEditor.java | 15 +++++++++++++++ .../weblite/jdeploy/interop/DesktopInterop.java | 4 ++++ .../jdeploy/services/GithubTokenService.java | 4 ++++ .../jdeploy/github/config/GithubConfig.java | 4 ++++ 4 files changed, 27 insertions(+) diff --git a/cli/src/main/java/ca/weblite/jdeploy/gui/JDeployProjectEditor.java b/cli/src/main/java/ca/weblite/jdeploy/gui/JDeployProjectEditor.java index e60eb3e7..2ce02819 100644 --- a/cli/src/main/java/ca/weblite/jdeploy/gui/JDeployProjectEditor.java +++ b/cli/src/main/java/ca/weblite/jdeploy/gui/JDeployProjectEditor.java @@ -1525,8 +1525,23 @@ private void initMenu() { openInTextEditor.setToolTipText("Open the package.json file for editing in your system text editor"); openInTextEditor.addActionListener(evt-> handleOpenInTextEditor()); + + JMenuItem openProjectDirectory = new JMenuItem("Open Project Directory"); + openProjectDirectory.setToolTipText("Open the project directory in your system file manager"); + openProjectDirectory.addActionListener(evt->{ + if (context.getDesktopInterop().isDesktopSupported()) { + try { + context.getDesktopInterop().openDirectory(packageJSONFile.getParentFile()); + } catch (Exception ex) { + showError("Failed to open project directory in file manager", ex); + } + } else { + showError("That feature isn't supported on this platform.", null); + } + }); file.addSeparator(); file.add(openInTextEditor); + file.add(openProjectDirectory); generateGithubWorkflowMenuItem = new JMenuItem("Create Github Workflow"); generateGithubWorkflowMenuItem.setToolTipText( diff --git a/cli/src/main/java/ca/weblite/jdeploy/interop/DesktopInterop.java b/cli/src/main/java/ca/weblite/jdeploy/interop/DesktopInterop.java index 11687563..4381dfdc 100644 --- a/cli/src/main/java/ca/weblite/jdeploy/interop/DesktopInterop.java +++ b/cli/src/main/java/ca/weblite/jdeploy/interop/DesktopInterop.java @@ -15,6 +15,10 @@ public void browse(URI url) throws Exception { Desktop.getDesktop().browse(url); } + public void openDirectory(File file) throws Exception { + Desktop.getDesktop().open(file); + } + public boolean isDesktopSupported() { return Desktop.isDesktopSupported(); } diff --git a/cli/src/main/java/ca/weblite/jdeploy/services/GithubTokenService.java b/cli/src/main/java/ca/weblite/jdeploy/services/GithubTokenService.java index 1512157d..4156f951 100644 --- a/cli/src/main/java/ca/weblite/jdeploy/services/GithubTokenService.java +++ b/cli/src/main/java/ca/weblite/jdeploy/services/GithubTokenService.java @@ -16,4 +16,8 @@ public GithubTokenService(GithubConfig config) { public String getToken() { return config.getToken(); } + + public void setToken(String token) { + config.setToken(token); + } } diff --git a/shared/src/main/java/ca/weblite/jdeploy/github/config/GithubConfig.java b/shared/src/main/java/ca/weblite/jdeploy/github/config/GithubConfig.java index 2a5096d2..0453f808 100644 --- a/shared/src/main/java/ca/weblite/jdeploy/github/config/GithubConfig.java +++ b/shared/src/main/java/ca/weblite/jdeploy/github/config/GithubConfig.java @@ -17,4 +17,8 @@ public GithubConfig(Config config) { public String getToken() { return config.getProperties().getProperty("github.token"); } + + public String setToken(String token) { + return (String) config.getProperties().setProperty("github.token", token); + } }