Revision: 29373
http://sourceforge.net/p/bibdesk/svn/29373
Author: hofman
Date: 2025-07-26 22:45:41 +0000 (Sat, 26 Jul 2025)
Log Message:
-----------
do return formatting errors by reference, don't construct error when no error
is requested
Modified Paths:
--------------
trunk/bibdesk/BDSKEditor.m
Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m 2025-07-26 16:31:24 UTC (rev 29372)
+++ trunk/bibdesk/BDSKEditor.m 2025-07-26 22:45:41 UTC (rev 29373)
@@ -123,9 +123,9 @@
- (void)fileURLDidChange:(NSNotification *)notification;
- (void)needsToBeFiledDidChange:(NSNotification *)notification;
-- (NSError *)errorForControl:(NSControl *)control
didFailToFormatString:(NSString *)string errorDescription:(NSString
*)errorString;
-- (NSError *)errorForControl:(NSControl *)control isValidObject:(id)obj;
-- (NSError *)errorForTextShouldEndEditing:(NSText *)aTextObject;
+- (BOOL)control:(NSControl *)control didFailToFormatString:(NSString *)string
errorDescription:(NSString *)errorString error:(NSError **)error;
+- (BOOL)control:(NSControl *)control isValidObject:(id)obj error:(NSError
**)error;
+- (BOOL)textShouldEndEditing:(NSText *)aTextObject error:(NSError **)error;
- (void)recordChangingField:(NSString *)fieldName toValue:(NSString *)value;
@@ -467,19 +467,14 @@
if (formatter) {
NSString *errorString = nil;
if (NO == [formatter getObjectValue:&obj forString:string
errorDescription:&errorString] &&
- (err = [self errorForControl:textField
didFailToFormatString:string errorDescription:errorString])) {
- if (error) *error = err;
+ NO == [self control:textField didFailToFormatString:string
errorDescription:errorString error:error])
return NO;
- }
}
- if ((err = [self errorForControl:textField isValidObject:obj])) {
- if (error) *error = err;
+ if (NO == [self control:textField isValidObject:obj error:error])
return NO;
- }
- } else if (currentEditedView && (err = [self
errorForTextShouldEndEditing:textView])) {
+ } else if (currentEditedView && NO == [self
textShouldEndEditing:textView error:error]) {
// the string of the edited textView has unbalanced braces
- if (error) *error = err;
return NO;
}
@@ -2020,10 +2015,13 @@
// Don't show an annoying warning. This fails only when invalid cite key
characters are used, which are simply removed by the formatter.
}
-- (NSError *)errorForControl:(NSControl *)control
didFailToFormatString:(NSString *)aString errorDescription:(NSString
*)errorString {
+- (BOOL)control:(NSControl *)control didFailToFormatString:(NSString *)aString
errorDescription:(NSString *)errorString error:(NSError **)error {
if (editorFlags.isEditable == NO)
- return nil;
+ return YES;
+ if (error == NULL)
+ return NO;
+
NSError *err = nil;
if (nil == errorString) {
@@ -2061,7 +2059,9 @@
}
}
- return err;
+ *error = err;
+
+ return NO;
}
// send by the formatter when formatting in getObjectValue... failed
@@ -2069,9 +2069,10 @@
if (editorFlags.isEditable == NO)
return YES;
- NSError *err = [self errorForControl:control didFailToFormatString:aString
errorDescription:error];
+ NSError *err = nil;
+ BOOL isValid = [self control:control didFailToFormatString:aString
errorDescription:error error:&err];
- if (err) {
+ if (isValid == NO) {
if ([err code] != kBDSKComplexStringError)
[self presentError:err modalForWindow:[self window] delegate:nil
didPresentSelector:NULL contextInfo:NULL];
else
@@ -2078,7 +2079,7 @@
NSBeep();
}
- return err != nil;
+ return isValid;
}
- (BOOL)attemptRecoveryFromError:(NSError *)error
optionIndex:(NSUInteger)recoveryOptionIndex {
@@ -2085,10 +2086,11 @@
return recoveryOptionIndex == 1;
}
-- (NSError *)errorForControl:(NSControl *)control isValidObject:(id)obj {
+- (BOOL)control:(NSControl *)control isValidObject:(id)obj error:(NSError
**)error {
if (editorFlags.isEditable == NO)
- return nil;
+ return YES;
+ BOOL isValid = YES;
NSError *err = nil;
if (control == citeKeyField) {
@@ -2100,23 +2102,29 @@
// check for fragile invalid characters, as the formatter doesn't do
this
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];
- [err setValue:self forKey:NSRecoveryAttempterErrorKey];
- [err setValue:@[NSLocalizedString(@"Remove", @"Button title"),
NSLocalizedString(@"Keep", @"Button title")]
forKey:NSLocalizedRecoveryOptionsErrorKey];
+ isValid == NO;
+ if (error) {
+ 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];
+ [err setValue:self forKey:NSRecoveryAttempterErrorKey];
+ [err setValue:@[NSLocalizedString(@"Remove", @"Button title"),
NSLocalizedString(@"Keep", @"Button title")]
forKey:NSLocalizedRecoveryOptionsErrorKey];
+ }
} else {
// check whether we won't crossref to the new citekey
BDSKCrossrefError errorCode = [publication canSetCiteKey:[control
stringValue]];
- if (errorCode == BDSKSelfCrossrefError)
- message = NSLocalizedString(@"An item cannot cross reference
to itself.", @"Informative text in alert dialog");
- else if (errorCode != BDSKNoCrossrefError) // shouldn't happen
- message = NSLocalizedString(@"Cannot set this cite key as this
would lead to a crossreff chain.", @"Informative text in alert dialog");
-
- if (message) {
- err = [NSError mutableLocalErrorWithCode:kBDSKFailedToCommit
localizedDescription:NSLocalizedString(@"Invalid Value", @"Message in alert
dialog when entering an invalid value")];
- [err setValue:message
forKey:NSLocalizedRecoverySuggestionErrorKey];
+ if (errorCode != BDSKNoCrossrefError) {
+ isValid = NO;
+ if (error) {
+ if (errorCode == BDSKSelfCrossrefError)
+ message = NSLocalizedString(@"An item cannot cross
reference to itself.", @"Informative text in alert dialog");
+ else // shouldn't happen
+ message = NSLocalizedString(@"Cannot set this cite key
as this would lead to a crossreff chain.", @"Informative text in alert dialog");
+
+ err = [NSError
mutableLocalErrorWithCode:kBDSKFailedToCommit
localizedDescription:NSLocalizedString(@"Invalid Value", @"Message in alert
dialog when entering an invalid value")];
+ [err setValue:message
forKey:NSLocalizedRecoverySuggestionErrorKey];
+ }
}
}
@@ -2132,42 +2140,48 @@
// check whether we won't get a crossref chain
BDSKCrossrefError errorCode = [publication canSetCrossref:obj];
- 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) {
- err = [NSError
mutableLocalErrorWithCode:kBDSKFailedToCommit
localizedDescription:NSLocalizedString(@"Invalid Crossref Value", @"Message in
alert dialog when entering an invalid Crossref key")];
- [err setValue:message
forKey:NSLocalizedRecoverySuggestionErrorKey];
+ if (errorCode != BDSKNoCrossrefError) {
+ isValid == NO;
+ if (error) {
+ 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");
+
+ err = [NSError
mutableLocalErrorWithCode:kBDSKFailedToCommit
localizedDescription:NSLocalizedString(@"Invalid Crossref Value", @"Message in
alert dialog when entering an invalid Crossref key")];
+ [err setValue:message
forKey:NSLocalizedRecoverySuggestionErrorKey];
+ }
}
}
}
}
- return err;
+ if (isValid == NO && error)
+ *error =err;
+
+ return isValid;
}
- (BOOL)control:(NSControl *)control isValidObject:(id)obj {
- NSError *err = [self errorForControl:control isValidObject:obj];
+ NSError *err = nil;
+ BOOL isValid = [self control:control isValidObject:obj error:&err];
- if (err == nil)
+ if (isValid)
return YES;
if ([err localizedRecoveryOptions]) {
- BOOL isValid = [self presentError:err];
+ isValid = [self presentError:err];
if (control == citeKeyField && isValid == NO) {
// user said to remove fragile characters
NSCharacterSet *invalidSet = [[BDSKTypeManager sharedManager]
fragileCiteKeyCharacterSet];
[control setStringValue:[obj
stringByReplacingCharactersInSet:invalidSet withString:@""]];
}
- return isValid;
} else {
[self presentError:err modalForWindow:[self window] delegate:nil
didPresentSelector:NULL contextInfo:NULL];
- return NO;
}
+ return isValid;
}
- (void)controlTextDidEndEditing:(NSNotification *)notification{
@@ -2254,26 +2268,27 @@
return [self commitEditing];
}
-- (NSError *)errorForTextShouldEndEditing:(NSText *)aTextObject{
+- (BOOL)textShouldEndEditing:(NSText *)aTextObject error:(NSError **)error{
BDSKASSERT(aTextObject == currentEditedView);
- if ([[currentEditedView string] isStringTeXQuotingBalancedWithBraces:YES
connected:NO])
- return nil;
-
- NSError *err = [NSError mutableLocalErrorWithCode:kBDSKFailedToCommit
localizedDescription:NSLocalizedString(@"Invalid Value", @"Message in alert
dialog when entering an invalid value")];
- [err setValue:NSLocalizedString(@"The value you entered contains
unbalanced braces and cannot be saved.", @"Informative text in alert dialog")
forKey:NSLocalizedRecoverySuggestionErrorKey];
- return err;
+ BOOL isValid = [[currentEditedView string]
isStringTeXQuotingBalancedWithBraces:YES connected:NO];
+ if (isValid == NO && error) {
+ NSError *err = [NSError mutableLocalErrorWithCode:kBDSKFailedToCommit
localizedDescription:NSLocalizedString(@"Invalid Value", @"Message in alert
dialog when entering an invalid value")];
+ [err setValue:NSLocalizedString(@"The value you entered contains
unbalanced braces and cannot be saved.", @"Informative text in alert dialog")
forKey:NSLocalizedRecoverySuggestionErrorKey];
+ *error = err;
+ }
+ return isValid;
}
- (BOOL)textShouldEndEditing:(NSText *)aTextObject {
BDSKASSERT(aTextObject == currentEditedView);
+ BOOL isValid = YES;
if (aTextObject == currentEditedView) {
- NSError *error = [self errorForTextShouldEndEditing:aTextObject];
- if (error) {
+ NSError *error = nil;
+ isValid = [self textShouldEndEditing:aTextObject error:&error];
+ if (isValid == NO)
[self presentError:error modalForWindow:[self window] delegate:nil
didPresentSelector:NULL contextInfo:NULL];
- return NO;
- }
}
- return YES;
+ return isValid;
}
// sent by the textViews
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