This is an automated email from the ASF dual-hosted git repository.

bamaer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new 6d809196cd Fix drop deleted projects from the project toolbar menu 
(#8703)
6d809196cd is described below

commit 6d809196cd2136b6b4ed776a1761466fd0af5446
Author: Lance <[email protected]>
AuthorDate: Wed Sep 30 20:12:13 2026 +0800

    Fix drop deleted projects from the project toolbar menu (#8703)
    
    Signed-off-by: leehaut <[email protected]>
---
 .../apache/hop/projects/gui/ProjectsGuiPlugin.java | 39 ++++++++++++++++++++--
 1 file changed, 36 insertions(+), 3 deletions(-)

diff --git 
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/gui/ProjectsGuiPlugin.java
 
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/gui/ProjectsGuiPlugin.java
index 74fb446242..10574d65b8 100644
--- 
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/gui/ProjectsGuiPlugin.java
+++ 
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/gui/ProjectsGuiPlugin.java
@@ -638,6 +638,30 @@ public class ProjectsGuiPlugin {
     }
   }
 
+  /**
+   * Remove a project from the toolbar recent list and persist that change. 
Called when a project
+   * registration is deleted so the project menu does not keep showing it.
+   */
+  public static void forgetLastUsedProject(String projectName) {
+    if (StringUtils.isEmpty(projectName)) {
+      return;
+    }
+
+    getLastUsedProjects();
+    if (!lastUsedProjects.remove(projectName)) {
+      return;
+    }
+
+    try {
+      AuditList auditList = new AuditList(new ArrayList<>(lastUsedProjects));
+      AuditManager.getActive()
+          .storeList(HopGui.DEFAULT_HOP_GUI_NAMESPACE, 
LAST_USED_PROJECTS_AUDIT_TYPE, auditList);
+    } catch (Exception e) {
+      LogChannel.GENERAL.logError(
+          "Error writing list of last used projects " + 
LAST_USED_PROJECTS_AUDIT_TYPE, e);
+    }
+  }
+
   
//////////////////////////////////////////////////////////////////////////////////
   // Environment toolbar items...
   //
@@ -873,17 +897,26 @@ public class ProjectsGuiPlugin {
 
     new MenuItem(menu, SWT.SEPARATOR);
 
-    // Display the last-used projects
+    // Display the last-used projects that are still registered in hop-config.
+    // The in-memory list can briefly lag a deletion; drop names that are 
already gone.
     List<String> names = new ArrayList<>(getLastUsedProjects());
+    List<String> registeredNames = 
ProjectsConfigSingleton.getConfig().listProjectConfigNames();
+    if (registeredNames == null) {
+      names.clear();
+    } else {
+      names.removeIf(name -> !registeredNames.contains(name));
+    }
 
     // If the user prefers to display in alphabetical order
     if 
(ProjectsConfigOptionPlugin.getInstance().getSortByNameLastUsedProjects()) {
       names.sort(String::compareToIgnoreCase);
     }
+    if (names.size() > LAST_USED_PROJECTS_MAX_ENTRIES) {
+      names = new ArrayList<>(names.subList(0, 
LAST_USED_PROJECTS_MAX_ENTRIES));
+    }
 
     String currentProjectName = HopNamespace.getNamespace();
 
-    int count = 0;
     for (String name : names) {
       MenuItem item = new MenuItem(menu, SWT.NONE);
       item.setText(name);
@@ -891,7 +924,6 @@ public class ProjectsGuiPlugin {
       if (currentProjectName.equalsIgnoreCase(name)) {
         item.setImage(GuiResource.getInstance().getImageCheck());
       }
-      if (++count == LAST_USED_PROJECTS_MAX_ENTRIES) break;
     }
 
     // Add a menu to open a dialog to select it
@@ -1392,6 +1424,7 @@ public class ProjectsGuiPlugin {
       try {
         config.removeProjectConfig(projectName);
         ProjectsConfigSingleton.saveConfig();
+        forgetLastUsedProject(projectName);
 
         if (StringUtils.isEmpty(config.getDefaultProject())) {
           updateProjectToolItem(null);

Reply via email to