Skip to content

Commit 036f77c

Browse files
committed
Duplicates Title Is Always On
1 parent ff1c0cc commit 036f77c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

CodeEdit/Features/WindowCommands/Utils/RecentProjectsMenu.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class RecentProjectsMenu: NSObject {
1111
func makeMenu() -> NSMenu {
1212
let menu = NSMenu(title: NSLocalizedString("Open Recent", comment: "Open Recent menu title"))
1313

14-
for projectPath in RecentProjectsStore.recentProjectURLs().prefix(10) {
14+
let paths = RecentProjectsStore.recentProjectURLs().prefix(10)
15+
16+
for projectPath in paths {
1517
let icon = NSWorkspace.shared.icon(forFile: projectPath.path())
1618
icon.size = NSSize(width: 16, height: 16)
1719

@@ -24,7 +26,14 @@ class RecentProjectsMenu: NSObject {
2426
primaryItem.image = icon
2527
primaryItem.representedObject = projectPath
2628

27-
let parentPath = projectPath.deletingLastPathComponent().path(percentEncoded: false).abbreviatingWithTildeInPath()
29+
let containsDuplicate = paths.contains { url in
30+
url != projectPath && url.lastPathComponent == projectPath.lastPathComponent
31+
}
32+
33+
let parentPath = projectPath
34+
.deletingLastPathComponent()
35+
.path(percentEncoded: false)
36+
.abbreviatingWithTildeInPath()
2837
let alternateTitle = NSMutableAttributedString(
2938
string: projectPath.lastPathComponent + " ", attributes: [.foregroundColor: NSColor.labelColor]
3039
)
@@ -33,6 +42,11 @@ class RecentProjectsMenu: NSObject {
3342
attributes: [.foregroundColor: NSColor.secondaryLabelColor]
3443
))
3544

45+
// If there's a duplicate, add the path.
46+
if containsDuplicate {
47+
primaryItem.attributedTitle = alternateTitle
48+
}
49+
3650
let alternateItem = NSMenuItem(
3751
title: "",
3852
action: #selector(recentProjectItemClicked(_:)),

0 commit comments

Comments
 (0)