mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 22:52:26 +00:00
Fixed issue with resetting the selected group on first unlock.
This commit is contained in:
@@ -116,8 +116,12 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
|
|||||||
#pragma mark Outline handling
|
#pragma mark Outline handling
|
||||||
|
|
||||||
- (void)showOutline {
|
- (void)showOutline {
|
||||||
|
MPDocument *document = self.windowController.document;
|
||||||
|
|
||||||
|
NSUUID *selectedUUID = document.tree.metaData.lastSelectedGroup;
|
||||||
|
NSUUID *visibleUUID = document.tree.metaData.lastTopVisibleGroup;
|
||||||
|
|
||||||
if(!_bindingEstablished) {
|
if(!_bindingEstablished) {
|
||||||
MPDocument *document = self.windowController.document;
|
|
||||||
self.treeController.childrenKeyPath = NSStringFromSelector(@selector(groups));
|
self.treeController.childrenKeyPath = NSStringFromSelector(@selector(groups));
|
||||||
[self.treeController bind:NSContentBinding toObject:document withKeyPath:NSStringFromSelector(@selector(tree)) options:nil];
|
[self.treeController bind:NSContentBinding toObject:document withKeyPath:NSStringFromSelector(@selector(tree)) options:nil];
|
||||||
[self.outlineView bind:NSContentBinding toObject:self.treeController withKeyPath:NSStringFromSelector(@selector(arrangedObjects)) options:nil];
|
[self.outlineView bind:NSContentBinding toObject:self.treeController withKeyPath:NSStringFromSelector(@selector(arrangedObjects)) options:nil];
|
||||||
@@ -126,21 +130,23 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
|
|||||||
self.outlineView.dataSource = self.datasource;
|
self.outlineView.dataSource = self.datasource;
|
||||||
_bindingEstablished = YES;
|
_bindingEstablished = YES;
|
||||||
}
|
}
|
||||||
NSTreeNode *node = [_outlineView itemAtRow:0];
|
NSTreeNode *node = [self.outlineView itemAtRow:0];
|
||||||
NSInteger topRow = 0;
|
[self _expandItems:node];
|
||||||
[self _expandItems:node topRow:&topRow];
|
NSInteger selectRow = [self _rowForUUID:selectedUUID node:node];
|
||||||
if(topRow > 0) {
|
NSInteger visibleRow = [self _rowForUUID:visibleUUID node:node];
|
||||||
NSRect rowRect = [self.outlineView rectOfRow:topRow];
|
if(selectRow > -1) {
|
||||||
|
[self.outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:selectRow] byExtendingSelection:NO];
|
||||||
|
}
|
||||||
|
if(visibleRow > -1) {
|
||||||
|
NSRect rowRect = [self.outlineView rectOfRow:visibleRow];
|
||||||
[self.outlineView scrollPoint:rowRect.origin];
|
[self.outlineView scrollPoint:rowRect.origin];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_expandItems:(NSTreeNode *)node topRow:(NSInteger *)topRow {
|
- (void)_expandItems:(NSTreeNode *)node {
|
||||||
NSAssert(NULL != topRow, @"Invalid paramter!");
|
|
||||||
id nodeItem = node.representedObject;
|
id nodeItem = node.representedObject;
|
||||||
if([nodeItem isKindOfClass:[KPKTree class]]) {
|
if([nodeItem isKindOfClass:KPKTree.class]) {
|
||||||
[self.outlineView expandItem:node expandChildren:NO];
|
[self.outlineView expandItem:node expandChildren:NO];
|
||||||
*topRow = -1;
|
|
||||||
}
|
}
|
||||||
else if([nodeItem respondsToSelector:@selector(isExpanded)]) {
|
else if([nodeItem respondsToSelector:@selector(isExpanded)]) {
|
||||||
if([nodeItem isExpanded]) {
|
if([nodeItem isExpanded]) {
|
||||||
@@ -151,23 +157,29 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(NSTreeNode *child in node.childNodes) {
|
for(NSTreeNode *child in node.childNodes) {
|
||||||
[self _expandItems:child topRow:topRow];
|
[self _expandItems:child];
|
||||||
}
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSInteger)_rowForUUID:(NSUUID *)uuid node:(NSTreeNode *)node {
|
||||||
|
NSInteger index = -1;
|
||||||
|
for(NSTreeNode *childNode in node.childNodes) {
|
||||||
|
index = [self _rowForUUID:uuid node:childNode];
|
||||||
|
if(-1 != index) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(![node.representedObject isKindOfClass:KPKGroup.class]) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
KPKGroup *group = node.representedObject;
|
||||||
|
if([group.uuid isEqual:uuid]) {
|
||||||
|
return [self.outlineView rowForItem:node];
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark Custom Setter/Getter
|
#pragma mark Custom Setter/Getter
|
||||||
- (void)setDatabaseNameWrapper:(NSString *)databaseNameWrapper {
|
- (void)setDatabaseNameWrapper:(NSString *)databaseNameWrapper {
|
||||||
if(![_databaseNameWrapper isEqualToString:databaseNameWrapper]) {
|
if(![_databaseNameWrapper isEqualToString:databaseNameWrapper]) {
|
||||||
@@ -284,6 +296,13 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
|
|||||||
return [self _itemIsRootNode:item];
|
return [self _itemIsRootNode:item];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSIndexSet *)outlineView:(NSOutlineView *)outlineView selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes {
|
||||||
|
return [proposedSelectionIndexes indexesPassingTest:^BOOL(NSUInteger idx, BOOL * _Nonnull stop) {
|
||||||
|
NSTreeNode *node = [outlineView itemAtRow:idx];
|
||||||
|
return [node.representedObject isKindOfClass:KPKGroup.class];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item {
|
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item {
|
||||||
return ![self _itemIsRootNode:item];
|
return ![self _itemIsRootNode:item];
|
||||||
}
|
}
|
||||||
@@ -344,7 +363,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
|
|||||||
|
|
||||||
- (BOOL)_itemIsRootNode:(id)item {
|
- (BOOL)_itemIsRootNode:(id)item {
|
||||||
id node = [item representedObject];
|
id node = [item representedObject];
|
||||||
return [node isKindOfClass:[KPKTree class]];
|
return [node isKindOfClass:KPKTree.class];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user