Redesigned Error Display
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
#import "MPExpression.h"
|
||||
#import "MPExpressionElement.h"
|
||||
#import "MPParsedExpression.h"
|
||||
|
||||
#import "MPPowerFunction.h"
|
||||
#import "MPParenthesisFunction.h"
|
||||
@@ -20,6 +21,7 @@
|
||||
|
||||
#import "MPExpressionStorage.h"
|
||||
#import "MPExpressionLayout.h"
|
||||
#import "MPFunctionLayout.h"
|
||||
|
||||
#import "MPFunctionsViewController.h"
|
||||
|
||||
@@ -33,6 +35,9 @@
|
||||
@property (nonatomic, strong) NSPopover *functionsPopover;
|
||||
@property (nonatomic, strong) MPFunctionsViewController *functionsViewController;
|
||||
|
||||
@property (nonatomic, strong) NSPopUpButton *syntaxErrorsPopUpButton;
|
||||
@property (nonatomic, strong) NSTextField *mathErrorTextField;
|
||||
|
||||
@property (nonatomic, strong) NSTimer *caretTimer;
|
||||
@property (nonatomic) NSTimeInterval caretBlinkRate;
|
||||
@property (nonatomic) BOOL caretVisible;
|
||||
@@ -336,7 +341,7 @@
|
||||
_expressionStorage = expressionStorage;
|
||||
|
||||
[self initializeButtons];
|
||||
[self initializeErrorMessageTextField];
|
||||
[self initializeErrorsViews];
|
||||
|
||||
self.selection = [[MPRangePath alloc] initWithRange:NSMakeRange(0, 0)];
|
||||
self.caretBlinkRate = 1.0;
|
||||
@@ -374,16 +379,27 @@
|
||||
constant:0]];
|
||||
}
|
||||
|
||||
- (void)initializeErrorMessageTextField
|
||||
- (void)initializeErrorsViews
|
||||
{
|
||||
NSTextField *errorLabel = self.errorMessageTextField;
|
||||
[self addSubview:errorLabel];
|
||||
NSDictionary *variableBindings = NSDictionaryOfVariableBindings(errorLabel);
|
||||
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[errorLabel]"
|
||||
|
||||
NSPopUpButton *syntaxErrors = self.syntaxErrorsPopUpButton;
|
||||
NSTextField *mathError = self.mathErrorTextField;
|
||||
[self addSubview:syntaxErrors];
|
||||
[self addSubview:mathError];
|
||||
NSDictionary *variableBindings = NSDictionaryOfVariableBindings(syntaxErrors, mathError);
|
||||
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[syntaxErrors]"
|
||||
options:0
|
||||
metrics:nil
|
||||
views:variableBindings]];
|
||||
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[errorLabel]-10-|"
|
||||
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[syntaxErrors]-10-|"
|
||||
options:0
|
||||
metrics:nil
|
||||
views:variableBindings]];
|
||||
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[mathError]"
|
||||
options:0
|
||||
metrics:nil
|
||||
views:variableBindings]];
|
||||
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[mathError]-10-|"
|
||||
options:0
|
||||
metrics:nil
|
||||
views:variableBindings]];
|
||||
@@ -405,6 +421,42 @@
|
||||
self.needsDisplay = YES;
|
||||
}
|
||||
|
||||
- (void)setSyntaxErrors:(NSArray *)syntaxErrors
|
||||
{
|
||||
_syntaxErrors = syntaxErrors;
|
||||
[self.syntaxErrorsPopUpButton removeAllItems];
|
||||
if (syntaxErrors.count == 0) {
|
||||
self.syntaxErrorsPopUpButton.hidden = YES;
|
||||
return;
|
||||
}
|
||||
self.syntaxErrorsPopUpButton.hidden = NO;
|
||||
[self.syntaxErrorsPopUpButton addItemWithTitle:@""];
|
||||
if (syntaxErrors.count == 1) {
|
||||
NSString *title = NSLocalizedString(@"1 Syntax Error", nil);
|
||||
NSDictionary *attributes = @{NSForegroundColorAttributeName: [NSColor redColor],
|
||||
NSFontAttributeName: [NSFont boldSystemFontOfSize:12.0]};
|
||||
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attributes];
|
||||
[self.syntaxErrorsPopUpButton itemAtIndex:0].attributedTitle = attributedTitle;
|
||||
} else {
|
||||
NSString *title = [NSString stringWithFormat:NSLocalizedString(@"%ld Syntax Errors", nil), syntaxErrors.count];
|
||||
NSDictionary *attributes = @{NSForegroundColorAttributeName: [NSColor redColor],
|
||||
NSFontAttributeName: [NSFont boldSystemFontOfSize:12.0]};
|
||||
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attributes];
|
||||
[self.syntaxErrorsPopUpButton itemAtIndex:0].attributedTitle = attributedTitle;
|
||||
}
|
||||
NSUInteger index = 0;
|
||||
for (NSError *error in syntaxErrors) {
|
||||
[self.syntaxErrorsPopUpButton addItemWithTitle:error.localizedDescription];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setMathError:(NSError *)mathError
|
||||
{
|
||||
_mathError = mathError;
|
||||
self.mathErrorTextField.stringValue = mathError != nil ? mathError.localizedDescription : @"";
|
||||
}
|
||||
|
||||
- (NSButton *)radiansDegreesButton
|
||||
{
|
||||
if (!_radiansDegreesButton) {
|
||||
@@ -447,19 +499,46 @@
|
||||
return _functionsButton;
|
||||
}
|
||||
|
||||
- (NSTextField *)errorMessageTextField
|
||||
- (NSPopUpButton *)syntaxErrorsPopUpButton
|
||||
{
|
||||
if (!_errorMessageTextField) {
|
||||
NSTextField *label = [[NSTextField alloc] initWithFrame:NSZeroRect];
|
||||
label.textColor = [NSColor redColor];
|
||||
label.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
label.bezeled = NO;
|
||||
label.drawsBackground = NO;
|
||||
label.editable = NO;
|
||||
label.selectable = NO;
|
||||
_errorMessageTextField = label;
|
||||
if (!_syntaxErrorsPopUpButton) {
|
||||
NSPopUpButton *button = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0, 0, 100, 26)
|
||||
pullsDown:YES];
|
||||
button.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[button.cell setArrowPosition:NSPopUpArrowAtBottom];
|
||||
button.bezelStyle = NSRecessedBezelStyle;
|
||||
button.buttonType = NSPushOnPushOffButton;
|
||||
button.showsBorderOnlyWhileMouseInside = YES;
|
||||
button.font = [NSFont boldSystemFontOfSize:12.0];
|
||||
button.hidden = YES;
|
||||
button.target = self;
|
||||
button.action = @selector(didSelectError:);
|
||||
_syntaxErrorsPopUpButton = button;
|
||||
}
|
||||
return _errorMessageTextField;
|
||||
return _syntaxErrorsPopUpButton;
|
||||
}
|
||||
|
||||
- (NSTextField *)mathErrorTextField
|
||||
{
|
||||
if (!_mathErrorTextField) {
|
||||
NSTextField *textField = [[NSTextField alloc] init];
|
||||
textField.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
textField.bordered = NO;
|
||||
textField.selectable = NO;
|
||||
textField.editable = NO;
|
||||
textField.textColor = [NSColor redColor];
|
||||
textField.font = [NSFont boldSystemFontOfSize:12.0];
|
||||
_mathErrorTextField = textField;
|
||||
}
|
||||
return _mathErrorTextField;
|
||||
}
|
||||
|
||||
- (void)didSelectError:(NSPopUpButton *)sender
|
||||
{
|
||||
NSError *error = self.syntaxErrors[sender.indexOfSelectedItem-1];
|
||||
NSIndexPath *pathToExpression = error.userInfo[MPPathToExpressionKey];
|
||||
pathToExpression = [pathToExpression indexPathByAddingIndex:[error.userInfo[MPErrorIndexKey] integerValue]];
|
||||
self.selection = MPMakeRangePath(pathToExpression, 0);
|
||||
}
|
||||
|
||||
#pragma mark Actions
|
||||
|
||||
Reference in New Issue
Block a user