From c014158904b6de6a1538f877c7c85713d60128cb 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 +++++++++- .../src/org/netbeans/modules/ide/branding/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..ddc3676fcb55 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 (ide.branding) 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/nb/ide.branding/src/org/netbeans/modules/ide/branding/layer.xml b/nb/ide.branding/src/org/netbeans/modules/ide/branding/layer.xml index 5228863f1144..37dd850ca9ee 100644 --- a/nb/ide.branding/src/org/netbeans/modules/ide/branding/layer.xml +++ b/nb/ide.branding/src/org/netbeans/modules/ide/branding/layer.xml @@ -38,6 +38,14 @@ + + + + + + + +