Skip to content

Commit

Permalink
Commented and rearranged code
Browse files Browse the repository at this point in the history
  • Loading branch information
andykellr committed Aug 27, 2014
1 parent ae93d00 commit 2ec3eb4
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions Music Randomizer/FolderMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,11 @@ class FolderMenu: NSObject, NSMenuDelegate {
self.folderPath = menuButton.selectedItem.representedObject as? NSString
}

// MARK: - menu button delegate

func clearStates() {
for item in menu.itemArray as [NSMenuItem] {
item.state = NSOffState
}
}
// MARK: - menu button selection

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

//
// Based on the current folderPath, indicates the current NSMenuItem to select
//
func getItemToSelect() -> NSMenuItem {
if let path = folderPath {
if let item = findMenuItem(path) {
Expand All @@ -125,13 +125,18 @@ class FolderMenu: NSObject, NSMenuDelegate {
return chooseMusicItem
}

func isChosenFolder() -> Bool {
if let path = folderPath {
return !isVolume()
//
// Clears the checkmark from all menu items
//
func clearStates() {
for item in menu.itemArray as [NSMenuItem] {
item.state = NSOffState
}
return false
}

//
// Adds the checkmark next to the selected menu item
//
func selectFolderItem() {
clearStates()

Expand All @@ -146,6 +151,15 @@ class FolderMenu: NSObject, NSMenuDelegate {
}

}

// MARK: - type of folderPath selected

func isChosenFolder() -> Bool {
if let path = folderPath {
return !isVolume()
}
return false
}

func isVolume() -> Bool {
let volumes = ejectableVolumes
Expand Down Expand Up @@ -175,6 +189,8 @@ class FolderMenu: NSObject, NSMenuDelegate {
}
}

// MARK: - menu button delegate

func menuNeedsUpdate(menu: NSMenu!) {
// find the volumes and show them in the menu

Expand Down

0 comments on commit 2ec3eb4

Please sign in to comment.