Revision: 29286
http://sourceforge.net/p/bibdesk/svn/29286
Author: hofman
Date: 2025-07-17 18:20:53 +0000 (Thu, 17 Jul 2025)
Log Message:
-----------
allow recovery from commit
Modified Paths:
--------------
trunk/bibdesk/BDSKEditor.h
trunk/bibdesk/BDSKEditor.m
Modified: trunk/bibdesk/BDSKEditor.h
===================================================================
--- trunk/bibdesk/BDSKEditor.h 2025-07-17 18:04:48 UTC (rev 29285)
+++ trunk/bibdesk/BDSKEditor.h 2025-07-17 18:20:53 UTC (rev 29286)
@@ -118,6 +118,7 @@
unsigned int didSetupFields:1;
unsigned int controllingQLPreviewPanel:1;
unsigned int controllingFVPreviewPanel:1;
+ unsigned int allowFragileCharacters:1;
} editorFlags;
}
Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m 2025-07-17 18:04:48 UTC (rev 29285)
+++ trunk/bibdesk/BDSKEditor.m 2025-07-17 18:20:53 UTC (rev 29286)
@@ -400,41 +400,6 @@
[self setEditing:NO];
}
-- (void)didPresentErrorWithRecovery:(BOOL)didRecover contextInfo:(void
*)contextInfo {
- NSInvocation *invocation = (NSInvocation *)CFBridgingRelease(contextInfo);
- if (invocation) {
- [invocation setArgument:&didRecover atIndex:3];
- [invocation invoke];
- }
-}
-- (void)commitEditingWithDelegate:(id)delegate
didCommitSelector:(SEL)didCommitSelector contextInfo:(void *)contextInfo
-{
- NSError *error = nil;
- BOOL didCommit = [self commitEditingAndReturnError:&error];
- if (didCommit == NO) {
- id aDelegate = nil;
- SEL aSelector = NULL;
- void *aContextInfo = NULL;
- if (delegate && didCommitSelector) {
- NSInvocation *invocation = [NSInvocation
invocationWithTarget:delegate selector:didCommitSelector];
- __unsafe_unretained id editor = self;
- [invocation setArgument:&editor atIndex:2];
- [invocation setArgument:&contextInfo atIndex:4];
- aDelegate = self;
- aSelector = @selector(didPresentErrorWithRecovery:contextInfo:);
- aContextInfo = (void *)CFBridgingRetain(invocation);
- }
- [self presentError:error modalForWindow:[self window]
delegate:aDelegate didPresentSelector:aSelector contextInfo:aContextInfo];
- } 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);
- });
- }
-}
-
- (BOOL)commitEditing
{
if (editorFlags.isEditing == NO)
@@ -486,8 +451,7 @@
return YES;
}
-- (BOOL)commitEditingAndReturnError:(NSError **)error
-
+- (BOOL)commitEditingAndReturnRecoverableError:(NSError **)error
{
if (editorFlags.isEditing == NO)
return YES;
@@ -590,6 +554,63 @@
return YES;
}
+- (BOOL)commitEditingAndReturnError:(NSError **)error {
+ BOOL didCommit = [self commitEditingAndReturnRecoverableError:error];
+ if (didCommit == NO && error && [*error localizedRecoveryOptions]) {
+ // no recovery possible, so just make it an unrecoverable error
+ NSError *err = [NSError mutableLocalErrorWithCode:kBDSKFailedToCommit
localizedDescription:[*error localizedDescription]];
+ NSString *errString = [*error localizedRecoverySuggestion];
+ NSRange r = [errString rangeOfString:@"."];
+ if (r.location != NSNotFound)
+ errString = [errString substringToIndex:NSMaxRange(r)];
+ [err setValue:errString forKey:NSLocalizedRecoverySuggestionErrorKey];
+ *error = err;
+ }
+ return didCommit;
+}
+
+- (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;
+ }
+ NSInvocation *invocation = (NSInvocation *)CFBridgingRelease(contextInfo);
+ if (invocation) {
+ [invocation setArgument:&didRecover atIndex:3];
+ [invocation invoke];
+ }
+}
+
+- (void)commitEditingWithDelegate:(id)delegate
didCommitSelector:(SEL)didCommitSelector contextInfo:(void *)contextInfo
+{
+ NSError *error = nil;
+ BOOL didCommit = [self commitEditingAndReturnRecoverableError:&error];
+ if (didCommit == NO) {
+ NSInvocation *invocation = nil;
+ if (delegate && didCommitSelector) {
+ invocation = [NSInvocation invocationWithTarget:delegate
selector:didCommitSelector];
+ __unsafe_unretained id editor = self;
+ [invocation setArgument:&editor atIndex:2];
+ [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);
+ });
+ }
+}
+
#pragma mark Actions
- (IBAction)copy:(id)sender {
@@ -2104,7 +2125,7 @@
NSRange r = [obj rangeOfCharacterFromSet:invalidSet];
// check for fragile invalid characters, as the formatter doesn't do
this
- if (r.location != NSNotFound) {
+ if (r.location != NSNotFound && editorFlags.allowFragileCharacters ==
NO) {
err = [NSError mutableLocalErrorWithCode:kBDSKFailedToCommit
localizedDescription:NSLocalizedString(@"Invalid Value", @"Message in alert
dialog when entering an invalid value")];
[err setValue:NSLocalizedString(@"The cite key you entered
contains characters that could be invalid in TeX. Do you want to keep them or
remove them?", @"Informative text in alert dialog")
forKey:NSLocalizedRecoverySuggestionErrorKey];
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