X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/6e879de483fcc0349bb3720d1eb8ae74dc6d3803..f9501d79d42bf4392c3b13e0e15e68a8e6280393:/MenuTunes.m?ds=sidebyside diff --git a/MenuTunes.m b/MenuTunes.m index 18565b9..74066d7 100755 --- a/MenuTunes.m +++ b/MenuTunes.m @@ -12,7 +12,7 @@ Things to do: */ #import "MenuTunes.h" -#import "MenuTunesView.h" +// #import "MenuTunesView.h" #import "PreferencesController.h" #import "HotKeyCenter.h" #import "StatusWindowController.h" @@ -66,12 +66,14 @@ Things to do: } statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength]; - [statusItem setImage:[NSImage imageNamed:@"menu.tiff"]]; + [[[statusItem _button] cell] setType:NSNullCellType]; + [statusItem setImage:[NSImage imageNamed:@"menu"]]; + [[statusItem _button] setAlternateImage:[NSImage imageNamed:@"selected_image"]]; [statusItem setHighlightMode:YES]; [statusItem setMenu:menu]; [statusItem retain]; - view = [[MenuTunesView alloc] initWithFrame:[[statusItem view] frame]]; - //[statusItem setView:view]; +// view = [[MenuTunesView alloc] initWithFrame:[[statusItem view] frame]]; +// [statusItem setView:view]; } @@ -187,17 +189,13 @@ Things to do: //Updates the menu with current player state, song, and upcoming songs - (void)updateMenu { - NSString *curSongName, *curAlbumName; + NSString *curAlbumName = [self runScriptAndReturnResult:@"return album of current track"]; NSMenuItem *menuItem; if ((iTunesPSN.highLongOfPSN == kNoProcess) && (iTunesPSN.lowLongOfPSN == 0)) { return; } - //Get the current track name and album. - curSongName = [self runScriptAndReturnResult:@"return name of current track"]; - curAlbumName = [self runScriptAndReturnResult:@"return album of current track"]; - if (upcomingSongsItem) { [self rebuildUpcomingSongsMenu]; } @@ -208,51 +206,55 @@ Things to do: [self rebuildEQPresetsMenu]; } - if ([curSongName length] > 0) { - int index = [menu indexOfItemWithTitle:@"Now Playing"]; - - if (index > -1) { - [menu removeItemAtIndex:index + 1]; + if (trackInfoIndex > -1) + { + NSString *curSongName; + curSongName = [self runScriptAndReturnResult:@"return name of current track"]; + if ([curSongName length] > 0) { + int index = [menu indexOfItemWithTitle:@"Now Playing"]; - if (didHaveAlbumName) { + if (index > -1) { [menu removeItemAtIndex:index + 1]; + + if (didHaveAlbumName) { + [menu removeItemAtIndex:index + 1]; + } } - } - - if ([curAlbumName length] > 0) { - menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curAlbumName] - action:nil - keyEquivalent:@""]; + + if ([curAlbumName length] > 0) { + menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curAlbumName] + action:nil + keyEquivalent:@""]; + [menu insertItem:menuItem atIndex:trackInfoIndex + 1]; + [menuItem release]; + } + + menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curSongName] + action:nil + keyEquivalent:@""]; [menu insertItem:menuItem atIndex:trackInfoIndex + 1]; [menuItem release]; - } - - menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curSongName] - action:nil - keyEquivalent:@""]; - [menu insertItem:menuItem atIndex:trackInfoIndex + 1]; - [menuItem release]; - - if (index == -1) { - menuItem = [[NSMenuItem alloc] initWithTitle:@"Now Playing" action:nil keyEquivalent:@""]; - [menu removeItemAtIndex:[menu indexOfItemWithTitle:@"No Song"]]; + + if (index == -1) { + menuItem = [[NSMenuItem alloc] initWithTitle:@"Now Playing" action:nil keyEquivalent:@""]; + [menu removeItemAtIndex:[menu indexOfItemWithTitle:@"No Song"]]; + [menu insertItem:menuItem atIndex:trackInfoIndex]; + [menuItem release]; + } + + } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) { + [menu removeItemAtIndex:trackInfoIndex]; + [menu removeItemAtIndex:trackInfoIndex]; + + if (didHaveAlbumName) { + [menu removeItemAtIndex:trackInfoIndex]; + } + + menuItem = [[NSMenuItem alloc] initWithTitle:@"No Song" action:nil keyEquivalent:@""]; [menu insertItem:menuItem atIndex:trackInfoIndex]; [menuItem release]; } - - } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) { - [menu removeItemAtIndex:trackInfoIndex]; - [menu removeItemAtIndex:trackInfoIndex]; - - if (didHaveAlbumName) { - [menu removeItemAtIndex:trackInfoIndex]; - } - - menuItem = [[NSMenuItem alloc] initWithTitle:@"No Song" action:nil keyEquivalent:@""]; - [menu insertItem:menuItem atIndex:trackInfoIndex]; - [menuItem release]; } - didHaveAlbumName = (([curAlbumName length] > 0) ? YES : NO); } @@ -514,6 +516,8 @@ andEventID:(AEEventID)eventID - (void)selectPlaylist:(id)sender { int playlist = [[sender representedObject] intValue]; + int curPlaylist = [[self runScriptAndReturnResult:@"return index of current playlist"] intValue]; + [[playlistMenu itemAtIndex:curPlaylist - 1] setState:NSOffState]; [self runScriptAndReturnResult:[NSString stringWithFormat:@"play playlist %i", playlist]]; [[playlistMenu itemAtIndex:playlist - 1] setState:NSOnState]; [self updateMenu]; @@ -722,7 +726,7 @@ isEqualToString:@"rewinding"]) { CloseComponent(asComponent); [statusItem release]; [menu release]; - [view release]; +// [view release]; [super dealloc]; }