I had no idea you could use class property access like this it's the best thing ever.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Sat, 2 Mar 2013 02:38:58 +0000 (03:38 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Sat, 2 Mar 2013 02:38:58 +0000 (03:38 +0100)
ApplicationController.m
ConfigsController.m
KeyInputTextView.m
Target.m
TargetConfig.m
TargetController.m
TargetMouseBtn.m
TargetMouseMove.m
TargetToggleMouseScope.m

index 61910a6..9a2db2a 100644 (file)
@@ -26,7 +26,7 @@
     self.targetController.enabled = NO;
     [self.jsController setup];
     [self.configsController load];
-    [[NSWorkspace sharedWorkspace].notificationCenter
+    [NSWorkspace.sharedWorkspace.notificationCenter
      addObserver:self
      selector:@selector(didSwitchApplication:)
      name:NSWorkspaceDidActivateApplicationNotification
@@ -34,8 +34,8 @@
 }
 
 - (void)applicationWillTerminate:(NSNotification *)aNotification {
-       [[NSUserDefaults standardUserDefaults] synchronize];
-    [[NSWorkspace sharedWorkspace].notificationCenter
+       [NSUserDefaults.standardUserDefaults synchronize];
+    [NSWorkspace.sharedWorkspace.notificationCenter
      removeObserver:self
      name:NSWorkspaceDidActivateApplicationNotification
      object:nil];
@@ -56,7 +56,7 @@
 }
 
 - (void)configsChanged {
-    NSInteger removeFrom = [self firstConfigMenuIndex];
+    NSInteger removeFrom = self.firstConfigMenuIndex;
     while (dockMenuBase.numberOfItems > removeFrom)
         [dockMenuBase removeItemAtIndex:dockMenuBase.numberOfItems - 1];
     int added = 0;
@@ -72,7 +72,7 @@
 }
 
 - (void)configChanged {
-    NSInteger firstConfig = [self firstConfigMenuIndex];
+    NSInteger firstConfig = self.firstConfigMenuIndex;
     Config *current = self.configsController.currentConfig;
     NSArray *configs = self.configsController.configs;
     for (NSUInteger i = 0; i < configs.count; ++i)
@@ -80,7 +80,7 @@
 }
 
 - (void)chooseConfig:(id)sender {
-    NSInteger idx = [dockMenuBase indexOfItem:sender] - [self firstConfigMenuIndex];
+    NSInteger idx = [dockMenuBase indexOfItem:sender] - self.firstConfigMenuIndex;
     Config *chosen = self.configsController.configs[idx];
     [_configsController activateConfig:chosen];
 }
index a3b8bcd..1c100f2 100644 (file)
     _currentConfig = config;
     [removeButton setEnabled:_configs[0] != config];
     [targetController loadCurrent];
-    [(ApplicationController *)[[NSApplication sharedApplication] delegate] configChanged];
+    [(ApplicationController *)NSApplication.sharedApplication.delegate configChanged];
     [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:[_configs indexOfObject:config]] byExtendingSelection:NO];
 }
 
 - (IBAction)addPressed:(id)sender {
     Config *newConfig = [[Config alloc] initWithName:@"Untitled"];
     [_configs addObject:newConfig];
-    [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
+    [(ApplicationController *)NSApplication.sharedApplication.delegate configsChanged];
     [tableView reloadData];
     [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:_configs.count - 1] byExtendingSelection:NO];
     [tableView editColumn:0 row:_configs.count - 1 withEvent:nil select:YES];
@@ -69,7 +69,7 @@
     
     [_configs removeObjectAtIndex:tableView.selectedRow];
     [tableView reloadData];
-    [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
+    [(ApplicationController *)NSApplication.sharedApplication.delegate configsChanged];
     [self activateConfig:_configs[0]];
     [self save];
 }
@@ -86,7 +86,7 @@
 - (void)tableView:(NSTableView *)view setObjectValue:(NSString *)obj forTableColumn:(NSTableColumn *)col row:(NSInteger)index {
     [(Config *)_configs[index] setName:obj];
     [tableView reloadData];
-    [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
+    [(ApplicationController *)NSApplication.sharedApplication.delegate configsChanged];
 }
 
 - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
 
 - (void)save {
     NSLog(@"Saving defaults.");
-    [[NSUserDefaults standardUserDefaults] setObject:[self dumpAll] forKey:@"configurations"];
+    [NSUserDefaults.standardUserDefaults setObject:[self dumpAll] forKey:@"configurations"];
 }
 
 - (void)load {
-    [self loadAllFrom:[[NSUserDefaults standardUserDefaults] objectForKey:@"configurations"]];
+    [self loadAllFrom:[NSUserDefaults.standardUserDefaults objectForKey:@"configurations"]];
 }
 
 - (NSDictionary *)dumpAll {
             current = 0;
         _configs = newConfigs;
         [tableView reloadData];
-        [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
+        [(ApplicationController *)NSApplication.sharedApplication.delegate configsChanged];
         [self activateConfig:_configs[current]];
     }
 }
         : nil;
     [stream close];
     
-    if (!([serialization isKindOfClass:[NSDictionary class]]
+    if (!([serialization isKindOfClass:NSDictionary.class]
           && serialization[@"entries"])) {
         *error = [NSError errorWithDomain:@"Enjoyable"
                                     code:0
                           }
                           
                           [self save];
-                          [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
+                          [(ApplicationController *)NSApplication.sharedApplication.delegate configsChanged];
                           [self activateConfig:cfg];
                           [targetController loadCurrent];
                           
index 91a2a34..6c8e094 100644 (file)
 }
 
 - (BOOL)becomeFirstResponder {
-    [self setBackgroundColor:[NSColor selectedTextBackgroundColor]];
+    self.backgroundColor = NSColor.selectedTextBackgroundColor;
     return [super becomeFirstResponder];
 }
 
 - (BOOL)resignFirstResponder {
-    [self setBackgroundColor:[NSColor textBackgroundColor]];
+    self.backgroundColor = NSColor.textBackgroundColor;
     return [super resignFirstResponder];
 }
 
index 36da021..700a151 100644 (file)
--- a/Target.m
+++ b/Target.m
 + (Target *)targetDeserialize:(NSDictionary *)serialization
                   withConfigs:(NSArray *)configs {
     // Don't crash loading old configs (but don't load them either).
-    if (![serialization isKindOfClass:[NSDictionary class]])
+    if (![serialization isKindOfClass:NSDictionary.class])
         return nil;
     NSString *type = serialization[@"type"];
-    for (Class cls in @[[TargetKeyboard class],
-                        [TargetConfig class],
-                        [TargetMouseMove class],
-                        [TargetMouseBtn class],
-                        [TargetMouseScroll class],
-                        [TargetToggleMouseScope class]
+    for (Class cls in @[TargetKeyboard.class,
+                        TargetConfig.class,
+                        TargetMouseMove.class,
+                        TargetMouseBtn.class,
+                        TargetMouseScroll.class,
+                        TargetToggleMouseScope.class
          ]) {
-        if ([type isEqualToString:[cls serializationCode]])
+        if ([type isEqualToString:cls.serializationCode])
             return [cls targetDeserialize:serialization withConfigs:configs];
     }
     
index a06f3fb..055f782 100644 (file)
@@ -37,7 +37,8 @@
 }
 
 - (void)trigger {
-    [[(ApplicationController *)[[NSApplication sharedApplication] delegate] configsController] activateConfig:_config];
+    ApplicationController *ctrl = NSApplication.sharedApplication.delegate;
+    [ctrl.configsController activateConfig:_config];
 }
 
 @end
index 2ecb060..75f58ab 100644 (file)
         title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", configsController.currentConfig.name, actFullName];
     }
 
-    if ([target isKindOfClass:[TargetKeyboard class]]) {
+    if ([target isKindOfClass:TargetKeyboard.class]) {
         [radioButtons selectCellAtRow:1 column:0];
         keyInput.vk = [(TargetKeyboard*)target vk];
-    } else if ([target isKindOfClass:[TargetConfig class]]) {
+    } else if ([target isKindOfClass:TargetConfig.class]) {
         [radioButtons selectCellAtRow:2 column:0];
         NSUInteger idx = [configsController.configs
                           indexOfObject:[(TargetConfig *)target config]];
         } else
             [configPopup selectItemAtIndex:idx];
     }
-    else if ([target isKindOfClass:[TargetMouseMove class]]) {
+    else if ([target isKindOfClass:TargetMouseMove.class]) {
         [radioButtons selectCellAtRow:3 column:0];
         [mouseDirSelect setSelectedSegment:[(TargetMouseMove *)target axis]];
     }
-    else if ([target isKindOfClass:[TargetMouseBtn class]]) {
+    else if ([target isKindOfClass:TargetMouseBtn.class]) {
         [radioButtons selectCellAtRow:4 column:0];
         mouseBtnSelect.selectedSegment = [(TargetMouseBtn *)target button] == kCGMouseButtonLeft ? 0 : 1;
     }
-    else if ([target isKindOfClass:[TargetMouseScroll class]]) {
+    else if ([target isKindOfClass:TargetMouseScroll.class]) {
         [radioButtons selectCellAtRow:5 column:0];
         scrollDirSelect.selectedSegment = [(TargetMouseScroll *)target amount] > 0;
     }
-    else if ([target isKindOfClass:[TargetToggleMouseScope class]]) {
+    else if ([target isKindOfClass:TargetToggleMouseScope.class]) {
         [radioButtons selectCellAtRow:6 column:0];
     } else {
         [radioButtons selectCellAtRow:self.enabled ? 0 : -1 column:0];
 }
 
 - (void)loadCurrent {
-    [self loadTarget:[self currentTarget] forAction:joystickController.selectedAction];
+    [self loadTarget:self.currentTarget forAction:joystickController.selectedAction];
 }
 
 - (void)focusKey {
index 653014a..951715d 100644 (file)
@@ -25,9 +25,8 @@
 }
 
 -(void) trigger {
-    NSRect screenRect = [[NSScreen mainScreen] frame];
-    CGFloat height = screenRect.size.height;
-    NSPoint mouseLoc = [NSEvent mouseLocation];
+    CGFloat height = NSScreen.mainScreen.frame.size.height;
+    NSPoint mouseLoc = NSEvent.mouseLocation;
     CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown;
     CGEventRef click = CGEventCreateMouseEvent(NULL,
                                                eventType,
@@ -38,9 +37,8 @@
 }
 
 -(void) untrigger {
-    NSRect screenRect = [[NSScreen mainScreen] frame];
-    CGFloat height = screenRect.size.height;
-    NSPoint mouseLoc = [NSEvent mouseLocation];
+    CGFloat height = NSScreen.mainScreen.frame.size.height;
+    NSPoint mouseLoc = NSEvent.mouseLocation;
     CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp;
     CGEventRef click = CGEventCreateMouseEvent(NULL,
                                                eventType,
index 9deabcc..3ec8f38 100644 (file)
         return NO;
     }
     
-    NSRect screenRect = [[NSScreen mainScreen] frame];
-    CGFloat height = screenRect.size.height;
+    CGFloat height = NSScreen.mainScreen.frame.size.height;
     
     // TODO
     float speed = 4.f;
-    if ([jc frontWindowOnly])
+    if (jc.frontWindowOnly)
         speed = 12.f;
     float dx = 0.f, dy = 0.f;
     if (_axis == 0)
@@ -70,7 +69,7 @@
     CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, (int)dx);
     CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, (int)dy);
     
-    if ([jc frontWindowOnly]) {
+    if (jc.frontWindowOnly) {
         ProcessSerialNumber psn;
         GetFrontProcess(&psn);
         CGEventPostToPSN(&psn, move);
index 2f03c2f..863a35f 100644 (file)
@@ -28,9 +28,9 @@
 - (void)trigger {
     // FIXME: It's hacky to get at the controller this way, but it's
     // also hacky to pass it. Shouldn't need to do either.
-    ApplicationController *ac = [NSApplication sharedApplication].delegate;
+    ApplicationController *ac = NSApplication.sharedApplication.delegate;
     JoystickController *jc = ac.jsController;
-    [jc setFrontWindowOnly: ![jc frontWindowOnly]];
+    jc.frontWindowOnly = !jc.frontWindowOnly;
 }
 
 @end