Revision: 27694
http://sourceforge.net/p/bibdesk/svn/27694
Author: hofman
Date: 2022-07-05 14:48:45 +0000 (Tue, 05 Jul 2022)
Log Message:
-----------
Redo changes to update smart and field groups only if needed. Now with correct
key path.
Modified Paths:
--------------
trunk/bibdesk/BibDocument.h
trunk/bibdesk/BibDocument_Groups.h
trunk/bibdesk/BibDocument_Groups.m
trunk/bibdesk/BibDocument_UI.m
Modified: trunk/bibdesk/BibDocument.h
===================================================================
--- trunk/bibdesk/BibDocument.h 2022-07-05 14:32:26 UTC (rev 27693)
+++ trunk/bibdesk/BibDocument.h 2022-07-05 14:48:45 UTC (rev 27694)
@@ -257,7 +257,7 @@
} docState;
struct _docFlags {
- unsigned int itemChangeMask:4;
+ unsigned int itemChangeMask:5;
unsigned int sortDescending:1;
unsigned int previousSortDescending:1;
unsigned int tmpSortDescending:1;
Modified: trunk/bibdesk/BibDocument_Groups.h
===================================================================
--- trunk/bibdesk/BibDocument_Groups.h 2022-07-05 14:32:26 UTC (rev 27693)
+++ trunk/bibdesk/BibDocument_Groups.h 2022-07-05 14:48:45 UTC (rev 27694)
@@ -55,6 +55,7 @@
- (void)updateSmartGroups;
- (void)updateFilteringGroups;
+- (BOOL)updateCategoryGroups:(BOOL)updateCategoryGroups
smartGroups:(BOOL)updateSmartGroups;
- (void)displaySelectedGroups;
- (BOOL)addPublications:(NSArray *)pubs toGroup:(BDSKCategoryGroup *)group;
Modified: trunk/bibdesk/BibDocument_Groups.m
===================================================================
--- trunk/bibdesk/BibDocument_Groups.m 2022-07-05 14:32:26 UTC (rev 27693)
+++ trunk/bibdesk/BibDocument_Groups.m 2022-07-05 14:48:45 UTC (rev 27694)
@@ -415,7 +415,7 @@
// reload (a section of) the outlineview and preserve the selection
- (void)reloadParentGroup:(BDSKParentGroup *)parentGroup {
- if (parentGroup && [groupOutlineView isItemExpanded:parentGroup] == NO)
+ if ([parentGroup isKindOfClass:[BDSKParentGroup class]] &&
[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)
@@ -426,10 +426,14 @@
NSArray *selectedGroups = [self selectedGroups];
- if (parentGroup)
+ if (parentGroup == nil) {
+ [groupOutlineView reloadData];
+ } else if ([parentGroup isKindOfClass:[BDSKParentGroup class]]) {
[groupOutlineView reloadItem:parentGroup reloadChildren:YES];
- else
- [groupOutlineView reloadData];
+ } else {
+ for (BDSKParentGroup *parent in (NSArray *)parentGroup)
+ [groupOutlineView reloadItem:parent reloadChildren:YES];
+ }
// select the current groups, if still around. Otherwise select Library
BOOL didSelect = [self selectGroups:selectedGroups];
@@ -576,6 +580,40 @@
[self reloadParentGroup:nil];
}
+- (BOOL)updateCategoryGroups:(BOOL)updateCategoryGroups
smartGroups:(BOOL)updateSmartGroups {
+ NSMutableArray *parentsToReload = [NSMutableArray array];
+ BOOL isSelected = NO;
+
+ if (updateSmartGroups) {
+ [[groups smartGroups]
makeObjectsPerformSelector:@selector(invalidateCount)];
+ isSelected = [self hasGroupTypeSelected:BDSKSmartGroupType];
+ if ([groupOutlineView isItemExpanded:[groups smartParent]] &&
[sortGroupsKey isEqualToString:BDSKDocumentCountKey]) {
+ [[groups smartParent] resort];
+ [parentsToReload addObject:[groups smartParent]];
+ }
+ }
+
+ if (updateCategoryGroups) {
+ isSelected = isSelected || [self
hasGroupTypeSelected:BDSKCategoryGroupType];
+ for (BDSKCategoryParentGroup *parent in [groups categoryParents]) {
+ [self willRemoveGroups:[parent children]];
+ [self rebuildCategoryGroups:parent];
+ if ([groupOutlineView isItemExpanded:parent])
+ [parentsToReload addObject:parent];
+ }
+ }
+
+ if ([parentsToReload count] == 1)
+ [self reloadParentGroup:[parentsToReload firstObject]];
+ else if ([parentsToReload count])
+ [self reloadParentGroup:(id)parentsToReload];
+ else if (isSelected)
+ [self displaySelectedGroups];
+ else
+ return NO;
+ return YES;
+}
+
- (void)displaySelectedGroups{
NSArray *selectedGroups = [self selectedGroups];
NSArray *array;
Modified: trunk/bibdesk/BibDocument_UI.m
===================================================================
--- trunk/bibdesk/BibDocument_UI.m 2022-07-05 14:32:26 UTC (rev 27693)
+++ trunk/bibdesk/BibDocument_UI.m 2022-07-05 14:48:45 UTC (rev 27694)
@@ -97,9 +97,10 @@
enum {
BDSKItemChangedGroupFieldMask = 1 << 0,
- BDSKItemChangedSearchKeyMask = 1 << 1,
- BDSKItemChangedSortKeyMask = 1 << 2,
- BDSKItemChangedFilesMask = 1 << 3
+ BDSKItemChangedSmartGroupMask = 1 << 1,
+ BDSKItemChangedSearchKeyMask = 1 << 2,
+ BDSKItemChangedSortKeyMask = 1 << 3,
+ BDSKItemChangedFilesMask = 1 << 4
};
#pragma mark -
@@ -1347,6 +1348,19 @@
return NO;
}
+static BOOL smartGroupsDependOnKey(NSArray *smartGroupKeys, NSString *key) {
+ if ([smartGroupKeys count] == 0)
+ return NO;
+ else if ([smartGroupKeys containsObject:BDSKDateModifiedString] ||
[smartGroupKeys containsObject:BDSKAllFieldsString])
+ return YES;
+ else if (key == nil || [smartGroupKeys containsObject:key])
+ return YES;
+ else if ([key isEqualToString:BDSKColorString])
+ return [smartGroupKeys containsObject:BDSKColorLabelString];
+ else
+ return NO;
+}
+
- (void)handlePrivateBibItemChanged{
// we can be called from a queue after the document was closed
if (docFlags.isDocumentClosed)
@@ -1353,45 +1367,38 @@
return;
BOOL changedIsSelected = [[NSSet setWithArray:[self selectedPublications]]
intersectsSet:changedPublications];
+ BOOL displayingLocal = NO == [self
hasGroupTypeSelected:BDSKExternalGroupType];
- if ((docFlags.itemChangeMask & BDSKItemChangedFilesMask) != 0 &&
- NO == [self hasGroupTypeSelected:BDSKExternalGroupType] &&
- changedIsSelected) {
+ if ((docFlags.itemChangeMask & BDSKItemChangedFilesMask) != 0 &&
displayingLocal && changedIsSelected) {
[self updateFileViews];
if (docFlags.controllingQLPreviewPanel ||
docFlags.controllingFVPreviewPanel)
[self previewURLs:nil];
}
- if((docFlags.itemChangeMask & BDSKItemChangedGroupFieldMask) != 0){
- // this handles all UI updates if we call it, so don't bother with any
others
- [self updateFilteringGroups];
- } else {
- // allow updating a smart group if it's selected
- [[groups smartGroups]
makeObjectsPerformSelector:@selector(invalidateCount)];
- [self updateSmartGroups];
- if (NO == [self hasGroupTypeSelected:BDSKExternalGroupType |
BDSKSmartGroupType]) {
- if ((docFlags.itemChangeMask & BDSKItemChangedSearchKeyMask) != 0)
{
- // this handles all UI updates if we call it, so don't bother
with any others
- [self search:nil];
- } else if ((docFlags.itemChangeMask & BDSKItemChangedSortKeyMask)
!= 0) {
- // groups and quicksearch won't update for us
- [self sortPubsByKey:nil];
- } else {
- NSArray *colIDs = [tableView tableColumnIdentifiers];
- for (BibItem *aPub in changedPublications) {
- NSUInteger row = [shownPublications indexOfObject:aPub];
- if (row == NSNotFound) continue;
- [[tableView rowViewAtRow:row makeIfNecessary:NO]
setColor:[aPub color]];
- [colIDs enumerateObjectsUsingBlock:^(NSString *colID,
NSUInteger column, BOOL *stop){
- NSTableCellView *view = [tableView viewAtColumn:column
row:row makeIfNecessary:NO];
- if (view)
- [self updateView:view forField:colID ofItem:aPub];
- }];
- }
+ BOOL didReload = [self updateCategoryGroups:(docFlags.itemChangeMask &
BDSKItemChangedGroupFieldMask) != 0 smartGroups:(docFlags.itemChangeMask &
BDSKItemChangedSmartGroupMask) != 0];
+
+ if (didReload == NO && displayingLocal) {
+ if ((docFlags.itemChangeMask & BDSKItemChangedSearchKeyMask) != 0) {
+ // this handles all UI updates if we call it, so don't bother with
any others
+ [self search:nil];
+ } else if ((docFlags.itemChangeMask & BDSKItemChangedSortKeyMask) !=
0) {
+ // groups and quicksearch won't update for us
+ [self sortPubsByKey:nil];
+ } else {
+ NSArray *colIDs = [tableView tableColumnIdentifiers];
+ for (BibItem *aPub in changedPublications) {
+ NSUInteger row = [shownPublications indexOfObject:aPub];
+ if (row == NSNotFound) continue;
+ [[tableView rowViewAtRow:row makeIfNecessary:NO]
setColor:[aPub color]];
+ [colIDs enumerateObjectsUsingBlock:^(NSString *colID,
NSUInteger column, BOOL *stop){
+ NSTableCellView *view = [tableView viewAtColumn:column
row:row makeIfNecessary:NO];
+ if (view)
+ [self updateView:view forField:colID ofItem:aPub];
+ }];
}
- if (changedIsSelected)
- [self updatePreviews];
}
+ if (changedIsSelected)
+ [self updatePreviews];
}
[changedPublications removeAllObjects];
@@ -1490,6 +1497,8 @@
if (docFlags.isDocumentClosed == NO) {
if (groupFieldsDependOnKey([self currentGroupFields], changedKey))
docFlags.itemChangeMask |= BDSKItemChangedGroupFieldMask;
+ if (smartGroupsDependOnKey([[groups smartGroups]
valueForKeyPath:@"@distinctUnionOfArrays.filter.conditions.key"], changedKey))
+ docFlags.itemChangeMask |= BDSKItemChangedSmartGroupMask;
if (sortKeyDependsOnKey(sortKey, changedKey) ||
sortKeyDependsOnKey(previousSortKey, changedKey))
docFlags.itemChangeMask |= BDSKItemChangedSortKeyMask;
if ([self displaysControlView:BDSKControlViewSearch] &&
searchKeyDependsOnKey([searchButtonBar selectedIdentifier], changedKey))
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit