Revision: 29310
          http://sourceforge.net/p/bibdesk/svn/29310
Author:   hofman
Date:     2025-07-20 15:40:27 +0000 (Sun, 20 Jul 2025)
Log Message:
-----------
set identifier for note text views to easliy get the field

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

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2025-07-20 14:20:05 UTC (rev 29309)
+++ trunk/bibdesk/BDSKEditor.m  2025-07-20 15:40:27 UTC (rev 29310)
@@ -128,8 +128,6 @@
 - (BOOL)control:(NSControl *)control isValidObject:(id)obj error:(NSError 
**)error;
 - (BOOL)textShouldEndEditing:(NSText *)aTextObject error:(NSError **)error;
 
-- (NSString *)currentEditedNoteField;
-
 - (void)recordChangingField:(NSString *)fieldName toValue:(NSString *)value;
 
 - (void)openParentItemForField:(NSString *)field;
@@ -252,21 +250,18 @@
     
     // Setup the textviews
     [notesView setUsesDefaultFont:YES];
-    NSString *currentValue = [publication valueOfField:BDSKAnnoteString 
inherit:NO];
-    if (currentValue)
-        [notesView setString:currentValue];
+    [notesView setIdentifier:BDSKAnnoteString];
+    [notesView setString:[publication valueOfField:BDSKAnnoteString 
inherit:NO] ?: @""];
     [notesView setEditable:editorFlags.isEditable];
     [notesView setTextColor:[NSColor textColor]];
+    [abstractView setIdentifier:BDSKAbstractString];
     [abstractView setUsesDefaultFont:YES];
-    currentValue = [publication valueOfField:BDSKAbstractString inherit:NO];
-    if (currentValue)
-        [abstractView setString:currentValue];
+    [abstractView setString:[publication valueOfField:BDSKAbstractString 
inherit:NO] ?: @""];
     [abstractView setEditable:editorFlags.isEditable];
     [abstractView setTextColor:[NSColor textColor]];
+    [rssDescriptionView setIdentifier:BDSKRssDescriptionString];
     [rssDescriptionView setUsesDefaultFont:YES];
-    currentValue = [publication valueOfField:BDSKRssDescriptionString 
inherit:NO];
-    if (currentValue)
-        [rssDescriptionView setString:currentValue];
+    [rssDescriptionView setString:[publication 
valueOfField:BDSKRssDescriptionString inherit:NO] ?: @""];
     [rssDescriptionView setEditable:editorFlags.isEditable];
     [rssDescriptionView setTextColor:[NSColor textColor]];
     if (@available(macOS 10.14, *)) {
@@ -362,9 +357,7 @@
             // need some reasonable state for annote et al. textviews
             [publication setEditedField:nil];
             [publication setEditedValue:nil];
-            NSString *field = [self currentEditedNoteField];
-            NSParameterAssert(nil != field);
-            [currentEditedView setString:[publication valueOfField:field 
inherit:NO] ?: @""];
+            [currentEditedView setString:[publication 
valueOfField:[currentEditedView identifier] inherit:NO] ?: @""];
             // make sure to stop editing
             [[self window] makeFirstResponder:[self window]];
         }
@@ -2231,25 +2224,11 @@
 
 #pragma mark annote/abstract/rss
 
-- (NSString *)currentEditedNoteField {
-    if (currentEditedView == notesView)
-        return BDSKAnnoteString;
-    else if (currentEditedView == abstractView)
-        return BDSKAbstractString;
-    else if (currentEditedView == rssDescriptionView)
-        return BDSKRssDescriptionString;
-    else
-        return nil;
-}
-
 - (void)textDidBeginEditing:(NSNotification *)aNotification{
        currentEditedView = [aNotification object];
     
-    NSString *field = [self currentEditedNoteField];
-    if (field) {
-        [publication setEditedField:field];
-        [publication setEditedValue:[[currentEditedView textStorage] 
mutableString]];
-    }
+    [publication setEditedField:[currentEditedView identifier]];
+    [publication setEditedValue:[[currentEditedView textStorage] 
mutableString]];
     
     [self setEditing:YES];
 }
@@ -2258,15 +2237,12 @@
     if (currentEditedView == nil)
         return;
     
-    NSString *field = [self currentEditedNoteField];
-    if (field) {
-        editorFlags.ignoreFieldChange = YES;
-        NSDictionary *notifInfo = @{BDSKBibItemKeyKey: field};
-        [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKBibItemChangedNotification
-                                                           object:publication
-                                                         userInfo:notifInfo];
-        editorFlags.ignoreFieldChange = NO;
-    }
+    editorFlags.ignoreFieldChange = YES;
+    NSDictionary *notifInfo = @{BDSKBibItemKeyKey: [currentEditedView 
identifier]};
+    [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKBibItemChangedNotification
+                                                       object:publication
+                                                     userInfo:notifInfo];
+    editorFlags.ignoreFieldChange = NO;
 }
 
 // Clear all the undo actions when changing tab items, just in case; otherwise 
we
@@ -2312,36 +2288,34 @@
     
     NSParameterAssert([self textShouldEndEditing:currentEditedView 
error:NULL]);
     
-    NSString *field = [self currentEditedNoteField];
-    if (field) {
-        [publication setEditedField:nil];
-        [publication setEditedValue:nil];
+    [publication setEditedField:nil];
+    [publication setEditedValue:nil];
+    
+    NSString *field = [currentEditedView identifier];
+    NSString *oldValue = [publication valueOfField:field inherit:NO] ?: @"";
+    NSString *value = [currentEditedView string];
+    
+    editorFlags.ignoreFieldChange = YES;
+    if (NO == [value isEqualAsComplexString:oldValue]) {
+        NSString *actionName = nil;
+        if (currentEditedView == notesView)
+            actionName = NSLocalizedString(@"Edit Annotation",@"Undo action 
name");
+        else if(currentEditedView == abstractView)
+            actionName = NSLocalizedString(@"Edit Abstract",@"Undo action 
name");
+        else if(currentEditedView == rssDescriptionView)
+            actionName = NSLocalizedString(@"Edit RSS Description",@"Undo 
action name");
         
-        NSString *oldValue = [publication valueOfField:field inherit:NO] ?: 
@"";
-        NSString *value = [currentEditedView string];
-        
-        editorFlags.ignoreFieldChange = YES;
-        if (NO == [value isEqualAsComplexString:oldValue]) {
-            NSString *actionName = nil;
-            if (currentEditedView == notesView)
-                actionName = NSLocalizedString(@"Edit Annotation",@"Undo 
action name");
-            else if(currentEditedView == abstractView)
-                actionName = NSLocalizedString(@"Edit Abstract",@"Undo action 
name");
-            else if(currentEditedView == rssDescriptionView)
-                actionName = NSLocalizedString(@"Edit RSS Description",@"Undo 
action name");
-            
-            [publication setField:field toValue:value];
-            [[self undoManager] setActionName:actionName];
-            [self userChangedField:field from:oldValue to:value];
-        } else {
-            // this is needed to update the search index and previews
-            NSDictionary *notifInfo = @{BDSKBibItemKeyKey: field, 
BDSKBibItemOldValueKey: oldValue, BDSKBibItemNewValueKey: value};
-            [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKBibItemChangedNotification
-                                                                
object:publication
-                                                              
userInfo:notifInfo];
-        }
-        editorFlags.ignoreFieldChange = NO;
+        [publication setField:field toValue:value];
+        [[self undoManager] setActionName:actionName];
+        [self userChangedField:field from:oldValue to:value];
+    } else {
+        // this is needed to update the search index and previews
+        NSDictionary *notifInfo = @{BDSKBibItemKeyKey: field, 
BDSKBibItemOldValueKey: oldValue, BDSKBibItemNewValueKey: value};
+        [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKBibItemChangedNotification
+                                                            object:publication
+                                                          userInfo:notifInfo];
     }
+    editorFlags.ignoreFieldChange = NO;
     
     currentEditedView = nil;
     [textViewUndoManager removeAllActions];
@@ -2413,7 +2387,7 @@
     }
     else if([changeKey isNoteField]){
         if(editorFlags.ignoreFieldChange == NO) {
-            if (currentEditedView && [[self currentEditedNoteField] 
isEqualToString:changeKey]) {
+            if (currentEditedView && [[currentEditedView identifier] 
isEqualToString:changeKey]) {
                 // make sure we are getting the actual current value rather 
than the edited value
                 [publication setEditedField:nil];
                 [currentEditedView setString:[publication 
valueOfField:changeKey inherit:NO] ?: @""];
@@ -2449,7 +2423,7 @@
         [authorTableView reloadData];
         if (editorFlags.ignoreFieldChange == NO) {
             if (currentEditedView) {
-                NSString *editedKey = [self currentEditedNoteField];
+                NSString *editedKey = [currentEditedView identifier];
                 // make sure we are getting the actual current value rather 
than the edited value
                 [publication setEditedField:nil];
                 [currentEditedView setString:[publication 
valueOfField:editedKey inherit:NO] ?: @""];

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



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to