Permalink
Browse files

Added demo UI

  • Loading branch information...
davedelong committed Feb 24, 2010
1 parent d12d318 commit 3db4cacf07383d3d30822d180695d78e9d6ad145
Showing with 843 additions and 32 deletions.
  1. +12 −0 DDHotKeyAppDelegate.h
  2. +72 −20 DDHotKeyAppDelegate.m
  3. +759 −12 English.lproj/MainMenu.xib
View
@@ -10,8 +10,20 @@
@interface DDHotKeyAppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
+ NSTextView *output;
}
@property (assign) IBOutlet NSWindow *window;
+@property (assign) IBOutlet NSTextView *output;
+
+- (void) addOutput:(NSString *)newOutput;
+
+- (IBAction) registerExample1:(id)sender;
+- (IBAction) registerExample2:(id)sender;
+- (IBAction) registerExample3:(id)sender;
+
+- (IBAction) unregisterExample1:(id)sender;
+- (IBAction) unregisterExample2:(id)sender;
+- (IBAction) unregisterExample3:(id)sender;
@end
View
@@ -11,35 +11,87 @@
@implementation DDHotKeyAppDelegate
-@synthesize window;
+@synthesize window, output;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
-
- DDHotKeyCenter * center = [[DDHotKeyCenter alloc] init];
-
- [center registerHotKeyWithTarget:self action:@selector(hotkeyWithEvent:) object:nil keyCode:9 modifierFlags:NSControlKeyMask];
- [center registerHotKeyWithTarget:self action:@selector(hotkeyWithEvent:object:) object:@"foo!" keyCode:9 modifierFlags:(NSControlKeyMask | NSAlternateKeyMask)];
-
- int theAnswer = 42;
- [center registerHotKeyWithBlock:^(NSEvent *hkEvent) {
- NSLog(@"Firing block hotkey");
- NSLog(@"Hotkey event: %@", hkEvent);
- NSLog(@"the answer is: %d", theAnswer);
- } keyCode:9 modifierFlags:(NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)];
-
- [center release];
+}
+
+- (void) addOutput:(NSString *)newOutput {
+ NSString * current = [output string];
+ [output setString:[current stringByAppendingFormat:@"%@\n", newOutput]];
+ [output scrollRangeToVisible:NSMakeRange([[output string] length], 0)];
}
- (void) hotkeyWithEvent:(NSEvent *)hkEvent {
- NSLog(@"Firing -[%@ %@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
- NSLog(@"Hotkey event: %@", hkEvent);
+ [self addOutput:[NSString stringWithFormat:@"Firing -[%@ %@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd)]];
+ [self addOutput:[NSString stringWithFormat:@"Hotkey event: %@", hkEvent]];
}
- (void) hotkeyWithEvent:(NSEvent *)hkEvent object:(id)anObject {
- NSLog(@"Firing -[%@ %@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
- NSLog(@"Hotkey event: %@", hkEvent);
- NSLog(@"Object: %@", anObject);
+ [self addOutput:[NSString stringWithFormat:@"Firing -[%@ %@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd)]];
+ [self addOutput:[NSString stringWithFormat:@"Hotkey event: %@", hkEvent]];
+ [self addOutput:[NSString stringWithFormat:@"Object: %@", anObject]];
+}
+
+- (IBAction) registerExample1:(id)sender {
+ [self addOutput:@"Attempting to register hotkey for example 1"];
+ DDHotKeyCenter * c = [[DDHotKeyCenter alloc] init];
+ if (![c registerHotKeyWithTarget:self action:@selector(hotkeyWithEvent:) object:nil keyCode:9 modifierFlags:NSControlKeyMask]) {
+ [self addOutput:@"Unable to register hotkey for example 1"];
+ } else {
+ [self addOutput:@"Registered hotkey for example 1"];
+ }
+ [c release];
+}
+
+- (IBAction) registerExample2:(id)sender {
+ [self addOutput:@"Attempting to register hotkey for example 2"];
+ DDHotKeyCenter * c = [[DDHotKeyCenter alloc] init];
+ if (![c registerHotKeyWithTarget:self action:@selector(hotkeyWithEvent:object:) object:@"hello, world!" keyCode:9 modifierFlags:(NSControlKeyMask | NSAlternateKeyMask)]) {
+ [self addOutput:@"Unable to register hotkey for example 2"];
+ } else {
+ [self addOutput:@"Registered hotkey for example 2"];
+ }
+ [c release];
+}
+
+- (IBAction) registerExample3:(id)sender {
+ [self addOutput:@"Attempting to register hotkey for example 3"];
+ DDHotKeyCenter * c = [[DDHotKeyCenter alloc] init];
+ int theAnswer = 42;
+ DDHotKeyTask task = ^(NSEvent *hkEvent) {
+ [self addOutput:@"Firing block hotkey"];
+ [self addOutput:[NSString stringWithFormat:@"Hotkey event: %@", hkEvent]];
+ [self addOutput:[NSString stringWithFormat:@"the answer is: %d", theAnswer]];
+ };
+ if (![c registerHotKeyWithBlock:task keyCode:9 modifierFlags:(NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)]) {
+ [self addOutput:@"Unable to register hotkey for example 3"];
+ } else {
+ [self addOutput:@"Registered hotkey for example 3"];
+ }
+ [c release];
+}
+
+- (IBAction) unregisterExample1:(id)sender {
+ DDHotKeyCenter * c = [[DDHotKeyCenter alloc] init];
+ [c unregisterHotKeyWithKeyCode:9 modifierFlags:NSControlKeyMask];
+ [self addOutput:@"Unregistered hotkey for example 1"];
+ [c release];
+}
+
+- (IBAction) unregisterExample2:(id)sender {
+ DDHotKeyCenter * c = [[DDHotKeyCenter alloc] init];
+ [c unregisterHotKeyWithKeyCode:9 modifierFlags:(NSControlKeyMask | NSAlternateKeyMask)];
+ [self addOutput:@"Unregistered hotkey for example 2"];
+ [c release];
+}
+
+- (IBAction) unregisterExample3:(id)sender {
+ DDHotKeyCenter * c = [[DDHotKeyCenter alloc] init];
+ [c unregisterHotKeyWithKeyCode:9 modifierFlags:(NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)];
+ [self addOutput:@"Unregistered hotkey for example 3"];
+ [c release];
}
@end
Oops, something went wrong.

0 comments on commit 3db4cac

Please sign in to comment.