From 7b55c37128eb980ee00764c6c561de5ec637132a Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Wed, 9 Jun 2021 22:01:43 -0400 Subject: [PATCH] machine view - clicking a parent-only row will toggle expansion also add animation proxy to bookmark code --- Ample/NewMachineViewController.m | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Ample/NewMachineViewController.m b/Ample/NewMachineViewController.m index 2f54ee7..ff7348b 100644 --- a/Ample/NewMachineViewController.m +++ b/Ample/NewMachineViewController.m @@ -43,13 +43,22 @@ #pragma mark - IBActions - (IBAction)clickAction:(id)sender { - NSInteger row = [_outlineView selectedRow]; + NSInteger row = [_outlineView clickedRow]; if (row < 0) return; - NSDictionary *d = [_outlineView itemAtRow: row]; - if (!d) return; - NSString *value = [d objectForKey: @"value"]; - if (!d) return; - [self setMachine: value]; + NSDictionary *item = [_outlineView itemAtRow: row]; + if (!item) return; + + NSString *value = [item objectForKey: @"value"]; + NSArray *children = [item objectForKey: @"children"]; + + if (value) { + [self setMachine: value]; + } else if (children) { + id ap = [_outlineView animator]; + [_outlineView isItemExpanded: item] ? [ap collapseItem: item] : [ap expandItem: item]; + } + + } @end @@ -163,7 +172,9 @@ - (BOOL)loadBookmark:(NSDictionary *)bookmark { NSString *machine = [bookmark objectForKey: @"machine"]; + + //NSInteger row = [_outlineView selectedRow]; if (!machine) { [self setMachine: nil]; @@ -177,7 +188,8 @@ for (NSDictionary *child in children) { if ([machine isEqualToString: [child objectForKey: @"value"]]) { - [_outlineView expandItem: parent]; + id ap = [_outlineView animator]; + [ap expandItem: parent]; NSInteger row = [_outlineView rowForItem: child]; if (row >= 0) { NSIndexSet *set = [NSIndexSet indexSetWithIndex: row];