Revision: 28561
          http://sourceforge.net/p/bibdesk/svn/28561
Author:   hofman
Date:     2024-01-06 18:12:46 +0000 (Sat, 06 Jan 2024)
Log Message:
-----------
Retain removed groups until after updating UI in calling methods rather than 
autoreleasing them.

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

Modified: trunk/bibdesk/BDSKGroupsArray.m
===================================================================
--- trunk/bibdesk/BDSKGroupsArray.m     2024-01-06 17:56:55 UTC (rev 28560)
+++ trunk/bibdesk/BDSKGroupsArray.m     2024-01-06 18:12:46 UTC (rev 28561)
@@ -217,6 +217,7 @@
     [[self document] willRemoveGroups:groupsToRemove];
     [parent removeChildGroup:group];
     [[self document] reloadParentGroup:parent];
+    groupsToRemove = nil;
 }
 
 - (void)addCategoryParent:(BDSKCategoryParentGroup *)group {

Modified: trunk/bibdesk/BibDocument_Groups.m
===================================================================
--- trunk/bibdesk/BibDocument_Groups.m  2024-01-06 17:56:55 UTC (rev 28560)
+++ trunk/bibdesk/BibDocument_Groups.m  2024-01-06 18:12:46 UTC (rev 28561)
@@ -403,8 +403,6 @@
 #pragma mark UI updating
 
 - (void)willRemoveGroups:(NSArray *)groupsToRemove {
-    // make sure removed groups aren't released before we reload and restore 
selection
-    [[groupsToRemove copy] autorelease];
     // abort editing groups that will be removed
     id responder = [documentWindow firstResponder];
     if ([responder isKindOfClass:[NSText class]] && [[responder delegate] 
isKindOfClass:[NSTextField class]]) {
@@ -572,12 +570,18 @@
     if ([groupOutlineView isItemExpanded:[groups smartParent]] && 
[sortGroupsKey isEqualToString:BDSKDocumentCountKey])
         [[groups smartParent] resort];
     
+    // retain removed groups until after reloading and restoring the selection
+    NSMutableArray *removedGroups = [NSMutableArray array];
+    
     for (BDSKCategoryParentGroup *parent in [groups categoryParents]) {
         [self willRemoveGroups:[parent children]];
+        [removedGroups addObjectsFromArray:[parent children]];
         [self rebuildCategoryGroups:parent];
     }
     
     [self reloadParentGroup:nil];
+    
+    removedGroups = nil;
 }
 
 - (BOOL)updateCategoryGroups:(BOOL)updateCategoryGroups 
smartGroups:(BOOL)updateSmartGroups {
@@ -598,10 +602,14 @@
         }
     }
     
+    // retain removed groups until after reloading and restoring the selection
+    NSMutableArray *removedGroups = [NSMutableArray array];
+    
     if (updateCategoryGroups) {
         isSelected = isSelected || [self 
hasGroupTypeSelected:BDSKCategoryGroupType];
         for (BDSKCategoryParentGroup *parent in [groups categoryParents]) {
             [self willRemoveGroups:[parent children]];
+            [removedGroups addObjectsFromArray:[parent children]];
             [self rebuildCategoryGroups:parent];
             if ([groupOutlineView isItemExpanded:parent])
                 [parentsToReload addObject:parent];
@@ -608,6 +616,7 @@
         }
     }
     
+    BOOL success = YES;
     if ([parentsToReload count] == 1) {
         [self reloadParentGroup:[parentsToReload firstObject]];
     } else if ([parentsToReload count]) {
@@ -618,9 +627,10 @@
         [self displaySelectedGroups];
         [tableView setScrollPositionAsPercentage:scrollPoint];
     } else {
-        return NO;
+        success = NO;
     }
-    return YES;
+    removedGroups = nil;
+    return success;
 }
 
 - (void)displaySelectedGroups{
@@ -767,9 +777,13 @@
 }
 
 - (void)removeCurrentGroupField:(NSString *)oldField {
+    // retain removed groups until after reloading and restoring the selection
+    NSMutableArray *removedGroups = [NSMutableArray array];
     for (BDSKCategoryParentGroup *group in [groups categoryParents]) {
         if ([[group key] isEqualToString:oldField]) {
             [self willRemoveGroups:[group children]];
+            [removedGroups addObjectsFromArray:[group children]];
+            [removedGroups addObject:group];
             [groups removeCategoryParent:group];
             [self reloadParentGroup:nil];
             [[NSUserDefaults standardUserDefaults] setObject:[self 
currentGroupFields] forKey:BDSKCurrentGroupFieldsKey];
@@ -776,18 +790,21 @@
             break;
         }
     }
-    
+    removedGroups = nil;
 }
 
 - (void)setCurrentGroupField:(NSString *)newField 
forGroup:(BDSKCategoryParentGroup *)group {
+    // retain removed groups until after reloading and restoring the selection
+    NSMutableArray *removedGroups = [NSMutableArray array];
     if ([[self currentGroupFields] containsObject:newField] == NO) {
         [group setKey:newField];
         [self willRemoveGroups:[group children]];
+        [removedGroups addObjectsFromArray:[group children]];
         [self rebuildCategoryGroups:group];
         [self reloadParentGroup:group];
         [[NSUserDefaults standardUserDefaults] setObject:[self 
currentGroupFields] forKey:BDSKCurrentGroupFieldsKey];
     }
-    
+    removedGroups = nil;
 }
 
 #pragma mark Actions

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

Reply via email to