Revision: 28176
          http://sourceforge.net/p/bibdesk/svn/28176
Author:   hofman
Date:     2023-02-23 15:21:18 +0000 (Thu, 23 Feb 2023)
Log Message:
-----------
do call Did Generate Cite Key hook also for keys that were not changed

Modified Paths:
--------------
    trunk/bibdesk/BDSKEditor.m
    trunk/bibdesk/BibDocument_Actions.m

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2023-02-23 10:10:19 UTC (rev 28175)
+++ trunk/bibdesk/BDSKEditor.m  2023-02-23 15:21:18 UTC (rev 28176)
@@ -974,15 +974,15 @@
             [alert setInformativeText:[NSString 
stringWithFormat:NSLocalizedString(@"The cite key for \"%@\" could not be 
generated because the generated key would be the same as the crossref key.", 
@"Informative text in alert dialog"), oldKey]];
             [alert beginSheetModalForWindow:[self window] 
completionHandler:NULL];
             return;
-        } else if ([oldKey isEqualToString:newKey]) {
-            return;
         }
         
-        [publication setCiteKey:newKey];
+        if ([oldKey isEqualToString:newKey] == NO) {
+            [publication setCiteKey:newKey];
+            
+            [[self undoManager] setActionName:NSLocalizedString(@"Generate 
Cite Key", @"Undo action name")];
+            [tabView selectFirstTabViewItem:self];
+        }
         
-        [[self undoManager] setActionName:NSLocalizedString(@"Generate Cite 
Key", @"Undo action name")];
-        [tabView selectFirstTabViewItem:self];
-        
         [[self document] 
runScriptHookWithName:BDSKScriptHookNameDidGenerateCiteKey
             forPublications:pubs
             field:BDSKCiteKeyString oldValues:oldValues newValues:[NSArray 
arrayWithObject:newKey]];

Modified: trunk/bibdesk/BibDocument_Actions.m
===================================================================
--- trunk/bibdesk/BibDocument_Actions.m 2023-02-23 10:10:19 UTC (rev 28175)
+++ trunk/bibdesk/BibDocument_Actions.m 2023-02-23 15:21:18 UTC (rev 28176)
@@ -1501,6 +1501,7 @@
         NSMutableArray *arrayOfPubs = [NSMutableArray array];
         NSMutableArray *arrayOfOldValues = [NSMutableArray array];
         NSMutableArray *arrayOfNewValues = [NSMutableArray array];
+        NSInteger numChanged = 0;
         
         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
         
@@ -1515,11 +1516,12 @@
                 [alert beginSheetModalForWindow:documentWindow 
completionHandler:NULL];
                 continue;
             }
+            [arrayOfPubs addObject:aPub];
+            [arrayOfOldValues addObject:oldKey];
+            [arrayOfNewValues addObject:newKey];
             if ([newKey isEqualToString:oldKey] == NO) {
-                [arrayOfPubs addObject:aPub];
-                [arrayOfOldValues addObject:oldKey];
-                [arrayOfNewValues addObject:newKey];
                 [aPub setCiteKey:newKey];
+                ++numChanged;
             }
             
             [pool release];
@@ -1529,12 +1531,12 @@
         // should be safe to release here since arrays were created outside 
the scope of this local pool
         [pool release];
         
-        if ([arrayOfPubs count] > 0) {
-            [[self undoManager] setActionName:([arrayOfPubs count] > 1 ? 
NSLocalizedString(@"Generate Cite Keys", @"Undo action name") : 
NSLocalizedString(@"Generate Cite Key", @"Undo action name"))];
-            
+        if (numChanged > 0)
+            [[self undoManager] setActionName:(numChanged > 1 ? 
NSLocalizedString(@"Generate Cite Keys", @"Undo action name") : 
NSLocalizedString(@"Generate Cite Key", @"Undo action name"))];
+        
+        if ([arrayOfPubs count] > 0)
             [self runScriptHookWithName:BDSKScriptHookNameDidGenerateCiteKey 
forPublications:arrayOfPubs
                 field:BDSKCiteKeyString oldValues:arrayOfOldValues 
newValues:arrayOfNewValues];
-        }
     }];
 }    
 

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