diff --git a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java index 6dfe663cb680..b0e68ac05305 100644 --- a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java +++ b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java @@ -139,7 +139,23 @@ public abstract class RecentProjectsManagerBase implements PersistentStateCompon protected String getProjectDisplayName(Project project) { return ""; } - + + private static Set getDuplicateProjectNames(Set openedPaths, Set recentPaths) { + Set names = ContainerUtil.newHashSet(); + Set duplicates = ContainerUtil.newHashSet(); + for (String path : openedPaths) { + if (!names.add(getProjectName(path))) { + duplicates.add(path); + } + } + for (String path : recentPaths) { + if (!names.add(getProjectName(path))) { + duplicates.add(path); + } + } + + return duplicates; + } /** * @param addClearListItem - used for detecting whether the "Clear List" action should be added @@ -149,35 +165,25 @@ public abstract class RecentProjectsManagerBase implements PersistentStateCompon public AnAction[] getRecentProjectsActions(boolean addClearListItem) { validateRecentProjects(); - Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); - - ArrayList actions = new ArrayList(); - final Map map = new LinkedHashMap(); - final List paths = new ArrayList(); - synchronized (myState) { - outer: for (String recentPath : myState.recentPaths) { - if (recentPath == null) { - continue; - } - - for (Project openProject : openProjects) { - final String path = getProjectPath(openProject); - if (path == null || recentPath.equals(path)) { - continue outer; - } - } - - final String projectName = getProjectName(recentPath); - map.put(projectName, map.containsKey(projectName) ? map.get(projectName) + 1 : 1); - paths.add(recentPath); - } + final Set openedPaths = ContainerUtil.newHashSet(); + for (Project openProject : ProjectManager.getInstance().getOpenProjects()) { + ContainerUtil.addIfNotNull(openedPaths, getProjectPath(openProject)); } + final LinkedHashSet paths; + synchronized (myState) { + paths = ContainerUtil.newLinkedHashSet(myState.recentPaths); + } + paths.remove(null); + paths.removeAll(openedPaths); + + ArrayList actions = new ArrayList(); + Set duplicates = getDuplicateProjectNames(openedPaths, paths); for (final String path : paths) { final String projectName = getProjectName(path); String displayName = myState.names.get(path); if (StringUtil.isEmptyOrSpaces(displayName)) { - displayName = map.get(projectName) > 1 ? path : projectName; + displayName = duplicates.contains(path) ? path : projectName; } actions.add(new ReopenProjectAction(path, projectName, displayName)); }