From e7c0b2d96e9e3209b5ba80cc1fdc8e7213cb5302 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Mon, 18 Mar 2013 14:40:50 +0100 Subject: [PATCH] Fix several cases where the UI did not properly reflect model changes. --- Classes/EnjoyableApplicationDelegate.m | 7 + Classes/NJDevice.m | 1 + Classes/NJDeviceController.m | 19 +- Classes/NJDeviceViewController.h | 3 + Classes/NJDeviceViewController.m | 12 +- Classes/NJInput.h | 2 +- Classes/NJInputAnalog.m | 2 +- Classes/NJInputButton.m | 2 +- Classes/NJInputHat.m | 2 +- Classes/NJMappingsController.h | 4 +- Classes/NJMappingsController.m | 14 +- Info.plist | 2 +- Resources/English.lproj/MainMenu.xib | 497 ++----------------------- 13 files changed, 70 insertions(+), 497 deletions(-) diff --git a/Classes/EnjoyableApplicationDelegate.m b/Classes/EnjoyableApplicationDelegate.m index 7c9ae7e..bf2a336 100644 --- a/Classes/EnjoyableApplicationDelegate.m +++ b/Classes/EnjoyableApplicationDelegate.m @@ -151,7 +151,11 @@ } else if (self.mappingsController[mapping.name]) { [self.mappingsController[mapping.name] mergeEntriesFrom:mapping]; } else if (mapping) { + [self.mvc beginUpdates]; [self.mappingsController addMapping:mapping]; + [self.mvc addedMappingAtIndex:self.mappingsController.count - 1 startEditing:NO]; + [self.mvc endUpdates]; + [self.mappingsController activateMapping:mapping]; } else { [window presentError:error modalForWindow:window @@ -360,7 +364,10 @@ } else if (self.mappingsController[mapping.name]) { [self.mappingsController[mapping.name] mergeEntriesFrom:mapping]; } else if (mapping) { + [self.mvc beginUpdates]; + [self.mvc addedMappingAtIndex:index startEditing:NO]; [self.mappingsController insertMapping:mapping atIndex:index]; + [self.mvc endUpdates]; } return !!mapping; } diff --git a/Classes/NJDevice.m b/Classes/NJDevice.m index ddc6cde..bf39251 100644 --- a/Classes/NJDevice.m +++ b/Classes/NJDevice.m @@ -72,6 +72,7 @@ static NSArray *InputsForElement(IOHIDDeviceRef device, id parent) { _vendorId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDVendorIDKey)) intValue]; _productId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDProductIDKey)) intValue]; self.children = InputsForElement(dev, self); + self.index = 1; } return self; } diff --git a/Classes/NJDeviceController.m b/Classes/NJDeviceController.m index 000df5f..bdd1bbf 100644 --- a/Classes/NJDeviceController.m +++ b/Classes/NJDeviceController.m @@ -117,22 +117,27 @@ } } -- (void)hidManager:(NJHIDManager *)manager deviceAdded:(IOHIDDeviceRef)device { - NJDevice *match = [[NJDevice alloc] initWithDevice:device]; - match.index = 1; +- (void)addDevice:(NJDevice *)device { BOOL available; do { available = YES; for (NJDevice *used in _devices) { - if ([used isEqual:match]) { - match.index += 1; + if ([used isEqual:device]) { + device.index += 1; available = NO; } } } while (!available); + + [_devices addObject:device]; +} - [_devices addObject:match]; +- (void)hidManager:(NJHIDManager *)manager deviceAdded:(IOHIDDeviceRef)device { + NJDevice *match = [[NJDevice alloc] initWithDevice:device]; + [devicesViewController beginUpdates]; + [self addDevice:match]; [devicesViewController addedDevice:match atIndex:_devices.count - 1]; + [devicesViewController endUpdates]; } - (NJDevice *)findDeviceByRef:(IOHIDDeviceRef)device { @@ -147,8 +152,10 @@ IOHIDDeviceRegisterInputValueCallback(device, NULL, NULL); if (match) { NSInteger idx = [_devices indexOfObjectIdenticalTo:match]; + [devicesViewController beginUpdates]; [_devices removeObjectAtIndex:idx]; [devicesViewController removedDevice:match atIndex:idx]; + [devicesViewController endUpdates]; } } diff --git a/Classes/NJDeviceViewController.h b/Classes/NJDeviceViewController.h index 6d039af..6935322 100644 --- a/Classes/NJDeviceViewController.h +++ b/Classes/NJDeviceViewController.h @@ -27,6 +27,9 @@ - (void)hidStarted; - (void)hidStopped; +- (void)beginUpdates; +- (void)endUpdates; + - (void)expandAndSelectItem:(NJInputPathElement *)item; - (NJInputPathElement *)selectedHandler; diff --git a/Classes/NJDeviceViewController.m b/Classes/NJDeviceViewController.m index f9ff141..5d0bf6a 100644 --- a/Classes/NJDeviceViewController.m +++ b/Classes/NJDeviceViewController.m @@ -36,6 +36,14 @@ [self expandRecursive:[self.delegate deviceViewController:self elementForUID:uid]]; } +- (void)beginUpdates { + [self.inputsTree beginUpdates]; +} + +- (void)endUpdates { + [self.inputsTree endUpdates]; +} + - (void)reexpandAll { for (NSString *uid in [_expanded copy]) [self expandRecursiveByUID:uid]; @@ -47,22 +55,18 @@ } - (void)addedDevice:(NJDevice *)device atIndex:(NSUInteger)idx { - [self.inputsTree beginUpdates]; [self.inputsTree insertItemsAtIndexes:[[NSIndexSet alloc] initWithIndex:idx] inParent:nil withAnimation:NSTableViewAnimationEffectFade]; [self reexpandAll]; - [self.inputsTree endUpdates]; self.noDevicesNotice.hidden = YES; } - (void)removedDevice:(NJDevice *)device atIndex:(NSUInteger)idx { BOOL anyDevices = !![self.delegate numberOfDevicesInDeviceList:self]; - [self.inputsTree beginUpdates]; [self.inputsTree removeItemsAtIndexes:[[NSIndexSet alloc] initWithIndex:idx] inParent:nil withAnimation:NSTableViewAnimationEffectFade]; - [self.inputsTree endUpdates]; self.noDevicesNotice.hidden = anyDevices || !self.hidStoppedNotice.isHidden; } diff --git a/Classes/NJInput.h b/Classes/NJInput.h index b530c37..ad7320e 100644 --- a/Classes/NJInput.h +++ b/Classes/NJInput.h @@ -10,7 +10,7 @@ @interface NJInput : NJInputPathElement -#define NJINPUT_DID(name, index) [[NSString alloc] initWithFormat:@"%s %d", name, index] +#define NJINPUT_EID(name, index) [[NSString alloc] initWithFormat:@"%s %d", name, index] #define NJINPUT_NAME(name, index) [[NSString alloc] initWithFormat:name, index] - (id)initWithName:(NSString *)name diff --git a/Classes/NJInputAnalog.m b/Classes/NJInputAnalog.m index 1f65f48..18a848b 100644 --- a/Classes/NJInputAnalog.m +++ b/Classes/NJInputAnalog.m @@ -23,7 +23,7 @@ static float normalize(CFIndex p, CFIndex min, CFIndex max) { parent:(NJInputPathElement *)parent { if ((self = [super initWithName:NJINPUT_NAME(NSLocalizedString(@"axis %d", @"axis name"), index) - eid:NJINPUT_DID("Axis", index) + eid:NJINPUT_EID("Axis", index) element:element parent:parent])) { self.children = @[[[NJInput alloc] initWithName:NSLocalizedString(@"axis low", @"axis low trigger") diff --git a/Classes/NJInputButton.m b/Classes/NJInputButton.m index 354220a..44a0beb 100644 --- a/Classes/NJInputButton.m +++ b/Classes/NJInputButton.m @@ -16,7 +16,7 @@ parent:(NJInputPathElement *)parent { if ((self = [super initWithName:NJINPUT_NAME(NSLocalizedString(@"button %d", @"button name"), index) - eid:NJINPUT_DID("Button", index) + eid:NJINPUT_EID("Button", index) element:element parent:parent])) { _max = IOHIDElementGetLogicalMax(element); diff --git a/Classes/NJInputHat.m b/Classes/NJInputHat.m index 0a5afa2..b4506d4 100644 --- a/Classes/NJInputHat.m +++ b/Classes/NJInputHat.m @@ -36,7 +36,7 @@ static BOOL active_fourway[20] = { parent:(NJInputPathElement *)parent { if ((self = [super initWithName:NJINPUT_NAME(NSLocalizedString(@"hat switch %d", @"hat switch name"), index) - eid:NJINPUT_DID("Hat Switch", index) + eid:NJINPUT_EID("Hat Switch", index) element:element parent:parent])) { self.children = @[[[NJInput alloc] initWithName:NSLocalizedString(@"hat up", @"hat switch up state") diff --git a/Classes/NJMappingsController.h b/Classes/NJMappingsController.h index 83ed8ef..9dd1e15 100644 --- a/Classes/NJMappingsController.h +++ b/Classes/NJMappingsController.h @@ -7,7 +7,6 @@ // @class NJMapping; -@class NJOutputController; @interface NJMappingsController : NSObject @@ -25,10 +24,9 @@ - (void)moveMoveMappingFromIndex:(NSInteger)fromIdx toIndex:(NSInteger)toIdx; - (void)renameMapping:(NJMapping *)mapping to:(NSString *)name; -- (void)mappingsChanged; - - (void)activateMapping:(NJMapping *)mapping; - (void)activateMappingForProcess:(NSRunningApplication *)app; + - (void)save; - (void)load; diff --git a/Classes/NJMappingsController.m b/Classes/NJMappingsController.m index 8f0492c..760b41b 100644 --- a/Classes/NJMappingsController.m +++ b/Classes/NJMappingsController.m @@ -11,8 +11,6 @@ #import "NJOutput.h" #import "NJEvents.h" -#define PB_ROW @"com.yukkurigames.Enjoyable.MappingRow" - @implementation NJMappingsController { NSMutableArray *_mappings; NJMapping *_manualMapping; @@ -95,7 +93,7 @@ NSLog(@"Switching to mapping %@.", mapping.name); _manualMapping = mapping; _currentMapping = mapping; - NSUInteger idx = [_mappings indexOfObjectIdenticalTo:_currentMapping]; + NSUInteger idx = [self indexOfMapping:_currentMapping]; [NSNotificationCenter.defaultCenter postNotificationName:NJEventMappingChanged object:self @@ -121,11 +119,9 @@ NSArray *storedMappings = [NSUserDefaults.standardUserDefaults arrayForKey:@"mappings"]; NSMutableArray* newMappings = [[NSMutableArray alloc] initWithCapacity:storedMappings.count]; - for (unsigned i = 0; i < storedMappings.count; ++i) { - NJMapping *mapping = [[NJMapping alloc] initWithSerialization:storedMappings[i]]; - [newMappings addObject:mapping]; - } - + for (NSDictionary *serialization in storedMappings) + [newMappings addObject: + [[NJMapping alloc] initWithSerialization:serialization]]; if (newMappings.count) { _mappings = newMappings; @@ -154,6 +150,7 @@ - (void)renameMapping:(NJMapping *)mapping to:(NSString *)name { mapping.name = name; + [self mappingsChanged]; if (mapping == _currentMapping) { // FIXME: Hack to trigger updates in the rest of the UI. _currentMapping = nil; @@ -161,7 +158,6 @@ [self activateMapping:mapping]; _manualMapping = manual; } - [self mappingsChanged]; } - (void)addMapping:(NJMapping *)mapping { diff --git a/Info.plist b/Info.plist index 30bd0d2..4a78c2b 100644 --- a/Info.plist +++ b/Info.plist @@ -46,7 +46,7 @@ CFBundleSignature ???? CFBundleVersion - 519 + 526 LSApplicationCategoryType public.app-category.utilities NSHumanReadableCopyright diff --git a/Resources/English.lproj/MainMenu.xib b/Resources/English.lproj/MainMenu.xib index 7306c41..7cd0972 100644 --- a/Resources/English.lproj/MainMenu.xib +++ b/Resources/English.lproj/MainMenu.xib @@ -500,7 +500,6 @@ -2147483374 {{20, 20}, {194, 283}} - _NS:22 YES @@ -530,7 +529,6 @@ Lg 274 {{20, 20}, {194, 283}} - _NS:22 YES @@ -565,7 +563,6 @@ aW5nLg {232, 321} - YES NO @@ -661,7 +658,6 @@ aW5nLg {{1, 1}, {232, 321}} - @@ -672,7 +668,6 @@ aW5nLg -2147483392 {{1, 1}, {8, 298}} - NO @@ -684,7 +679,6 @@ aW5nLg -2147483392 {{-100, -100}, {473, 15}} - NO 1 @@ -695,7 +689,6 @@ aW5nLg {234, 323} - 150034 @@ -709,7 +702,6 @@ aW5nLg {234, 323} - _NS:9 NSView @@ -723,7 +715,6 @@ aW5nLg 268 {{197, 157}, {193, 21}} - _NS:9 YES @@ -748,7 +739,6 @@ aW5nLg 265 {{189, 117}, {224, 20}} - _NS:9 YES @@ -790,7 +780,6 @@ aW5nLg 268 {{343, 31}, {70, 18}} - _NS:9 YES @@ -821,7 +810,6 @@ aW5nLg 265 {{189, 33}, {150, 20}} - _NS:9 YES @@ -866,7 +854,6 @@ aW5nLg 265 {{191, 24}, {146, 16}} - _NS:9 YES @@ -892,7 +879,6 @@ aW5nLg 265 {{189, 70}, {224, 24}} - _NS:9 YES @@ -946,7 +932,6 @@ aW5nLg 265 {{191, 108}, {220, 16}} - _NS:9 YES @@ -972,7 +957,6 @@ aW5nLg 265 {{191, 196}, {220, 23}} - _NS:9 NJKeyInputField @@ -982,7 +966,6 @@ aW5nLg 265 {{188, 153}, {226, 26}} - YES @@ -1015,7 +998,6 @@ aW5nLg 268 {{24, 20}, {163, 250}} - NO 6 @@ -1146,7 +1128,6 @@ aW5nLg 266 {{9, 286}, {412, 17}} - YES @@ -1170,7 +1151,6 @@ aW5nLg 10 {{12, 276}, {406, 5}} - {0, 0} @@ -1197,7 +1177,6 @@ aW5nLg {{233, 0}, {431, 323}} - _NS:9 NSView @@ -1205,7 +1184,6 @@ aW5nLg {664, 323} - {{0, 0}, {1440, 878}} @@ -1231,7 +1209,6 @@ aW5nLg 256 {198, 198} - YES NO @@ -1289,7 +1266,6 @@ aW5nLg {{1, 1}, {198, 198}} - @@ -1300,7 +1276,6 @@ aW5nLg -2147483392 {{306, 1}, {15, 403}} - NO @@ -1312,7 +1287,6 @@ aW5nLg -2147483392 {{-100, -100}, {366, 16}} - NO 1 @@ -1323,7 +1297,6 @@ aW5nLg {{0, 20}, {200, 200}} - 150034 @@ -1339,7 +1312,6 @@ aW5nLg 268 {{66, -1}, {68, 23}} - _NS:22 YES @@ -1368,7 +1340,6 @@ aW5nLg 292 {{0, -1}, {34, 23}} - YES @@ -1395,7 +1366,6 @@ aW5nLg 292 {{166, -1}, {34, 23}} - YES 67108864 @@ -1417,7 +1387,6 @@ aW5nLg 292 {{133, -1}, {34, 23}} - YES @@ -1440,7 +1409,6 @@ aW5nLg 292 {{33, -1}, {34, 23}} - YES @@ -1465,30 +1433,9 @@ aW5nLg {200, 220} - NSView - - EnjoyableApplicationDelegate - - - NJMappingsController - - - NJDeviceController - - - NJOutputController - - - - 0 - 1 - 0.0 - 0.0 - YES - @@ -1561,6 +1508,32 @@ aW5nLg + + EnjoyableApplicationDelegate + + + + 0 + 1 + 0.0 + 0.0 + YES + + + NJMappingsController + + + NJDeviceController + + + NJOutputController + + + NJDeviceViewController + + + NJMappingsViewController + NJMappingMenuController @@ -1573,12 +1546,6 @@ aW5nLg SUUpdater - - NJDeviceViewController - - - NJMappingsViewController - @@ -3363,417 +3330,7 @@ aW5nLg 1024 - - - - EnjoyableApplicationDelegate - NSObject - - id - id - id - - - - exportMappingClicked: - id - - - importMappingClicked: - id - - - restoreToForeground: - id - - - - NSMenu - NJMappingsController - NJMappingsViewController - NSMenu - NSWindow - - - - dockMenu - NSMenu - - - mappingsController - NJMappingsController - - - mvc - NJMappingsViewController - - - statusItemMenu - NSMenu - - - window - NSWindow - - - - IBProjectSource - ./Classes/EnjoyableApplicationDelegate.h - - - - NJDeviceController - NSObject - - simulatingEventsChanged: - NSButton - - - simulatingEventsChanged: - - simulatingEventsChanged: - NSButton - - - - NJDeviceViewController - NJMappingsController - NJOutputController - NSButton - - - - devicesViewController - NJDeviceViewController - - - mappingsController - NJMappingsController - - - outputController - NJOutputController - - - simulatingEventsButton - NSButton - - - - IBProjectSource - ./Classes/NJDeviceController.h - - - - NJDeviceViewController - NSObject - - id - NSView - NSOutlineView - NSView - - - - delegate - id - - - hidStoppedNotice - NSView - - - inputsTree - NSOutlineView - - - noDevicesNotice - NSView - - - - IBProjectSource - ./Classes/NJDeviceViewController.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 - - - - NJMappingsController - NSObject - - IBProjectSource - ./Classes/NJMappingsController.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 - - - - NJDeviceController - NJKeyInputField - NSPopUpButton - NJMappingsController - NSSegmentedControl - NSSegmentedControl - NSSlider - NSMatrix - NSSegmentedControl - NSSlider - NSButton - NSTextField - NSButton - - - - inputController - NJDeviceController - - - keyInput - NJKeyInputField - - - mappingPopup - NSPopUpButton - - - mappingsController - NJMappingsController - - - 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 - - - - + 0 IBCocoaFramework YES -- 2.20.1