@@ -11,113 +11,95 @@ struct ContentFooterBar: View {
1111 var body : some View {
1212 let l10n = L10n . shared
1313 HStack {
14- HeaderIconButton ( systemName : " arrow.up.arrow.down " , help : l10n [ " sort.help " ] ) {
15- showSortMenu ( )
14+ HeaderActionMenu (
15+ systemName : " arrow.up.arrow.down " ,
16+ help : l10n [ " sort.help " ] ,
17+ arrowEdge : . bottom ,
18+ ) { dismiss in
19+ sortActions ( dismiss : dismiss )
1620 }
1721 Spacer ( )
18- HeaderIconButton ( systemName : " gearshape " , help : l10n [ " menu.settings " ] ) {
19- showSettingsMenu ( )
22+ HeaderActionMenu (
23+ systemName : " gearshape " ,
24+ help : l10n [ " menu.settings " ] ,
25+ arrowEdge : . bottom ,
26+ ) { dismiss in
27+ settingsActions ( dismiss : dismiss )
2028 }
2129 }
2230 . padding ( . horizontal , 16 )
2331 . padding ( . vertical , 6 )
2432 }
2533
26- // MARK: - Sort Menu
34+ // MARK: - Sort Actions
2735
28- private func showSortMenu ( ) {
36+ private func sortActions ( dismiss : @escaping ( ) -> Void ) -> some View {
2937 let l10n = L10n . shared
30- let menu = NSMenu ( )
31- let delegate = NSApp . delegate as? AppDelegate
32-
33- for option in AppSettings . SortBy . allCases {
34- let action : Selector = switch option {
35- case . name : #selector( AppDelegate . setSortByName )
36- case . dateModified : #selector( AppDelegate . setSortByDateModified )
37- case . dateCreated : #selector( AppDelegate . setSortByDateCreated )
38- }
39- let iconName = switch option {
40- case . name : " textformat "
41- case . dateModified : " clock "
42- case . dateCreated : " calendar "
38+ return VStack ( spacing : 2 ) {
39+ ForEach ( AppSettings . SortBy . allCases , id : \. self ) { option in
40+ HeaderActionButton (
41+ title : option . displayName ( l10n ) ,
42+ systemName : sortIcon ( for : option ) ,
43+ isSelected : settings . sortBy == option ,
44+ ) {
45+ dismiss ( )
46+ settings . sortBy = option
47+ }
4348 }
44- let item = NSMenuItem ( title : option . displayName ( l10n ) , action : action , keyEquivalent : " " )
45- item . image = NSImage ( systemSymbolName : iconName , accessibilityDescription : nil )
46- item . target = delegate
47- item . state = settings . sortBy == option ? . on : . off
48- menu . addItem ( item )
49- }
5049
51- menu . addItem ( . separator ( ) )
50+ Divider ( )
51+ . padding ( . vertical , 2 )
5252
53- let dirItem = NSMenuItem (
54- title : settings . sortAscending ? l10n [ " sort.ascending " ] : l10n [ " sort.descending " ] ,
55- action : #selector( AppDelegate . toggleSortDirection ) ,
56- keyEquivalent : " " ,
57- )
58- dirItem . image = NSImage (
59- systemSymbolName : settings . sortAscending ? " arrow.up " : " arrow.down " ,
60- accessibilityDescription : nil ,
61- )
62- dirItem . target = delegate
63- menu . addItem ( dirItem )
64-
65- popUpMenu ( menu )
53+ HeaderActionButton (
54+ title : settings . sortAscending ? l10n [ " sort.ascending " ] : l10n [ " sort.descending " ] ,
55+ systemName : settings . sortAscending ? " arrow.up " : " arrow.down " ,
56+ ) {
57+ dismiss ( )
58+ settings . sortAscending . toggle ( )
59+ }
60+ }
6661 }
6762
68- // MARK: - Settings Menu
69-
70- private func showSettingsMenu ( ) {
71- let l10n = L10n . shared
72- let menu = NSMenu ( )
73- let delegate = NSApp . delegate as? AppDelegate
74-
75- let trashItem = NSMenuItem (
76- title : l10n [ " common.trash " ] ,
77- action : #selector( AppDelegate . showTrash ) ,
78- keyEquivalent : " " ,
79- )
80- trashItem . image = NSImage ( systemSymbolName : " trash " , accessibilityDescription : nil )
81- trashItem . target = delegate
82- menu . addItem ( trashItem )
83-
84- menu . addItem ( . separator ( ) )
85-
86- menu . addActionItem ( title : l10n [ " menu.settings " ] , icon : " gearshape " ) { [ openSettings ] in
87- openSettings ( )
63+ private func sortIcon ( for option : AppSettings . SortBy ) -> String {
64+ switch option {
65+ case . name : " textformat "
66+ case . dateModified : " clock "
67+ case . dateCreated : " calendar "
8868 }
69+ }
8970
90- let updateItem = NSMenuItem (
91- title : l10n [ " menu.checkUpdates " ] ,
92- action : #selector( AppDelegate . checkForUpdates ) ,
93- keyEquivalent : " " ,
94- )
95- updateItem . image = NSImage ( systemSymbolName : " arrow.triangle.2.circlepath " , accessibilityDescription : nil )
96- updateItem . target = delegate
97- menu . addItem ( updateItem )
71+ // MARK: - Settings Actions
9872
99- menu . addItem ( . separator ( ) )
73+ private func settingsActions ( dismiss : @escaping ( ) -> Void ) -> some View {
74+ let l10n = L10n . shared
75+ return VStack ( spacing : 2 ) {
76+ HeaderActionButton ( title : l10n [ " common.trash " ] , systemName : " trash " ) {
77+ dismiss ( )
78+ noteStore . openTrash ( )
79+ }
10080
101- let quitItem = NSMenuItem (
102- title : l10n [ " menu.quit " ] ,
103- action : #selector( AppDelegate . quitApp ) ,
104- keyEquivalent : " " ,
105- )
106- quitItem . image = NSImage ( systemSymbolName : " power " , accessibilityDescription : nil )
107- quitItem . target = delegate
108- menu . addItem ( quitItem )
81+ Divider ( )
82+ . padding ( . vertical , 2 )
10983
110- popUpMenu ( menu )
111- }
84+ HeaderActionButton ( title : l10n [ " menu.settings " ] , systemName : " gearshape " ) {
85+ dismiss ( )
86+ openSettings ( )
87+ }
88+ HeaderActionButton (
89+ title : l10n [ " menu.checkUpdates " ] ,
90+ systemName : " arrow.triangle.2.circlepath " ,
91+ ) {
92+ dismiss ( )
93+ AppDelegate . shared ? . checkForUpdates ( )
94+ }
11295
113- // MARK: - Helpers
96+ Divider ( )
97+ . padding ( . vertical , 2 )
11498
115- /// Show an NSMenu at the current click location.
116- private func popUpMenu ( _ menu : NSMenu ) {
117- guard let event = NSApp . currentEvent ,
118- let view = event . window ? . contentView
119- else { return }
120- menu . prepareItemImagesForContextPresentation ( )
121- NSMenu . popUpContextMenu ( menu , with : event , for : view )
99+ HeaderActionButton ( title : l10n [ " menu.quit " ] , systemName : " power " ) {
100+ dismiss ( )
101+ NSApplication . shared . terminate ( nil )
102+ }
103+ }
122104 }
123105}
0 commit comments