return [self findInputByCookie:cookie];
}
+- (BOOL)isEqual:(id)object {
+ return [object isKindOfClass:NJDevice.class]
+ && [[object uid] isEqualToString:self.uid];
+}
+
+- (NSUInteger)hash {
+ return self.uid.hash;
+}
+
+- (id <NJInputPathElement>)elementForUID:(NSString *)uid {
+ if ([uid isEqualToString:self.uid])
+ return self;
+ else if (![uid hasPrefix:self.uid])
+ return nil;
+ else {
+ for (id <NJInputPathElement> elem in self.children) {
+ id <NJInputPathElement> ret = [elem elementForUID:uid];
+ if (ret)
+ return ret;
+ }
+ }
+ return nil;
+}
+
@end
NSTimer *_continuousOutputsTick;
NSMutableArray *_continousOutputs;
NSMutableArray *_devices;
+ NSMutableArray *_expanded;
}
+#define EXPANDED_MEMORY_MAX_SIZE 100
+
- (id)init {
if ((self = [super init])) {
_devices = [[NSMutableArray alloc] initWithCapacity:16];
_continousOutputs = [[NSMutableArray alloc] initWithCapacity:32];
+
+ NSArray *expanded = [NSUserDefaults.standardUserDefaults objectForKey:@"expanded rows"];
+ if (![expanded isKindOfClass:NSArray.class])
+ expanded = @[];
+ _expanded = [[NSMutableArray alloc] initWithCapacity:MAX(16, _expanded.count)];
+ [_expanded addObjectsFromArray:expanded];
+
[NSNotificationCenter.defaultCenter
addObserver:self
selector:@selector(applicationDidFinishLaunching:)
}
}
+- (void)expandRecursiveByUID:(NSString *)uid {
+ for (NJDevice *dev in _devices) {
+ id item = [dev elementForUID:uid];
+ if (item)
+ [self expandRecursive:item];
+ }
+}
+
- (void)addRunningOutput:(NJOutput *)output {
// Axis events will trigger every small movement, don't keep
// re-adding them or they trigger multiple times each time.
dev.index = findAvailableIndex(_devices, dev);
[_devices addObject:dev];
[outlineView reloadData];
+ [self reexpandAll];
connectDevicePrompt.hidden = !!_devices.count;
}
return ![self outlineView:outlineView_ isGroupItem:item];
}
+- (void)outlineViewItemDidExpand:(NSNotification *)notification {
+ id <NJInputPathElement> item = notification.userInfo[@"NSObject"];
+ NSString *uid = item.uid;
+ if (![_expanded containsObject:uid])
+ [_expanded addObject:uid];
+ while (_expanded.count > EXPANDED_MEMORY_MAX_SIZE)
+ [_expanded removeObjectAtIndex:0];
+ [NSUserDefaults.standardUserDefaults setObject:_expanded
+ forKey:@"expanded rows"];
+}
+
+- (void)outlineViewItemDidCollapse:(NSNotification *)notification {
+ id <NJInputPathElement> item = notification.userInfo[@"NSObject"];
+ [_expanded removeObject:item.uid];
+ [NSUserDefaults.standardUserDefaults setObject:_expanded
+ forKey:@"expanded rows"];
+}
+
- (void)setTranslatingEvents:(BOOL)translatingEvents {
if (translatingEvents != _translatingEvents) {
_translatingEvents = translatingEvents;
}
}
+- (void)reexpandAll {
+ for (NSString *uid in [_expanded copy])
+ [self expandRecursiveByUID:uid];
+}
+
- (void)closeHidIfDisabled:(NSNotification *)application {
if (!self.translatingEvents)
[self closeHid];