X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/b5111a52983c34e3d63dd8547a1f259a7cb5edda..0b727e3ec3a58f5751bb8f41079162c1c4c09e2d:/MenuController.m diff --git a/MenuController.m b/MenuController.m index c207e66..424957f 100755 --- a/MenuController.m +++ b/MenuController.m @@ -22,6 +22,7 @@ - (NSMenu *)playlistsMenu; - (NSMenu *)eqMenu; - (NSMenu *)artistsMenu; +- (NSMenu *)albumsMenu; - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers onItem:(id )item; - (BOOL)iPodWithNameAutomaticallyUpdates:(NSString *)name; @@ -88,6 +89,11 @@ [tempItem setSubmenu:nil]; } + if ( (tempItem = [_currentMenu itemWithTag:6]) ) { + ITDebugLog(@"Removing \"Albums\" submenu."); + [tempItem setSubmenu:nil]; + } + ITDebugLog(@"Begin building menu."); //create our menu @@ -397,7 +403,6 @@ NS_DURING [[_eqMenu itemAtIndex:0] setState:[mtr equalizerEnabled] ? NSOnState : NSOffState]; [[_eqMenu itemAtIndex:([mtr currentEQPresetIndex] + 1)] setState:NSOnState]; - [[_eqMenu itemAtIndex:([mtr currentEQPresetIndex] - 1)] setState:NSOnState]; NS_HANDLER [[MainController sharedController] networkError:localException]; NS_ENDHANDLER @@ -439,11 +444,13 @@ keyEquivalent:@""]; [tempItem setSubmenu:_artistsMenu]; [tempItem setTag:5]; - - itemEnum = [[_eqMenu itemArray] objectEnumerator]; - while ( (tempItem = [itemEnum nextObject]) ) { - [tempItem setState:NSOffState]; - } + } else if ([nextObject isEqualToString:@"albums"]) { + ITDebugLog(@"Add \"Albums\" submenu."); + tempItem = [menu addItemWithTitle:NSLocalizedString(@"albums", @"Albums") + action:nil + keyEquivalent:@""]; + [tempItem setSubmenu:_albumsMenu]; + [tempItem setTag:6]; } } ITDebugLog(@"Finished building menu."); @@ -520,6 +527,13 @@ ITDebugLog(@"Beginning Rebuild of \"Artists\" submenu."); _artistsMenu = [self artistsMenu]; } + + if ([menu containsObject:@"albums"]) { + ITDebugLog(@"Releasing albums menu"); + [_albumsMenu release]; + ITDebugLog(@"Beginning Rebuild of \"Albums\" submenu."); + _albumsMenu = [self albumsMenu]; + } ITDebugLog(@"Done rebuilding all of the submenus."); } @@ -556,7 +570,6 @@ { NSMenu *upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""]; int numSongs = 0, numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"]; - NS_DURING numSongs = [[[MainController sharedController] currentRemote] numberOfSongsInPlaylistAtIndex:_currentPlaylist]; NS_HANDLER @@ -733,11 +746,6 @@ tempItem = [eqMenu addItemWithTitle:@"Enabled" action:@selector(performEqualizerMenuAction:) keyEquivalent:@""]; [tempItem setTag:-1]; [tempItem setTarget:self]; - NS_DURING - [tempItem setState:[[[MainController sharedController] currentRemote] equalizerEnabled] ? NSOnState : NSOffState]; - NS_HANDLER - [[MainController sharedController] networkError:localException]; - NS_ENDHANDLER [eqMenu addItem:[NSMenuItem separatorItem]]; for (i = 0; i < [eqPresets count]; i++) { @@ -757,7 +765,7 @@ - (NSMenu *)artistsMenu { - NSMenu *artistsMenu = [[NSMenu alloc] initWithTitle:@""]; + NSMenu *artistsMenu = [[NSMenu alloc] initWithTitle:@"Artists"]; NSEnumerator *artistsEnumerator; NSString *nextArtist; id tempItem; @@ -765,8 +773,7 @@ NS_DURING artistsEnumerator = [[[[MainController sharedController] currentRemote] artists] objectEnumerator]; while ( (nextArtist = [artistsEnumerator nextObject]) ) { - tempItem = [artistsMenu addItemWithTitle:nextArtist action:@selector(performArtistsMenuAction:) keyEquivalent:@""]; - [tempItem setRepresentedObject:nextArtist]; + tempItem = [artistsMenu addItemWithTitle:nextArtist action:@selector(performBrowseMenuAction:) keyEquivalent:@""]; [tempItem setTarget:self]; } NS_HANDLER @@ -776,6 +783,26 @@ return artistsMenu; } +- (NSMenu *)albumsMenu +{ + NSMenu *albumsMenu = [[NSMenu alloc] initWithTitle:@"Albums"]; + NSEnumerator *albumsEnumerator; + NSString *nextAlbum; + id tempItem; + ITDebugLog(@"Building \"Albums\" menu."); + NS_DURING + albumsEnumerator = [[[[MainController sharedController] currentRemote] albums] objectEnumerator]; + while ( (nextAlbum = [albumsEnumerator nextObject]) ) { + tempItem = [albumsMenu addItemWithTitle:nextAlbum action:@selector(performBrowseMenuAction:) keyEquivalent:@""]; + [tempItem setTarget:self]; + } + NS_HANDLER + [[MainController sharedController] networkError:localException]; + NS_ENDHANDLER + ITDebugLog(@"Done Building \"Albums\" menu"); + return albumsMenu; +} + - (void)performMainMenuAction:(id)sender { switch ( [sender tag] ) @@ -846,15 +873,15 @@ [[MainController sharedController] selectSongAtIndex:[sender tag]]; } -- (void)performArtistsMenuAction:(id)sender +- (void)performBrowseMenuAction:(id)sender { - ITDebugLog(@"Artist action selected on item with object %i", [sender representedObject]); + ITDebugLog(@"Browse action selected on item named %@", [sender title]); /* ** 1 - Artist ** 2 - Album ** 3 - Genre? */ - //[[MainController sharedController] createAndPlayPlaylistWithTerm:[sender representedObject] ofType:1]; + [[MainController sharedController] makePlaylistWithTerm:[sender title] ofType:(([[[sender menu] title] isEqualToString:@"Artists"]) ? 1 : 2)]; } - (void)updateMenu