self.targetController.enabled = NO;
[self.jsController setup];
[self.configsController load];
- [[NSWorkspace sharedWorkspace].notificationCenter
+ [NSWorkspace.sharedWorkspace.notificationCenter
addObserver:self
selector:@selector(didSwitchApplication:)
name:NSWorkspaceDidActivateApplicationNotification
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
- [[NSUserDefaults standardUserDefaults] synchronize];
- [[NSWorkspace sharedWorkspace].notificationCenter
+ [NSUserDefaults.standardUserDefaults synchronize];
+ [NSWorkspace.sharedWorkspace.notificationCenter
removeObserver:self
name:NSWorkspaceDidActivateApplicationNotification
object:nil];
}
- (void)configsChanged {
- NSInteger removeFrom = [self firstConfigMenuIndex];
+ NSInteger removeFrom = self.firstConfigMenuIndex;
while (dockMenuBase.numberOfItems > removeFrom)
[dockMenuBase removeItemAtIndex:dockMenuBase.numberOfItems - 1];
int added = 0;
}
- (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)
}
- (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];
}
_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];
[_configs removeObjectAtIndex:tableView.selectedRow];
[tableView reloadData];
- [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
+ [(ApplicationController *)NSApplication.sharedApplication.delegate configsChanged];
[self activateConfig:_configs[0]];
[self save];
}
- (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];
}
- (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];
}
+ (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];
}
}
- (void)trigger {
- [[(ApplicationController *)[[NSApplication sharedApplication] delegate] configsController] activateConfig:_config];
+ ApplicationController *ctrl = NSApplication.sharedApplication.delegate;
+ [ctrl.configsController activateConfig:_config];
}
@end
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 {
}
-(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,
}
-(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,
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)
CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, (int)dx);
CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, (int)dy);
- if ([jc frontWindowOnly]) {
+ if (jc.frontWindowOnly) {
ProcessSerialNumber psn;
GetFrontProcess(&psn);
CGEventPostToPSN(&psn, move);
- (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