Redesigned Error Display
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
|
||||
#import "MPDocument.h"
|
||||
|
||||
#import "MPParsedExpression.h"
|
||||
|
||||
@implementation MPDocument
|
||||
|
||||
- (id)init
|
||||
@@ -60,13 +62,15 @@
|
||||
|
||||
#pragma mark Actions
|
||||
- (IBAction)evaluateExpression:(id)sender {
|
||||
NSError *error;
|
||||
NSDecimalNumber *result = [self.expressionView.expressionStorage evaluateWithError:&error];
|
||||
if (error) {
|
||||
self.expressionView.errorMessageTextField.stringValue = error.localizedDescription;
|
||||
} else {
|
||||
self.expressionView.errorMessageTextField.stringValue = @"";
|
||||
NSArray *errors;
|
||||
MPParsedExpression *parsedExpression = [self.expressionView.expressionStorage parse:&errors];
|
||||
NSError *mathError;
|
||||
NSDecimalNumber *result;
|
||||
if (parsedExpression) {
|
||||
result = [parsedExpression evaluate:&mathError];
|
||||
}
|
||||
self.expressionView.syntaxErrors = errors;
|
||||
self.expressionView.mathError = mathError;
|
||||
self.resultLabel.stringValue = result != nil ? [result descriptionWithLocale:[NSLocale currentLocale]] : @"";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user