Skip to content

Commit

Permalink
more progress with setting custom shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingmachine committed Sep 28, 2012
1 parent 4f9725d commit 5cad4ee
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 199 deletions.
10 changes: 1 addition & 9 deletions Foreman.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@
children = (
6556948F1615184600D08518 /* Preferences */,
651CDD8B15E794F400461C13 /* nibs */,
655694791615138100D08518 /* Supporting Files */,
65DE63BB15F17192007BF140 /* Resources */,
65956E691604BBD800FC6A70 /* Drawer */,
658EC5101602970F00DEB218 /* BaseViews */,
Expand All @@ -284,6 +283,7 @@
6517C0F715E149BD00135B11 /* Supporting Files */ = {
isa = PBXGroup;
children = (
6556947B161513A700D08518 /* PTHotKey */,
6517C0F815E149BD00135B11 /* Foreman-Info.plist */,
6517C0F915E149BD00135B11 /* InfoPlist.strings */,
6517C0FC15E149BD00135B11 /* main.m */,
Expand Down Expand Up @@ -332,14 +332,6 @@
path = DDHotKey;
sourceTree = "<group>";
};
655694791615138100D08518 /* Supporting Files */ = {
isa = PBXGroup;
children = (
6556947B161513A700D08518 /* PTHotKey */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
6556947B161513A700D08518 /* PTHotKey */ = {
isa = PBXGroup;
children = (
Expand Down
23 changes: 12 additions & 11 deletions Foreman/PreferencesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,14 @@
//

#import "PreferencesController.h"
#import "Headers.h"

@implementation PreferencesController

- (id)init {
self = [super init];
if (self) {
userDefaults = [NSUserDefaults standardUserDefaults];

// [shortcutRecorder setCanCaptureGlobalHotKeys:YES]; // Defined in interface builder
// [shortcutRecorderTwo setCanCaptureGlobalHotKeys:YES];

PTKeyCombo *keys = [[PTKeyCombo alloc] initWithPlistRepresentation:[userDefaults objectForKey:@"globalShortcut"]];
KeyCombo someKeyCombo = SRMakeKeyCombo([keys keyCode], SRCarbonToCocoaFlags([keys modifiers]));
[shortcutRecorder setKeyCombo:someKeyCombo];
}
return self;
}
Expand All @@ -38,12 +32,13 @@ - (void)shortcutRecorder:(SRRecorderControl *)aRecorder keyComboDidChange:(KeyCo
akeyCombo = [[PTKeyCombo alloc] initWithKeyCode:code modifiers:flags];

if (aRecorder == shortcutRecorder) {
NSLog(@"yes");
[hotKeyCenter unregisterHotKey:otherHotKey]; // The Key to happiness

otherHotKey = [[PTHotKey alloc] initWithIdentifier:[userDefaults objectForKey:@"hi"] keyCombo:akeyCombo];
[userDefaults setObject:[akeyCombo plistRepresentation] forKey:@"hi"];
[otherHotKey setTarget:self];
[otherHotKey setAction:@selector(sayBye)];
otherHotKey = [[PTHotKey alloc] initWithIdentifier:[userDefaults objectForKey:@"globalShortcut"] keyCombo:akeyCombo];
[userDefaults setObject:[akeyCombo plistRepresentation] forKey:@"globalShortcut"];
[otherHotKey setTarget:[App delegate]];
[otherHotKey setAction:@selector(toggle:)];
[hotKeyCenter registerHotKey:otherHotKey];
}
// if (newKeyCombo.code == ShortcutRecorderEmptyCode & newKeyCombo.flags == ShortcutRecorderEmptyFlags) {
Expand Down Expand Up @@ -72,4 +67,10 @@ + (BOOL)universalAccessNeedsToBeTurnedOn {
}
}


- (void)windowDidBecomeKey:(NSNotification *)notification {
PTKeyCombo *keys = [[PTKeyCombo alloc] initWithPlistRepresentation:[userDefaults objectForKey:@"globalShortcut"]];
KeyCombo someKeyCombo = SRMakeKeyCombo([keys keyCode], SRCarbonToCocoaFlags([keys modifiers]));
[shortcutRecorder setKeyCombo:someKeyCombo];
}
@end
Loading

0 comments on commit 5cad4ee

Please sign in to comment.