From d3380c830eb0a3d23beef1bb7976c0d39a236c73 Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 29 Feb 2016 19:20:55 +0100 Subject: [PATCH] restoring of last visibleTopGroup and lastSelectedGroup is working --- MacPass/MPOutlineViewController.m | 32 +++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/MacPass/MPOutlineViewController.m b/MacPass/MPOutlineViewController.m index 128d4c4f..dc06d713 100644 --- a/MacPass/MPOutlineViewController.m +++ b/MacPass/MPOutlineViewController.m @@ -110,13 +110,20 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; _bindingEstablished = YES; } NSTreeNode *node = [_outlineView itemAtRow:0]; - [self _expandItems:node]; + NSInteger topRow; + [self _expandItems:node topRow:&topRow]; + if(topRow > 0) { + NSRect rowRect = [self.outlineView rectOfRow:topRow]; + [self.outlineView scrollPoint:rowRect.origin]; + } } -- (void)_expandItems:(NSTreeNode *)node { +- (void)_expandItems:(NSTreeNode *)node topRow:(NSInteger *)topRow { + NSAssert(NULL != topRow, @"Invalid paramter!"); id nodeItem = node.representedObject; if([nodeItem isKindOfClass:[KPKTree class]]) { [self.outlineView expandItem:node expandChildren:NO]; + *topRow = -1; } else if([nodeItem respondsToSelector:@selector(isExpanded)]) { if([nodeItem isExpanded]) { @@ -127,7 +134,20 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; } } for(NSTreeNode *child in node.childNodes) { - [self _expandItems:child]; + [self _expandItems:child topRow:topRow]; + } + if([nodeItem respondsToSelector:@selector(uuid)]) { + MPDocument *document = self.windowController.document; + NSUUID *uuid = [nodeItem uuid]; + if(*topRow != 1 && [document.tree.metaData.lastTopVisibleGroup isEqual:uuid]) { + *topRow = [self.outlineView rowForItem:node]; + } + if([uuid isEqual:document.tree.metaData.lastSelectedGroup]) { + NSInteger selectedRow = [self.outlineView rowForItem:node]; + if(selectedRow >= 0) { + [self.outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow] byExtendingSelection:NO]; + } + } } } @@ -180,10 +200,13 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; if(nil == clipView || self.outlineView.enclosingScrollView.contentView != clipView) { return; // Wrong view } - NSInteger topRow = [self.outlineView rowAtPoint:clipView.bounds.origin]; + /* padding to compensate for clipped items */ + CGPoint point = CGPointMake(clipView.bounds.origin.x, clipView.bounds.origin.y + 11); + NSInteger topRow = [self.outlineView rowAtPoint:point]; id item = [[self.outlineView itemAtRow:topRow] representedObject]; if([item isKindOfClass:[KPKGroup class]]) { KPKGroup *group = item; + NSLog(@"%@", group.title); KPKTree *tree = [self.treeController.content firstObject]; tree.metaData.lastTopVisibleGroup = group.uuid; } @@ -253,6 +276,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; NSTreeNode *treeNode = [_outlineView itemAtRow:[_outlineView selectedRow]]; KPKGroup *selectedGroup = [treeNode representedObject]; MPDocument *document = [[self windowController] document]; + document.tree.metaData.lastSelectedGroup = selectedGroup ? selectedGroup.uuid : [NSUUID nullUUID]; document.selectedGroup = selectedGroup; }