@@ -24,28 +24,29 @@ class RecentProjectsMenu: NSObject {
2424 primaryItem. image = icon
2525 primaryItem. representedObject = projectPath
2626
27- // let alternateTitle = NSMutableAttributedString(
28- // string: projectPath.lastPathComponent + " ", attributes: [.foregroundColor: NSColor.labelColor]
29- // )
30- // alternateTitle.append(NSAttributedString(
31- // string: path,
32- // attributes: [.foregroundColor: NSColor.secondaryLabelColor]
33- // ))
34- //
35- // let alternateItem = NSMenuItem(
36- // title: "",
37- // action: #selector(recentProjectItemClicked(_:)),
38- // keyEquivalent: ""
39- // )
40- // alternateItem.attributedTitle = alternateTitle
41- // alternateItem.target = self
42- // alternateItem.image = icon
43- // alternateItem.representedObject = projectPath
44- // alternateItem.isAlternate = true
45- // alternateItem.keyEquivalentModifierMask = [.option]
27+ let parentPath = projectPath. deletingLastPathComponent ( ) . path ( percentEncoded: false ) . abbreviatingWithTildeInPath ( )
28+ let alternateTitle = NSMutableAttributedString (
29+ string: projectPath. lastPathComponent + " " , attributes: [ . foregroundColor: NSColor . labelColor]
30+ )
31+ alternateTitle. append ( NSAttributedString (
32+ string: parentPath,
33+ attributes: [ . foregroundColor: NSColor . secondaryLabelColor]
34+ ) )
35+
36+ let alternateItem = NSMenuItem (
37+ title: " " ,
38+ action: #selector( recentProjectItemClicked ( _: ) ) ,
39+ keyEquivalent: " "
40+ )
41+ alternateItem. attributedTitle = alternateTitle
42+ alternateItem. target = self
43+ alternateItem. image = icon
44+ alternateItem. representedObject = projectPath
45+ alternateItem. isAlternate = true
46+ alternateItem. keyEquivalentModifierMask = [ . option]
4647
4748 menu. addItem ( primaryItem)
48- // menu.addItem(alternateItem)
49+ menu. addItem ( alternateItem)
4950 }
5051
5152 menu. addItem ( NSMenuItem . separator ( ) )
@@ -77,80 +78,4 @@ class RecentProjectsMenu: NSObject {
7778 func clearMenuItemClicked( _ sender: NSMenuItem ) {
7879 RecentProjectsStore . clearList ( )
7980 }
80-
81- private func duplicateProjectMenuItem( _ projectPath: URL ) -> NSMenuItem {
82- let item = NSMenuItem ( )
83- let stack = NSStackView ( )
84- stack. orientation = . horizontal
85- stack. spacing = 8
86-
87- let icon = NSImageView ( image: NSWorkspace . shared. icon ( forFile: projectPath. path ( ) ) )
88- icon. frame. size = NSSize ( width: 16 , height: 16 )
89- let title = NSTextField ( labelWithString: projectPath. lastPathComponent)
90-
91- let separator = NSTextField ( labelWithString: " ⎯ " )
92-
93- let projectParent = projectPath. deletingLastPathComponent ( )
94-
95- let secondaryIcon = NSImageView ( image: NSWorkspace . shared. icon ( forFile: projectParent. path ( ) ) )
96- secondaryIcon. frame. size = NSSize ( width: 16 , height: 16 )
97- let secondaryTitle = NSTextField (
98- labelWithString: projectParent. path ( percentEncoded: false ) . abbreviatingWithTildeInPath ( )
99- )
100-
101- stack. addArrangedSubview ( icon)
102- stack. addArrangedSubview ( title)
103- stack. addArrangedSubview ( secondaryIcon)
104- stack. addArrangedSubview ( secondaryTitle)
105-
106- item. view = stack
107-
108- return item
109- }
11081}
111-
112- //struct RecentProjectsMenu: View {
113- // @State private var recentProjects: [URL] = []
114- // @State private var controlKeyPressed: Bool = false
115- //
116- // var body: some View {
117- // Group {
118- // ForEach(recentProjects, id: \.self) { url in
119- // Button {
120- // NSDocumentController.shared.openDocument(
121- // withContentsOf: url,
122- // display: true,
123- // completionHandler: { _, _, _ in }
124- // )
125- // } label: {
126- // RecentProjectMenuItem(
127- // projectPath: url,
128- // controlKeyPressed: controlKeyPressed
129- //// hasDuplicate: recentProjects.contains(where: {
130- //// $0 != url && $0.lastPathComponent == url.lastPathComponent
131- //// })
132- // )
133- // }
134- // }
135- // Divider()
136- // Button {
137- // RecentProjectsStore.clearList()
138- // } label: {
139- // Text("Clear Recent Menu")
140- // }
141- // }
142- // .onAppear {
143- // updateProjects()
144- // }
145- // .onReceive(NotificationCenter.default.publisher(for: RecentProjectsStore.didUpdateNotification)) { _ in
146- // updateProjects()
147- // }
148- // .onReceive(NSEvent.publisher(scope: .local, matching: .flagsChanged)) { output in
149- // controlKeyPressed = output.modifierFlags.contains(.control)
150- // }
151- // }
152- //
153- // private func updateProjects() {
154- // recentProjects = Array(RecentProjectsStore.recentProjectURLs().prefix(10))
155- // }
156- //}
0 commit comments