Improved Code Style
This commit is contained in:
@@ -9,10 +9,12 @@
|
|||||||
@import Cocoa;
|
@import Cocoa;
|
||||||
#import "MPLayout.h"
|
#import "MPLayout.h"
|
||||||
#import "MPExpression.h"
|
#import "MPExpression.h"
|
||||||
|
#import "MPFunctionLayout.h"
|
||||||
|
|
||||||
@interface MPExpressionLayout : MPLayout
|
@interface MPExpressionLayout : MPLayout
|
||||||
|
|
||||||
- (instancetype)initRootLayoutWithExpression:(MPExpression *)expression;
|
- (instancetype)initWithExpression:(MPExpression *)expression
|
||||||
|
parent:(MPFunctionLayout *)parent;
|
||||||
|
|
||||||
@property (readonly, nonatomic, weak) MPExpression *expression;
|
@property (readonly, nonatomic, weak) MPExpression *expression;
|
||||||
|
|
||||||
|
|||||||
@@ -41,36 +41,23 @@
|
|||||||
@implementation MPExpressionLayout
|
@implementation MPExpressionLayout
|
||||||
|
|
||||||
# pragma mark Creation Methods
|
# pragma mark Creation Methods
|
||||||
- (instancetype)initRootLayoutWithExpression:(MPExpression *)expression
|
- (instancetype)initWithExpression:(MPExpression *)expression
|
||||||
|
parent:(MPFunctionLayout *)parent
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super initWithParent:parent];
|
||||||
if (self) {
|
if (self) {
|
||||||
_expression = expression;
|
_expression = expression;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithElementAtPath:(NSIndexPath *)path
|
|
||||||
inRootExpression:(MPExpression *)rootExpression
|
|
||||||
parent:(MPLayout *)parent
|
|
||||||
{
|
|
||||||
self = [super initWithElementAtPath:path
|
|
||||||
inRootExpression:rootExpression
|
|
||||||
parent:parent];
|
|
||||||
if (self) {
|
|
||||||
_expression = [rootExpression elementAtIndexPath:path];
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark Cache Methods
|
#pragma mark Cache Methods
|
||||||
- (MPLayout *)childLayoutAtIndex:(NSUInteger)index
|
- (MPLayout *)childLayoutAtIndex:(NSUInteger)index
|
||||||
{
|
{
|
||||||
id cachedObject = [self cachableObjectForIndex:index generator:^id{
|
id cachedObject = [self cachableObjectForIndex:index generator:^id{
|
||||||
NSIndexPath *indexPath = [self.expression.indexPath indexPathByAddingIndex:index];
|
MPFunction *function = (MPFunction *)[self.expression elementAtIndex:index];
|
||||||
MPFunctionLayout *layout = [MPFunctionLayout functionLayoutForFunctionAtIndexPath:indexPath
|
MPFunctionLayout *layout = [MPFunctionLayout functionLayoutForFunction:function
|
||||||
inRootExpression:self.expression.rootExpression
|
parent:self];
|
||||||
parent:self];
|
|
||||||
layout.flipped = self.flipped;
|
layout.flipped = self.flipped;
|
||||||
layout.usesSmallSize = self.usesSmallSize;
|
layout.usesSmallSize = self.usesSmallSize;
|
||||||
return layout;
|
return layout;
|
||||||
@@ -114,7 +101,7 @@
|
|||||||
- (NSRect)boundingRectForRange:(NSRange)range
|
- (NSRect)boundingRectForRange:(NSRange)range
|
||||||
{
|
{
|
||||||
NSUInteger startOffset;
|
NSUInteger startOffset;
|
||||||
NSUInteger startElementIndex = [self.expression indexOfElementAtSymbolLocation:range.location
|
NSUInteger startElementIndex = [self.expression indexOfElementAtLocation:range.location
|
||||||
offset:&startOffset];
|
offset:&startOffset];
|
||||||
// Calculate x position
|
// Calculate x position
|
||||||
CGFloat x = 0, width = 0;
|
CGFloat x = 0, width = 0;
|
||||||
@@ -139,7 +126,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
NSUInteger endOffset;
|
NSUInteger endOffset;
|
||||||
NSUInteger endElementIndex = [self.expression indexOfElementAtSymbolLocation:NSMaxRange(range)
|
NSUInteger endElementIndex = [self.expression indexOfElementAtLocation:NSMaxRange(range)
|
||||||
offset:&endOffset];
|
offset:&endOffset];
|
||||||
|
|
||||||
// Selection is inside of one string element
|
// Selection is inside of one string element
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
{
|
{
|
||||||
self = [super initWithElements:elements];
|
self = [super initWithElements:elements];
|
||||||
if (self) {
|
if (self) {
|
||||||
_rootLayout = [[MPExpressionLayout alloc] initRootLayoutWithExpression:self];
|
_rootLayout = [[MPExpressionLayout alloc] initWithExpression:self parent:nil];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -32,11 +32,11 @@
|
|||||||
- (void)setExpressionView:(MPExpressionView *)expressionView
|
- (void)setExpressionView:(MPExpressionView *)expressionView
|
||||||
{
|
{
|
||||||
_expressionView = expressionView;
|
_expressionView = expressionView;
|
||||||
self.rootLayout = [[MPExpressionLayout alloc] initRootLayoutWithExpression:self];
|
self.rootLayout = [[MPExpressionLayout alloc] initWithExpression:self parent:nil];
|
||||||
self.rootLayout.flipped = expressionView.isFlipped;
|
self.rootLayout.flipped = expressionView.isFlipped;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didChangeElementsInRangePath:(MPRangePath *)rangePath
|
- (void)didChangeElementsInIndexedRangePath:(MPRangePath *)rangePath
|
||||||
replacementLength:(NSUInteger)replacementLength
|
replacementLength:(NSUInteger)replacementLength
|
||||||
{
|
{
|
||||||
if (rangePath.location.length == 0) {
|
if (rangePath.location.length == 0) {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
@property (readonly, nonatomic, strong) MPExpressionStorage *expressionStorage;
|
@property (readonly, nonatomic, strong) MPExpressionStorage *expressionStorage;
|
||||||
|
|
||||||
@property (nonatomic, getter = isEditable) BOOL editable;
|
// @property (nonatomic, getter = isEditable) BOOL editable;
|
||||||
@property (nonatomic, strong) MPRangePath *selection;
|
@property (nonatomic, strong) MPRangePath *selection;
|
||||||
|
|
||||||
@property (nonatomic, weak) id target;
|
@property (nonatomic, weak) id target;
|
||||||
|
|||||||
@@ -112,7 +112,7 @@
|
|||||||
MPExpression *targetExpression = [self.expressionStorage elementAtIndexPath:targetExpressionPath];
|
MPExpression *targetExpression = [self.expressionStorage elementAtIndexPath:targetExpressionPath];
|
||||||
NSUInteger locationInTarget = selectionPath.lastIndex;
|
NSUInteger locationInTarget = selectionPath.lastIndex;
|
||||||
NSUInteger locationInElement;
|
NSUInteger locationInElement;
|
||||||
NSUInteger targetElementIndex = [targetExpression indexOfElementAtSymbolLocation:locationInTarget
|
NSUInteger targetElementIndex = [targetExpression indexOfElementAtLocation:locationInTarget
|
||||||
offset:&locationInElement];
|
offset:&locationInElement];
|
||||||
|
|
||||||
id<MPExpressionElement> targetElement;
|
id<MPExpressionElement> targetElement;
|
||||||
@@ -172,7 +172,7 @@
|
|||||||
MPExpression *targetExpression = [self.expressionStorage elementAtIndexPath:targetExpressionPath];
|
MPExpression *targetExpression = [self.expressionStorage elementAtIndexPath:targetExpressionPath];
|
||||||
NSUInteger locationInTarget = selectionPath.lastIndex;
|
NSUInteger locationInTarget = selectionPath.lastIndex;
|
||||||
NSUInteger locationInElement;
|
NSUInteger locationInElement;
|
||||||
NSUInteger targetElementIndex = [targetExpression indexOfElementAtSymbolLocation:locationInTarget
|
NSUInteger targetElementIndex = [targetExpression indexOfElementAtLocation:locationInTarget
|
||||||
offset:&locationInElement];
|
offset:&locationInElement];
|
||||||
|
|
||||||
NSUInteger previousElementIndex = targetElementIndex - (locationInElement == 0 ? 1 : 0);
|
NSUInteger previousElementIndex = targetElementIndex - (locationInElement == 0 ? 1 : 0);
|
||||||
|
|||||||
@@ -11,9 +11,8 @@
|
|||||||
|
|
||||||
@interface MPFunctionLayout : MPLayout
|
@interface MPFunctionLayout : MPLayout
|
||||||
|
|
||||||
+ (MPFunctionLayout *)functionLayoutForFunctionAtIndexPath:(NSIndexPath *)path
|
+ (MPFunctionLayout *)functionLayoutForFunction:(MPFunction *)function
|
||||||
inRootExpression:(MPExpression *)rootExpression
|
parent:(MPExpressionLayout *)parent;
|
||||||
parent:(MPExpressionLayout *)parent;
|
|
||||||
|
|
||||||
@property (readonly, nonatomic, weak) MPFunction *function;
|
@property (readonly, nonatomic, weak) MPFunction *function;
|
||||||
|
|
||||||
@@ -21,6 +20,9 @@
|
|||||||
|
|
||||||
@interface MPFunctionLayout (MPSubclassOverride)
|
@interface MPFunctionLayout (MPSubclassOverride)
|
||||||
|
|
||||||
|
- (instancetype)initWithFunction:(MPFunction *)function
|
||||||
|
parent:(MPExpressionLayout *)parent;
|
||||||
|
|
||||||
#pragma mark Cache Methods
|
#pragma mark Cache Methods
|
||||||
- (CTLineRef)lineForPrivateCacheIndex:(NSUInteger)index
|
- (CTLineRef)lineForPrivateCacheIndex:(NSUInteger)index
|
||||||
generator:(CTLineRef (^)())generator;
|
generator:(CTLineRef (^)())generator;
|
||||||
|
|||||||
@@ -16,31 +16,23 @@
|
|||||||
@implementation MPFunctionLayout
|
@implementation MPFunctionLayout
|
||||||
|
|
||||||
#pragma mark Creation Methods
|
#pragma mark Creation Methods
|
||||||
+ (MPFunctionLayout *)functionLayoutForFunctionAtIndexPath:(NSIndexPath *)path
|
+ (MPFunctionLayout *)functionLayoutForFunction:(MPFunction *)function
|
||||||
inRootExpression:(MPExpression *)rootExpression
|
parent:(MPExpressionLayout *)parent
|
||||||
parent:(MPExpressionLayout *)parent
|
|
||||||
{
|
{
|
||||||
MPFunction *function = [rootExpression elementAtIndexPath:path];
|
|
||||||
Class class = [function class];
|
Class class = [function class];
|
||||||
if (class == [MPSumFunction class]) {
|
if (class == [MPSumFunction class]) {
|
||||||
return [[MPSumFunctionLayout alloc] initWithElementAtPath:path
|
return [[MPSumFunctionLayout alloc] initWithFunction:function parent:parent];
|
||||||
inRootExpression:rootExpression
|
|
||||||
parent:parent];
|
|
||||||
}
|
}
|
||||||
return [[self alloc] initWithElementAtPath:path
|
return [[self alloc] initWithFunction:function
|
||||||
inRootExpression:rootExpression
|
parent:parent];
|
||||||
parent:parent];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithElementAtPath:(NSIndexPath *)path
|
- (instancetype)initWithFunction:(MPFunction *)function
|
||||||
inRootExpression:(MPExpression *)rootExpression
|
parent:(MPExpressionLayout *)parent
|
||||||
parent:(MPLayout *)parent
|
|
||||||
{
|
{
|
||||||
self = [super initWithElementAtPath:path
|
self = [super initWithParent:parent];
|
||||||
inRootExpression:rootExpression
|
|
||||||
parent:parent];
|
|
||||||
if (self) {
|
if (self) {
|
||||||
_function = [rootExpression elementAtIndexPath:path];
|
_function = function;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -62,10 +54,9 @@
|
|||||||
- (MPLayout *)childLayoutAtIndex:(NSUInteger)index
|
- (MPLayout *)childLayoutAtIndex:(NSUInteger)index
|
||||||
{
|
{
|
||||||
return [self cachableObjectForIndex:index generator:^id{
|
return [self cachableObjectForIndex:index generator:^id{
|
||||||
NSIndexPath *childPath = [self.function.indexPath indexPathByAddingIndex:index];
|
MPExpression *child = [self.function childAtIndex:index];
|
||||||
MPExpressionLayout *layout = [[MPExpressionLayout alloc] initWithElementAtPath:childPath
|
MPExpressionLayout *layout = [[MPExpressionLayout alloc] initWithExpression:child
|
||||||
inRootExpression:self.function.rootExpression
|
parent:self];
|
||||||
parent:self];
|
|
||||||
layout.flipped = self.flipped;
|
layout.flipped = self.flipped;
|
||||||
layout.usesSmallSize = (index == 0 || index == 1) ? YES : self.usesSmallSize;
|
layout.usesSmallSize = (index == 0 || index == 1) ? YES : self.usesSmallSize;
|
||||||
return layout;
|
return layout;
|
||||||
|
|||||||
@@ -15,9 +15,7 @@
|
|||||||
|
|
||||||
#pragma mark Creation Methods
|
#pragma mark Creation Methods
|
||||||
- (instancetype)init;
|
- (instancetype)init;
|
||||||
- (instancetype)initWithElementAtPath:(NSIndexPath *)path
|
- (instancetype)initWithParent:(MPLayout *)parent;
|
||||||
inRootExpression:(MPExpression *)rootExpression
|
|
||||||
parent:(MPLayout *)parent;
|
|
||||||
|
|
||||||
#pragma mark Properties
|
#pragma mark Properties
|
||||||
- (NSFont *)font;
|
- (NSFont *)font;
|
||||||
|
|||||||
@@ -35,9 +35,7 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithElementAtPath:(NSIndexPath *)path
|
- (instancetype)initWithParent:(MPLayout *)parent
|
||||||
inRootExpression:(MPExpression *)rootExpression
|
|
||||||
parent:(MPLayout *)parent
|
|
||||||
{
|
{
|
||||||
self = [self init];
|
self = [self init];
|
||||||
if (self) {
|
if (self) {
|
||||||
|
|||||||
Reference in New Issue
Block a user