5 // Created by Joseph Spiros on Wed Apr 30 2003.
6 // Copyright (c) 2003 iThink Software. All rights reserved.
9 #import "MenuController.h"
10 #import "MainController.h"
11 #import <ITFoundation/ITDebug.h>
12 #import <ITKit/ITHotKeyCenter.h>
13 #import <ITKit/ITHotKey.h>
14 #import <ITKit/ITKeyCombo.h>
15 #import <ITKit/ITCategory-NSMenu.h>
17 @interface MenuController (SubmenuMethods)
18 - (NSMenu *)ratingMenu;
19 - (NSMenu *)upcomingSongsMenu;
20 - (NSMenu *)playlistsMenu;
22 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
23 onItem:(NSMenuItem *)item;
26 @implementation MenuController
30 if ( (self = [super init]) ) {
31 _menuLayout = [[NSMutableArray alloc] initWithCapacity:0];
38 NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
39 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
40 NSArray *menuArray = [defaults arrayForKey:@"menu"];
41 NSEnumerator *enumerator = [menuArray objectEnumerator];
44 NSEnumerator *itemEnum;
46 NSArray *hotKeys = [[ITHotKeyCenter sharedCenter] allHotKeys];
49 _currentPlaylist = [currentRemote currentPlaylistIndex];
50 _playingRadio = ([currentRemote currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist);
52 ITDebugLog(@"Reset menu if required.");
54 //Kill the old submenu items
55 if ( (tempItem = [_currentMenu itemWithTag:1]) ) {
56 ITDebugLog(@"Removing \"Song Rating\" submenu.");
57 [tempItem setSubmenu:nil];
60 if ( (tempItem = [_currentMenu itemWithTag:2]) ) {
61 ITDebugLog(@"Removing \"Upcoming Songs\" submenu.");
62 [tempItem setSubmenu:nil];
65 if ( (tempItem = [_currentMenu itemWithTag:3]) ) {
66 ITDebugLog(@"Removing \"EQ Presets\" submenu.");
67 [tempItem setSubmenu:nil];
70 if ( (tempItem = [_currentMenu itemWithTag:4]) ) {
71 ITDebugLog(@"Removing \"Playlists\" submenu.");
72 [tempItem setSubmenu:nil];
75 ITDebugLog(@"Begin building menu.");
78 while ( (nextObject = [enumerator nextObject]) ) {
80 if ([nextObject isEqualToString:@"playPause"]) {
81 ITDebugLog(@"Add \"Play\"/\"Pause\" menu item.");
82 tempItem = [menu addItemWithTitle:NSLocalizedString(@"play", @"Play")
83 action:@selector(performMainMenuAction:)
85 [tempItem setTag:MTMenuPlayPauseItem];
86 [tempItem setTarget:self];
88 itemEnum = [hotKeys objectEnumerator];
89 while ( (hotKey = [itemEnum nextObject]) ) {
90 if ([[hotKey name] isEqualToString:@"PlayPause"]) {
91 ITKeyCombo *combo = [hotKey keyCombo];
92 [self setKeyEquivalentForCode:[combo keyCode]
93 andModifiers:[combo modifiers]
98 ITDebugLog(@"Set \"Play\"/\"Pause\" menu item's title to correct state.");
99 switch ([currentRemote playerPlayingState]) {
100 case ITMTRemotePlayerPlaying:
101 [tempItem setTitle:NSLocalizedString(@"pause", @"Pause")];
103 case ITMTRemotePlayerRewinding:
104 case ITMTRemotePlayerForwarding:
105 [tempItem setTitle:NSLocalizedString(@"resume", @"Resume")];
110 } else if ([nextObject isEqualToString:@"nextTrack"]) {
111 ITDebugLog(@"Add \"Next Track\" menu item.");
112 tempItem = [menu addItemWithTitle:NSLocalizedString(@"nextTrack", @"Next Track")
113 action:@selector(performMainMenuAction:)
116 itemEnum = [hotKeys objectEnumerator];
117 while ( (hotKey = [itemEnum nextObject]) ) {
118 if ([[hotKey name] isEqualToString:@"NextTrack"]) {
119 ITKeyCombo *combo = [hotKey keyCombo];
120 [self setKeyEquivalentForCode:[combo keyCode]
121 andModifiers:[combo modifiers]
126 if (_currentPlaylist) {
127 [tempItem setTag:MTMenuNextTrackItem];
128 [tempItem setTarget:self];
130 } else if ([nextObject isEqualToString:@"prevTrack"]) {
131 ITDebugLog(@"Add \"Previous Track\" menu item.");
132 tempItem = [menu addItemWithTitle:NSLocalizedString(@"prevTrack", @"Previous Track")
133 action:@selector(performMainMenuAction:)
136 itemEnum = [hotKeys objectEnumerator];
137 while ( (hotKey = [itemEnum nextObject]) ) {
138 if ([[hotKey name] isEqualToString:@"PrevTrack"]) {
139 ITKeyCombo *combo = [hotKey keyCombo];
140 [self setKeyEquivalentForCode:[combo keyCode]
141 andModifiers:[combo modifiers]
146 if (_currentPlaylist) {
147 [tempItem setTag:MTMenuPreviousTrackItem];
148 [tempItem setTarget:self];
150 } else if ([nextObject isEqualToString:@"fastForward"]) {
151 ITDebugLog(@"Add \"Fast Forward\" menu item.");
152 tempItem = [menu addItemWithTitle:NSLocalizedString(@"fastForward", @"Fast Forward")
153 action:@selector(performMainMenuAction:)
155 if (_currentPlaylist) {
156 [tempItem setTag:MTMenuFastForwardItem];
157 [tempItem setTarget:self];
159 } else if ([nextObject isEqualToString:@"rewind"]) {
160 ITDebugLog(@"Add \"Rewind\" menu item.");
161 tempItem = [menu addItemWithTitle:NSLocalizedString(@"rewind", @"Rewind")
162 action:@selector(performMainMenuAction:)
164 if (_currentPlaylist) {
165 [tempItem setTag:MTMenuRewindItem];
166 [tempItem setTarget:self];
168 } else if ([nextObject isEqualToString:@"showPlayer"]) {
169 ITDebugLog(@"Add \"Show Player\" menu item.");
170 tempItem = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@",
171 NSLocalizedString(@"show", @"Show"),
172 [[[MainController sharedController] currentRemote] playerSimpleName]]
173 action:@selector(performMainMenuAction:)
176 itemEnum = [hotKeys objectEnumerator];
177 while ( (hotKey = [itemEnum nextObject]) ) {
178 if ([[hotKey name] isEqualToString:@"ShowPlayer"]) {
179 ITKeyCombo *combo = [hotKey keyCombo];
180 [self setKeyEquivalentForCode:[combo keyCode]
181 andModifiers:[combo modifiers]
186 [tempItem setTarget:self];
187 [tempItem setTag:MTMenuShowPlayerItem];
188 } else if ([nextObject isEqualToString:@"preferences"]) {
189 ITDebugLog(@"Add \"Preferences...\" menu item.");
190 tempItem = [menu addItemWithTitle:NSLocalizedString(@"preferences", @"Preferences...")
191 action:@selector(performMainMenuAction:)
193 [tempItem setTag:MTMenuPreferencesItem];
194 [tempItem setTarget:self];
195 } else if ([nextObject isEqualToString:@"quit"]) {
196 ITDebugLog(@"Add \"Quit\" menu item.");
197 tempItem = [menu addItemWithTitle:NSLocalizedString(@"quit", @"Quit")
198 action:@selector(performMainMenuAction:)
200 [tempItem setTag:MTMenuQuitItem];
201 [tempItem setTarget:self];
202 if ([[MainController sharedController] blingBling] == NO) {
203 ITDebugLog(@"Add \"Register MenuTunes...\" menu item.");
204 tempItem = [menu addItemWithTitle:NSLocalizedString(@"register", @"Register MenuTunes...") action:@selector(performMainMenuAction:) keyEquivalent:@""];
205 [tempItem setTag:MTMenuRegisterItem];
206 [tempItem setTarget:self];
208 } else if ([nextObject isEqualToString:@"trackInfo"]) {
209 ITDebugLog(@"Check to see if a Track is playing...");
210 //Handle playing radio too
211 if (_currentPlaylist) {
212 NSString *title = [currentRemote currentSongTitle];
214 ITDebugLog(@"A Track is Playing, Add \"Track Info\" menu items.");
215 ITDebugLog(@"Add \"Now Playing\" menu item.");
216 [menu addItemWithTitle:NSLocalizedString(@"nowPlaying", @"Now Playing") action:NULL keyEquivalent:@""];
218 if ([title length] > 0) {
219 ITDebugLog(@"Add Track Title (\"%@\") menu item.", title);
221 [menu addItemWithTitle:title action:nil keyEquivalent:@""]];
224 if ([defaults boolForKey:@"showAlbum"]) {
225 NSString *curAlbum = [currentRemote currentSongAlbum];
226 ITDebugLog(@"Add Track Album (\"%@\") menu item.", curAlbum);
227 if ([curAlbum length]) {
229 [menu addItemWithTitle:curAlbum action:nil keyEquivalent:@""]];
233 if ([defaults boolForKey:@"showArtist"]) {
234 NSString *curArtist = [currentRemote currentSongArtist];
235 ITDebugLog(@"Add Track Artist (\"%@\") menu item.", curArtist);
236 if ([curArtist length]) {
238 [menu addItemWithTitle:curArtist action:nil keyEquivalent:@""]];
242 if ([defaults boolForKey:@"showTrackNumber"]) {
243 int track = [currentRemote currentSongTrack];
244 ITDebugLog(@"Add Track Number (\"Track %i\") menu item.", track);
247 [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %i", NSLocalizedString(@"track", @"Track"), track] action:nil keyEquivalent:@""]];
251 if ([defaults boolForKey:@"showTime"]) {
252 int left = [[currentRemote currentSongRemaining] intValue];
253 NSString *remaining = [NSString stringWithFormat:@"%i:%02i", left / 60, left % 60];
254 ITDebugLog(@"Add Track Remaining (\"%@/%@\") menu item.", remaining, [currentRemote currentSongLength]);
255 [menu indentItem:[menu addItemWithTitle:[NSString stringWithFormat:@"%@/%@", remaining, [currentRemote currentSongLength]] action:nil keyEquivalent:@""]];
258 if ([defaults boolForKey:@"showTrackRating"]) {
259 NSString *string = nil;
260 switch ((int)([currentRemote currentSongRating] * 5)) {
262 string = [NSString stringWithUTF8String:"☆☆☆☆☆"];
265 string = [NSString stringWithUTF8String:"★☆☆☆☆"];
268 string = [NSString stringWithUTF8String:"★★☆☆☆"];
271 string = [NSString stringWithUTF8String:"★★★☆☆"];
274 string = [NSString stringWithUTF8String:"★★★★☆"];
277 string = [NSString stringWithUTF8String:"★★★★★"];
280 ITDebugLog(@"Add Track Rating (\"%@\") menu item.", string);
281 [menu indentItem:[menu addItemWithTitle:string action:nil keyEquivalent:@""]];
284 ITDebugLog(@"No Track is Playing, Add \"No Song\" menu item.");
285 [menu addItemWithTitle:NSLocalizedString(@"noSong", @"No Song") action:NULL keyEquivalent:@""];
287 } else if ([nextObject isEqualToString:@"separator"]) {
288 ITDebugLog(@"Add a separator menu item.");
289 [menu addItem:[NSMenuItem separatorItem]];
291 } else if ([nextObject isEqualToString:@"songRating"]) {
292 ITDebugLog(@"Add \"Song Rating\" submenu.");
293 tempItem = [menu addItemWithTitle:NSLocalizedString(@"songRating", @"Song Rating")
296 [tempItem setSubmenu:_ratingMenu];
298 if (_playingRadio || !_currentPlaylist) {
299 [tempItem setEnabled:NO];
302 itemEnum = [[_ratingMenu itemArray] objectEnumerator];
303 while ( (tempItem = [itemEnum nextObject]) ) {
304 [tempItem setState:NSOffState];
307 [[_ratingMenu itemAtIndex:([currentRemote currentSongRating] * 5)] setState:NSOnState];
308 } else if ([nextObject isEqualToString:@"upcomingSongs"]) {
309 ITDebugLog(@"Add \"Upcoming Songs\" submenu.");
310 tempItem = [menu addItemWithTitle:NSLocalizedString(@"upcomingSongs", @"Upcoming Songs")
313 [tempItem setSubmenu:_upcomingSongsMenu];
315 if (_playingRadio || !_currentPlaylist) {
316 [tempItem setEnabled:NO];
318 } else if ([nextObject isEqualToString:@"playlists"]) {
319 ITDebugLog(@"Add \"Playlists\" submenu.");
320 tempItem = [menu addItemWithTitle:NSLocalizedString(@"playlists", @"Playlists")
323 [tempItem setSubmenu:_playlistsMenu];
325 } else if ([nextObject isEqualToString:@"eqPresets"]) {
326 ITDebugLog(@"Add \"EQ Presets\" submenu.");
327 tempItem = [menu addItemWithTitle:NSLocalizedString(@"eqPresets", @"EQ Presets")
330 [tempItem setSubmenu:_eqMenu];
333 itemEnum = [[_eqMenu itemArray] objectEnumerator];
334 while ( (tempItem = [itemEnum nextObject]) ) {
335 [tempItem setState:NSOffState];
337 [[_eqMenu itemAtIndex:([currentRemote currentEQPresetIndex] - 1)] setState:NSOnState];
340 ITDebugLog(@"Finished building menu.");
341 [_currentMenu release];
346 - (NSMenu *)menuForNoPlayer
348 NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
349 NSMenuItem *tempItem;
350 ITDebugLog(@"Creating menu for when player isn't running.");
351 ITDebugLog(@"Add \"Open %@\" menu item.", [[[MainController sharedController] currentRemote] playerSimpleName]);
352 tempItem = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"open", @"Open"), [[[MainController sharedController] currentRemote] playerSimpleName]] action:@selector(performMainMenuAction:) keyEquivalent:@""];
353 [tempItem setTag:MTMenuShowPlayerItem];
354 [tempItem setTarget:self];
355 ITDebugLog(@"Add a separator menu item.");
356 [menu addItem:[NSMenuItem separatorItem]];
357 ITDebugLog(@"Add \"Preferences...\" menu item.");
358 tempItem = [menu addItemWithTitle:NSLocalizedString(@"preferences", @"Preferences...") action:@selector(performMainMenuAction:) keyEquivalent:@""];
359 [tempItem setTag:MTMenuPreferencesItem];
360 [tempItem setTarget:self];
361 if ([[MainController sharedController] blingBling] == NO) {
362 ITDebugLog(@"Add \"Register MenuTunes...\" menu item.");
363 tempItem = [menu addItemWithTitle:NSLocalizedString(@"register", @"Register MenuTunes...") action:@selector(performMainMenuAction:) keyEquivalent:@""];
364 [tempItem setTag:MTMenuRegisterItem];
365 [tempItem setTarget:self];
367 ITDebugLog(@"Add \"Quit\" menu item.");
368 tempItem = [menu addItemWithTitle:NSLocalizedString(@"quit", @"Quit") action:@selector(performMainMenuAction:) keyEquivalent:@""];
369 [tempItem setTag:MTMenuQuitItem];
370 [tempItem setTarget:self];
371 return [menu autorelease];
374 - (void)rebuildSubmenus
376 ITDebugLog(@"Rebuilding all of the submenus.");
378 currentRemote = [[MainController sharedController] currentRemote];
379 _currentPlaylist = [currentRemote currentPlaylistIndex];
380 _currentTrack = [currentRemote currentSongIndex];
381 _playingRadio = ([currentRemote currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist);
383 [_ratingMenu release];
384 [_upcomingSongsMenu release];
385 [_playlistsMenu release];
387 ITDebugLog(@"Beginning Rebuild of \"Song Rating\" submenu.");
388 _ratingMenu = [self ratingMenu];
389 ITDebugLog(@"Beginning Rebuild of \"Upcoming Songs\" submenu.");
390 _upcomingSongsMenu = [self upcomingSongsMenu];
391 ITDebugLog(@"Beginning Rebuild of \"Playlists\" submenu.");
392 _playlistsMenu = [self playlistsMenu];
393 ITDebugLog(@"Beginning Rebuild of \"EQ Presets\" submenu.");
394 _eqMenu = [self eqMenu];
395 ITDebugLog(@"Done rebuilding all of the submenus.");
398 - (NSMenu *)ratingMenu
400 NSMenu *ratingMenu = [[NSMenu alloc] initWithTitle:@""];
401 NSEnumerator *itemEnum;
404 SEL itemSelector = @selector(performRatingMenuAction:);
406 ITDebugLog(@"Building \"Song Rating\" menu.");
408 [ratingMenu addItemWithTitle:[NSString stringWithUTF8String:"☆☆☆☆☆"] action:nil keyEquivalent:@""];
409 [ratingMenu addItemWithTitle:[NSString stringWithUTF8String:"★☆☆☆☆"] action:nil keyEquivalent:@""];
410 [ratingMenu addItemWithTitle:[NSString stringWithUTF8String:"★★☆☆☆"] action:nil keyEquivalent:@""];
411 [ratingMenu addItemWithTitle:[NSString stringWithUTF8String:"★★★☆☆"] action:nil keyEquivalent:@""];
412 [ratingMenu addItemWithTitle:[NSString stringWithUTF8String:"★★★★☆"] action:nil keyEquivalent:@""];
413 [ratingMenu addItemWithTitle:[NSString stringWithUTF8String:"★★★★★"] action:nil keyEquivalent:@""];
415 itemEnum = [[ratingMenu itemArray] objectEnumerator];
416 while ( (anItem = [itemEnum nextObject]) ) {
417 ITDebugLog(@"Setting up \"%@\" menu item.", [anItem title]);
418 [anItem setAction:itemSelector];
419 [anItem setTarget:self];
420 [anItem setTag:itemTag];
423 ITDebugLog(@"Done Building \"Song Rating\" menu.");
427 - (NSMenu *)upcomingSongsMenu
429 NSMenu *upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
430 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:_currentPlaylist];
431 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
433 ITDebugLog(@"Building \"Upcoming Songs\" menu.");
435 if (_currentPlaylist && !_playingRadio) {
439 for (i = _currentTrack + 1; i <= _currentTrack + numSongsInAdvance; i++) {
441 NSString *curSong = [currentRemote songTitleAtIndex:i];
442 NSMenuItem *songItem;
443 ITDebugLog(@"Adding song: %@", curSong);
444 songItem = [upcomingSongsMenu addItemWithTitle:curSong action:@selector(performUpcomingSongsMenuAction:) keyEquivalent:@""];
446 [songItem setTarget:self];
453 ITDebugLog(@"Done Building \"Upcoming Songs\" menu.");
454 return upcomingSongsMenu;
457 - (NSMenu *)playlistsMenu
459 NSMenu *playlistsMenu = [[NSMenu alloc] initWithTitle:@""];
460 NSArray *playlists = [currentRemote playlists];
461 NSMenuItem *tempItem;
464 ITDebugLog(@"Building \"Playlists\" menu.");
466 for (i = 0; i < [playlists count]; i++) {
467 NSString *curPlaylist = [playlists objectAtIndex:i];
468 ITDebugLog(@"Adding playlist: %@", curPlaylist);
469 tempItem = [playlistsMenu addItemWithTitle:curPlaylist action:@selector(performPlaylistMenuAction:) keyEquivalent:@""];
470 [tempItem setTag:i + 1];
471 [tempItem setTarget:self];
474 if (!_playingRadio && _currentPlaylist) {
475 [[playlistsMenu itemAtIndex:_currentPlaylist - 1] setState:NSOnState];
477 ITDebugLog(@"Done Building \"Playlists\" menu");
478 return playlistsMenu;
483 NSMenu *eqMenu = [[NSMenu alloc] initWithTitle:@""];
484 NSArray *eqPresets = [currentRemote eqPresets];
485 NSMenuItem *tempItem;
488 ITDebugLog(@"Building \"EQ Presets\" menu.");
490 for (i = 0; i < [eqPresets count]; i++) {
492 if ( ( name = [eqPresets objectAtIndex:i] ) ) {
493 ITDebugLog(@"Adding EQ Preset: %@", name);
494 tempItem = [eqMenu addItemWithTitle:name
495 action:@selector(performEqualizerMenuAction:)
498 [tempItem setTarget:self];
501 ITDebugLog(@"Done Building \"EQ Presets\" menu");
505 - (void)performMainMenuAction:(id)sender
507 switch ( [sender tag] )
509 case MTMenuPlayPauseItem:
510 ITDebugLog(@"Performing Menu Action: Play/Pause");
511 [[MainController sharedController] playPause];
513 case MTMenuFastForwardItem:
514 ITDebugLog(@"Performing Menu Action: Fast Forward");
515 [[MainController sharedController] fastForward];
517 case MTMenuRewindItem:
518 ITDebugLog(@"Performing Menu Action: Rewind");
519 [[MainController sharedController] rewind];
521 case MTMenuPreviousTrackItem:
522 ITDebugLog(@"Performing Menu Action: Previous Track");
523 [[MainController sharedController] prevSong];
525 case MTMenuNextTrackItem:
526 ITDebugLog(@"Performing Menu Action: Next Track");
527 [[MainController sharedController] nextSong];
529 case MTMenuShowPlayerItem:
530 ITDebugLog(@"Performing Menu Action: Show Main Interface");
531 [[MainController sharedController] showPlayer];
533 case MTMenuPreferencesItem:
534 ITDebugLog(@"Performing Menu Action: Preferences...");
535 [[MainController sharedController] showPreferences];
538 ITDebugLog(@"Performing Menu Action: Quit");
539 [[MainController sharedController] quitMenuTunes];
541 case MTMenuRegisterItem:
542 ITDebugLog(@"Performing Menu Action: Register");
543 [[MainController sharedController] blingNow];
546 ITDebugLog(@"Performing Menu Action: Unimplemented Menu Item OR Child-bearing Menu Item");
551 - (void)performRatingMenuAction:(id)sender
553 ITDebugLog(@"Rating action selected on item with tag %i", [sender tag]);
554 [[MainController sharedController] selectSongRating:[sender tag]];
557 - (void)performPlaylistMenuAction:(id)sender
559 ITDebugLog(@"Playlist action selected on item with tag %i", [sender tag]);
560 [[MainController sharedController] selectPlaylistAtIndex:[sender tag]];
563 - (void)performEqualizerMenuAction:(id)sender
565 ITDebugLog(@"EQ action selected on item with tag %i", [sender tag]);
566 [[MainController sharedController] selectEQPresetAtIndex:[sender tag]];
569 - (void)performUpcomingSongsMenuAction:(id)sender
571 ITDebugLog(@"Song action selected on item with tag %i", [sender tag]);
572 [[MainController sharedController] selectSongAtIndex:[sender tag]];
577 ITDebugLog(@"Update Menu");
578 [_currentMenu update];
581 - (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem
586 //This is never used I know, keep it though
587 - (NSString *)systemUIColor
589 NSDictionary *tmpDict;
591 if ( (tmpDict = [NSDictionary dictionaryWithContentsOfFile:[@"~/Library/Preferences/.GlobalPreferences.plist" stringByExpandingTildeInPath]]) ) {
592 if ( (tmpNumber = [tmpDict objectForKey:@"AppleAquaColorVariant"]) ) {
593 if ( ([tmpNumber intValue] == 1) ) {
606 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
607 onItem:(NSMenuItem *)item
609 unichar charcode = 'a';
611 long cocoaModifiers = 0;
612 static long carbonToCocoa[6][2] =
614 { cmdKey, NSCommandKeyMask },
615 { optionKey, NSAlternateKeyMask },
616 { controlKey, NSControlKeyMask },
617 { shiftKey, NSShiftKeyMask },
620 ITDebugLog(@"Setting Key Equivelent on menu item \"%@\".", [item title]);
622 for (i = 0; i < 6; i++) {
623 if (modifiers & carbonToCocoa[i][0]) {
624 cocoaModifiers += carbonToCocoa[i][1];
627 [item setKeyEquivalentModifierMask:cocoaModifiers];
629 //Missing key combos for some keys. Must find them later.
633 ITDebugLog(@"Keycode for menu item \"%@\": 36 (Return)", [item title]);
638 ITDebugLog(@"Keycode for menu item \"%@\": 48 (Tab)", [item title]);
645 ITDebugLog(@"Keycode for menu item \"%@\": 49 (Space)", [item title]);
646 // Haven't tested this, though it should work.
647 // This doesn't work. :'(
649 //[[NSString stringWithString:@"Space"] getCharacters:&buffer];
651 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
652 ITDebugLog(@"%@", menuRef);
653 SetMenuItemCommandKey(menuRef, 0, NO, 49);
654 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
655 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
658 [[NSString stringWithString:@"_"] getCharacters:&buffer]; // this will have to do for now :(
664 ITDebugLog(@"Keycode for menu item \"%@\": 51 (Delete)", [item title]);
665 charcode = NSDeleteFunctionKey;
669 ITDebugLog(@"Keycode for menu item \"%@\": 53 (Escape)", [item title]);
674 ITDebugLog(@"Keycode for menu item \"%@\": 71 (Escape)", [item title]);
679 ITDebugLog(@"Keycode for menu item \"%@\": 76 (Return)", [item title]);
684 ITDebugLog(@"Keycode for menu item \"%@\": 96 (F5)", [item title]);
685 charcode = NSF5FunctionKey;
689 ITDebugLog(@"Keycode for menu item \"%@\": 97 (F6)", [item title]);
690 charcode = NSF6FunctionKey;
694 ITDebugLog(@"Keycode for menu item \"%@\": 98 (F7)", [item title]);
695 charcode = NSF7FunctionKey;
699 ITDebugLog(@"Keycode for menu item \"%@\": 99 (F3)", [item title]);
700 charcode = NSF3FunctionKey;
704 ITDebugLog(@"Keycode for menu item \"%@\": 100 (F8)", [item title]);
705 charcode = NSF8FunctionKey;
709 ITDebugLog(@"Keycode for menu item \"%@\": 101 (F9)", [item title]);
710 charcode = NSF9FunctionKey;
714 ITDebugLog(@"Keycode for menu item \"%@\": 103 (F11)", [item title]);
715 charcode = NSF11FunctionKey;
719 ITDebugLog(@"Keycode for menu item \"%@\": 105 (F3)", [item title]);
720 charcode = NSF3FunctionKey;
724 ITDebugLog(@"Keycode for menu item \"%@\": 107 (F14)", [item title]);
725 charcode = NSF14FunctionKey;
729 ITDebugLog(@"Keycode for menu item \"%@\": 109 (F10)", [item title]);
730 charcode = NSF10FunctionKey;
734 ITDebugLog(@"Keycode for menu item \"%@\": 111 (F12)", [item title]);
735 charcode = NSF12FunctionKey;
739 ITDebugLog(@"Keycode for menu item \"%@\": 113 (F13)", [item title]);
740 charcode = NSF13FunctionKey;
744 ITDebugLog(@"Keycode for menu item \"%@\": 114 (Insert)", [item title]);
745 charcode = NSInsertFunctionKey;
749 ITDebugLog(@"Keycode for menu item \"%@\": 115 (Home)", [item title]);
750 charcode = NSHomeFunctionKey;
754 ITDebugLog(@"Keycode for menu item \"%@\": 116 (PgUp)", [item title]);
755 charcode = NSPageUpFunctionKey;
759 ITDebugLog(@"Keycode for menu item \"%@\": 117 (Delete)", [item title]);
760 charcode = NSDeleteFunctionKey;
764 ITDebugLog(@"Keycode for menu item \"%@\": 118 (F4)", [item title]);
765 charcode = NSF4FunctionKey;
769 ITDebugLog(@"Keycode for menu item \"%@\": 119 (End)", [item title]);
770 charcode = NSEndFunctionKey;
774 ITDebugLog(@"Keycode for menu item \"%@\": 120 (F2)", [item title]);
775 charcode = NSF2FunctionKey;
779 ITDebugLog(@"Keycode for menu item \"%@\": 121 (PgDown)", [item title]);
780 charcode = NSPageDownFunctionKey;
784 ITDebugLog(@"Keycode for menu item \"%@\": 122 (F1)", [item title]);
785 charcode = NSF1FunctionKey;
789 ITDebugLog(@"Keycode for menu item \"%@\": 123 (Left Arrow)", [item title]);
790 charcode = NSLeftArrowFunctionKey;
794 ITDebugLog(@"Keycode for menu item \"%@\": 124 (Right Arrow)", [item title]);
795 charcode = NSRightArrowFunctionKey;
799 ITDebugLog(@"Keycode for menu item \"%@\": 125 (Down Arrow)", [item title]);
800 charcode = NSDownArrowFunctionKey;
804 ITDebugLog(@"Keycode for menu item \"%@\": 126 (Up Arrow)", [item title]);
805 charcode = NSUpArrowFunctionKey;
809 if (charcode == 'a') {
815 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
816 keyTrans = KeyTranslate(kchr, code, &state);
818 ITDebugLog(@"Keycode for menu item \"%@\": %i (%c)", [item title], code, charCode);
819 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
820 } else if (charcode != 'b') {
821 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];
823 ITDebugLog(@"Done setting key equivalent on menu item: %@", [item title]);