restoring of last visibleTopGroup and lastSelectedGroup is working

This commit is contained in:
michael starke
2016-02-29 19:20:55 +01:00
parent 80d4b0e99e
commit d3380c830e

View File

@@ -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;
}