From 3db4cacf07383d3d30822d180695d78e9d6ad145 Mon Sep 17 00:00:00 2001 From: Dave DeLong Date: Wed, 24 Feb 2010 14:52:09 -0600 Subject: Added demo UI --- DDHotKeyAppDelegate.h | 12 + DDHotKeyAppDelegate.m | 92 ++++-- English.lproj/MainMenu.xib | 771 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 843 insertions(+), 32 deletions(-) diff --git a/DDHotKeyAppDelegate.h b/DDHotKeyAppDelegate.h index ab448a1..4b4cbac 100644 --- a/DDHotKeyAppDelegate.h +++ b/DDHotKeyAppDelegate.h @@ -10,8 +10,20 @@ @interface DDHotKeyAppDelegate : NSObject { 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 diff --git a/DDHotKeyAppDelegate.m b/DDHotKeyAppDelegate.m index a091fc6..888bf32 100644 --- a/DDHotKeyAppDelegate.m +++ b/DDHotKeyAppDelegate.m @@ -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 diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index 8fbe809..880d908 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -2,18 +2,18 @@ 1060 - 10A324 - 719 - 1015 - 418.00 + 10C540 + 732 + 1038.25 + 458.00 com.apple.InterfaceBuilder.CocoaPlugin - 719 + 732 YES - + YES @@ -1327,6 +1327,377 @@ 256 + + YES + + + 268 + {{17, 321}, {130, 17}} + + YES + + 68288064 + 272630784 + Example 1 (⌃v): + + LucidaGrande + 13 + 1044 + + + + 6 + System + controlColor + + 3 + MC42NjY2NjY2NjY3AA + + + + 6 + System + controlTextColor + + 3 + MAA + + + + + + + 268 + {{17, 289}, {117, 17}} + + YES + + 68288064 + 272630784 + Example 2 (⌃⌥v): + + + + + + + + + 268 + {{17, 257}, {130, 17}} + + YES + + 68288064 + 272630784 + Example 3 (⌃⌥⌘v): + + + + + + + + + 265 + {{360, 313}, {106, 32}} + + YES + + 67239424 + 134217728 + Unregister + + + -2038284033 + 129 + + + 200 + 25 + + + + + 265 + {{254, 313}, {106, 32}} + + YES + + 67239424 + 134217728 + Register + + + -2038284033 + 129 + + + 200 + 25 + + + + + 265 + {{360, 281}, {106, 32}} + + YES + + 67239424 + 134217728 + Unregister + + + -2038284033 + 129 + + + 200 + 25 + + + + + 265 + {{254, 281}, {106, 32}} + + YES + + 67239424 + 134217728 + Register + + + -2038284033 + 129 + + + 200 + 25 + + + + + 265 + {{360, 249}, {106, 32}} + + YES + + 67239424 + 134217728 + Unregister + + + -2038284033 + 129 + + + 200 + 25 + + + + + 265 + {{254, 249}, {106, 32}} + + YES + + 67239424 + 134217728 + Register + + + -2038284033 + 129 + + + 200 + 25 + + + + + 18 + + YES + + + 256 + + YES + + + 274 + + YES + + + 2304 + + YES + + + 2322 + {391, 179} + + + + + + + + + + + YES + + + 134 + + + + 391 + 1 + + + 12261 + 0 + + + 3 + MQA + + + YES + + YES + NSBackgroundColor + NSColor + + + YES + + 6 + System + selectedTextBackgroundColor + + + + 6 + System + selectedTextColor + + + + + + + YES + + YES + NSColor + NSCursor + NSUnderline + + + YES + + 1 + MCAwIDEAA + + + {8, -8} + 13 + + + + + + + 6 + {463, 1e+07} + {223, 122} + + + + {{1, 1}, {391, 179}} + + + + + + {4, -5} + 1 + + 4 + + + + 256 + {{392, 1}, {15, 179}} + + + _doScroller: + 1 + 0.85256409645080566 + + + + -2147483392 + {{-100, -100}, {87, 18}} + + 1 + + _doScroller: + 1 + 0.94565218687057495 + + + {{18, 14}, {408, 181}} + + + 18 + + + + + + {{1, 1}, {444, 205}} + + + + {{17, 16}, {446, 221}} + + {0, 0} + + 67239424 + 0 + Output + + LucidaGrande + 11 + 3100 + + + 6 + System + textBackgroundColor + + + + 3 + MCAwLjgwMDAwMDAxMTkAA + + + + 1 + 0 + 2 + NO + + {480, 360} @@ -2023,6 +2394,62 @@ 532 + + + registerExample1: + + + + 556 + + + + registerExample2: + + + + 557 + + + + registerExample3: + + + + 558 + + + + unregisterExample1: + + + + 559 + + + + unregisterExample2: + + + + 560 + + + + unregisterExample3: + + + + 561 + + + + output + + + + 562 + @@ -2576,6 +3003,19 @@ 372 + + YES + + + + + + + + + + + @@ -3064,6 +3504,167 @@ + + 533 + + + YES + + + + + + 534 + + + + + 535 + + + YES + + + + + + 536 + + + + + 537 + + + YES + + + + + + 538 + + + + + 539 + + + YES + + + + + + 540 + + + + + 541 + + + YES + + + + + + 542 + + + + + 543 + + + YES + + + + + + 544 + + + YES + + + + + + 545 + + + + + 546 + + + + + 547 + + + YES + + + + + + 548 + + + YES + + + + + + 549 + + + + + 550 + + + + + 555 + + + YES + + + + + + 551 + + + YES + + + + + + + + 554 + + + + + 553 + + + + + 552 + + + @@ -3286,6 +3887,28 @@ 515.IBPluginDependency 516.IBPluginDependency 517.IBPluginDependency + 533.IBPluginDependency + 534.IBPluginDependency + 535.IBPluginDependency + 536.IBPluginDependency + 537.IBPluginDependency + 538.IBPluginDependency + 539.IBPluginDependency + 540.IBPluginDependency + 541.IBPluginDependency + 542.IBPluginDependency + 543.IBPluginDependency + 544.IBPluginDependency + 545.IBPluginDependency + 546.IBPluginDependency + 547.IBPluginDependency + 548.IBPluginDependency + 549.IBPluginDependency + 550.IBPluginDependency + 551.IBPluginDependency + 552.IBPluginDependency + 553.IBPluginDependency + 554.IBPluginDependency 56.IBPluginDependency 56.ImportedFromIB2 57.IBEditorWindowLastContentRect @@ -3427,7 +4050,7 @@ com.apple.InterfaceBuilder.CocoaPlugin {{525, 802}, {197, 73}} - {{380, 836}, {512, 20}} + {{380, 836}, {439, 20}} com.apple.InterfaceBuilder.CocoaPlugin {74, 862} @@ -3452,9 +4075,9 @@ com.apple.InterfaceBuilder.CocoaPlugin - {{380, 496}, {480, 360}} + {{414, 496}, {480, 360}} com.apple.InterfaceBuilder.CocoaPlugin - {{380, 496}, {480, 360}} + {{414, 496}, {480, 360}} {{33, 99}, {480, 360}} {3.40282e+38, 3.40282e+38} @@ -3540,6 +4163,28 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin {{286, 129}, {275, 183}} com.apple.InterfaceBuilder.CocoaPlugin @@ -3591,7 +4236,7 @@ - 532 + 562 @@ -3599,9 +4244,39 @@ DDHotKeyAppDelegate NSObject + + YES + + YES + registerExample1: + registerExample2: + registerExample3: + unregisterExample1: + unregisterExample2: + unregisterExample3: + + + YES + id + id + id + id + id + id + + - window - NSWindow + YES + + YES + output + window + + + YES + NSTextView + NSWindow + IBProjectSource @@ -3611,6 +4286,14 @@ YES + + NSActionCell + NSCell + + IBFrameworkSource + AppKit.framework/Headers/NSActionCell.h + + NSApplication NSResponder @@ -3654,6 +4337,14 @@ AppKit.framework/Headers/NSUserInterfaceItemSearching.h + + NSBox + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSBox.h + + NSBrowser NSControl @@ -3662,6 +4353,30 @@ AppKit.framework/Headers/NSBrowser.h + + NSButton + NSControl + + IBFrameworkSource + AppKit.framework/Headers/NSButton.h + + + + NSButtonCell + NSActionCell + + IBFrameworkSource + AppKit.framework/Headers/NSButtonCell.h + + + + NSCell + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSCell.h + + NSControl NSView @@ -4035,6 +4750,22 @@ AppKit.framework/Headers/NSResponder.h + + NSScrollView + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSScrollView.h + + + + NSScroller + NSControl + + IBFrameworkSource + AppKit.framework/Headers/NSScroller.h + + NSTableView NSControl @@ -4048,6 +4779,22 @@ AppKit.framework/Headers/NSText.h + + NSTextField + NSControl + + IBFrameworkSource + AppKit.framework/Headers/NSTextField.h + + + + NSTextFieldCell + NSActionCell + + IBFrameworkSource + AppKit.framework/Headers/NSTextFieldCell.h + + NSTextView NSText -- cgit v1.2.3