Revision: 28951
          http://sourceforge.net/p/bibdesk/svn/28951
Author:   hofman
Date:     2024-09-27 17:01:12 +0000 (Fri, 27 Sep 2024)
Log Message:
-----------
Remember empty field grroup separately and ignore invalidate author groups early

Modified Paths:
--------------
    trunk/bibdesk/BibDocument_Groups.m

Modified: trunk/bibdesk/BibDocument_Groups.m
===================================================================
--- trunk/bibdesk/BibDocument_Groups.m  2024-09-27 16:38:51 UTC (rev 28950)
+++ trunk/bibdesk/BibDocument_Groups.m  2024-09-27 17:01:12 UTC (rev 28951)
@@ -469,12 +469,18 @@
     CFMutableBagRef bag = CFBagCreateMutable(kCFAllocatorDefault, 0, 
&bagCallBacks);
     
     NSMapTable *oldGroups = nil;
+    BDSKCategoryGroup *oldEmptyGroup = nil;
     BDSKCategoryGroup *group = [[parent categoryGroups] firstObject];
     
-    if ([groupField isEqualToString:[group key]] && [groupField isPersonField] 
== [[group name] isKindOfClass:[BibAuthor class]]) {
+    if ([groupField isEqualToString:[group key]] && isPersonField == [[group 
name] isKindOfClass:[BibAuthor class]]) {
         oldGroups = [NSMapTable strongToStrongObjectsMapTable];
-        for (BDSKCategoryGroup *aGroup in [parent categoryGroups])
-            [oldGroups setObject:aGroup forKey:[aGroup name]];
+        for (BDSKCategoryGroup *aGroup in [parent categoryGroups]) {
+            // don't reuse groups with invalidated authors
+            if ([aGroup isEmpty])
+                oldEmptyGroup = aGroup;
+            else if (isPersonField == NO || [(BibAuthor *)[aGroup name] 
publication] != nil)
+                [oldGroups setObject:aGroup forKey:[aGroup name]];
+        }
     }
     
     NSInteger emptyCount = 0;
@@ -497,12 +503,7 @@
     
     // now add the group names that we found from our BibItems, using a 
generic folder icon
     for (id groupName in hashTable) {
-        group = [oldGroups objectForKey:groupName];
-        // don't reuse groups with invalidated authors
-        if (isPersonField && [(BibAuthor *)[group name] publication] == nil)
-            group = nil;
-        if (group == nil)
-            group = [[BDSKCategoryGroup alloc] initWithName:groupName 
key:groupField];
+        group = [oldGroups objectForKey:groupName] ?: [[BDSKCategoryGroup 
alloc] initWithName:groupName key:groupField];
         [group setCount:CFBagGetCountOfValue(bag, (__bridge void *)groupName)];
         [mutableGroups addObject:group];
     }
@@ -510,7 +511,7 @@
     // add the "empty" group at index 0; this is a group of pubs whose value 
is empty for this field, so they
     // will not be contained in any of the other groups for the currently 
selected group field (hence multiple selection is desirable)
     if (emptyCount > 0) {
-        group = [oldGroups objectForKey:[BibAuthor emptyAuthor]];
+        group = oldEmptyGroup;
         if (group == nil)
             group = [[BDSKCategoryGroup alloc] initWithName:nil 
key:groupField];
         [group setCount:emptyCount];

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

Reply via email to