Revision: 27514
http://sourceforge.net/p/bibdesk/svn/27514
Author: hofman
Date: 2022-06-01 09:33:24 +0000 (Wed, 01 Jun 2022)
Log Message:
-----------
Only change cite key for generated cite keys that differ
Modified Paths:
--------------
trunk/bibdesk/BibDocument_Actions.m
trunk/bibdesk/BibItem+Scripting.m
Modified: trunk/bibdesk/BibDocument_Actions.m
===================================================================
--- trunk/bibdesk/BibDocument_Actions.m 2022-06-01 06:30:17 UTC (rev 27513)
+++ trunk/bibdesk/BibDocument_Actions.m 2022-06-01 09:33:24 UTC (rev 27514)
@@ -1466,17 +1466,18 @@
- (void)generateCiteKeysForPublications:(NSArray *)pubs{
// !!! early return
- if ([self commitPendingEdits] == NO) {
- NSBeep();
- return;
+ for (id editor in [self windowControllers]) {
+ // only commit editors for publications for which we try to generate a
cite key
+ if ([editor isKindOfClass:[BDSKEditor class]] && [pubs
containsObject:[editor publication]] && [editor commitEditing] == NO) {
+ NSBeep();
+ return;
+ }
}
- NSArray *arrayOfPubs = [[pubs copy] autorelease]; // copy in case we were
passed a mutable aray and the order changes
- NSArray *arrayOfOldValues = [arrayOfPubs valueForKey:@"citeKey"];
- NSArray *arrayOfNewValues = [arrayOfPubs valueForKey:@"suggestedCiteKey"];
+ pubs = [[pubs copy] autorelease]; // copy in case we were passed a mutable
aray and the order changes
- [self runScriptHookWithName:BDSKScriptHookNameWillGenerateCiteKey
forPublications:arrayOfPubs
- field:BDSKCiteKeyString oldValues:arrayOfOldValues
newValues:arrayOfNewValues
+ [self runScriptHookWithName:BDSKScriptHookNameWillGenerateCiteKey
forPublications:pubs
+ field:BDSKCiteKeyString oldValues:[pubs valueForKey:@"citeKey"]
newValues:[pubs valueForKey:@"suggestedCiteKey"]
completionHandler:^(BOOL cancelled){
if (cancelled) {
@@ -1484,9 +1485,14 @@
return;
}
+ NSMutableArray *arrayOfPubs = [NSMutableArray array];
+ NSMutableArray *arrayOfOldValues = [NSMutableArray array];
+ NSMutableArray *arrayOfNewValues = [NSMutableArray array];
+
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- for (BibItem *aPub in arrayOfPubs){
+ for (BibItem *aPub in pubs){
+ NSString *oldKey = [aPub citeKey];
NSString *newKey = [aPub suggestedCiteKey];
NSString *crossref = [aPub valueOfField:BDSKCrossrefString
inherit:NO];
if (crossref != nil && [crossref isCaseInsensitiveEqual:newKey]) {
@@ -1496,7 +1502,12 @@
[alert beginSheetModalForWindow:documentWindow
completionHandler:NULL];
continue;
}
- [aPub setCiteKey:newKey];
+ if ([newKey isEqualToString:oldKey] == NO) {
+ [aPub setCiteKey:newKey];
+ [arrayOfPubs addObject:aPub];
+ [arrayOfOldValues addObject:oldKey];
+ [arrayOfNewValues addObject:newKey];
+ }
[pool release];
pool = [[NSAutoreleasePool alloc] init];
@@ -1505,12 +1516,12 @@
// should be safe to release here since arrays were created outside
the scope of this local pool
[pool release];
- [[self undoManager] setActionName:([arrayOfPubs count] > 1 ?
NSLocalizedString(@"Generate Cite Keys", @"Undo action name") :
NSLocalizedString(@"Generate Cite Key", @"Undo action name"))];
-
- NSArray *newValues = [arrayOfPubs valueForKey:@"citeKey"];
-
- [self runScriptHookWithName:BDSKScriptHookNameDidGenerateCiteKey
forPublications:arrayOfPubs
- field:BDSKCiteKeyString oldValues:arrayOfOldValues
newValues:newValues];
+ if ([arrayOfPubs count] > 0) {
+ [[self undoManager] setActionName:([arrayOfPubs count] > 1 ?
NSLocalizedString(@"Generate Cite Keys", @"Undo action name") :
NSLocalizedString(@"Generate Cite Key", @"Undo action name"))];
+
+ [self runScriptHookWithName:BDSKScriptHookNameDidGenerateCiteKey
forPublications:arrayOfPubs
+ field:BDSKCiteKeyString oldValues:arrayOfOldValues
newValues:arrayOfNewValues];
+ }
}];
}
Modified: trunk/bibdesk/BibItem+Scripting.m
===================================================================
--- trunk/bibdesk/BibItem+Scripting.m 2022-06-01 06:30:17 UTC (rev 27513)
+++ trunk/bibdesk/BibItem+Scripting.m 2022-06-01 09:33:24 UTC (rev 27514)
@@ -66,7 +66,7 @@
Returns a path to the BibItem for Apple Script
Needs a properly working -document method to work with multpiple documents.
*/
-- (NSScriptObjectSpecifier *) objectSpecifier {
+- (NSScriptObjectSpecifier *) objectSpecifier {log_method();
// only items belonging to an owner are scriptable
if ([self owner]) {
NSScriptObjectSpecifier *containerRef = [(id)[self owner]
objectSpecifier];
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