Revision: 11900
          http://bibdesk.svn.sourceforge.net/bibdesk/?rev=11900&view=rev
Author:   hofman
Date:     2007-12-13 09:35:56 -0800 (Thu, 13 Dec 2007)

Log Message:
-----------
Change userInfo for bib change notification and handle changes of the whole 
pubFields dictionary in the editor.

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

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2007-12-13 16:45:25 UTC (rev 11899)
+++ trunk/bibdesk/BDSKEditor.m  2007-12-13 17:35:56 UTC (rev 11900)
@@ -1874,22 +1874,30 @@
 
 - (void)bibDidChange:(NSNotification *)notification{
        NSDictionary *userInfo = [notification userInfo];
-       NSString *changeType = [userInfo objectForKey:@"type"];
        NSString *changeKey = [userInfo objectForKey:@"key"];
-       NSString *newValue = [userInfo objectForKey:@"value"];
+       NSString *newValue = [userInfo objectForKey:@"newValue"];
        BibItem *sender = (BibItem *)[notification object];
        NSString *crossref = [publication valueOfField:BDSKCrossrefString 
inherit:NO];
        BOOL parentDidChange = (crossref != nil && 
                                                        ([crossref 
caseInsensitiveCompare:[sender citeKey]] == NSOrderedSame || 
-                                                        [crossref 
caseInsensitiveCompare:[userInfo objectForKey:@"oldCiteKey"]] == 
NSOrderedSame));
+                                                        [crossref 
caseInsensitiveCompare:[userInfo objectForKey:@"oldValue"]] == NSOrderedSame));
        
     // If it is not our item or his crossref parent, we don't care, but our 
parent may have changed his cite key
        if (sender != publication && NO == parentDidChange)
                return;
        
-       if([changeType isEqualToString:@"Add/Del File"]){
+       if([changeKey isEqualToString:BDSKLocalFileString]){
         [fileView reloadIcons];
     }
+       else if([changeKey isEqualToString:BDSKPubTypeString]){
+               [self resetFieldsIfNeeded];
+               [self updateTypePopup];
+       }
+       else if([changeKey isEqualToString:BDSKCiteKeyString]){
+               [citeKeyField setStringValue:newValue];
+               [self updateCiteKeyAutoGenerateStatus];
+        [self updateCiteKeyDuplicateWarning];
+       }
        else if([changeKey isEqualToString:BDSKCrossrefString] || 
           (parentDidChange && [changeKey isEqualToString:BDSKCiteKeyString])){
         // Reset if the crossref changed, or our parent's cite key changed.
@@ -1902,15 +1910,6 @@
                [authorTableView reloadData];
                [[self window] setTitle:[publication displayTitle]];
        }
-       else if([changeKey isEqualToString:BDSKPubTypeString]){
-               [self resetFieldsIfNeeded];
-               [self updateTypePopup];
-       }
-       else if([changeKey isEqualToString:BDSKCiteKeyString]){
-               [citeKeyField setStringValue:newValue];
-               [self updateCiteKeyAutoGenerateStatus];
-        [self updateCiteKeyDuplicateWarning];
-       }
     else if([changeKey isNoteField]){
         if(ignoreFieldChange == NO) {
             if([changeKey isEqualToString:BDSKAnnoteString]){
@@ -1950,7 +1949,7 @@
                        }
                }
        }
-    else{
+    else if (changeKey){
         // this is a normal field displayed in the tableView
         
         if([changeKey isEqualToString:BDSKTitleString] || [changeKey 
isEqualToString:BDSKChapterString] || [changeKey 
isEqualToString:BDSKPagesString])
@@ -1965,6 +1964,28 @@
             // a field value changed
             [self reloadTable];
         }
+    }
+       else{
+        // changeKey == nil, all fields are set
+               [self resetFields];
+        [self setupMatrix];
+        if(ignoreFieldChange == NO) {
+           // make a copy of the current value, so we don't overwrite it when 
we set the field value to the text storage
+            NSString *tmpValue = [[publication valueOfField:BDSKAnnoteString 
inherit:NO] copy];
+            [notesView setString:(tmpValue == nil ? @"" : tmpValue)];
+            [tmpValue release];
+            tmpValue = [[publication valueOfField:BDSKAbstractString 
inherit:NO] copy];
+            [abstractView setString:(tmpValue == nil ? @"" : tmpValue)];
+            [tmpValue release];
+            tmpValue = [[publication valueOfField:BDSKRssDescriptionString 
inherit:NO] copy];
+            [rssDescriptionView setString:(tmpValue == nil ? @"" : tmpValue)];
+            [tmpValue release];
+            if(currentEditedView)
+                [[self window] makeFirstResponder:[self window]];
+            [notesViewUndoManager removeAllActions];
+            [abstractViewUndoManager removeAllActions];
+            [rssDescriptionViewUndoManager removeAllActions];
+        }
        }
     
 }
@@ -2080,7 +2101,7 @@
     if (field) {
         // this is needed to update the search index and tex preview
         NSString *value = [publication valueOfField:field];
-        NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:value, @"value", field, @"key", @"Change", 
@"type", value, @"oldValue", [publication owner], @"owner", nil];
+        NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:field, @"key", value, @"newValue", value, 
@"oldValue", nil];
         [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKBibItemChangedNotification
                                                             object:publication
                                                           userInfo:notifInfo];

Modified: trunk/bibdesk/BDSKFiler.m
===================================================================
--- trunk/bibdesk/BDSKFiler.m   2007-12-13 16:45:25 UTC (rev 11899)
+++ trunk/bibdesk/BDSKFiler.m   2007-12-13 17:35:56 UTC (rev 11900)
@@ -205,7 +205,7 @@
                 
                 [file update];
                 // make sure the UI is notified that the linked file has 
changed, as this is often called after setField:toValue:
-                NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:@"Add/Del File", @"type", [pub owner], @"owner", 
nil];
+                NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:BDSKLocalFileString, @"key", nil];
                 [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKBibItemChangedNotification
                                                                     object:pub
                                                                   
userInfo:notifInfo];

Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2007-12-13 16:45:25 UTC (rev 11899)
+++ trunk/bibdesk/BibDocument.m 2007-12-13 17:35:56 UTC (rev 11900)
@@ -2581,20 +2581,20 @@
 - (void)handleBibItemChangedNotification:(NSNotification *)notification{
 
        NSDictionary *userInfo = [notification userInfo];
+    BibItem *pub = [notification object];
     
     // see if it's ours
-       if([userInfo objectForKey:@"owner"] != self)
+       if([pub owner] != self)
         return;
 
        NSString *changedKey = [userInfo objectForKey:@"key"];
-    BibItem *pub = [notification object];
     NSString *key = [pub citeKey];
     NSString *oldKey = nil;
     NSEnumerator *pubEnum = [publications objectEnumerator];
     
     // need to handle cite keys and crossrefs if a cite key changed
     if([changedKey isEqualToString:BDSKCiteKeyString]){
-        oldKey = [userInfo objectForKey:@"oldCiteKey"];
+        oldKey = [userInfo objectForKey:@"oldValue"];
         [publications changeCiteKey:oldKey toCiteKey:key forItem:pub];
         if([NSString isEmptyString:oldKey])
             oldKey = nil;

Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m     2007-12-13 16:45:25 UTC (rev 11899)
+++ trunk/bibdesk/BibItem.m     2007-12-13 17:35:56 UTC (rev 11900)
@@ -950,7 +950,7 @@
        }
        [self updateMetadataForKey:BDSKPubTypeString];
                
-    NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:newType, @"value", BDSKPubTypeString, @"key", 
@"Change", @"type", owner, @"owner", nil];
+    NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:BDSKPubTypeString, @"key", newType, @"newValue", 
oldType, @"oldValue", nil];
     [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKBibItemChangedNotification
                                                                                
                                object:self
                                                                                
                          userInfo:notifInfo];
@@ -996,7 +996,7 @@
        }
        [self updateMetadataForKey:BDSKCiteKeyString];
                
-    NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:newCiteKey, @"value", BDSKCiteKeyString, @"key", 
@"Change", @"type", oldCiteKey, @"oldCiteKey", owner, @"owner", nil];
+    NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:BDSKCiteKeyString, @"key", newCiteKey, 
@"newValue", oldCiteKey, @"oldValue", nil];
 
     [[NSFileManager defaultManager] 
removeSpotlightCacheFileForCiteKey:oldCiteKey];
     [oldCiteKey release];
@@ -1120,7 +1120,7 @@
                
                [self setPubFields:newFields];
                
-               NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:@"Add/Del Fields", @"type", owner, @"owner", nil]; 
// cmh: maybe not the best info, but handled correctly
+               NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:nil]; // cmh: maybe not the best info, but handled 
correctly
                [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKBibItemChangedNotification
                                                                                
                                        object:self
                                                                                
                                  userInfo:notifInfo];
@@ -1156,8 +1156,8 @@
     [pubFields setValue:[date description] forKey:BDSKDateModifiedString];
        [self updateMetadataForKey:key];
        
-       NSMutableDictionary *notifInfo = [NSMutableDictionary 
dictionaryWithObjectsAndKeys:key, @"key", @"Change Field", @"type", owner, 
@"owner", nil];
-    [notifInfo setValue:value forKey:@"value"];
+       NSMutableDictionary *notifInfo = [NSMutableDictionary 
dictionaryWithObjectsAndKeys:key, @"key", nil];
+    [notifInfo setValue:value forKey:@"newValue"];
     [notifInfo setValue:oldValue forKey:@"oldValue"];
     [oldValue release];
     
@@ -2542,7 +2542,7 @@
     if ([owner fileURL])
         [aFile update];
        
-    NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:@"Add/Del File", @"type", owner, @"owner", nil];
+    NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:BDSKLocalFileString, @"key", nil];
        [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKBibItemChangedNotification
                                                                                
                                object:self
                                                                                
                          userInfo:notifInfo];
@@ -2556,7 +2556,7 @@
     [self removeFileToBeFiled:file];
     [files removeObjectAtIndex:idx];
        
-    NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:@"Add/Del File", @"type", owner, @"owner", nil];
+    NSDictionary *notifInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:BDSKLocalFileString, @"key", nil];
        [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKBibItemChangedNotification
                                                                                
                                object:self
                                                                                
                          userInfo:notifInfo];


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://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to