Last active
August 29, 2015 14:22
-
-
Save erica/68e68a8239d5cf71211a to your computer and use it in GitHub Desktop.
Playground Toybox - Mac Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *const ToyboxNotification = @"com.sadun.ToyboxNotification"; | |
NSString *const kIdentity = @"kIdentity"; | |
NSString *const kTrigger = @"kTrigger"; | |
NSString *const kString = @"kString"; | |
NSString *const kValue = @"kValue"; | |
NSString *const kRadio = @"kRadio"; | |
NSString *const kRadioRow = @"kRadioRow"; | |
NSString *const kRadioColumn = @"kRadioColumn"; | |
@implementation AppDelegate | |
- (IBAction)postRadio:(NSMatrix <NSUserInterfaceItemIdentification> *)sender | |
{ | |
NSNotification *note = [NSNotification notificationWithName:ToyboxNotification object:kRadio userInfo:@{kIdentity:sender.identifier, kRadioRow:@(sender.selectedRow), kRadioColumn:@(sender.selectedColumn)}]; | |
[[NSDistributedNotificationCenter defaultCenter] postNotification:note]; | |
} | |
- (IBAction)postString:(NSTextField <NSUserInterfaceItemIdentification> *)sender | |
{ | |
NSNotification *note = [NSNotification notificationWithName:ToyboxNotification object:kString userInfo:@{kIdentity:sender.identifier, kString:sender.stringValue}]; | |
[[NSDistributedNotificationCenter defaultCenter] postNotification:note]; | |
} | |
- (IBAction)postValue:(NSControl <NSUserInterfaceItemIdentification> *)sender | |
{ | |
NSNumber *value = @(0); | |
if ([sender respondsToSelector:@selector(floatValue)]) | |
{ | |
NSSlider *slider = (NSSlider *) sender; | |
value = @(slider.floatValue); | |
} | |
else if ([sender respondsToSelector:@selector(state)]) | |
{ | |
NSButton *button = (NSButton *) sender; | |
value = @([button state] == NSOnState); | |
} | |
NSNotification *note = [NSNotification notificationWithName:ToyboxNotification object:kValue userInfo:@{kIdentity:sender.identifier, kValue:value}]; | |
[[NSDistributedNotificationCenter defaultCenter] postNotification:note]; | |
} | |
- (IBAction)trigger:(id <NSUserInterfaceItemIdentification>)sender | |
{ | |
NSNotification *note = [NSNotification notificationWithName:ToyboxNotification object:kTrigger userInfo:@{kIdentity:sender.identifier}]; | |
[[NSDistributedNotificationCenter defaultCenter] postNotification:note]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment