From 8fa589c4e6be7272402952c4f929f81763700212 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Wed, 13 Mar 2013 10:44:55 +0100 Subject: [PATCH] Show a special message when the HID was closed during deactivation. --- Classes/NJDeviceController.h | 1 + Classes/NJDeviceController.m | 27 +++++++++-- Info.plist | 2 +- Resources/English.lproj/MainMenu.xib | 70 ++++++++++++++++++++++++---- 4 files changed, 88 insertions(+), 12 deletions(-) diff --git a/Classes/NJDeviceController.h b/Classes/NJDeviceController.h index c0002e8..71a0ed1 100644 --- a/Classes/NJDeviceController.h +++ b/Classes/NJDeviceController.h @@ -17,6 +17,7 @@ IBOutlet NJMappingsController *mappingsController; IBOutlet NSButton *translatingEventsButton; IBOutlet NSView *connectDevicePrompt; + IBOutlet NSView *hidSleepingPrompt; } @property (nonatomic, readonly) NJInput *selectedInput; diff --git a/Classes/NJDeviceController.m b/Classes/NJDeviceController.m index a1e5868..2a1546c 100644 --- a/Classes/NJDeviceController.m +++ b/Classes/NJDeviceController.m @@ -78,12 +78,17 @@ } } -- (void)expandRecursiveByUID:(NSString *)uid { +- (id)elementForUID:(NSString *)uid { for (NJDevice *dev in _devices) { id item = [dev elementForUID:uid]; if (item) - [self expandRecursive:item]; + return item; } + return nil; +} + +- (void)expandRecursiveByUID:(NSString *)uid { + [self expandRecursive:[self elementForUID:uid]]; } - (void)addRunningOutput:(NJOutput *)output { @@ -158,6 +163,7 @@ static int findAvailableIndex(NSArray *list, NJDevice *dev) { [_devices addObject:dev]; [outlineView reloadData]; [self reexpandAll]; + hidSleepingPrompt.hidden = YES; connectDevicePrompt.hidden = !!_devices.count; } @@ -185,6 +191,7 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD [_devices removeObject:match]; [outlineView reloadData]; connectDevicePrompt.hidden = !!_devices.count; + hidSleepingPrompt.hidden = YES; } if (_devices.count == 1) [outlineView expandItem:_devices[0]]; @@ -236,6 +243,8 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD } else { IOHIDManagerRegisterDeviceMatchingCallback(_hidManager, add_callback, (__bridge void *)self); IOHIDManagerRegisterDeviceRemovalCallback(_hidManager, remove_callback, (__bridge void *)self); + hidSleepingPrompt.hidden = YES; + connectDevicePrompt.hidden = !!_devices.count; } } @@ -249,7 +258,8 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD } [_devices removeAllObjects]; [outlineView reloadData]; - connectDevicePrompt.hidden = !!_devices.count; + hidSleepingPrompt.hidden = NO; + connectDevicePrompt.hidden = YES; } - (NJInput *)selectedInput { @@ -280,6 +290,10 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn } - (void)outlineViewSelectionDidChange:(NSNotification *)notification { + id item = [outlineView itemAtRow:outlineView.selectedRow]; + if (item) + [NSUserDefaults.standardUserDefaults setObject:item.uid + forKey:@"selected input"]; [outputController loadCurrent]; } @@ -332,6 +346,13 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn - (void)reexpandAll { for (NSString *uid in [_expanded copy]) [self expandRecursiveByUID:uid]; + if (outlineView.selectedRow == -1) { + NSString *selectedUid = [NSUserDefaults.standardUserDefaults objectForKey:@"selected input"]; + id item = [self elementForUID:selectedUid]; + NSInteger row = [outlineView rowForItem:item]; + if (row >= 0) + [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; + } } - (void)closeHidIfDisabled:(NSNotification *)application { diff --git a/Info.plist b/Info.plist index 49083b1..2add159 100644 --- a/Info.plist +++ b/Info.plist @@ -46,7 +46,7 @@ CFBundleSignature ???? CFBundleVersion - 213 + 222 LSApplicationCategoryType public.app-category.utilities NSHumanReadableCopyright diff --git a/Resources/English.lproj/MainMenu.xib b/Resources/English.lproj/MainMenu.xib index 47b41c1..c63659b 100644 --- a/Resources/English.lproj/MainMenu.xib +++ b/Resources/English.lproj/MainMenu.xib @@ -496,26 +496,52 @@ 275 - + - 274 + -2147483374 {{20, 20}, {194, 283}} _NS:22 YES - + 603979776 134217728 - Tm8gaW5wdXQgZGV2aWNlcyB3ZXJlIGZvdW5kLgoKQ29ubmVjdCBhIGRldmljZSB0byBiZWdpbiBtYXBw -aW5nLg - + SW5wdXQgaXMgY3VycmVudGx5IGRpc2FibGVkLgoKU3dpdGNoIGJhY2sgdG8gcmUtZW5hYmxlIGlucHV0 +Lg + LucidaGrande-Bold 14 16 _NS:22 + + -2041823232 + 134 + + + 400 + 75 + + NO + + + + 274 + {{20, 20}, {194, 283}} + + + + _NS:22 + YES + + 603979776 + 134217728 + Tm8gaW5wdXQgZGV2aWNlcyB3ZXJlIGZvdW5kLgoKQ29ubmVjdCBhIGRldmljZSB0byBiZWdpbiBtYXBw +aW5nLg + + _NS:22 -2041823232 134 @@ -741,7 +767,6 @@ aW5nLg {{343, 31}, {70, 18}} - _NS:9 YES @@ -1668,6 +1693,14 @@ aW5nLg 915 + + + hidSleepingPrompt + + + + 976 + mappingsController @@ -2599,6 +2632,7 @@ aW5nLg + @@ -2956,6 +2990,19 @@ aW5nLg + + 974 + + + + + + + + 975 + + + @@ -3205,12 +3252,14 @@ aW5nLg com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin - 971 + 976 @@ -3273,6 +3322,7 @@ aW5nLg NSView + NSView NJMappingsController NSOutlineView NJOutputController @@ -3283,6 +3333,10 @@ aW5nLg connectDevicePrompt NSView + + hidSleepingPrompt + NSView + mappingsController NJMappingsController -- 2.30.2