From e550a6aac8ec6f76b51b8b9b99908154f652e0d9 Mon Sep 17 00:00:00 2001 From: vspader Date: Sun, 10 Sep 2006 21:27:20 +0000 Subject: [PATCH] Added hotkey preferences. --- AppController.h | 6 + AppController.m | 118 +++++++++--------- Cog.xcodeproj/project.pbxproj | 8 ++ .../English.lproj/Preferences.nib/classes.nib | 19 ++- .../English.lproj/Preferences.nib/info.nib | 6 +- .../Preferences.nib/keyedobjects.nib | Bin 1939 -> 6631 bytes .../General/General.xcodeproj/project.pbxproj | 22 ++++ Preferences/General/HotKeyPane.h | 12 +- Preferences/General/HotKeyPane.m | 79 +++++++++++- Preferences/PreferencesController.m | 2 +- 10 files changed, 206 insertions(+), 66 deletions(-) diff --git a/AppController.h b/AppController.h index 94b3fad25..483bc517d 100644 --- a/AppController.h +++ b/AppController.h @@ -4,6 +4,8 @@ #import "PlaylistController.h" #import "FileTreeController.h" +#import "NDHotKeyEvent.h" + @interface AppController : NSObject { @@ -25,6 +27,10 @@ IBOutlet NSDrawer *fileDrawer; IBOutlet FileTreeController *fileTreeController; + + NDHotKeyEvent *playHotKey; + NDHotKeyEvent *prevHotKey; + NDHotKeyEvent *nextHotKey; } - (IBAction)openFiles:(id)sender; diff --git a/AppController.m b/AppController.m index c165f86c7..d7d785c1a 100644 --- a/AppController.m +++ b/AppController.m @@ -206,75 +206,77 @@ - (void)initDefaults { NSMutableDictionary *userDefaultsValuesDict = [NSMutableDictionary dictionary]; - [userDefaultsValuesDict setObject:[NSNumber numberWithInt:35] forKey:@"hotkeyCodePlay"]; - [userDefaultsValuesDict setObject:[NSNumber numberWithInt:controlKey+cmdKey] forKey:@"hotkeyModifiersPlay"]; + [userDefaultsValuesDict setObject:[NSNumber numberWithInt:35] forKey:@"hotKeyPlayKeyCode"]; + [userDefaultsValuesDict setObject:[NSNumber numberWithInt:(NSControlKeyMask|NSCommandKeyMask)] forKey:@"hotKeyPlayModifiers"]; + [userDefaultsValuesDict setObject:[NSNumber numberWithInt:'P'] forKey:@"hotKeyPlayCharacter"]; - [userDefaultsValuesDict setObject:[NSNumber numberWithInt:45] forKey:@"hotkeyCodeNext"]; - [userDefaultsValuesDict setObject:[NSNumber numberWithInt:controlKey+cmdKey] forKey:@"hotkeyModifiersNext"]; - - [userDefaultsValuesDict setObject:[NSNumber numberWithInt:15] forKey:@"hotkeyCodePrevious"]; - [userDefaultsValuesDict setObject:[NSNumber numberWithInt:controlKey+cmdKey] forKey:@"hotkeyModifiersPrevious"]; + [userDefaultsValuesDict setObject:[NSNumber numberWithInt:45] forKey:@"hotKeyNextKeyCode"]; + [userDefaultsValuesDict setObject:[NSNumber numberWithInt:(NSControlKeyMask|NSCommandKeyMask)] forKey:@"hotKeyNextModifiers"]; + [userDefaultsValuesDict setObject:[NSNumber numberWithInt:'N'] forKey:@"hotKeyNextCharacter"]; + [userDefaultsValuesDict setObject:[NSNumber numberWithInt:15] forKey:@"hotKeyPreviousKeyCode"]; + [userDefaultsValuesDict setObject:[NSNumber numberWithInt:(NSControlKeyMask|NSCommandKeyMask)] forKey:@"hotKeyPreviousModifiers"]; + [userDefaultsValuesDict setObject:[NSNumber numberWithInt:'R'] forKey:@"hotKeyPreviousCharacter"]; + //Register and sync defaults [[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict]; [[NSUserDefaults standardUserDefaults] synchronize]; + + [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.hotKeyPlayKeyCode" options:0 context:nil]; + [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.hotKeyPreviousKeyCode" options:0 context:nil]; + [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.hotKeyNextKeyCode" options:0 context:nil]; +} + +- (void) observeValueForKeyPath:(NSString *)keyPath + ofObject:(id)object + change:(NSDictionary *)change + context:(void *)context +{ + if ([keyPath isEqualToString:@"values.hotKeyPlayKeyCode"]) { + [self registerHotKeys]; + } + else if ([keyPath isEqualToString:@"values.hotKeyPreviousKeyCode"]) { + [self registerHotKeys]; + } + else if ([keyPath isEqualToString:@"values.hotKeyNextKeyCode"]) { + [self registerHotKeys]; + } } -//Register the Hotkeys. Added by Chris Henderson, 21 May 2006 -//See http://www.dbachrach.com/blog/2005/11/program-global-hotkeys-in-cocoa-easily.html - (void)registerHotKeys { - EventHotKeyRef gMyHotKeyRef; - EventHotKeyID gMyHotKeyID; - EventTypeSpec eventType; - eventType.eventClass=kEventClassKeyboard; - eventType.eventKind=kEventHotKeyPressed; - InstallApplicationEventHandler(&handleHotKey,1,&eventType,self,NULL); - //Play - gMyHotKeyID.signature='htk1'; - gMyHotKeyID.id=1; - if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodePlay"]!=-999) - { - RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodePlay"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyModifiersPlay"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef); - } - //Previous - gMyHotKeyID.signature='htk2'; - gMyHotKeyID.id=2; - if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodePrevious"]!=-999) - { - NSLog(@"REGISTERING: %i", [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodePrevious"]); - RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodePrevious"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyModifiersPrevious"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef); - } - //Next - gMyHotKeyID.signature='htk3'; - gMyHotKeyID.id=3; - if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeNext"]!=-999) - { - RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeNext"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyModifiersNext"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef); - } + NSLog(@"REGISTERING HOTKEYS"); + + [playHotKey release]; + playHotKey = [[NDHotKeyEvent alloc] + initWithKeyCode: [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"hotKeyPlayKeyCode"] intValue] + character: [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"hotKeyPlayCharacter"] intValue] + modifierFlags: [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"hotKeyPlayModifiers"] intValue] + ]; + + [prevHotKey release]; + prevHotKey = [[NDHotKeyEvent alloc] + initWithKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousKeyCode"] + character: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousCharacter"] + modifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousModifiers"] + ]; + + [nextHotKey release]; + nextHotKey = [[NDHotKeyEvent alloc] + initWithKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextKeyCode"] + character: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextCharacter"] + modifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextModifiers"] + ]; + + [playHotKey setTarget:self selector:@selector(clickPlay)]; + [prevHotKey setTarget:self selector:@selector(clickPrev)]; + [nextHotKey setTarget:self selector:@selector(clickNext)]; + + [playHotKey setEnabled:YES]; + [prevHotKey setEnabled:YES]; + [nextHotKey setEnabled:YES]; } -//Handle the Hotkeys. Added by Chris Henderson, 21 May 2006 -OSStatus handleHotKey(EventHandlerCallRef nextHandler,EventRef theEvent,void *userData) -{ - EventHotKeyID hkID; - GetEventParameter(theEvent,kEventParamDirectObject,typeEventHotKeyID,NULL,sizeof(hkID),NULL,&hkID); - int i = hkID.id; - - NSLog(@"Handling: %i", i); - switch (i) - { - case 1: [userData clickPlay]; - break; - case 2: [userData clickPrev]; - break; - case 3: [userData clickNext]; - break; - } - return noErr; -} - - - (void)clickPlay { [playButton performClick:nil]; diff --git a/Cog.xcodeproj/project.pbxproj b/Cog.xcodeproj/project.pbxproj index 3d3d8d72b..6e7cb781a 100644 --- a/Cog.xcodeproj/project.pbxproj +++ b/Cog.xcodeproj/project.pbxproj @@ -112,6 +112,8 @@ 8E7A0F2B0A8FEB4A00F27EE8 /* shuffle_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 8E7A0F170A8FEB4A00F27EE8 /* shuffle_on.png */; }; 8E7A0F2C0A8FEB4A00F27EE8 /* volume_high.png in Resources */ = {isa = PBXBuildFile; fileRef = 8E7A0F180A8FEB4A00F27EE8 /* volume_high.png */; }; 8E7A0F2D0A8FEB4A00F27EE8 /* volume_low.png in Resources */ = {isa = PBXBuildFile; fileRef = 8E7A0F190A8FEB4A00F27EE8 /* volume_low.png */; }; + 8E7C2B160AACE0F2009B4EAD /* NDHotKeyEvent.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8E7C2B140AACE0F2009B4EAD /* NDHotKeyEvent.h */; }; + 8E7C2B170AACE0F2009B4EAD /* NDHotKeyEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E7C2B150AACE0F2009B4EAD /* NDHotKeyEvent.m */; }; 8EA917300A336CC30087CDE2 /* Shorten.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8EA9172F0A336CC30087CDE2 /* Shorten.framework */; }; 8EB450080A2BB8B300AA711F /* Cog Help in Resources */ = {isa = PBXBuildFile; fileRef = 8EB44FF90A2BB8B300AA711F /* Cog Help */; }; 8EB971790A44B74A009803E3 /* MAD.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8E1849C40A43DB5C0084C69D /* MAD.framework */; }; @@ -180,6 +182,7 @@ 8E07AAF10AAC910500A4B32F /* SS_PreferencePaneProtocol.h in CopyFiles */, 8E07AAF20AAC910500A4B32F /* SS_PrefsController.h in CopyFiles */, 8E07AB780AAC930B00A4B32F /* PreferencesController.h in CopyFiles */, + 8E7C2B160AACE0F2009B4EAD /* NDHotKeyEvent.h in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -331,6 +334,8 @@ 8E7A0F170A8FEB4A00F27EE8 /* shuffle_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = shuffle_on.png; sourceTree = ""; }; 8E7A0F180A8FEB4A00F27EE8 /* volume_high.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = volume_high.png; sourceTree = ""; }; 8E7A0F190A8FEB4A00F27EE8 /* volume_low.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = volume_low.png; sourceTree = ""; }; + 8E7C2B140AACE0F2009B4EAD /* NDHotKeyEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NDHotKeyEvent.h; sourceTree = ""; }; + 8E7C2B150AACE0F2009B4EAD /* NDHotKeyEvent.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NDHotKeyEvent.m; sourceTree = ""; }; 8EA9172F0A336CC30087CDE2 /* Shorten.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Shorten.framework; path = Libraries/Shorten/build/Release/Shorten.framework; sourceTree = ""; }; 8EB44FF90A2BB8B300AA711F /* Cog Help */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "Cog Help"; sourceTree = ""; }; 8EFFCD420AA093AF00C458A5 /* DirectoryNode.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DirectoryNode.h; sourceTree = ""; }; @@ -522,6 +527,8 @@ 8E75752209F31D5A0080F1EE /* TrackingSlider.m */, 8E4C7F060A0509FC003BE25F /* DragScrollView.h */, 8E4C7F070A0509FC003BE25F /* DragScrollView.m */, + 8E7C2B140AACE0F2009B4EAD /* NDHotKeyEvent.h */, + 8E7C2B150AACE0F2009B4EAD /* NDHotKeyEvent.m */, ); path = Custom; sourceTree = ""; @@ -870,6 +877,7 @@ 8EFFCD780AA093AF00C458A5 /* UKMainThreadProxy.m in Sources */, 8E07AAF30AAC910500A4B32F /* SS_PrefsController.m in Sources */, 8E07AB790AAC930B00A4B32F /* PreferencesController.m in Sources */, + 8E7C2B170AACE0F2009B4EAD /* NDHotKeyEvent.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Preferences/General/English.lproj/Preferences.nib/classes.nib b/Preferences/General/English.lproj/Preferences.nib/classes.nib index ec6441322..f955ac163 100644 --- a/Preferences/General/English.lproj/Preferences.nib/classes.nib +++ b/Preferences/General/English.lproj/Preferences.nib/classes.nib @@ -2,7 +2,24 @@ IBClasses = ( {CLASS = FileDrawerPane; LANGUAGE = ObjC; SUPERCLASS = PreferencePane; }, {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = HotKeyPane; LANGUAGE = ObjC; SUPERCLASS = PreferencePane; }, + {CLASS = HotKeyControl; LANGUAGE = ObjC; SUPERCLASS = NDHotKeyControl; }, + { + ACTIONS = { + grabNextHotKey = id; + grabPlayHotKey = id; + grabPrevHotKey = id; + hotKeyChanged = id; + }; + CLASS = HotKeyPane; + LANGUAGE = ObjC; + OUTLETS = { + nextHotKeyControl = HotKeyControl; + playHotKeyControl = HotKeyControl; + prevHotKeyControl = HotKeyControl; + }; + SUPERCLASS = PreferencePane; + }, + {CLASS = NDHotKeyControl; LANGUAGE = ObjC; SUPERCLASS = NSTextField; }, { CLASS = PrefPaneController; LANGUAGE = ObjC; diff --git a/Preferences/General/English.lproj/Preferences.nib/info.nib b/Preferences/General/English.lproj/Preferences.nib/info.nib index 72f7bc250..a8ff62dd3 100644 --- a/Preferences/General/English.lproj/Preferences.nib/info.nib +++ b/Preferences/General/English.lproj/Preferences.nib/info.nib @@ -7,16 +7,16 @@ IBEditorPositions 10 - -9 537 668 209 0 0 1024 746 + 178 415 668 209 0 0 1024 746 11 - 155 171 241 464 0 0 1024 746 + 290 507 273 151 0 0 1024 746 IBFramework Version 446.1 IBOpenObjects - 11 10 + 11 IBSystem Version 8J135 diff --git a/Preferences/General/English.lproj/Preferences.nib/keyedobjects.nib b/Preferences/General/English.lproj/Preferences.nib/keyedobjects.nib index d5763a9621ba8fec832b2e3972270a0cdbd060e3..8eb2ab49e99d9d7a96299a5068141bd38a3440fe 100644 GIT binary patch literal 6631 zcma)A349aP)<5@VvQLs(!YWHCWf5y_OKB;Tr7bO#r7fhCQc5vxLkWhYBx%c5yt41B z%D$CdKwOZAD7gD6AZi5^0mT*lp3l!G?)u=JnMq3(-}lV?nwd$@oaKN1_ndR5tjgyN zh2!JT0Raj+;6M)sFoI=lj5}C9$y?(I7RBIK$Q$q%#DoJ?MKOW0$)56XXoBF#bq(`O z_f(`u1SKE~w!aM~Fptm4h||O>++jB(hlR(%3Opo0FGz+o=m+VL1!G_WltDT8VFoOL zrLYW^!#3Cs`(QsDgro2`I0h%+Id~aff!E*+ya^ZJUHA(A0pG&+@H702=!k__iA$s*Z`ZjwjxNs)TxCS_zYnM#826`4V1k-20ZUM(Xl z$QrViQ1TF2Pd1P(q@L_1d&og@2!C5o4wEC~DRP`VL!KuukeA8pT9H4x_{A zC|X3P(e-o#-AFgl&G01MLbuXwbUWQa>*-Fqi|(d-=w7-HKBfEVBlG}0NDskh^ig`4 zK1Ls>Ptd36G5XBt7=N|T_n{zx4ea0m0Ys2M1}C(Dme2}XLmOxdcR)L64;`Q*L_sHr zhRzTJU7#y;gYIxA^nkk{7Vd^PxCi3Z4CiUtE_C~>nd}f-&Q`ElY#BSuRx$&7jG0&+o6a6(dImx_ zMjH_EMCb`g7`Pg&;u7PSZh|1?2R#$>-F^@H91aG2K2NX#QlK}aLZ2cnAWx`RyYS;v z_0R|UmZF;KP&hC}3#O8yS$f6Ea~C z^hIn(REOONrppr^o$JDH?a6E?JS;e1Fbshl7z)E+IE;W?$b)P({e)o#A0FW@ErcvH~_ri#Y&=`=JV^LJ&d_ zhH9vRTA0S{tP|_Ol2~t+#?o0f8^-c4q8Bq^7SzFPxF5Y?nC5YK%!PR{9~QtuSOkmF zn5(+V6I6VeAjp`k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@PmChq&%jfpQu~!)XLfqG{AfXVZMT zh*r^+bT!>XH`A?jJKaV1(GJ=}U#D--qx2X(LEoaM={b6VUZn$ckPgus^ftXi@6vmW zF*S=~DJ+epvkaES3@n$;WeZpZGqY+|%T}?CYzN!T+S#k@po<-5z3eROX9H}I4Y3>S zCcDG#vR~MJ2!vn=1vP|0IE;r$5D%%K13hFyHq3$|C;=0cLK#?~9vWdSY=UjD6L!IF z*aL3Z3;SR{bi!+J2oA#$=!N5O5>CMx_z*sVkKrtQ3g^Lf0s7$*T!t%f4X(p5{KW%! zFc0A>9?msf%cFQaPvD7sDo^2QJe_CoEN #import "PreferencePane.h" - +#import "HotKeyControl.h" @interface HotKeyPane : PreferencePane { - + IBOutlet HotKeyControl *playHotKeyControl; + IBOutlet HotKeyControl *prevHotKeyControl; + IBOutlet HotKeyControl *nextHotKeyControl; } +- (IBAction) grabPlayHotKey:(id)sender; +- (IBAction) grabPrevHotKey:(id)sender; +- (IBAction) grabNextHotKey:(id)sender; + +- (IBAction) hotKeyChanged:(id)sender; + @end diff --git a/Preferences/General/HotKeyPane.m b/Preferences/General/HotKeyPane.m index 92665e80f..664af8ecb 100644 --- a/Preferences/General/HotKeyPane.m +++ b/Preferences/General/HotKeyPane.m @@ -7,7 +7,7 @@ // #import "HotKeyPane.h" - +#import "NDHotKeyEvent.h" @implementation HotKeyPane @@ -15,6 +15,83 @@ { [self setName:@"Hot Keys"]; [self setIcon:@"hot_keys"]; + +// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object: [view window]]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object: [view window]]; + + [prevHotKeyControl setKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousKeyCode"] ]; + [prevHotKeyControl setCharacter: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousCharacter"] ]; + [prevHotKeyControl setModifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPreviousModifiers"] ]; + + [prevHotKeyControl updateStringValue]; + + [nextHotKeyControl setKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextKeyCode"] ]; + [nextHotKeyControl setCharacter: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextCharacter"] ]; + [nextHotKeyControl setModifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyNextModifiers"] ]; + + [nextHotKeyControl updateStringValue]; + + [playHotKeyControl setKeyCode: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPlayKeyCode"] ]; + [playHotKeyControl setCharacter: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPlayCharacter"] ]; + [playHotKeyControl setModifierFlags: [[NSUserDefaults standardUserDefaults] integerForKey:@"hotKeyPlayModifiers"] ]; + + [playHotKeyControl updateStringValue]; +} + +/*- (void)windowDidBecomeKey:(id)notification +{ + if ([notification object] == [view window]) { + NSLog(@"BECAME KEY: %@", notification); + [playHotKeyControl startObserving]; + [prevHotKeyControl startObserving]; + [nextHotKeyControl startObserving]; + } +} +*/ +- (void)windowDidResignKey:(id)notification +{ + if ([notification object] == [view window]) { + NSLog(@"RESIGNED KEY: %@", notification); + [playHotKeyControl stopObserving]; + [prevHotKeyControl stopObserving]; + [nextHotKeyControl stopObserving]; + } +} + +- (IBAction) grabPlayHotKey:(id)sender +{ + [playHotKeyControl startObserving]; +} + +- (IBAction) grabPrevHotKey:(id)sender +{ + [prevHotKeyControl startObserving]; +} + +- (IBAction) grabNextHotKey:(id)sender +{ + [nextHotKeyControl startObserving]; +} + +- (IBAction) hotKeyChanged:(id)sender +{ + if (sender == playHotKeyControl) { + [[NSUserDefaults standardUserDefaults] setInteger:[playHotKeyControl character] forKey:@"hotKeyPlayCharacter"]; + [[NSUserDefaults standardUserDefaults] setInteger:[playHotKeyControl modifierFlags] forKey:@"hotKeyPlayModifiers"]; + [[NSUserDefaults standardUserDefaults] setInteger:[playHotKeyControl keyCode] forKey:@"hotKeyPlayKeyCode"]; + } + else if (sender == prevHotKeyControl) { + [[NSUserDefaults standardUserDefaults] setInteger:[prevHotKeyControl character] forKey:@"hotKeyPreviousCharacter"]; + [[NSUserDefaults standardUserDefaults] setInteger:[prevHotKeyControl modifierFlags] forKey:@"hotKeyPreviousModifiers"]; + [[NSUserDefaults standardUserDefaults] setInteger:[prevHotKeyControl keyCode] forKey:@"hotKeyPreviousKeyCode"]; + } + else if (sender == nextHotKeyControl) { + [[NSUserDefaults standardUserDefaults] setInteger:[nextHotKeyControl character] forKey:@"hotKeyNextCharacter"]; + [[NSUserDefaults standardUserDefaults] setInteger:[nextHotKeyControl modifierFlags] forKey:@"hotKeyNextModifiers"]; + [[NSUserDefaults standardUserDefaults] setInteger:[nextHotKeyControl keyCode] forKey:@"hotKeyNextKeyCode"]; + } + + [sender stopObserving]; } @end diff --git a/Preferences/PreferencesController.m b/Preferences/PreferencesController.m index b01dd821d..3170adb54 100644 --- a/Preferences/PreferencesController.m +++ b/Preferences/PreferencesController.m @@ -22,7 +22,7 @@ [prefs setDebug:YES]; // Set which panes are included, and their order. -// [prefs setPanesOrder:[NSArray arrayWithObjects:@"General", @"Updating", @"A Non-Existent Preference Pane", nil]]; + //[prefs setPanesOrder:[NSArray arrayWithObjects:@"General", @"Updating", @"A Non-Existent Preference Pane", nil]]; } // Show the preferences window.