Revision: 11879
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=11879&view=rev
Author:   hofman
Date:     2007-12-12 06:06:38 -0800 (Wed, 12 Dec 2007)

Log Message:
-----------
Factor more field edits through recordChangingField:toValue: to avoid code 
duplication.

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

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2007-12-12 13:47:35 UTC (rev 11878)
+++ trunk/bibdesk/BDSKEditor.m  2007-12-12 14:06:38 UTC (rev 11879)
@@ -1075,7 +1075,7 @@
        int newRating = [cell rating];
                
        if(newRating != oldRating) {
-               [publication setField:field toRatingValue:newRating];
+               [self recordChangingField:setField:field 
toRatingValue:newRating];
         [self userChangedField:field from:[NSString stringWithFormat:@"%i", 
oldRating] to:[NSString stringWithFormat:@"%i", newRating]];
                [[self undoManager] setActionName:NSLocalizedString(@"Change 
Rating", @"Undo action name")];
        }
@@ -1692,7 +1692,36 @@
 - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText 
*)fieldEditor{
     BOOL endEdit = YES;
     
-    if (control == citeKeyField) {
+    if (control == tableView) {
+        
+        NSString *field = [fields objectAtIndex:[tableView editedRow]];
+        NSString *value = [fieldEditor string];
+        
+        if ([field isEqualToString:BDSKCrossrefString] && [NSString 
isEmptyString:value] == NO) {
+            NSString *message = nil;
+            
+            // check whether we won't get a crossref chain
+            int errorCode = [publication canSetCrossref:value 
andCiteKey:[publication citeKey]];
+            if (errorCode == BDSKSelfCrossrefError)
+                message = NSLocalizedString(@"An item cannot cross reference 
to itself.", @"Informative text in alert dialog");
+            else if (errorCode == BDSKChainCrossrefError)
+                message = NSLocalizedString(@"Cannot cross reference to an 
item that has the Crossref field set.", @"Informative text in alert dialog");
+            else if (errorCode == BDSKIsCrossreffedCrossrefError)
+                message = NSLocalizedString(@"Cannot set the Crossref field, 
as the current item is cross referenced.", @"Informative text in alert dialog");
+            
+            if (message) {
+                BDSKAlert *alert = [BDSKAlert 
alertWithMessageText:NSLocalizedString(@"Invalid Crossref Value", @"Message in 
alert dialog when entering an invalid Crossref key") 
+                                                     
defaultButton:NSLocalizedString(@"OK", @"Button title")
+                                                   alternateButton:nil
+                                                       otherButton:nil
+                                         informativeTextWithFormat:message];
+                
+                [alert runSheetModalForWindow:[self window]];
+                ignoreEdit = YES;
+            }
+        }
+        
+    } else if (control == citeKeyField) {
                
         NSString *message = nil;
         NSString *cancelButton = nil;
@@ -2332,10 +2361,7 @@
                }
                
         // add the crossref field if it doesn't exist, then set it to the 
citekey of the drag source's bibitem
-               [publication setField:BDSKCrossrefString toValue:crossref];
-        
-        [self userChangedField:BDSKCrossrefString from:oldValue to:crossref];
-               [[self undoManager] setActionName:NSLocalizedString(@"Edit 
Publication", @"Undo action name")];
+               [self recordChangingField:BDSKCrossrefString toValue:crossref];
                
         return YES;
         
@@ -2535,32 +2561,6 @@
 - (void)tableView:(NSTableView *)tv setObjectValue:(id)object 
forTableColumn:(NSTableColumn *)tableColumn row:(int)row {
        if ([tv isEqual:tableView] && [[tableColumn identifier] 
isEqualToString:@"value"] && ignoreEdit == NO) {
         NSString *field = [fields objectAtIndex:row];
-        
-        if ([field isEqualToString:BDSKCrossrefString] && [NSString 
isEmptyString:object] == NO) {
-            NSString *message = nil;
-            
-            // check whether we won't get a crossref chain
-            int errorCode = [publication canSetCrossref:object 
andCiteKey:[publication citeKey]];
-            if (errorCode == BDSKSelfCrossrefError)
-                message = NSLocalizedString(@"An item cannot cross reference 
to itself.", @"Informative text in alert dialog");
-            else if (errorCode == BDSKChainCrossrefError)
-                message = NSLocalizedString(@"Cannot cross reference to an 
item that has the Crossref field set.", @"Informative text in alert dialog");
-            else if (errorCode == BDSKIsCrossreffedCrossrefError)
-                message = NSLocalizedString(@"Cannot set the Crossref field, 
as the current item is cross referenced.", @"Informative text in alert dialog");
-            
-            if (message) {
-                BDSKAlert *alert = [BDSKAlert 
alertWithMessageText:NSLocalizedString(@"Invalid Crossref Value", @"Message in 
alert dialog when entering an invalid Crossref key") 
-                                                     
defaultButton:NSLocalizedString(@"OK", @"Button title")
-                                                   alternateButton:nil
-                                                       otherButton:nil
-                                         informativeTextWithFormat:message];
-                
-                [alert runSheetModalForWindow:[self window]];
-                [tableView reloadData];
-                return;
-            }
-        }
-        
         NSString *oldValue = [publication valueOfField:field];
         if (oldValue == nil)
             oldValue = @"";
@@ -2602,20 +2602,14 @@
                 
                 NSData *pbData = [pboard dataForType:BDSKBibItemPboardType];
                 NSArray *draggedPubs = [[self document] 
newPublicationsFromArchivedData:pbData];
-                NSString *citeKeys = [[draggedPubs valueForKey:@"citeKey"] 
componentsJoinedByString:@","];
-                NSString *oldValue = [[[publication valueOfField:field 
inherit:NO] retain] autorelease];
-                NSString *newValue;
                 
                 if ([draggedPubs count]) {
-                    if ([NSString isEmptyString:oldValue])   
-                        newValue = citeKeys;
-                    else
-                        newValue = [NSString stringWithFormat:@"%@,%@", 
oldValue, citeKeys];
                     
-                    [publication setField:field toValue:newValue];
+                    NSString *citeKeys = [[draggedPubs valueForKey:@"citeKey"] 
componentsJoinedByString:@","];
+                    NSString *oldValue = [[[publication valueOfField:field 
inherit:NO] retain] autorelease];
+                    NSString *newValue = [NSString isEmptyString:oldValue] ? 
citeKeys : [NSString stringWithFormat:@"%@,%@", oldValue, citeKeys];
                     
-                    [self userChangedField:field from:oldValue to:newValue];
-                    [[self undoManager] setActionName:NSLocalizedString(@"Edit 
Publication", @"Undo action name")];
+                    [self recordChangingField:field toValue:newValue];
                     
                     return YES;
                 }
@@ -2625,7 +2619,6 @@
                 NSData *pbData = [pboard dataForType:BDSKBibItemPboardType];
                 NSArray *draggedPubs = [[self document] 
newPublicationsFromArchivedData:pbData];
                 NSString *crossref = [[draggedPubs firstObject] citeKey];
-                NSString *oldValue;
                 
                 if ([NSString isEmptyString:crossref])
                     return NO;
@@ -2650,13 +2643,8 @@
                     return NO;
                 }
                 
-                oldValue = [[[publication valueOfField:BDSKCrossrefString] 
retain] autorelease];
+                [self recordChangingField:BDSKCrossrefString toValue:crossref];
                 
-                [publication setField:BDSKCrossrefString toValue:crossref];
-                
-                [self userChangedField:BDSKCrossrefString from:oldValue 
to:crossref];
-                [[self undoManager] setActionName:NSLocalizedString(@"Edit 
Publication", @"Undo action name")];
-                
                 return YES;
                     
             }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to