From: Joe Wreschnig Date: Wed, 20 Mar 2013 20:39:13 +0000 (+0100) Subject: Output view controller now has a delegate rather than a direct reference to the input... X-Git-Tag: version-1.1~6 X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=4fd28dc6483fd7c8323196abdbf4f1833a284e03;p=enjoyable.git Output view controller now has a delegate rather than a direct reference to the input controller. --- diff --git a/Classes/EnjoyableApplicationDelegate.h b/Classes/EnjoyableApplicationDelegate.h index d9408aa..0207036 100644 --- a/Classes/EnjoyableApplicationDelegate.h +++ b/Classes/EnjoyableApplicationDelegate.h @@ -16,11 +16,12 @@ NJInputControllerDelegate, NJDeviceViewControllerDelegate, NJMappingsViewControllerDelegate, + NJOutputViewControllerDelegate, NJMappingMenuDelegate, NSWindowDelegate> -@property (nonatomic, strong) IBOutlet NJInputController *inputController; -@property (nonatomic, strong) IBOutlet NJOutputViewController *outputController; +@property (nonatomic, strong) IBOutlet NJInputController *ic; +@property (nonatomic, strong) IBOutlet NJOutputViewController *oc; @property (nonatomic, strong) IBOutlet NJMappingsViewController *mvc; @property (nonatomic, strong) IBOutlet NJDeviceViewController *dvc; diff --git a/Classes/EnjoyableApplicationDelegate.m b/Classes/EnjoyableApplicationDelegate.m index 83d0771..beab960 100644 --- a/Classes/EnjoyableApplicationDelegate.m +++ b/Classes/EnjoyableApplicationDelegate.m @@ -20,7 +20,7 @@ - (void)didSwitchApplication:(NSNotification *)note { NSRunningApplication *activeApp = note.userInfo[NSWorkspaceApplicationKey]; if (activeApp) - [self.inputController activateMappingForProcess:activeApp]; + [self.ic activateMappingForProcess:activeApp]; } - (void)applicationWillFinishLaunching:(NSNotification *)notification { @@ -40,11 +40,11 @@ name:NJEventSimulationStopped object:nil]; - [self.inputController load]; + [self.ic load]; [self.mvc.mappingList reloadData]; [self.mvc changedActiveMappingToIndex: - [self.inputController indexOfMapping: - self.inputController.currentMapping]]; + [self.ic indexOfMapping: + self.ic.currentMapping]]; statusItem = [NSStatusBar.systemStatusBar statusItemWithLength:36]; statusItem.image = [NSImage imageNamed:@"Status Menu Icon Disabled"]; @@ -136,6 +136,7 @@ [self performSelector:@selector(flashStatusItem) withObject:self afterDelay:0.2 * i]; + [self loadOutputForInput:self.dvc.selectedHandler]; } - (NSMenu *)applicationDockMenu:(NSApplication *)sender { @@ -148,16 +149,16 @@ NSURL *URL = [NSURL fileURLWithPath:filename]; NJMapping *mapping = [NJMapping mappingWithContentsOfURL:URL error:&error]; - if ([[self.inputController mappingForKey:mapping.name] hasConflictWith:mapping]) { - [self promptForMapping:mapping atIndex:self.inputController.mappings.count]; - } else if ([self.inputController mappingForKey:mapping.name]) { - [[self.inputController mappingForKey:mapping.name] mergeEntriesFrom:mapping]; + if ([[self.ic mappingForKey:mapping.name] hasConflictWith:mapping]) { + [self promptForMapping:mapping atIndex:self.ic.mappings.count]; + } else if ([self.ic mappingForKey:mapping.name]) { + [[self.ic mappingForKey:mapping.name] mergeEntriesFrom:mapping]; } else if (mapping) { [self.mvc beginUpdates]; - [self.inputController addMapping:mapping]; - [self.mvc addedMappingAtIndex:self.inputController.mappings.count - 1 startEditing:NO]; + [self.ic addMapping:mapping]; + [self.mvc addedMappingAtIndex:self.ic.mappings.count - 1 startEditing:NO]; [self.mvc endUpdates]; - [self.inputController activateMapping:mapping]; + [self.ic activateMapping:mapping]; } else { [self.window presentError:error modalForWindow:self.window @@ -169,7 +170,7 @@ } - (void)mappingWasChosen:(NJMapping *)mapping { - [self.inputController activateMapping:mapping]; + [self.ic activateMapping:mapping]; } - (void)mappingListShouldOpen { @@ -229,12 +230,12 @@ NSError *error; NJMapping *mapping = [NJMapping mappingWithContentsOfURL:panel.URL error:&error]; - if ([[self.inputController mappingForKey:mapping.name] hasConflictWith:mapping]) { - [self promptForMapping:mapping atIndex:self.inputController.mappings.count]; - } else if ([self.inputController mappingForKey:mapping.name]) { - [[self.inputController mappingForKey:mapping.name] mergeEntriesFrom:mapping]; + if ([[self.ic mappingForKey:mapping.name] hasConflictWith:mapping]) { + [self promptForMapping:mapping atIndex:self.ic.mappings.count]; + } else if ([self.ic mappingForKey:mapping.name]) { + [[self.ic mappingForKey:mapping.name] mergeEntriesFrom:mapping]; } else if (mapping) { - [self.inputController addMapping:mapping]; + [self.ic addMapping:mapping]; } else { [self.window presentError:error modalForWindow:self.window @@ -249,7 +250,7 @@ - (void)exportMappingClicked:(id)sender { NSSavePanel *panel = [NSSavePanel savePanel]; panel.allowedFileTypes = @[ @"enjoyable" ]; - NJMapping *mapping = self.inputController.currentMapping; + NJMapping *mapping = self.ic.currentMapping; panel.nameFieldStringValue = [mapping.name stringByFixingPathComponent]; [panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) { @@ -277,15 +278,15 @@ [alert.window orderOut:nil]; switch (returnCode) { case NSAlertFirstButtonReturn: // Merge - [self.inputController mergeMapping:newMapping intoMapping:oldMapping]; - [self.inputController activateMapping:oldMapping]; + [self.ic mergeMapping:newMapping intoMapping:oldMapping]; + [self.ic activateMapping:oldMapping]; break; case NSAlertThirdButtonReturn: // New Mapping [self.mvc beginUpdates]; - [self.inputController addMapping:newMapping]; + [self.ic addMapping:newMapping]; [self.mvc addedMappingAtIndex:idx startEditing:YES]; [self.mvc endUpdates]; - [self.inputController activateMapping:newMapping]; + [self.ic activateMapping:newMapping]; break; default: // Cancel, other. break; @@ -293,7 +294,7 @@ } - (void)promptForMapping:(NJMapping *)mapping atIndex:(NSInteger)idx { - NJMapping *mergeInto = [self.inputController mappingForKey:mapping.name]; + NJMapping *mergeInto = [self.ic mappingForKey:mapping.name]; NSAlert *conflictAlert = [[NSAlert alloc] init]; conflictAlert.messageText = NSLocalizedString(@"import conflict prompt", @"Title of import conflict alert"); conflictAlert.informativeText = @@ -311,18 +312,18 @@ } - (NSInteger)numberOfMappings:(NJMappingsViewController *)mvc { - return self.inputController.mappings.count; + return self.ic.mappings.count; } - (NJMapping *)mappingsViewController:(NJMappingsViewController *)mvc mappingForIndex:(NSUInteger)idx { - return self.inputController.mappings[idx]; + return self.ic.mappings[idx]; } - (void)mappingsViewController:(NJMappingsViewController *)mvc renameMappingAtIndex:(NSInteger)index toName:(NSString *)name { - [self.inputController renameMapping:self.inputController.mappings[index] + [self.ic renameMapping:self.ic.mappings[index] to:name]; } @@ -330,7 +331,7 @@ canMoveMappingFromIndex:(NSInteger)fromIdx toIndex:(NSInteger)toIdx { return fromIdx != toIdx && fromIdx != 0 && toIdx != 0 - && toIdx < (NSInteger)self.inputController.mappings.count; + && toIdx < (NSInteger)self.ic.mappings.count; } - (void)mappingsViewController:(NJMappingsViewController *)mvc @@ -338,7 +339,7 @@ toIndex:(NSInteger)toIdx { [mvc beginUpdates]; [mvc.mappingList moveRowAtIndex:fromIdx toIndex:toIdx]; - [self.inputController moveMoveMappingFromIndex:fromIdx toIndex:toIdx]; + [self.ic moveMoveMappingFromIndex:fromIdx toIndex:toIdx]; [mvc endUpdates]; } @@ -351,7 +352,7 @@ removeMappingAtIndex:(NSInteger)idx { [mvc beginUpdates]; [mvc removedMappingAtIndex:idx]; - [self.inputController removeMappingAtIndex:idx]; + [self.ic removeMappingAtIndex:idx]; [mvc endUpdates]; } @@ -361,14 +362,14 @@ error:(NSError **)error { NJMapping *mapping = [NJMapping mappingWithContentsOfURL:url error:error]; - if ([[self.inputController mappingForKey:mapping.name] hasConflictWith:mapping]) { + if ([[self.ic mappingForKey:mapping.name] hasConflictWith:mapping]) { [self promptForMapping:mapping atIndex:index]; - } else if ([self.inputController mappingForKey:mapping.name]) { - [[self.inputController mappingForKey:mapping.name] mergeEntriesFrom:mapping]; + } else if ([self.ic mappingForKey:mapping.name]) { + [[self.ic mappingForKey:mapping.name] mergeEntriesFrom:mapping]; } else if (mapping) { [self.mvc beginUpdates]; [self.mvc addedMappingAtIndex:index startEditing:NO]; - [self.inputController insertMapping:mapping atIndex:index]; + [self.ic insertMapping:mapping atIndex:index]; [self.mvc endUpdates]; } return !!mapping; @@ -377,39 +378,44 @@ - (void)mappingsViewController:(NJMappingsViewController *)mvc addMapping:(NJMapping *)mapping { [mvc beginUpdates]; - [mvc addedMappingAtIndex:self.inputController.mappings.count startEditing:YES]; - [self.inputController addMapping:mapping]; + [mvc addedMappingAtIndex:self.ic.mappings.count startEditing:YES]; + [self.ic addMapping:mapping]; [mvc endUpdates]; - [self.inputController activateMapping:mapping]; + [self.ic activateMapping:mapping]; } - (void)mappingsViewController:(NJMappingsViewController *)mvc choseMappingAtIndex:(NSInteger)idx { - [self.inputController activateMapping:self.inputController.mappings[idx]]; + [self.ic activateMapping:self.ic.mappings[idx]]; } - (id)deviceViewController:(NJDeviceViewController *)dvc elementForUID:(NSString *)uid { - return [self.inputController elementForUID:uid]; + return [self.ic elementForUID:uid]; +} + +- (void)loadOutputForInput:(NJInput *)input { + NJOutput *output = self.ic.currentMapping[input]; + [self.oc loadOutput:output forInput:input]; } - (void)deviceViewControllerDidSelectNothing:(NJDeviceViewController *)dvc { - [self.outputController loadInput:dvc.selectedHandler]; + [self loadOutputForInput:nil]; } - (void)deviceViewController:(NJDeviceViewController *)dvc didSelectBranch:(NJInputPathElement *)handler { - [self.outputController loadInput:dvc.selectedHandler]; + [self loadOutputForInput:dvc.selectedHandler]; } - (void)deviceViewController:(NJDeviceViewController *)dvc didSelectHandler:(NJInputPathElement *)handler { - [self.outputController loadInput:dvc.selectedHandler]; + [self loadOutputForInput:dvc.selectedHandler]; } - (void)deviceViewController:(NJDeviceViewController *)dvc didSelectDevice:(NJInputPathElement *)device { - [self.outputController loadInput:dvc.selectedHandler]; + [self loadOutputForInput:dvc.selectedHandler]; } - (void)inputController:(NJInputController *)ic @@ -432,8 +438,8 @@ - (void)inputController:(NJInputController *)ic didInput:(NJInput *)input { [self.dvc expandAndSelectItem:input]; - [self.outputController loadInput:input]; - [self.outputController focusKey]; + [self loadOutputForInput:input]; + [self.oc focusKey]; } - (void)inputController:(NJInputController *)ic didError:(NSError *)error { @@ -452,16 +458,28 @@ } - (NSInteger)numberOfDevicesInDeviceList:(NJDeviceViewController *)dvc { - return self.inputController.devices.count; + return self.ic.devices.count; } - (NJDevice *)deviceViewController:(NJDeviceViewController *)dvc deviceForIndex:(NSUInteger)idx { - return self.inputController.devices[idx]; + return self.ic.devices[idx]; } - (IBAction)simulatingEventsChanged:(NSButton *)sender { - self.inputController.simulatingEvents = sender.state == NSOnState; + self.ic.simulatingEvents = sender.state == NSOnState; +} + +- (void)outputViewController:(NJOutputViewController *)ovc + setOutput:(NJOutput *)output + forInput:(NJInput *)input { + self.ic.currentMapping[input] = output; + [self.ic save]; +} + +- (NJMapping *)outputViewController:(NJOutputViewController *)ovc + mappingForIndex:(NSUInteger)index { + return self.ic.mappings[index]; } @end diff --git a/Classes/NJOutputMapping.m b/Classes/NJOutputMapping.m index cfcc34f..2ee6a84 100644 --- a/Classes/NJOutputMapping.m +++ b/Classes/NJOutputMapping.m @@ -33,7 +33,7 @@ - (void)trigger { EnjoyableApplicationDelegate *ctrl = (EnjoyableApplicationDelegate *)NSApplication.sharedApplication.delegate; if (_mapping) { - [ctrl.inputController activateMapping:_mapping]; + [ctrl.ic activateMapping:_mapping]; self.mappingName = _mapping.name; } else { // TODO: Show an error message? Unobtrusively since something diff --git a/Classes/NJOutputViewController.h b/Classes/NJOutputViewController.h index 2f50ef8..a35c735 100644 --- a/Classes/NJOutputViewController.h +++ b/Classes/NJOutputViewController.h @@ -8,9 +8,11 @@ #import "NJKeyInputField.h" -@class NJInputController; -@class NJOutput; @class NJInput; +@class NJOutput; +@class NJMapping; + +@protocol NJOutputViewControllerDelegate; @interface NJOutputViewController : NSObject { IBOutlet NJKeyInputField *keyInput; @@ -22,14 +24,15 @@ IBOutlet NSSlider *scrollSpeedSlider; IBOutlet NSTextField *title; IBOutlet NSPopUpButton *mappingPopup; - IBOutlet NJInputController *inputController; IBOutlet NSButton *smoothCheck; IBOutlet NSButton *unknownMapping; } -@property (assign) BOOL enabled; +@property (nonatomic, weak) IBOutlet id delegate; + +- (void)loadOutput:(NJOutput *)output forInput:(NJInput *)input; +- (void)focusKey; -- (void)loadInput:(NJInput *)input; - (IBAction)radioChanged:(id)sender; - (IBAction)mdirChanged:(id)sender; - (IBAction)mbtnChanged:(id)sender; @@ -38,6 +41,14 @@ - (IBAction)scrollSpeedChanged:(id)sender; - (IBAction)scrollTypeChanged:(id)sender; -- (void)focusKey; +@end + +@protocol NJOutputViewControllerDelegate + +- (NJMapping *)outputViewController:(NJOutputViewController *)ovc + mappingForIndex:(NSUInteger)index; +- (void)outputViewController:(NJOutputViewController *)ovc + setOutput:(NJOutput *)output + forInput:(NJInput *)input; @end diff --git a/Classes/NJOutputViewController.m b/Classes/NJOutputViewController.m index a0f356f..ee5d260 100644 --- a/Classes/NJOutputViewController.m +++ b/Classes/NJOutputViewController.m @@ -30,11 +30,6 @@ selector:@selector(mappingListDidChange:) name:NJEventMappingListChanged object:nil]; - [NSNotificationCenter.defaultCenter - addObserver:self - selector:@selector(mappingDidChange:) - name:NJEventMappingChanged - object:nil]; } return self; } @@ -157,10 +152,6 @@ [self commit]; } -- (NJOutput *)currentOutput { - return inputController.currentMapping[_input]; -} - - (NJOutput *)makeOutput { switch (radioButtons.selectedRow) { case 0: @@ -176,7 +167,8 @@ break; case 2: { NJOutputMapping *c = [[NJOutputMapping alloc] init]; - c.mapping = inputController.mappings[mappingPopup.indexOfSelectedItem]; + c.mapping = [self.delegate outputViewController:self + mappingForIndex:mappingPopup.indexOfSelectedItem]; return c; } case 3: { @@ -204,8 +196,9 @@ - (void)commit { [self cleanUpInterface]; - inputController.currentMapping[_input] = [self makeOutput]; - [inputController save]; + [self.delegate outputViewController:self + setOutput:[self makeOutput] + forInput:_input]; } - (BOOL)enabled { @@ -227,11 +220,12 @@ } - (void)loadOutput:(NJOutput *)output forInput:(NJInput *)input { + _input = input; if (!input) { - self.enabled = NO; + [self setEnabled:NO]; title.stringValue = @""; } else { - self.enabled = YES; + [self setEnabled:YES]; NSString *inpFullName = input.name; for (NJInputPathElement *cur = input.parent; cur; cur = cur.parent) { inpFullName = [[NSString alloc] initWithFormat:@"%@ ▸ %@", cur.name, inpFullName]; @@ -273,11 +267,6 @@ [self cleanUpInterface]; } -- (void)loadInput:(NJInput *)input { - _input = input; - [self loadOutput:self.currentOutput forInput:input]; -} - - (void)focusKey { if (radioButtons.selectedRow <= 1) [keyInput.window makeFirstResponder:keyInput]; @@ -300,8 +289,4 @@ [mappingPopup selectItemWithIdenticalRepresentedObject:current]; } -- (void)mappingDidChange:(NSNotification *)note { - [self loadInput:_input]; -} - @end diff --git a/Info.plist b/Info.plist index 93dd01a..8ad8cc0 100644 --- a/Info.plist +++ b/Info.plist @@ -46,7 +46,7 @@ CFBundleSignature ???? CFBundleVersion - 565 + 571 LSApplicationCategoryType public.app-category.utilities NSHumanReadableCopyright diff --git a/Resources/English.lproj/MainMenu.xib b/Resources/English.lproj/MainMenu.xib index 44865f4..15e852a 100644 --- a/Resources/English.lproj/MainMenu.xib +++ b/Resources/English.lproj/MainMenu.xib @@ -1728,14 +1728,6 @@ aW5nLg 1025 - - - outputController - - - - 1027 - simulatingEventsChanged: @@ -1754,11 +1746,19 @@ aW5nLg - inputController + ic - 1032 + 1036 + + + + oc + + + + 1037 @@ -1930,11 +1930,11 @@ aW5nLg - inputController + delegate - + - 1034 + 1035 @@ -3309,402 +3309,9 @@ aW5nLg - 1034 - - - - - EnjoyableApplicationDelegate - NSObject - - id - id - id - NSButton - - - - exportMappingClicked: - id - - - importMappingClicked: - id - - - restoreToForeground: - id - - - simulatingEventsChanged: - NSButton - - - - NSMenu - NJDeviceViewController - NJInputController - NJMappingsViewController - NJOutputController - NSButton - NSMenu - NSWindow - - - - dockMenu - NSMenu - - - dvc - NJDeviceViewController - - - inputController - NJInputController - - - mvc - NJMappingsViewController - - - outputController - NJOutputController - - - simulatingEventsButton - NSButton - - - statusItemMenu - NSMenu - - - window - NSWindow - - - - IBProjectSource - ./Classes/EnjoyableApplicationDelegate.h - - - - NJDeviceViewController - NSObject - - id - NSView - NSOutlineView - NSView - - - - delegate - id - - - hidStoppedNotice - NSView - - - inputsTree - NSOutlineView - - - noDevicesNotice - NSView - - - - IBProjectSource - ./Classes/NJDeviceViewController.h - - - - NJInputController - NSObject - - delegate - id - - - delegate - - delegate - id - - - - IBProjectSource - ./Classes/NJInputController.h - - - - NJKeyInputField - NSControl - - delegate - id - - - delegate - - delegate - id - - - - IBProjectSource - ./Classes/NJKeyInputField.h - - - - NJMappingMenuController - NSObject - - id - NSMenuItem - NSMenu - - - - delegate - id - - - eventSimulationToggle - NSMenuItem - - - menu - NSMenu - - - - IBProjectSource - ./Classes/NJMappingMenuController.h - - - - NJMappingsViewController - NSViewController - - id - id - id - id - id - - - - addClicked: - id - - - mappingTriggerClicked: - id - - - moveDownClicked: - id - - - moveUpClicked: - id - - - removeClicked: - id - - - - id - NSTableView - NSPopover - NSButton - NSButton - NSButton - NSButton - - - - delegate - id - - - mappingList - NSTableView - - - mappingListPopover - NSPopover - - - mappingListTrigger - NSButton - - - moveDown - NSButton - - - moveUp - NSButton - - - removeMapping - NSButton - - - - IBProjectSource - ./Classes/NJMappingsViewController.h - - - - NJOutputController - NSObject - - id - id - id - id - id - id - id - - - - mbtnChanged: - id - - - mdirChanged: - id - - - mouseSpeedChanged: - id - - - radioChanged: - id - - - scrollSpeedChanged: - id - - - scrollTypeChanged: - id - - - sdirChanged: - id - - - - NJInputController - NJKeyInputField - NSPopUpButton - NSSegmentedControl - NSSegmentedControl - NSSlider - NSMatrix - NSSegmentedControl - NSSlider - NSButton - NSTextField - NSButton - - - - inputController - NJInputController - - - keyInput - NJKeyInputField - - - mappingPopup - NSPopUpButton - - - mouseBtnSelect - NSSegmentedControl - - - mouseDirSelect - NSSegmentedControl - - - mouseSpeedSlider - NSSlider - - - radioButtons - NSMatrix - - - scrollDirSelect - NSSegmentedControl - - - scrollSpeedSlider - NSSlider - - - smoothCheck - NSButton - - - title - NSTextField - - - unknownMapping - NSButton - - - - IBProjectSource - ./Classes/NJOutputController.h - - - - SUUpdater - NSObject - - checkForUpdates: - id - - - checkForUpdates: - - checkForUpdates: - id - - - - delegate - id - - - delegate - - delegate - id - - - - IBProjectSource - ./Classes/SUUpdater.h - - - + 1037 + 0 IBCocoaFramework YES