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 61910a6e247ddd8280770715e8a607e83324c114..9a2db2af3c1d31a5034f7cae19c235516b8ae03c 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 a3b8bcd750fee3cb5d3aec449043c5e7015517c8..1c100f2c9809949a2976913646ba0a391a68974c 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 91a2a3453d797d1f2a1494469e16cddbf2166f43..6c8e0948db6af42107e8c9b2e6b3955a8865fd1f 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 36da02126a8aff435624ffa0c4d3bb4726a5ab84..700a15112526857ceba3b4f2980c887629ff56a2 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 a06f3fb4f00b5ea1fdc7c911f3c2d6f39177e93b..055f7822cecc51d49666af84d824248d535a9391 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 2ecb06057f80e90a909de3616713302d47a6af40..75f58abe48f3d1254126baec71dab0721a09a5f2 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 653014ab22e90fb563820ee8b608caa08a857655..951715d8c6ed614c8e917d0bca1f73a53e550a28 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 9deabccdc9a55c1217b83396bb027546687412cf..3ec8f38ff440d68b300d3742ad186cd3327ca391 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 2f03c2fb74cfda407c851f7e7166173817e73e18..863a35fda7d1df27182ff543ff8fec040ddbe59a 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