From 57148c61a701ff8ff0d8b2caa016b39b1b70f8a0 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Mon, 8 Sep 2025 08:55:17 +0200 Subject: [PATCH] Add NetBeansProjects dir to Favorites tab - projects dir is now registered as favorite - fixed bug: when a custom project dir location is specified by setting 'netbeans.projects.dir', the dir is now automatically created, instead of falling back to the default dir, which gave the impression that the property isn't working --- .../modules/project/ui/OpenProjectListSettings.java | 7 +++++-- .../netbeans/modules/project/ui/ProjectUtilities.java | 10 +++++++++- .../netbeans/modules/project/ui/resources/layer.xml | 8 ++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ide/projectui/src/org/netbeans/modules/project/ui/OpenProjectListSettings.java b/ide/projectui/src/org/netbeans/modules/project/ui/OpenProjectListSettings.java index 2032e89c83e1..fa602d15f00f 100644 --- a/ide/projectui/src/org/netbeans/modules/project/ui/OpenProjectListSettings.java +++ b/ide/projectui/src/org/netbeans/modules/project/ui/OpenProjectListSettings.java @@ -38,7 +38,7 @@ */ public class OpenProjectListSettings { - private static OpenProjectListSettings INSTANCE = new OpenProjectListSettings(); + private static final OpenProjectListSettings INSTANCE = new OpenProjectListSettings(); private static final String RECENT_PROJECTS_DISPLAY_NAMES = "RecentProjectsDisplayNames"; //NOI18N private static final String RECENT_PROJECTS_DISPLAY_ICONS = "RecentProjectsIcons"; //NOI18N @@ -310,8 +310,11 @@ public File getProjectsFolder(boolean create) { if (result == null || !(new File(result)).exists()) { // property for overriding default projects dir location String userPrjDir = System.getProperty("netbeans.projects.dir"); // NOI18N - if (userPrjDir != null) { + if (userPrjDir != null && !userPrjDir.isBlank()) { File f = new File(userPrjDir); + if (create && !f.exists()) { + f.mkdirs(); + } if (f.exists() && f.isDirectory()) { return FileUtil.normalizeFile(f); } diff --git a/ide/projectui/src/org/netbeans/modules/project/ui/ProjectUtilities.java b/ide/projectui/src/org/netbeans/modules/project/ui/ProjectUtilities.java index 388524766847..5f992c213160 100644 --- a/ide/projectui/src/org/netbeans/modules/project/ui/ProjectUtilities.java +++ b/ide/projectui/src/org/netbeans/modules/project/ui/ProjectUtilities.java @@ -44,7 +44,6 @@ import org.netbeans.api.actions.Openable; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectUtils; -import static org.netbeans.modules.project.ui.Bundle.*; import org.netbeans.modules.project.ui.groups.Group; import org.netbeans.spi.project.AuxiliaryConfiguration; import org.netbeans.spi.project.ui.support.ProjectConvertors; @@ -60,6 +59,7 @@ import org.openide.util.Exceptions; import org.openide.util.Mutex; import org.openide.util.NbBundle.Messages; +import org.openide.util.Utilities; import org.openide.windows.Mode; import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; @@ -68,6 +68,8 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import static org.netbeans.modules.project.ui.Bundle.*; + /** The util methods for projectui module. * * @author Jiri Rechtacek @@ -601,6 +603,12 @@ private static List getOpenFilesUrls(Project p, String groupName) { } return new ArrayList<>(set); } + + // called from layer.xml on Favorites tab open + public static URL getProjectsFolder() throws MalformedURLException { + File projectsFolder = OpenProjectListSettings.getInstance().getProjectsFolder(true); + return Utilities.toURI(projectsFolder).toURL(); + } // interface for handling project's documents stored in project private.xml // it serves for a unit test of OpenProjectList diff --git a/ide/projectui/src/org/netbeans/modules/project/ui/resources/layer.xml b/ide/projectui/src/org/netbeans/modules/project/ui/resources/layer.xml index cfcb8b01328f..2ee5b5b059c4 100644 --- a/ide/projectui/src/org/netbeans/modules/project/ui/resources/layer.xml +++ b/ide/projectui/src/org/netbeans/modules/project/ui/resources/layer.xml @@ -130,6 +130,14 @@ + + + + + + + +