Revision: 28254
          http://sourceforge.net/p/bibdesk/svn/28254
Author:   hofman
Date:     2023-05-22 14:21:43 +0000 (Mon, 22 May 2023)
Log Message:
-----------
Fix validation for autogeneration of ite key. Rename validation methods.

Modified Paths:
--------------
    trunk/bibdesk/BDSKEditor.m
    trunk/bibdesk/BDSKTextImportController.m
    trunk/bibdesk/BibDocument.m
    trunk/bibdesk/BibItem.h
    trunk/bibdesk/BibItem.m

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2023-05-18 14:20:20 UTC (rev 28253)
+++ trunk/bibdesk/BDSKEditor.m  2023-05-22 14:21:43 UTC (rev 28254)
@@ -2853,7 +2853,7 @@
 }
 
 - (void)updateCiteKeyAutoGenerateStatus{
-       if ([publication shouldAutogenerateCiteKey]) {
+       if ([publication needsToAutogenerateCiteKey]) {
                if ([[statusBar iconIdentifiers] 
containsObject:BDSKNeedsToGenerateCiteKeyIdentifier] == NO) {
                        NSString *tooltip = NSLocalizedString(@"The cite key 
needs to be generated.", @"Tool tip message");
                        [statusBar addIcon:[NSImage 
imageNamed:@"CiteKeyPreferences"] 
withIdentifier:BDSKNeedsToGenerateCiteKeyIdentifier toolTip:tooltip];

Modified: trunk/bibdesk/BDSKTextImportController.m
===================================================================
--- trunk/bibdesk/BDSKTextImportController.m    2023-05-18 14:20:20 UTC (rev 
28253)
+++ trunk/bibdesk/BDSKTextImportController.m    2023-05-22 14:21:43 UTC (rev 
28254)
@@ -1128,8 +1128,7 @@
     BibItem *item = [self publication];
     [item setField:fieldName toValue:value];
        [[self undoManager] setActionName:NSLocalizedString(@"Edit 
Publication", @"Undo action name")];
-    if([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKCiteKeyAutogenerateKey] &&
-       [item canGenerateAndSetCiteKey]){
+    if([item canAutogenerateCiteKey]){
         [self generateCiteKey:nil];
         if ([item hasEmptyOrDefaultCiteKey] == NO)
             [statusLine setStringValue:NSLocalizedString(@"Autogenerated Cite 
Key.", @"Status message")];

Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2023-05-18 14:20:20 UTC (rev 28253)
+++ trunk/bibdesk/BibDocument.m 2023-05-22 14:21:43 UTC (rev 28254)
@@ -2193,12 +2193,10 @@
     BOOL hasDuplicateCiteKey = NO;
     
     for (pub in newPubs) {
-        if ((autoGenerate == NO && [pub hasEmptyOrDefaultCiteKey]) ||
-            (autoGenerate && [pub canGenerateAndSetCiteKey])) { // @@ or 
should we check for hasEmptyOrDefaultCiteKey ?
+        if ((autoGenerate ? [pub canAutogenerateCiteKey] : [pub 
hasEmptyOrDefaultCiteKey]))
             [autogeneratePubs addObject:pub];
-        } else if ([pub isValidCiteKey:[pub citeKey]] == NO) {
+        else if ([pub isValidCiteKey:[pub citeKey]] == NO)
             hasDuplicateCiteKey = YES;
-        }
     }
     if ([autogeneratePubs count])
         [self generateCiteKeysForPublications:autogeneratePubs];
@@ -2599,7 +2597,7 @@
             continue;
         
         // generate cite key if we have enough information
-        if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKCiteKeyAutogenerateKey] && [pub canGenerateAndSetCiteKey])
+        if ([pub canAutogenerateCiteKey])
             [generateKeyPubs addObject:pub];
         
         // autofile paper if we have enough information

Modified: trunk/bibdesk/BibItem.h
===================================================================
--- trunk/bibdesk/BibItem.h     2023-05-18 14:20:20 UTC (rev 28253)
+++ trunk/bibdesk/BibItem.h     2023-05-22 14:21:43 UTC (rev 28254)
@@ -590,8 +590,8 @@
 
 @property (nonatomic, readonly) BOOL hasEmptyOrDefaultCiteKey;
 
-@property (nonatomic, readonly) BOOL shouldAutogenerateCiteKey;
-@property (nonatomic, readonly) BOOL canGenerateAndSetCiteKey;
+@property (nonatomic, readonly) BOOL needsToAutogenerateCiteKey;
+@property (nonatomic, readonly) BOOL canAutogenerateCiteKey;
 
 /*
  @method canSetCrossref:

Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m     2023-05-18 14:20:20 UTC (rev 28253)
+++ trunk/bibdesk/BibItem.m     2023-05-22 14:21:43 UTC (rev 28254)
@@ -199,7 +199,7 @@
 @implementation BibItem
 
 @synthesize owner, macroResolver, downloads, fileOrder, identifierURL, 
date=pubDate, dateAdded, dateModified, pubType, citeKey, hasBeenEdited, 
pubFields, searchScore, imported, itemIndex;
-@dynamic undoManager, localFiles, existingLocalFiles, remoteURLs, usedMacros, 
usedLocalMacros, allPeople, people, numberOfAuthors, pubAuthors, firstAuthor, 
secondAuthor, thirdAuthor, lastAuthor, bibTeXAuthorString, 
numberOfAuthorsOrEditors, pubAuthorsOrEditors, firstAuthorOrEditor, 
secondAuthorOrEditor, thirdAuthorOrEditor, lastAuthorOrEditor, crossrefParent, 
title, displayTitle, container, sortingTitle, sortingContainer, 
sortingBooktitle, rating, color, suggestedCiteKey, hasEmptyOrDefaultCiteKey, 
shouldAutogenerateCiteKey, canGenerateAndSetCiteKey, allFieldNames, 
searchIndexInfo, completionObject, bibTeXString, RISStringValue, MODSXMLValue, 
endNoteXMLValue, wordXMLValue, RSSStringValue, requiredFields, optionalFields, 
defaultFields, allFields, fields, urls, persons, fieldComponents, authors, 
editors, authorsOrEditors, keywords, currentDate, textSkimNotes, 
richTextSkimNotes, linkedText, remoteURL, localURL, localUrlPath, URLFields, 
skimNotesForLocalURL, bdskURL;
+@dynamic undoManager, localFiles, existingLocalFiles, remoteURLs, usedMacros, 
usedLocalMacros, allPeople, people, numberOfAuthors, pubAuthors, firstAuthor, 
secondAuthor, thirdAuthor, lastAuthor, bibTeXAuthorString, 
numberOfAuthorsOrEditors, pubAuthorsOrEditors, firstAuthorOrEditor, 
secondAuthorOrEditor, thirdAuthorOrEditor, lastAuthorOrEditor, crossrefParent, 
title, displayTitle, container, sortingTitle, sortingContainer, 
sortingBooktitle, rating, color, suggestedCiteKey, hasEmptyOrDefaultCiteKey, 
needsToAutogenerateCiteKey, canAutogenerateCiteKey, allFieldNames, 
searchIndexInfo, completionObject, bibTeXString, RISStringValue, MODSXMLValue, 
endNoteXMLValue, wordXMLValue, RSSStringValue, requiredFields, optionalFields, 
defaultFields, allFields, fields, urls, persons, fieldComponents, authors, 
editors, authorsOrEditors, keywords, currentDate, textSkimNotes, 
richTextSkimNotes, linkedText, remoteURL, localURL, localUrlPath, URLFields, 
skimNotesForLocalURL, bdskURL;
 
 + (void)initialize
 {
@@ -1092,19 +1092,22 @@
     return [NSString isEmptyString:key] || [key 
isEqualToString:defaultCiteKey] || [key isEqualToString:placeholderCiteKey];
 }
 
-- (BOOL)shouldAutogenerateCiteKey
+- (BOOL)needsToAutogenerateCiteKey
 {
     if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKCiteKeyAutogenerateKey] == NO)
         return NO;
-    return [[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKCiteKeyAutogenerateExistingKey] ? [self 
hasEmptyOrDefaultCiteKey] : hasEditedCiteKey;
+    else if ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKCiteKeyAutogenerateExistingKey])
+        return hasEditedCiteKey == NO;
+    else
+        return [self hasEmptyOrDefaultCiteKey];
 }
 
-- (BOOL)canGenerateAndSetCiteKey
+- (BOOL)canAutogenerateCiteKey
 {
     NSArray *requiredFields = [[BDSKTypeManager sharedManager] 
requiredFieldsForCiteKey];
     
     // see if it needs to be set (hasEmptyOrDefaultCiteKey)
-    if (nil == requiredFields || ([[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKCiteKeyAutogenerateExistingKey] ? hasEditedCiteKey : [self 
hasEmptyOrDefaultCiteKey]))
+    if (nil == requiredFields || NO == [self needsToAutogenerateCiteKey])
                return NO;
     
     // see if we have enough fields to generate it

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