Skip to content

Commit 2ec3eb4

Browse files
committed
Commented and rearranged code
1 parent ae93d00 commit 2ec3eb4

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

Music Randomizer/FolderMenu.swift

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,11 @@ class FolderMenu: NSObject, NSMenuDelegate {
9494
self.folderPath = menuButton.selectedItem.representedObject as? NSString
9595
}
9696

97-
// MARK: - menu button delegate
98-
99-
func clearStates() {
100-
for item in menu.itemArray as [NSMenuItem] {
101-
item.state = NSOffState
102-
}
103-
}
97+
// MARK: - menu button selection
10498

99+
//
100+
// Finds the first non-hidden NSMenuItem with the specified path
101+
//
105102
func findMenuItem(path: String) -> NSMenuItem? {
106103
for item in menu.itemArray as [NSMenuItem] {
107104
if let menupath = item.representedObject as? String {
@@ -113,6 +110,9 @@ class FolderMenu: NSObject, NSMenuDelegate {
113110
return nil
114111
}
115112

113+
//
114+
// Based on the current folderPath, indicates the current NSMenuItem to select
115+
//
116116
func getItemToSelect() -> NSMenuItem {
117117
if let path = folderPath {
118118
if let item = findMenuItem(path) {
@@ -125,13 +125,18 @@ class FolderMenu: NSObject, NSMenuDelegate {
125125
return chooseMusicItem
126126
}
127127

128-
func isChosenFolder() -> Bool {
129-
if let path = folderPath {
130-
return !isVolume()
128+
//
129+
// Clears the checkmark from all menu items
130+
//
131+
func clearStates() {
132+
for item in menu.itemArray as [NSMenuItem] {
133+
item.state = NSOffState
131134
}
132-
return false
133135
}
134136

137+
//
138+
// Adds the checkmark next to the selected menu item
139+
//
135140
func selectFolderItem() {
136141
clearStates()
137142

@@ -146,6 +151,15 @@ class FolderMenu: NSObject, NSMenuDelegate {
146151
}
147152

148153
}
154+
155+
// MARK: - type of folderPath selected
156+
157+
func isChosenFolder() -> Bool {
158+
if let path = folderPath {
159+
return !isVolume()
160+
}
161+
return false
162+
}
149163

150164
func isVolume() -> Bool {
151165
let volumes = ejectableVolumes
@@ -175,6 +189,8 @@ class FolderMenu: NSObject, NSMenuDelegate {
175189
}
176190
}
177191

192+
// MARK: - menu button delegate
193+
178194
func menuNeedsUpdate(menu: NSMenu!) {
179195
// find the volumes and show them in the menu
180196

0 commit comments

Comments
 (0)