From 15ffde7f0fb55fc80c142bf306ed5bccc1404f2d Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 29 Feb 2016 16:14:21 +0100 Subject: [PATCH 1/3] scrolling state of group outline gets updated --- MacPass/MPOutlineViewController.m | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/MacPass/MPOutlineViewController.m b/MacPass/MPOutlineViewController.m index 3ff54fc4..37e0f748 100644 --- a/MacPass/MPOutlineViewController.m +++ b/MacPass/MPOutlineViewController.m @@ -84,6 +84,13 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; name:MPDidActivateViewNotification object:self.outlineView]; + + NSView *clipView = self.outlineView.enclosingScrollView.contentView; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(_outlineDidScroll:) + name:NSViewBoundsDidChangeNotification + object:clipView]; + } - (NSResponder *)reconmendedFirstResponder { @@ -107,6 +114,8 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; } - (void)_expandItems:(NSTreeNode *)node { + KPKTree *tree = self.treeController.content; + id nodeItem = [node representedObject]; if([nodeItem isKindOfClass:[KPKTree class]]) { [self.outlineView expandItem:node expandChildren:NO]; @@ -168,6 +177,20 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; document.selectedItem = document.selectedGroup; } +- (void)_outlineDidScroll:(NSNotification *)notification { + NSView *clipView = notification.object; + if(nil == clipView || self.outlineView.enclosingScrollView.contentView != clipView) { + return; // Wrong view + } + NSInteger topRow = [self.outlineView rowAtPoint:clipView.bounds.origin]; + id item = [[self.outlineView itemAtRow:topRow] representedObject]; + if([item isKindOfClass:[KPKGroup class]]) { + KPKGroup *group = item; + KPKTree *tree = self.treeController.content; + tree.metaData.lastTopVisibleGroup = group.uuid; + } +} + # pragma mark MPDocument Notifications - (void)_didAddGroup:(NSNotification *)notification { NSDictionary *userInfo = [notification userInfo]; @@ -181,8 +204,8 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; } - (id)itemUnderMouse { - NSPoint mouseLocation = [[self.outlineView window] mouseLocationOutsideOfEventStream]; - NSPoint localPoint = [self.outlineView convertPoint:mouseLocation fromView:[[self.outlineView window] contentView]]; + NSPoint mouseLocation = [self.outlineView.window mouseLocationOutsideOfEventStream]; + NSPoint localPoint = [self.outlineView convertPoint:mouseLocation fromView:self.outlineView.window.contentView]; NSInteger row = [self.outlineView rowAtPoint:localPoint]; if(row == -1) { return nil; // No row was hit From 80d4b0e99ee3553875882db4142527ad7fa41170 Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 29 Feb 2016 16:27:32 +0100 Subject: [PATCH 2/3] Fixed wrong retrieval of tree from NSTreeController --- MacPass/MPOutlineViewController.m | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/MacPass/MPOutlineViewController.m b/MacPass/MPOutlineViewController.m index 37e0f748..128d4c4f 100644 --- a/MacPass/MPOutlineViewController.m +++ b/MacPass/MPOutlineViewController.m @@ -114,9 +114,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; } - (void)_expandItems:(NSTreeNode *)node { - KPKTree *tree = self.treeController.content; - - id nodeItem = [node representedObject]; + id nodeItem = node.representedObject; if([nodeItem isKindOfClass:[KPKTree class]]) { [self.outlineView expandItem:node expandChildren:NO]; } @@ -128,7 +126,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; [self.outlineView collapseItem:node]; } } - for(NSTreeNode *child in [node childNodes]) { + for(NSTreeNode *child in node.childNodes) { [self _expandItems:child]; } } @@ -186,7 +184,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; id item = [[self.outlineView itemAtRow:topRow] representedObject]; if([item isKindOfClass:[KPKGroup class]]) { KPKGroup *group = item; - KPKTree *tree = self.treeController.content; + KPKTree *tree = [self.treeController.content firstObject]; tree.metaData.lastTopVisibleGroup = group.uuid; } } From d3380c830eb0a3d23beef1bb7976c0d39a236c73 Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 29 Feb 2016 19:20:55 +0100 Subject: [PATCH 3/3] 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; }