1 #import "PreferencesController.h"
2 #import "MainController.h"
3 #import "HotKeyCenter.h"
4 #import <ITKit/ITWindowPositioning.h>
6 #define SENDER_STATE (([sender state] == NSOnState) ? YES : NO)
8 /*************************************************************************/
10 #pragma mark PRIVATE INTERFACE
11 /*************************************************************************/
13 @interface PreferencesController (Private)
15 - (void)setupCustomizationTables;
16 - (void)setupMenuItems;
18 - (IBAction)changeMenus:(id)sender;
19 - (void)setLaunchesAtLogin:(BOOL)flag;
23 @implementation PreferencesController
26 /*************************************************************************/
28 #pragma mark STATIC VARIABLES
29 /*************************************************************************/
31 static PreferencesController *prefs = nil;
34 /*************************************************************************/
36 #pragma mark INITIALIZATION METHODS
37 /*************************************************************************/
39 + (PreferencesController *)sharedPrefs;
42 prefs = [[self alloc] init];
49 if ( (self = [super init]) ) {
50 df = [[NSUserDefaults standardUserDefaults] retain];
51 hotKeysDictionary = [[NSMutableDictionary alloc] init];
58 /*************************************************************************/
60 #pragma mark ACCESSOR METHODS
61 /*************************************************************************/
68 - (void)setController:(id)object
70 [controller autorelease];
71 controller = [object retain];
75 /*************************************************************************/
77 #pragma mark INSTANCE METHODS
78 /*************************************************************************/
80 - (IBAction)showPrefsWindow:(id)sender
82 if (! window) { // If window does not exist yet, then the nib hasn't been loaded.
83 [self setupWindow]; // Load in the nib, and perform any initial setup.
84 [self setupCustomizationTables]; // Setup the DnD manu config tables.
85 [self setupMenuItems]; // Setup the arrays of menu items
86 [self setupUI]; // Sets up additional UI
87 [window setDelegate:self];
90 [window setLevel:NSStatusWindowLevel];
92 [window makeKeyAndOrderFront:self];
93 [NSApp activateIgnoringOtherApps:YES];
96 - (IBAction)changeGeneralSetting:(id)sender
98 BOOL rebuildRequired = NO;
100 if ( [sender tag] == 1010) {
101 [self setLaunchesAtLogin:SENDER_STATE];
102 } else if ( [sender tag] == 1020) {
103 [df setBool:SENDER_STATE forKey:@"LaunchPlayerWithMT"];
104 } else if ( [sender tag] == 1030) {
105 [df setInteger:[sender intValue] forKey:@"SongsInAdvance"];
106 rebuildRequired = YES;
107 } else if ( [sender tag] == 1040) {
108 // This will not be executed. Song info always shows the title of the song.
109 // [df setBool:SENDER_STATE forKey:@"showName"];
110 // rebuildRequired = YES;
111 } else if ( [sender tag] == 1050) {
112 [df setBool:SENDER_STATE forKey:@"showArtist"];
113 rebuildRequired = YES;
114 } else if ( [sender tag] == 1060) {
115 [df setBool:SENDER_STATE forKey:@"showAlbum"];
116 rebuildRequired = YES;
117 } else if ( [sender tag] == 1070) {
118 [df setBool:SENDER_STATE forKey:@"showTime"];
119 rebuildRequired = YES;
120 } else if ( [sender tag] == 1080) {
121 [df setBool:SENDER_STATE forKey:@"showTrackNumber"];
122 rebuildRequired = YES;
123 } else if ( [sender tag] == 1090) {
124 [df setBool:SENDER_STATE forKey:@"showTrackRating"];
125 rebuildRequired = YES;
128 if ( rebuildRequired ) {
129 //[controller rebuildMenu];
130 // redraw song info status window, or upcoming songs here
136 - (IBAction)changeStatusWindowSetting:(id)sender
138 if ( [sender tag] == 2010) {
139 [df setInteger:[sender selectedRow] forKey:@"statusWindowVerticalPosition"];
140 [df setInteger:[sender selectedColumn] forKey:@"statusWindowHorizontalPosition"];
141 // update the window's position here
142 } else if ( [sender tag] == 2020) {
143 // update screen selection
144 } else if ( [sender tag] == 2030) {
145 // Update appearance effect
146 } else if ( [sender tag] == 2040) {
147 // Update Vanish Effect
148 } else if ( [sender tag] == 2050) {
149 // Update appearance speed
150 } else if ( [sender tag] == 2060) {
151 // Update vanish speed
152 } else if ( [sender tag] == 2070) {
153 // Update vanish delay
154 } else if ( [sender tag] == 2080) {
155 // Update "Song Info window when song changes" setting.
156 [df setBool:SENDER_STATE forKey:@"showSongInfoOnChange"];
160 - (IBAction)changeHotKey:(id)sender
162 switch ([sender tag])
165 [self setKeyCombo:[hotKeysDictionary objectForKey:@"PlayPause"]];
166 [self setCurrentHotKey:@"PlayPause"];
169 [self setKeyCombo:[hotKeysDictionary objectForKey:@"NextTrack"]];
170 [self setCurrentHotKey:@"NextTrack"];
173 [self setKeyCombo:[hotKeysDictionary objectForKey:@"PrevTrack"]];
174 [self setCurrentHotKey:@"PrevTrack"];
177 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ToggleVisualizer"]];
178 [self setCurrentHotKey:@"ToggleVisualizer"];
181 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ToggleLoop"]];
182 [self setCurrentHotKey:@"ToggleLoop"];
185 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ToggleShuffle"]];
186 [self setCurrentHotKey:@"ToggleShuffle"];
189 [self setKeyCombo:[hotKeysDictionary objectForKey:@"TrackInfo"]];
190 [self setCurrentHotKey:@"TrackInfo"];
193 [self setKeyCombo:[hotKeysDictionary objectForKey:@"UpcomingSongs"]];
194 [self setCurrentHotKey:@"UpcomingSongs"];
197 [self setKeyCombo:[hotKeysDictionary objectForKey:@"IncrementVolume"]];
198 [self setCurrentHotKey:@"IncrementVolume"];
201 [self setKeyCombo:[hotKeysDictionary objectForKey:@"DecrementVolume"]];
202 [self setCurrentHotKey:@"DecrementVolume"];
205 [self setKeyCombo:[hotKeysDictionary objectForKey:@"IncrementRating"]];
206 [self setCurrentHotKey:@"IncrementRating"];
209 [self setKeyCombo:[hotKeysDictionary objectForKey:@"DecrementRating"]];
210 [self setCurrentHotKey:@"DecrementRating"];
215 - (void)registerDefaults
218 NSMutableDictionary *loginWindow;
219 NSMutableArray *loginArray;
220 NSEnumerator *loginEnum;
223 [df setObject:[NSArray arrayWithObjects:
238 @"Current Track Info",
239 nil] forKey:@"menu"];
241 [df setInteger:5 forKey:@"SongsInAdvance"];
242 // [df setBool:YES forKey:@"showName"]; // Song info will always show song title.
243 [df setBool:YES forKey:@"showArtist"];
244 [df setBool:NO forKey:@"showAlbum"];
245 [df setBool:NO forKey:@"showTime"];
249 loginWindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
250 loginArray = [loginWindow objectForKey:@"AutoLaunchedApplicationDictionary"];
251 loginEnum = [loginArray objectEnumerator];
253 while ( (anItem = [loginEnum nextObject]) ) {
254 if ( [[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]] ) {
259 [loginWindow release];
262 // We must fix it so it is no longer suxy
264 if (NSRunInformationalAlertPanel(@"Auto-launch MenuTunes", @"Would you like MenuTunes to automatically launch at login?", @"Yes", @"No", nil) == NSOKButton) {
265 AEDesc scriptDesc, resultDesc;
266 NSString *script = [NSString stringWithFormat:@"tell application \"System Events\"\nmake new login item at end of login items with properties {path:\"%@\", kind:\"APPLICATION\"}\nend tell", [[NSBundle mainBundle] bundlePath]];
267 ComponentInstance asComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
269 AECreateDesc(typeChar, [script cString], [script cStringLength],
272 OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
274 AEDisposeDesc(&scriptDesc);
275 AEDisposeDesc(&resultDesc);
277 CloseComponent(asComponent);
282 - (IBAction)cancelHotKey:(id)sender
284 [[NSNotificationCenter defaultCenter] removeObserver:self];
285 [NSApp endSheet:keyComboPanel];
286 [keyComboPanel orderOut:nil];
289 - (IBAction)clearHotKey:(id)sender
291 [self setKeyCombo:[KeyCombo clearKeyCombo]];
294 - (IBAction)okHotKey:(id)sender
296 NSString *string = [combo userDisplayRep];
297 NSEnumerator *enumerator = [hotKeysDictionary keyEnumerator];
299 BOOL duplicateCombo = NO;
305 while ( (enumKey = [enumerator nextObject]) ) {
306 if (![enumKey isEqualToString:currentHotKey]) {
307 if (![combo isEqual:[KeyCombo clearKeyCombo]] &&
308 [combo isEqual:[hotKeysDictionary objectForKey:enumKey]]) {
309 [window setLevel:NSNormalWindowLevel];
310 if ( NSRunAlertPanel(@"Duplicate Key Combo", @"The specified key combo is already in use...", @"Replace", @"Cancel", nil) ) {
311 [hotKeysDictionary setObject:[KeyCombo clearKeyCombo] forKey:currentHotKey];
312 if ([enumKey isEqualToString:@"PlayPause"]) {
313 [playPauseButton setTitle:@""];
314 } else if ([enumKey isEqualToString:@"NextTrack"]) {
315 [nextTrackButton setTitle:@""];
316 } else if ([enumKey isEqualToString:@"PrevTrack"]) {
317 [previousTrackButton setTitle:@""];
318 } else if ([enumKey isEqualToString:@"ToggleVisualizer"]) {
319 [visualizerButton setTitle:@""];
320 } else if ([enumKey isEqualToString:@"TrackInfo"]) {
321 [trackInfoButton setTitle:@""];
322 } else if ([enumKey isEqualToString:@"UpcomingSongs"]) {
323 [upcomingSongsButton setTitle:@""];
324 } else if ([enumKey isEqualToString:@"IncrementVolume"]) {
325 [volumeIncrementButton setTitle:@""];
326 } else if ([enumKey isEqualToString:@"DecrementVolume"]) {
327 [volumeDecrementButton setTitle:@""];
328 } else if ([enumKey isEqualToString:@"IncrementRating"]) {
329 [ratingIncrementButton setTitle:@""];
330 } else if ([enumKey isEqualToString:@"DecrementRating"]) {
331 [ratingDecrementButton setTitle:@""];
332 } else if ([enumKey isEqualToString:@"ToggleShuffle"]) {
333 [toggleShuffleButton setTitle:@""];
334 } else if ([enumKey isEqualToString:@"ToggleLoop"]) {
335 [toggleLoopButton setTitle:@""];
337 [df setKeyCombo:[KeyCombo clearKeyCombo] forKey:enumKey];
341 [window setLevel:NSStatusWindowLevel];
346 if (!duplicateCombo) {
347 [hotKeysDictionary setObject:combo forKey:currentHotKey];
348 [df setKeyCombo:combo forKey:currentHotKey];
350 if ([currentHotKey isEqualToString:@"PlayPause"]) {
351 [playPauseButton setTitle:string];
352 } else if ([currentHotKey isEqualToString:@"NextTrack"]) {
353 [nextTrackButton setTitle:string];
354 } else if ([currentHotKey isEqualToString:@"PrevTrack"]) {
355 [previousTrackButton setTitle:string];
356 } else if ([currentHotKey isEqualToString:@"ToggleVisualizer"]) {
357 [visualizerButton setTitle:string];
358 } else if ([currentHotKey isEqualToString:@"TrackInfo"]) {
359 [trackInfoButton setTitle:string];
360 } else if ([currentHotKey isEqualToString:@"UpcomingSongs"]) {
361 [upcomingSongsButton setTitle:string];
362 } else if ([currentHotKey isEqualToString:@"IncrementVolume"]) {
363 [volumeIncrementButton setTitle:string];
364 } else if ([currentHotKey isEqualToString:@"DecrementVolume"]) {
365 [volumeDecrementButton setTitle:string];
366 } else if ([currentHotKey isEqualToString:@"IncrementRating"]) {
367 [ratingIncrementButton setTitle:string];
368 } else if ([currentHotKey isEqualToString:@"DecrementRating"]) {
369 [ratingDecrementButton setTitle:string];
370 } else if ([currentHotKey isEqualToString:@"ToggleShuffle"]) {
371 [toggleShuffleButton setTitle:string];
372 } else if ([currentHotKey isEqualToString:@"ToggleLoop"]) {
373 [toggleLoopButton setTitle:string];
376 [self cancelHotKey:sender];
381 /*************************************************************************/
383 #pragma mark HOTKEY SUPPORT METHODS
384 /*************************************************************************/
386 - (void)setCurrentHotKey:(NSString *)key
388 [currentHotKey autorelease];
389 currentHotKey = [key copy];
390 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyEvent:) name:@"KeyBroadcasterEvent" object:nil];
391 [NSApp beginSheet:keyComboPanel modalForWindow:window modalDelegate:self didEndSelector:nil contextInfo:nil];
394 - (void)keyEvent:(NSNotification *)note
396 NSDictionary *info = [note userInfo];
401 keyCode = [[info objectForKey:@"KeyCode"] shortValue];
402 modifiers = [[info objectForKey:@"Modifiers"] longValue];
404 newCombo = [[KeyCombo alloc] initWithKeyCode:keyCode andModifiers:modifiers];
405 [self setKeyCombo:newCombo];
408 - (void)setKeyCombo:(KeyCombo *)newCombo
412 combo = [newCombo copy];
414 string = [combo userDisplayRep];
418 [keyComboField setStringValue:string];
422 /*************************************************************************/
424 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
425 /*************************************************************************/
429 if ( ! [NSBundle loadNibNamed:@"Preferences" owner:self] ) {
430 NSLog( @"Failed to load Preferences.nib" );
436 - (void)setupCustomizationTables
438 NSImageCell *imgCell = [[[NSImageCell alloc] initImageCell:nil] autorelease];
440 // Set the table view cells up
441 [imgCell setImageScaling:NSScaleNone];
442 [[menuTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
443 [[allTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
445 // Register for drag and drop
446 [menuTableView registerForDraggedTypes:[NSArray arrayWithObjects:
447 @"MenuTableViewPboardType",
448 @"AllTableViewPboardType",
450 [allTableView registerForDraggedTypes:[NSArray arrayWithObjects:
451 @"MenuTableViewPboardType",
452 @"AllTableViewPboardType",
456 - (void)setupMenuItems
458 NSEnumerator *itemEnum;
460 // Set the list of items you can have.
461 availableItems = [[NSMutableArray alloc] initWithObjects:
462 @"Current Track Info",
476 // Get our preferred menu
477 myItems = [[df arrayForKey:@"menu"] mutableCopy];
479 // Delete items in the availableItems array that are already part of the menu
480 itemEnum = [myItems objectEnumerator];
481 while ( (anItem = [itemEnum nextObject]) ) {
482 if ( ! [anItem isEqualToString:@"<separator>"] ) {
483 [availableItems removeObject:anItem];
487 // Items that show should a submenu image
488 submenuItems = [[NSArray alloc] initWithObjects:
498 NSMutableDictionary *loginwindow;
499 NSMutableArray *loginarray;
500 NSEnumerator *loginEnum;
503 // Fill in the number of songs in advance to show field
504 [songsInAdvance setIntValue:[df integerForKey:@"SongsInAdvance"]];
506 // Fill in hot key buttons
507 if ([df objectForKey:@"PlayPause"]){
508 anItem = [df keyComboForKey:@"PlayPause"];
509 [hotKeysDictionary setObject:anItem forKey:@"PlayPause"];
510 [playPauseButton setTitle:[anItem userDisplayRep]];
512 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"PlayPause"];
515 if ([df objectForKey:@"NextTrack"]) {
516 anItem = [df keyComboForKey:@"NextTrack"];
517 [hotKeysDictionary setObject:anItem forKey:@"NextTrack"];
518 [nextTrackButton setTitle:[anItem userDisplayRep]];
520 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"NextTrack"];
523 if ([df objectForKey:@"PrevTrack"]) {
524 anItem = [df keyComboForKey:@"PrevTrack"];
525 [hotKeysDictionary setObject:anItem forKey:@"PrevTrack"];
526 [previousTrackButton setTitle:[anItem userDisplayRep]];
528 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"PrevTrack"];
531 if ([df objectForKey:@"ToggleVisualizer"]) {
532 anItem = [df keyComboForKey:@"ToggleVisualizer"];
533 [hotKeysDictionary setObject:anItem forKey:@"ToggleVisualizer"];
534 [visualizerButton setTitle:[anItem userDisplayRep]];
536 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleVisualizer"];
539 if ([df objectForKey:@"TrackInfo"]) {
540 anItem = [df keyComboForKey:@"TrackInfo"];
541 [hotKeysDictionary setObject:anItem forKey:@"TrackInfo"];
542 [trackInfoButton setTitle:[anItem userDisplayRep]];
544 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"TrackInfo"];
547 if ([df objectForKey:@"UpcomingSongs"]) {
548 anItem = [df keyComboForKey:@"UpcomingSongs"];
549 [hotKeysDictionary setObject:anItem forKey:@"UpcomingSongs"];
550 [upcomingSongsButton setTitle:[anItem userDisplayRep]];
552 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"UpcomingSongs"];
555 if ([df objectForKey:@"IncrementVolume"]) {
556 anItem = [df keyComboForKey:@"IncrementVolume"];
557 [hotKeysDictionary setObject:anItem forKey:@"IncrementVolume"];
558 [volumeIncrementButton setTitle:[anItem userDisplayRep]];
560 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"IncrementVolume"];
563 if ([df objectForKey:@"DecrementVolume"]) {
564 anItem = [df keyComboForKey:@"DecrementVolume"];
565 [hotKeysDictionary setObject:anItem forKey:@"DecrementVolume"];
566 [volumeDecrementButton setTitle:[anItem userDisplayRep]];
568 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"DecrementVolume"];
571 if ([df objectForKey:@"IncrementRating"]) {
572 anItem = [df keyComboForKey:@"IncrementRating"];
573 [hotKeysDictionary setObject:anItem forKey:@"IncrementRating"];
574 [ratingIncrementButton setTitle:[anItem userDisplayRep]];
576 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"IncrementRating"];
579 if ([df objectForKey:@"DecrementRating"]) {
580 anItem = [df keyComboForKey:@"DecrementRating"];
581 [hotKeysDictionary setObject:anItem forKey:@"DecrementRating"];
582 [ratingDecrementButton setTitle:[anItem userDisplayRep]];
584 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"DecrementRating"];
587 if ([df objectForKey:@"ToggleLoop"]) {
588 anItem = [df keyComboForKey:@"ToggleLoop"];
589 [hotKeysDictionary setObject:anItem forKey:@"ToggleLoop"];
590 [toggleLoopButton setTitle:[anItem userDisplayRep]];
592 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleLoop"];
595 if ([df objectForKey:@"ToggleShuffle"]) {
596 anItem = [df keyComboForKey:@"ToggleShuffle"];
597 [hotKeysDictionary setObject:anItem forKey:@"ToggleShuffle"];
598 [toggleShuffleButton setTitle:[anItem userDisplayRep]];
600 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleShuffle"];
603 // Check current track info buttons
604 [albumCheckbox setState:[df boolForKey:@"showAlbum"] ? NSOnState : NSOffState];
605 [nameCheckbox setState:NSOnState]; // Song info will ALWAYS show song title.
606 [nameCheckbox setEnabled:NO]; // Song info will ALWAYS show song title.
607 [artistCheckbox setState:[df boolForKey:@"showArtist"] ? NSOnState : NSOffState];
608 [trackTimeCheckbox setState:[df boolForKey:@"showTime"] ? NSOnState : NSOffState];
610 // Set the launch at login checkbox state
612 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
613 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
615 loginEnum = [loginarray objectEnumerator];
616 while ( (anItem = [loginEnum nextObject]) ) {
617 if ([[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
618 [launchAtLoginCheckbox setState:NSOnState];
623 - (IBAction)changeMenus:(id)sender
625 [df setObject:myItems forKey:@"menu"];
629 - (void)setLaunchesAtLogin:(BOOL)flag
632 NSMutableDictionary *loginwindow;
633 NSMutableArray *loginarray;
634 ComponentInstance temp = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);;
639 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
640 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
642 for (i = 0; i < [loginarray count]; i++) {
643 NSDictionary *tempDict = [loginarray objectAtIndex:i];
644 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
650 AEDesc scriptDesc, resultDesc;
651 NSString *script = [NSString stringWithFormat:@"tell application \"System Events\"\nmake new login item at end of login items with properties {path:\"%@\", kind:\"APPLICATION\"}\nend tell", [[NSBundle mainBundle] bundlePath]];
653 AECreateDesc(typeChar, [script cString], [script cStringLength],
656 OSADoScript(temp, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
658 AEDisposeDesc(&scriptDesc);
659 AEDisposeDesc(&resultDesc);
660 CloseComponent(temp);
664 NSMutableDictionary *loginwindow;
665 NSMutableArray *loginarray;
669 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
670 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
672 for (i = 0; i < [loginarray count]; i++) {
673 NSDictionary *tempDict = [loginarray objectAtIndex:i];
674 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
675 [loginarray removeObjectAtIndex:i];
676 [df setPersistentDomain:loginwindow forName:@"loginwindow"];
685 /*************************************************************************/
687 #pragma mark NSWindow DELEGATE METHODS
688 /*************************************************************************/
690 - (void)windowWillClose:(NSNotification *)note
692 [(MainController *)controller closePreferences];
696 /*************************************************************************/
698 #pragma mark NSTableView DATASOURCE METHODS
699 /*************************************************************************/
701 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
703 if (aTableView == menuTableView) {
704 return [myItems count];
706 return [availableItems count];
710 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
712 if (aTableView == menuTableView) {
713 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
714 NSString *object = [myItems objectAtIndex:rowIndex];
715 if ([object isEqualToString:@"Show Player"]) {
716 return [NSString stringWithFormat:@"Show %@", [[controller currentRemote] playerSimpleName]];
720 if ([submenuItems containsObject:[myItems objectAtIndex:rowIndex]])
722 return [NSImage imageNamed:@"submenu"];
728 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
729 return [availableItems objectAtIndex:rowIndex];
731 if ([submenuItems containsObject:[availableItems objectAtIndex:rowIndex]]) {
732 return [NSImage imageNamed:@"submenu"];
740 - (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard
742 if (tableView == menuTableView) {
743 [pboard declareTypes:[NSArray arrayWithObjects:@"MenuTableViewPboardType", nil] owner:self];
744 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"MenuTableViewPboardType"];
748 if (tableView == allTableView) {
749 [pboard declareTypes:[NSArray arrayWithObjects:@"AllTableViewPboardType", nil] owner:self];
750 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"AllTableViewPboardType"];
756 - (BOOL)tableView:(NSTableView*)tableView acceptDrop:(id <NSDraggingInfo>)info row:(int)row dropOperation:(NSTableViewDropOperation)operation
760 NSString *dragData, *temp;
762 pb = [info draggingPasteboard];
764 if ([[pb types] containsObject:@"MenuTableViewPboardType"]) {
765 dragData = [pb stringForType:@"MenuTableViewPboardType"];
766 dragRow = [dragData intValue];
767 temp = [myItems objectAtIndex:dragRow];
768 [myItems removeObjectAtIndex:dragRow];
770 if (tableView == menuTableView) {
772 [myItems insertObject:temp atIndex:row - 1];
774 [myItems insertObject:temp atIndex:row];
777 if (![temp isEqualToString:@"<separator>"]) {
778 [availableItems addObject:temp];
781 } else if ([[pb types] containsObject:@"AllTableViewPboardType"]) {
782 dragData = [pb stringForType:@"AllTableViewPboardType"];
783 dragRow = [dragData intValue];
784 temp = [availableItems objectAtIndex:dragRow];
786 if (![temp isEqualToString:@"<separator>"]) {
787 [availableItems removeObjectAtIndex:dragRow];
789 [myItems insertObject:temp atIndex:row];
792 [menuTableView reloadData];
793 [allTableView reloadData];
794 [self changeMenus:self];
798 - (NSDragOperation)tableView:(NSTableView*)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)operation
800 if (tableView == allTableView) {
801 if ([[[info draggingPasteboard] types] containsObject:@"AllTableViewPboardType"]) {
802 return NSDragOperationNone;
805 if ([[[info draggingPasteboard] types] containsObject:@"MenuTableViewPboardType"]) {
806 NSString *item = [myItems objectAtIndex:[[[info draggingPasteboard] stringForType:@"MenuTableViewPboardType"] intValue]];
807 if ([item isEqualToString:@"Preferences"] || [item isEqualToString:@"Quit"]) {
808 return NSDragOperationNone;
812 [tableView setDropRow:-1 dropOperation:NSTableViewDropOn];
813 return NSDragOperationGeneric;
816 if (operation == NSTableViewDropOn || row == -1)
818 return NSDragOperationNone;
821 return NSDragOperationGeneric;
825 /*************************************************************************/
827 #pragma mark DEALLOCATION METHODS
828 /*************************************************************************/
832 [self setKeyCombo:nil];
833 [hotKeysDictionary release];
834 [keyComboPanel release];
835 [menuTableView setDataSource:nil];
836 [allTableView setDataSource:nil];
837 [controller release];
838 [availableItems release];
839 [submenuItems release];