Revision: 26520 http://sourceforge.net/p/bibdesk/svn/26520 Author: hofman Date: 2021-07-27 21:54:37 +0000 (Tue, 27 Jul 2021) Log Message: ----------- Just reload and restore group selection after making changes, but make sure removed groups are not immediately released as they may be needed to restore the selection
Modified Paths: -------------- trunk/bibdesk/BDSKGroupsArray.m trunk/bibdesk/BibDocument_Groups.h trunk/bibdesk/BibDocument_Groups.m Modified: trunk/bibdesk/BDSKGroupsArray.m =================================================================== --- trunk/bibdesk/BDSKGroupsArray.m 2021-07-27 21:13:44 UTC (rev 26519) +++ trunk/bibdesk/BDSKGroupsArray.m 2021-07-27 21:54:37 UTC (rev 26520) @@ -202,9 +202,8 @@ return; if ((groupType & BDSKTempRemovableGroupType) == 0) [[[self undoManager] prepareWithInvocationTarget:self] removeChildGroup:group]; - [[self document] modifyChildrenOfParentGroup:parent changes:^{ - [parent addChildGroup:group]; - }]; + [parent addChildGroup:group]; + [[self document] reloadParentGroup:parent]; } - (void)removeChildGroup:(BDSKGroup *)group { @@ -216,9 +215,8 @@ if (([group groupType] & BDSKTempRemovableGroupType) == 0) [[[self undoManager] prepareWithInvocationTarget:self] addChildGroup:group]; [[self document] willRemoveGroups:groupsToRemove]; - [[self document] modifyChildrenOfParentGroup:parent changes:^{ - [parent removeChildGroup:group]; - }]; + [parent removeChildGroup:group]; + [[self document] reloadParentGroup:parent]; } - (void)setSharedGroups:(NSArray *)array{ @@ -228,9 +226,8 @@ [[NSNotificationCenter defaultCenter] postNotificationName:BDSKWillRemoveExternalGroupsNotification object:[self document] userInfo:[NSDictionary dictionaryWithObjectsAndKeys:removedGroups, BDSKDocumentGroupsKey, nil]]; [removedGroups release]; - [[self document] modifyChildrenOfParentGroup:[self externalParent] changes:^{ - [[self externalParent] setSharedGroups:array]; - }]; + [[self externalParent] setSharedGroups:array]; + [[self document] reloadParentGroup:[self externalParent]]; } - (void)addCategoryParent:(BDSKCategoryParentGroup *)group { Modified: trunk/bibdesk/BibDocument_Groups.h =================================================================== --- trunk/bibdesk/BibDocument_Groups.h 2021-07-27 21:13:44 UTC (rev 26519) +++ trunk/bibdesk/BibDocument_Groups.h 2021-07-27 21:54:37 UTC (rev 26520) @@ -80,7 +80,7 @@ - (void)handleExternalGroupUpdatedNotification:(NSNotification *)notification; - (void)willRemoveGroups:(NSArray *)groupsToRemove; -- (void)modifyChildrenOfParentGroup:(BDSKParentGroup *)parentGroup changes:(void(^)(void))changes; +- (void)reloadParentGroup:(BDSKParentGroup *)parentGroup; - (BDSKGroupCellView *)viewForGroup:(BDSKGroup *)group; - (void)updateCountBubbleForGroup:(BDSKGroup *)group inView:(BDSKGroupCellView *)view; Modified: trunk/bibdesk/BibDocument_Groups.m =================================================================== --- trunk/bibdesk/BibDocument_Groups.m 2021-07-27 21:13:44 UTC (rev 26519) +++ trunk/bibdesk/BibDocument_Groups.m 2021-07-27 21:54:37 UTC (rev 26520) @@ -384,6 +384,10 @@ #pragma mark UI updating - (void)willRemoveGroups:(NSArray *)groupsToRemove { + // make sure removed groups aren't released before we reload and restore selection + if ([groupOutlineView respondsToSelector:@selector(stronglyReferencesItems)] == NO) + [[groupsToRemove copy] autorelease]; + // abort editing groups that will be removed id responder = [documentWindow firstResponder]; if ([responder isKindOfClass:[NSText class]] && [[responder delegate] isKindOfClass:[NSTextField class]]) { NSInteger row = [groupOutlineView rowForView:responder]; @@ -392,8 +396,11 @@ } } -// perform some changes that affect the groups, follow with reload of the outlineview and preserve the selection -- (void)modifyChildrenOfParentGroup:(BDSKParentGroup *)parentGroup changes:(void(^)(void))changes { +// reload (a section of) the outlineview and preserve the selection +- (void)reloadParentGroup:(BDSKParentGroup *)parentGroup { + if (parentGroup && [groupOutlineView isItemExpanded:parentGroup] == NO) + return; + // this is a hack to keep us from getting selection change notifications while sorting (which updates the TeX and attributed text previews) // this is a hack to avoid a loop in as reloadItem:reloadChildren: calls outlineViewItemDidExpand: docFlags.ignoreGroupUIChange = YES; @@ -401,29 +408,25 @@ NSPoint scrollPoint = [tableView scrollPositionAsPercentage]; NSArray *selectedGroups = [self selectedGroups]; + + if (parentGroup) + [groupOutlineView reloadItem:parentGroup reloadChildren:YES]; + else + [groupOutlineView reloadData]; - changes(); + // select the current groups, if still around. Otherwise select Library + BOOL didSelect = [self selectGroups:selectedGroups]; - if (parentGroup == nil || [groupOutlineView isItemExpanded:parentGroup]) { - if (parentGroup) - [groupOutlineView reloadItem:parentGroup reloadChildren:YES]; - else - [groupOutlineView reloadData]; - - // select the current groups, if still around. Otherwise select Library - BOOL didSelect = [self selectGroups:selectedGroups]; - - // the selection may not have changed, so we won't get this from the notification - [self displaySelectedGroups]; - // but notification will be ignored, we may unselect a web or search group - if ([[self selectedGroups] isEqualToArray:selectedGroups] == NO) - [self handleGroupTableSelectionChangedNotification:nil]; - - // The search: in displaySelectedGroups will change the main table's scroll location, which isn't necessarily what we want (say when clicking the add button for a search group pub). If we selected the same groups as previously, we should scroll to the old location instead of centering. - if (didSelect) - [tableView setScrollPositionAsPercentage:scrollPoint]; - } + // the selection may not have changed, so we won't get this from the notification + [self displaySelectedGroups]; + // but notification will be ignored, we may unselect a web or search group + if ([[self selectedGroups] isEqualToArray:selectedGroups] == NO) + [self handleGroupTableSelectionChangedNotification:nil]; + // The search: in displaySelectedGroups will change the main table's scroll location, which isn't necessarily what we want (say when clicking the add button for a search group pub). If we selected the same groups as previously, we should scroll to the old location instead of centering. + if (didSelect) + [tableView setScrollPositionAsPercentage:scrollPoint]; + // reset docFlags.ignoreGroupUIChange = NO; } @@ -543,21 +546,20 @@ } - (void)updateFilteringGroups { - [self modifyChildrenOfParentGroup:nil changes:^{ - - // update the count for the first item, not sure if it should be done here - [[groups libraryGroup] setCount:[publications count]]; - - // update the count for the smart groups when we're not loading a new set and they're displayed - [[groups smartGroups] makeObjectsPerformSelector:@selector(invalidateCount)]; - if ([groupOutlineView isItemExpanded:[groups smartParent]] && [sortGroupsKey isEqualToString:BDSKDocumentCountKey]) - [[groups smartParent] resort]; - - for (BDSKCategoryParentGroup *parent in [groups categoryParents]) { - [self willRemoveGroups:[parent children]]; - [self rebuildCategoryGroups:parent]; - } - }]; + // update the count for the first item, not sure if it should be done here + [[groups libraryGroup] setCount:[publications count]]; + + // update the count for the smart groups when we're not loading a new set and they're displayed + [[groups smartGroups] makeObjectsPerformSelector:@selector(invalidateCount)]; + if ([groupOutlineView isItemExpanded:[groups smartParent]] && [sortGroupsKey isEqualToString:BDSKDocumentCountKey]) + [[groups smartParent] resort]; + + for (BDSKCategoryParentGroup *parent in [groups categoryParents]) { + [self willRemoveGroups:[parent children]]; + [self rebuildCategoryGroups:parent]; + } + + [self reloadParentGroup:nil]; } - (void)displaySelectedGroups{ @@ -699,9 +701,8 @@ if ([[self currentGroupFields] containsObject:newField] == NO) { BDSKCategoryParentGroup *group = [[[BDSKCategoryParentGroup alloc] initWithKey:newField] autorelease]; [self rebuildCategoryGroups:group]; - [self modifyChildrenOfParentGroup:nil changes:^{ - [groups addCategoryParent:group]; - }]; + [groups addCategoryParent:group]; + [self reloadParentGroup:group]; // this is to set the sort descriptors and sorts the children [groupOutlineView expandItem:group]; [[NSUserDefaults standardUserDefaults] setObject:[self currentGroupFields] forKey:BDSKCurrentGroupFieldsKey]; @@ -712,9 +713,8 @@ for (BDSKCategoryParentGroup *group in [groups categoryParents]) { if ([[group key] isEqualToString:oldField]) { [self willRemoveGroups:[group children]]; - [self modifyChildrenOfParentGroup:nil changes:^{ - [groups removeCategoryParent:group]; - }]; + [groups removeCategoryParent:group]; + [self reloadParentGroup:nil]; [[NSUserDefaults standardUserDefaults] setObject:[self currentGroupFields] forKey:BDSKCurrentGroupFieldsKey]; break; } @@ -726,9 +726,8 @@ if ([[self currentGroupFields] containsObject:newField] == NO) { [group setKey:newField]; [self willRemoveGroups:[group children]]; - [self modifyChildrenOfParentGroup:group changes:^{ - [self rebuildCategoryGroups:group]; - }]; + [self rebuildCategoryGroups:group]; + [self reloadParentGroup:group]; [[NSUserDefaults standardUserDefaults] setObject:[self currentGroupFields] forKey:BDSKCurrentGroupFieldsKey]; } @@ -1193,9 +1192,8 @@ [self addPublications:pubs toGroup:group]; [groupOutlineView deselectAll:nil]; - [self modifyChildrenOfParentGroup:parent changes:^{ - [self rebuildCategoryGroups:parent]; - }]; + [self rebuildCategoryGroups:parent]; + [self reloadParentGroup:parent]; dispatch_async(dispatch_get_main_queue(), ^{ [self editGroupWithoutWarning:group]; @@ -1566,13 +1564,12 @@ [[NSUserDefaults standardUserDefaults] setBool:docFlags.sortGroupsDescending forKey:BDSKSortGroupsDescendingKey]; } - [self modifyChildrenOfParentGroup:nil changes:^{ - NSArray *sortDescriptors = [self groupSortDescriptors]; - for (BDSKParentGroup *parent in groups) { - if ([groupOutlineView isItemExpanded:parent]) - [parent sortUsingDescriptors:sortDescriptors]; - } - }]; + NSArray *sortDescriptors = [self groupSortDescriptors]; + for (BDSKParentGroup *parent in groups) { + if ([groupOutlineView isItemExpanded:parent]) + [parent sortUsingDescriptors:sortDescriptors]; + } + [self reloadParentGroup:nil]; } // this should only be called when the item is expanded This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit