Archived
1

Redesigned Error Display

This commit is contained in:
Kim Wittenburg
2014-11-24 22:43:29 +01:00
parent 7a32e3b0b6
commit 6067600e81
4 changed files with 120 additions and 35 deletions

View File

@@ -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]] : @"";
}