Skip to content

Commit

Permalink
Duplicates Title Is Always On
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoolwinter committed Nov 8, 2024
1 parent ff1c0cc commit 036f77c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions CodeEdit/Features/WindowCommands/Utils/RecentProjectsMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class RecentProjectsMenu: NSObject {
func makeMenu() -> NSMenu {

Check failure on line 11 in CodeEdit/Features/WindowCommands/Utils/RecentProjectsMenu.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Function body should span 50 lines or less excluding comments and whitespace: currently spans 53 lines (function_body_length)
let menu = NSMenu(title: NSLocalizedString("Open Recent", comment: "Open Recent menu title"))

for projectPath in RecentProjectsStore.recentProjectURLs().prefix(10) {
let paths = RecentProjectsStore.recentProjectURLs().prefix(10)

for projectPath in paths {
let icon = NSWorkspace.shared.icon(forFile: projectPath.path())
icon.size = NSSize(width: 16, height: 16)

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

let parentPath = projectPath.deletingLastPathComponent().path(percentEncoded: false).abbreviatingWithTildeInPath()
let containsDuplicate = paths.contains { url in
url != projectPath && url.lastPathComponent == projectPath.lastPathComponent
}

let parentPath = projectPath
.deletingLastPathComponent()
.path(percentEncoded: false)
.abbreviatingWithTildeInPath()
let alternateTitle = NSMutableAttributedString(
string: projectPath.lastPathComponent + " ", attributes: [.foregroundColor: NSColor.labelColor]
)
Expand All @@ -33,6 +42,11 @@ class RecentProjectsMenu: NSObject {
attributes: [.foregroundColor: NSColor.secondaryLabelColor]
))

// If there's a duplicate, add the path.
if containsDuplicate {
primaryItem.attributedTitle = alternateTitle
}

let alternateItem = NSMenuItem(
title: "",
action: #selector(recentProjectItemClicked(_:)),
Expand Down

0 comments on commit 036f77c

Please sign in to comment.