Revision: 29369
http://sourceforge.net/p/bibdesk/svn/29369
Author: hofman
Date: 2025-07-26 15:59:40 +0000 (Sat, 26 Jul 2025)
Log Message:
-----------
return error as output from methgods rather than by reference
Modified Paths:
--------------
trunk/bibdesk/BDSKEditor.m
Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m 2025-07-25 21:40:20 UTC (rev 29368)
+++ trunk/bibdesk/BDSKEditor.m 2025-07-26 15:59:40 UTC (rev 29369)
@@ -123,9 +123,9 @@
- (void)fileURLDidChange:(NSNotification *)notification;
- (void)needsToBeFiledDidChange:(NSNotification *)notification;
-- (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;
+- (NSError *)errorForControl:(NSControl *)control
didFailToFormatString:(NSString *)string errorDescription:(NSString
*)errorString;
+- (NSError *)errorForControl:(NSControl *)control isValidObject:(id)obj;
+- (NSError *)errorForTextShouldEndEditing:(NSText *)aTextObject;
- (void)recordChangingField:(NSString *)fieldName toValue:(NSString *)value;
@@ -449,6 +449,7 @@
NSTextView *textView = (NSTextView *)firstResponder;
NSTextField *textField = nil;
NSInteger editedRow = -1;
+ NSError *err = nil;
if ([textView isFieldEditor]) {
firstResponder = (NSResponder *)[textView delegate];
if ([firstResponder isKindOfClass:[NSTextField class]])
@@ -466,14 +467,19 @@
if (formatter) {
NSString *errorString = nil;
if (NO == [formatter getObjectValue:&obj forString:string
errorDescription:&errorString] &&
- NO == [self control:textField didFailToFormatString:string
errorDescription:errorString error:error])
+ (err = [self errorForControl:textField
didFailToFormatString:string errorDescription:errorString])) {
+ if (error) *error = err;
return NO;
+ }
}
- if (NO == [self control:textField isValidObject:obj error:error])
+ if ((err = [self errorForControl:textField isValidObject:obj])) {
+ if (error) *error = err;
return NO;
+ }
- } else if (currentEditedView && [self textShouldEndEditing:textView
error:error] == NO) {
+ } else if (currentEditedView && (err = [self
errorForTextShouldEndEditing:textView])) {
// the string of the edited textView has unbalanced braces
+ if (error) *error = err;
return NO;
}
@@ -2014,9 +2020,9 @@
// Don't show an annoying warning. This fails only when invalid cite key
characters are used, which are simply removed by the formatter.
}
-- (BOOL)control:(NSControl *)control didFailToFormatString:(NSString *)aString
errorDescription:(NSString *)errorString error:(NSError **)error {
+- (NSError *)errorForControl:(NSControl *)control
didFailToFormatString:(NSString *)aString errorDescription:(NSString
*)errorString {
if (editorFlags.isEditable == NO)
- return YES;
+ return nil;
NSError *err = nil;
@@ -2055,9 +2061,7 @@
}
}
- if (error)
- *error = err;
- return NO;
+ return err;
}
// send by the formatter when formatting in getObjectValue... failed
@@ -2065,17 +2069,16 @@
if (editorFlags.isEditable == NO)
return YES;
- NSError *err = nil;
- BOOL accept = [self control:control didFailToFormatString:aString
errorDescription:error error:&err];
+ NSError *err = [self errorForControl:control didFailToFormatString:aString
errorDescription:error];
- if (accept == NO) {
- if (err && [err code] != kBDSKComplexStringError)
+ if (err) {
+ if ([err code] != kBDSKComplexStringError)
[self presentError:err modalForWindow:[self window] delegate:nil
didPresentSelector:NULL contextInfo:NULL];
else
NSBeep();
}
- return accept;
+ return err != nil;
}
- (BOOL)attemptRecoveryFromError:(NSError *)error
optionIndex:(NSUInteger)recoveryOptionIndex {
@@ -2082,11 +2085,10 @@
return recoveryOptionIndex == 1;
}
-- (BOOL)control:(NSControl *)control isValidObject:(id)obj error:(NSError
**)error {
+- (NSError *)errorForControl:(NSControl *)control isValidObject:(id)obj {
if (editorFlags.isEditable == NO)
- return YES;
+ return nil;
- BOOL isValid = YES;
NSError *err = nil;
if (control == citeKeyField) {
@@ -2102,7 +2104,6 @@
[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;
} else {
@@ -2116,7 +2117,6 @@
if (message) {
err = [NSError mutableLocalErrorWithCode:kBDSKFailedToCommit
localizedDescription:NSLocalizedString(@"Invalid Value", @"Message in alert
dialog when entering an invalid value")];
[err setValue:message
forKey:NSLocalizedRecoverySuggestionErrorKey];
- isValid = NO;
}
}
@@ -2142,25 +2142,21 @@
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];
- isValid = NO;
}
}
}
}
- if (isValid == NO && error)
- *error = err;
- return isValid;
+ return err;
}
- (BOOL)control:(NSControl *)control isValidObject:(id)obj {
- NSError *err = nil;
- BOOL isValid = [self control:control isValidObject:obj error:&err];
+ NSError *err = [self errorForControl:control isValidObject:obj];
- if (isValid)
+ if (err == nil)
return YES;
- isValid = [self presentError:err];
+ BOOL isValid = [self presentError:err];
if (control == citeKeyField && [err localizedRecoveryOptions] && isValid
== NO) {
// user said to remove fragile characters
@@ -2255,15 +2251,14 @@
return [self commitEditing];
}
-- (BOOL)textShouldEndEditing:(NSText *)aTextObject error:(NSError **)error {
+- (NSError *)errorForTextShouldEndEditing:(NSText *)aTextObject{
BDSKASSERT(aTextObject == currentEditedView);
- BOOL rv = ([[currentEditedView string]
isStringTeXQuotingBalancedWithBraces:YES connected:NO]);
- if (NO == rv && error) {
+ if (NO == [[currentEditedView string]
isStringTeXQuotingBalancedWithBraces:YES connected:NO]) {
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 err;
}
- return rv;
+ return nil;
}
- (BOOL)textShouldEndEditing:(NSText *)aTextObject {
@@ -2270,9 +2265,8 @@
BDSKASSERT(aTextObject == currentEditedView);
BOOL rv = YES;
if (aTextObject == currentEditedView) {
- NSError *error = nil;
- rv = [self textShouldEndEditing:aTextObject error:&error];
- if (NO == rv && error)
+ NSError *error = [self errorForTextShouldEndEditing:aTextObject];
+ if (error)
[self presentError:error modalForWindow:[self window] delegate:nil
didPresentSelector:NULL contextInfo:NULL];
}
return rv;
@@ -2285,7 +2279,7 @@
if (currentEditedView == nil)
return;
- NSParameterAssert([self textShouldEndEditing:currentEditedView
error:NULL]);
+ NSParameterAssert([[currentEditedView string]
isStringTeXQuotingBalancedWithBraces:YES connected:NO]);
[publication setEditedField:nil];
[publication setEditedValue:nil];
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