From f9903acac24bb4be43e370d5f3eb942510f727e1 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Sat, 2 Mar 2013 03:38:58 +0100 Subject: [PATCH] I had no idea you could use class property access like this it's the best thing ever. --- ApplicationController.m | 12 ++++++------ ConfigsController.m | 18 +++++++++--------- KeyInputTextView.m | 4 ++-- Target.m | 16 ++++++++-------- TargetConfig.m | 3 ++- TargetController.m | 14 +++++++------- TargetMouseBtn.m | 10 ++++------ TargetMouseMove.m | 7 +++---- TargetToggleMouseScope.m | 4 ++-- 9 files changed, 43 insertions(+), 45 deletions(-) diff --git a/ApplicationController.m b/ApplicationController.m index 61910a6..9a2db2a 100644 --- a/ApplicationController.m +++ b/ApplicationController.m @@ -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]; } diff --git a/ConfigsController.m b/ConfigsController.m index a3b8bcd..1c100f2 100644 --- a/ConfigsController.m +++ b/ConfigsController.m @@ -50,14 +50,14 @@ _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 { @@ -99,11 +99,11 @@ - (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 { @@ -141,7 +141,7 @@ current = 0; _configs = newConfigs; [tableView reloadData]; - [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged]; + [(ApplicationController *)NSApplication.sharedApplication.delegate configsChanged]; [self activateConfig:_configs[current]]; } } @@ -154,7 +154,7 @@ : nil; [stream close]; - if (!([serialization isKindOfClass:[NSDictionary class]] + if (!([serialization isKindOfClass:NSDictionary.class] && serialization[@"entries"])) { *error = [NSError errorWithDomain:@"Enjoyable" code:0 @@ -220,7 +220,7 @@ } [self save]; - [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged]; + [(ApplicationController *)NSApplication.sharedApplication.delegate configsChanged]; [self activateConfig:cfg]; [targetController loadCurrent]; diff --git a/KeyInputTextView.m b/KeyInputTextView.m index 91a2a34..6c8e094 100644 --- a/KeyInputTextView.m +++ b/KeyInputTextView.m @@ -161,12 +161,12 @@ } - (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]; } diff --git a/Target.m b/Target.m index 36da021..700a151 100644 --- a/Target.m +++ b/Target.m @@ -31,17 +31,17 @@ + (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]; } diff --git a/TargetConfig.m b/TargetConfig.m index a06f3fb..055f782 100644 --- a/TargetConfig.m +++ b/TargetConfig.m @@ -37,7 +37,8 @@ } - (void)trigger { - [[(ApplicationController *)[[NSApplication sharedApplication] delegate] configsController] activateConfig:_config]; + ApplicationController *ctrl = NSApplication.sharedApplication.delegate; + [ctrl.configsController activateConfig:_config]; } @end diff --git a/TargetController.m b/TargetController.m index 2ecb060..75f58ab 100644 --- a/TargetController.m +++ b/TargetController.m @@ -170,10 +170,10 @@ 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]]; @@ -183,19 +183,19 @@ } 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]; @@ -204,7 +204,7 @@ } - (void)loadCurrent { - [self loadTarget:[self currentTarget] forAction:joystickController.selectedAction]; + [self loadTarget:self.currentTarget forAction:joystickController.selectedAction]; } - (void)focusKey { diff --git a/TargetMouseBtn.m b/TargetMouseBtn.m index 653014a..951715d 100644 --- a/TargetMouseBtn.m +++ b/TargetMouseBtn.m @@ -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, diff --git a/TargetMouseMove.m b/TargetMouseMove.m index 9deabcc..3ec8f38 100644 --- a/TargetMouseMove.m +++ b/TargetMouseMove.m @@ -46,12 +46,11 @@ 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); diff --git a/TargetToggleMouseScope.m b/TargetToggleMouseScope.m index 2f03c2f..863a35f 100644 --- a/TargetToggleMouseScope.m +++ b/TargetToggleMouseScope.m @@ -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 -- 2.20.1