From 006651d8e5e8e14795278e4f397c337f6bd73c2a Mon Sep 17 00:00:00 2001 From: Kim Wittenburg Date: Sun, 7 Sep 2014 16:50:11 +0200 Subject: [PATCH] Interface Redesign to show evaluation results --- MathPad/Base.lproj/MPDocument.xib | 75 ++++++++++++++++++++++++------- MathPad/MPDocument.h | 8 ++-- MathPad/MPDocument.m | 14 +++--- 3 files changed, 70 insertions(+), 27 deletions(-) diff --git a/MathPad/Base.lproj/MPDocument.xib b/MathPad/Base.lproj/MPDocument.xib index dbf8825..5a585a5 100644 --- a/MathPad/Base.lproj/MPDocument.xib +++ b/MathPad/Base.lproj/MPDocument.xib @@ -6,7 +6,9 @@ - + + + @@ -22,28 +24,67 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + diff --git a/MathPad/MPDocument.h b/MathPad/MPDocument.h index 6b69ad2..44e2134 100644 --- a/MathPad/MPDocument.h +++ b/MathPad/MPDocument.h @@ -6,12 +6,14 @@ // Copyright (c) 2014 Kim Wittenburg. All rights reserved. // -@class MPDocument, MPExpressionView; +#import @interface MPDocument : NSDocument -@property (weak) IBOutlet MPExpressionView *resultExpressionView; +@property (weak) IBOutlet MPExpressionView *expressionView; +@property (weak) IBOutlet NSTextField *resultLabel; +@property (weak) IBOutlet NSTextField *errorLabel; -- (IBAction)evaluateExpressiom:(id)sender; +- (IBAction)evaluateExpression:(id)sender; @end diff --git a/MathPad/MPDocument.m b/MathPad/MPDocument.m index f06ef47..2765fc0 100644 --- a/MathPad/MPDocument.m +++ b/MathPad/MPDocument.m @@ -7,7 +7,6 @@ // #import "MPDocument.h" -#import "MPView.h" @implementation MPDocument @@ -30,6 +29,8 @@ - (void)windowControllerDidLoadNib:(NSWindowController *)aController { [super windowControllerDidLoadNib:aController]; + self.expressionView.target = self; + self.expressionView.action = @selector(evaluateExpression:); // Add any code here that needs to be executed once the windowController has loaded the document's window. } @@ -58,12 +59,11 @@ } #pragma mark Actions -- (IBAction)evaluateExpressiom:(id)sender { - NSError *error; - NSLog(@"Result: %f", [self.resultExpressionView.expressionStorage evaluateExpression:&error]); - if (error) { - NSLog(@"Error: %@", error); - } +- (IBAction)evaluateExpression:(id)sender { + MPParseError *error; + NSDecimalNumber *result = [self.expressionView.expressionStorage evaluateWithError:&error]; + self.resultLabel.stringValue = result != nil ? result.description : @"Error!"; + self.errorLabel.stringValue = error != nil ? error.description : @"No Error"; } @end