Skip to content

Commit ced01db

Browse files
committed
Make Function Shorter
1 parent 036f77c commit ced01db

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

CodeEdit/Features/WindowCommands/Utils/RecentProjectsMenu.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class RecentProjectsMenu: NSObject {
1616
for projectPath in paths {
1717
let icon = NSWorkspace.shared.icon(forFile: projectPath.path())
1818
icon.size = NSSize(width: 16, height: 16)
19+
let alternateTitle = alternateTitle(for: projectPath)
1920

2021
let primaryItem = NSMenuItem(
2122
title: projectPath.lastPathComponent,
@@ -30,18 +31,6 @@ class RecentProjectsMenu: NSObject {
3031
url != projectPath && url.lastPathComponent == projectPath.lastPathComponent
3132
}
3233

33-
let parentPath = projectPath
34-
.deletingLastPathComponent()
35-
.path(percentEncoded: false)
36-
.abbreviatingWithTildeInPath()
37-
let alternateTitle = NSMutableAttributedString(
38-
string: projectPath.lastPathComponent + " ", attributes: [.foregroundColor: NSColor.labelColor]
39-
)
40-
alternateTitle.append(NSAttributedString(
41-
string: parentPath,
42-
attributes: [.foregroundColor: NSColor.secondaryLabelColor]
43-
))
44-
4534
// If there's a duplicate, add the path.
4635
if containsDuplicate {
4736
primaryItem.attributedTitle = alternateTitle
@@ -76,6 +65,21 @@ class RecentProjectsMenu: NSObject {
7665
return menu
7766
}
7867

68+
private func alternateTitle(for projectPath: URL) -> NSAttributedString {
69+
let parentPath = projectPath
70+
.deletingLastPathComponent()
71+
.path(percentEncoded: false)
72+
.abbreviatingWithTildeInPath()
73+
let alternateTitle = NSMutableAttributedString(
74+
string: projectPath.lastPathComponent + " ", attributes: [.foregroundColor: NSColor.labelColor]
75+
)
76+
alternateTitle.append(NSAttributedString(
77+
string: parentPath,
78+
attributes: [.foregroundColor: NSColor.secondaryLabelColor]
79+
))
80+
return alternateTitle
81+
}
82+
7983
@objc
8084
func recentProjectItemClicked(_ sender: NSMenuItem) {
8185
guard let projectURL = sender.representedObject as? URL else {

0 commit comments

Comments
 (0)