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 d5763a962..8eb2ab49e 100644 Binary files a/Preferences/General/English.lproj/Preferences.nib/keyedobjects.nib and b/Preferences/General/English.lproj/Preferences.nib/keyedobjects.nib differ diff --git a/Preferences/General/General.xcodeproj/project.pbxproj b/Preferences/General/General.xcodeproj/project.pbxproj index dabfd3a46..4217ca10d 100644 --- a/Preferences/General/General.xcodeproj/project.pbxproj +++ b/Preferences/General/General.xcodeproj/project.pbxproj @@ -16,6 +16,10 @@ 8E07ABDC0AAC95BC00A4B32F /* file_drawer.png in Resources */ = {isa = PBXBuildFile; fileRef = 8E07ABDA0AAC95BC00A4B32F /* file_drawer.png */; }; 8E07ABDD0AAC95BC00A4B32F /* hot_keys.png in Resources */ = {isa = PBXBuildFile; fileRef = 8E07ABDB0AAC95BC00A4B32F /* hot_keys.png */; }; 8E07AC050AAC968C00A4B32F /* Preferences.nib in Resources */ = {isa = PBXBuildFile; fileRef = 8E07AC030AAC968C00A4B32F /* Preferences.nib */; }; + 8E6C12160AACAE4100819171 /* NDHotKeyControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E6C12130AACAE4100819171 /* NDHotKeyControl.m */; }; + 8E6C12170AACAE4100819171 /* NDHotKeyEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E6C12150AACAE4100819171 /* NDHotKeyEvent.m */; }; + 8E6C123A0AACAEF200819171 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E6C12390AACAEF200819171 /* Carbon.framework */; }; + 8E6C13A00AACBAB500819171 /* HotKeyControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E6C139F0AACBAB500819171 /* HotKeyControl.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -38,6 +42,13 @@ 8E07ABDA0AAC95BC00A4B32F /* file_drawer.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = file_drawer.png; path = Icons/file_drawer.png; sourceTree = ""; }; 8E07ABDB0AAC95BC00A4B32F /* hot_keys.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = hot_keys.png; path = Icons/hot_keys.png; sourceTree = ""; }; 8E07AC040AAC968C00A4B32F /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/Preferences.nib; sourceTree = ""; }; + 8E6C12120AACAE4100819171 /* NDHotKeyControl.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NDHotKeyControl.h; sourceTree = ""; }; + 8E6C12130AACAE4100819171 /* NDHotKeyControl.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NDHotKeyControl.m; sourceTree = ""; }; + 8E6C12140AACAE4100819171 /* NDHotKeyEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NDHotKeyEvent.h; sourceTree = ""; }; + 8E6C12150AACAE4100819171 /* NDHotKeyEvent.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NDHotKeyEvent.m; sourceTree = ""; }; + 8E6C12390AACAEF200819171 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = ""; }; + 8E6C139E0AACBAB500819171 /* HotKeyControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HotKeyControl.h; sourceTree = ""; }; + 8E6C139F0AACBAB500819171 /* HotKeyControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HotKeyControl.m; sourceTree = ""; }; D2F7E65807B2D6F200F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = ""; }; /* End PBXFileReference section */ @@ -47,6 +58,7 @@ buildActionMask = 2147483647; files = ( 8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */, + 8E6C123A0AACAEF200819171 /* Carbon.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -97,6 +109,12 @@ 8E07AA7F0AAC8EA200A4B32F /* FileDrawerPane.m */, 8E07AA800AAC8EA200A4B32F /* HotKeyPane.h */, 8E07AA810AAC8EA200A4B32F /* HotKeyPane.m */, + 8E6C12120AACAE4100819171 /* NDHotKeyControl.h */, + 8E6C12130AACAE4100819171 /* NDHotKeyControl.m */, + 8E6C12140AACAE4100819171 /* NDHotKeyEvent.h */, + 8E6C12150AACAE4100819171 /* NDHotKeyEvent.m */, + 8E6C139E0AACBAB500819171 /* HotKeyControl.h */, + 8E6C139F0AACBAB500819171 /* HotKeyControl.m */, ); name = Classes; sourceTree = ""; @@ -104,6 +122,7 @@ 1058C7ACFEA557BF11CA2CBB /* Linked Frameworks */ = { isa = PBXGroup; children = ( + 8E6C12390AACAEF200819171 /* Carbon.framework */, 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */, ); name = "Linked Frameworks"; @@ -203,6 +222,9 @@ 8E07AA880AAC8EA200A4B32F /* HotKeyPane.m in Sources */, 8E07AA890AAC8EA200A4B32F /* PreferencePane.m in Sources */, 8E07AA8A0AAC8EA200A4B32F /* PrefPaneController.m in Sources */, + 8E6C12160AACAE4100819171 /* NDHotKeyControl.m in Sources */, + 8E6C12170AACAE4100819171 /* NDHotKeyEvent.m in Sources */, + 8E6C13A00AACBAB500819171 /* HotKeyControl.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Preferences/General/HotKeyPane.h b/Preferences/General/HotKeyPane.h index a2feec602..4402d243b 100644 --- a/Preferences/General/HotKeyPane.h +++ b/Preferences/General/HotKeyPane.h @@ -8,10 +8,18 @@ #import #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.