Revision: 29287
          http://sourceforge.net/p/bibdesk/svn/29287
Author:   hofman
Date:     2025-07-17 21:09:41 +0000 (Thu, 17 Jul 2025)
Log Message:
-----------
Use callback for commit errors only when having recovery options. Don't show 
errors for complex string errors.

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

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2025-07-17 18:20:53 UTC (rev 29286)
+++ trunk/bibdesk/BDSKEditor.m  2025-07-17 21:09:41 UTC (rev 29287)
@@ -570,16 +570,21 @@
 }
 
 - (void)didPresentErrorWithRecovery:(BOOL)didRecover contextInfo:(void 
*)contextInfo {
-    if (didRecover) {
-        // we must be committing the citeKeyField with fragile characters
-        editorFlags.allowFragileCharacters = YES;
-        NSTextView *textView = (NSTextView *)[citeKeyField currentEditor];
-        NSArray *selection = [textView selectedRanges];
-        if ([[self window] makeFirstResponder:[self window]] == NO)
-            didRecover = NO;
-        else if ([[self window] makeFirstResponder:citeKeyField])
-            [(NSTextView *)[citeKeyField currentEditor] 
setSafeSelectedRanges:selection];
-        editorFlags.allowFragileCharacters = NO;
+    NSTextView *textView = (NSTextView *)[citeKeyField currentEditor];
+    if (textView) {
+        if (didRecover) {
+            // we must be committing the citeKeyField with fragile characters
+            NSArray *selection = [textView selectedRanges];
+            editorFlags.allowFragileCharacters = YES;
+            if ([[self window] makeFirstResponder:[self window]] == NO)
+                didRecover = NO;
+            else if ([[self window] makeFirstResponder:citeKeyField])
+                [(NSTextView *)[citeKeyField currentEditor] 
setSafeSelectedRanges:selection];
+            editorFlags.allowFragileCharacters = NO;
+        } else {
+            NSCharacterSet *invalidSet = [[BDSKTypeManager sharedManager] 
fragileCiteKeyCharacterSet];
+            [citeKeyField setStringValue:[[textView string] 
stringByReplacingCharactersInSet:invalidSet withString:@""]];
+        }
     }
     NSInvocation *invocation = (NSInvocation *)CFBridgingRelease(contextInfo);
     if (invocation) {
@@ -588,11 +593,10 @@
     }
 }
 
-- (void)commitEditingWithDelegate:(id)delegate 
didCommitSelector:(SEL)didCommitSelector contextInfo:(void *)contextInfo
-{
+- (void)commitEditingWithDelegate:(id)delegate 
didCommitSelector:(SEL)didCommitSelector contextInfo:(void *)contextInfo {
     NSError *error = nil;
     BOOL didCommit = [self commitEditingAndReturnRecoverableError:&error];
-    if (didCommit == NO) {
+    if (didCommit == NO && [error localizedRecoveryOptions]) {
         NSInvocation *invocation = nil;
         if (delegate && didCommitSelector) {
             invocation = [NSInvocation invocationWithTarget:delegate 
selector:didCommitSelector];
@@ -601,13 +605,17 @@
             [invocation setArgument:&contextInfo atIndex:4];
         }
         [self presentError:error modalForWindow:[self window] delegate:self 
didPresentSelector:@selector(didPresentErrorWithRecovery:contextInfo:) 
contextInfo:(void *)CFBridgingRetain(invocation)];
-    } else if (delegate && didCommitSelector) {
-        // - (void)editor:(id)editor didCommit:(BOOL)didCommit 
contextInfo:(void *)contextInfo
-        dispatch_async(dispatch_get_main_queue(), ^{
-            void (*didCommitImp)(id, SEL, id, BOOL, void *) = (void (*)(id, 
SEL, id, BOOL, void *))[delegate methodForSelector:didCommitSelector];
-            if (didCommitImp)
-                didCommitImp(delegate, didCommitSelector, self, didCommit, 
contextInfo);
-        });
+    } else {
+        if (didCommit == NO && error && [error code] != 
kBDSKComplexStringError)
+            [self presentError:error modalForWindow:[self window] delegate:nil 
didPresentSelector:NULL contextInfo:NULL];
+        if (delegate && didCommitSelector) {
+            // - (void)editor:(id)editor didCommit:(BOOL)didCommit 
contextInfo:(void *)contextInfo
+            dispatch_async(dispatch_get_main_queue(), ^{
+                void (*didCommitImp)(id, SEL, id, BOOL, void *) = (void 
(*)(id, SEL, id, BOOL, void *))[delegate methodForSelector:didCommitSelector];
+                if (didCommitImp)
+                    didCommitImp(delegate, didCommitSelector, self, didCommit, 
contextInfo);
+            });
+        }
     }
 }
 

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