diff options
author | Alex Merry <alex.merry@cs.ox.ac.uk> | 2013-02-04 14:45:56 +0000 |
---|---|---|
committer | Alex Merry <alex.merry@cs.ox.ac.uk> | 2013-02-04 14:45:56 +0000 |
commit | 19e555267a2170d38e77e563192bfafe20d2f5c5 (patch) | |
tree | 526dff96fc68289ba6ff932f16dfe748b8991f11 /tikzit/src/common | |
parent | fe1b43c7b7c83e392b60ffc71ac29f7e63810f58 (diff) |
Only change style settings when OK is clicked
If the user clicks Cancel, nothing changes.
Diffstat (limited to 'tikzit/src/common')
-rw-r--r-- | tikzit/src/common/EdgeStyle.h | 1 | ||||
-rw-r--r-- | tikzit/src/common/EdgeStyle.m | 10 | ||||
-rw-r--r-- | tikzit/src/common/NodeStyle.h | 5 | ||||
-rw-r--r-- | tikzit/src/common/NodeStyle.m | 10 | ||||
-rw-r--r-- | tikzit/src/common/StyleManager.h | 4 | ||||
-rw-r--r-- | tikzit/src/common/StyleManager.m | 42 |
6 files changed, 71 insertions, 1 deletions
diff --git a/tikzit/src/common/EdgeStyle.h b/tikzit/src/common/EdgeStyle.h index 83c3ecd..a51f129 100644 --- a/tikzit/src/common/EdgeStyle.h +++ b/tikzit/src/common/EdgeStyle.h @@ -64,6 +64,7 @@ typedef enum { - (id)init; - (id)initWithName:(NSString*)nm; + (EdgeStyle*)defaultEdgeStyleWithName:(NSString*)nm; +- (void) updateFromStyle:(EdgeStyle*)style; @end diff --git a/tikzit/src/common/EdgeStyle.m b/tikzit/src/common/EdgeStyle.m index 7a638c9..15fbff8 100644 --- a/tikzit/src/common/EdgeStyle.m +++ b/tikzit/src/common/EdgeStyle.m @@ -83,6 +83,16 @@ [super dealloc]; } +- (void) updateFromStyle:(EdgeStyle*)style { + [self setName:[style name]]; + [self setCategory:[style category]]; + [self setHeadStyle:[style headStyle]]; + [self setTailStyle:[style tailStyle]]; + [self setDecorationStyle:[style decorationStyle]]; + [self setThickness:[style thickness]]; + [self setColorRGB:[style colorRGB]]; +} + + (EdgeStyle*)defaultEdgeStyleWithName:(NSString*)nm { return [[[EdgeStyle alloc] initWithName:nm] autorelease]; } diff --git a/tikzit/src/common/NodeStyle.h b/tikzit/src/common/NodeStyle.h index 68aafad..034f95d 100644 --- a/tikzit/src/common/NodeStyle.h +++ b/tikzit/src/common/NodeStyle.h @@ -115,6 +115,11 @@ */ + (NodeStyle*)defaultNodeStyleWithName:(NSString *)nm; +/*! + * Make this style the same as the given one + */ +- (void) updateFromStyle:(NodeStyle*)style; + @end // vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/NodeStyle.m b/tikzit/src/common/NodeStyle.m index 268715b..f81d7eb 100644 --- a/tikzit/src/common/NodeStyle.m +++ b/tikzit/src/common/NodeStyle.m @@ -95,6 +95,16 @@ [super dealloc]; } +- (void) updateFromStyle:(NodeStyle*)style { + [self setStrokeThickness:[style strokeThickness]]; + [self setScale:[style scale]]; + [self setStrokeColorRGB:[style strokeColorRGB]]; + [self setFillColorRGB:[style fillColorRGB]]; + [self setName:[style name]]; + [self setShapeName:[style shapeName]]; + [self setCategory:[style category]]; +} + + (NodeStyle*)defaultNodeStyleWithName:(NSString*)nm { return [[[NodeStyle alloc] initWithName:nm] autorelease]; } diff --git a/tikzit/src/common/StyleManager.h b/tikzit/src/common/StyleManager.h index 0fb2436..bc920e7 100644 --- a/tikzit/src/common/StyleManager.h +++ b/tikzit/src/common/StyleManager.h @@ -19,7 +19,7 @@ #import "NodeStyle.h" #import "EdgeStyle.h" -@interface StyleManager: NSObject { +@interface StyleManager: NSObject <NSCopying> { NSMutableArray *nodeStyles; NSMutableArray *edgeStyles; } @@ -42,6 +42,8 @@ - (void) addEdgeStyle:(EdgeStyle*)style; - (void) removeEdgeStyle:(EdgeStyle*)style; +- (void) updateFromManager:(StyleManager*)manager; + @end // vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/StyleManager.m b/tikzit/src/common/StyleManager.m index 837a094..ae0d488 100644 --- a/tikzit/src/common/StyleManager.m +++ b/tikzit/src/common/StyleManager.m @@ -294,6 +294,48 @@ [style release]; } +- (void) updateFromManager:(StyleManager*)m { + NSMutableArray *ns = [NSMutableArray arrayWithCapacity:[[m nodeStyles] count]]; + for (NodeStyle *style in [m nodeStyles]) { + NodeStyle *currentStyle = [self nodeStyleForName:[style name]]; + if (currentStyle != nil) { + [currentStyle updateFromStyle:style]; + [ns addObject:currentStyle]; + } else { + [ns addObject:[[style copy] autorelease]]; + } + } + NSMutableArray *es = [NSMutableArray arrayWithCapacity:[[m edgeStyles] count]]; + for (EdgeStyle *style in [m edgeStyles]) { + EdgeStyle *currentStyle = [self edgeStyleForName:[style name]]; + if (currentStyle != nil) { + [currentStyle updateFromStyle:style]; + [es addObject:currentStyle]; + } else { + [es addObject:[[style copy] autorelease]]; + } + } + [self _setNodeStyles:ns]; + [self _setEdgeStyles:es]; +} + +- (id) copyWithZone:(NSZone*)zone { + StyleManager *m = [[StyleManager allocWithZone:zone] init]; + + NSMutableArray *ns = [NSMutableArray arrayWithCapacity:[nodeStyles count]]; + for (NodeStyle *style in nodeStyles) { + [ns addObject:[[style copyWithZone:zone] autorelease]]; + } + NSMutableArray *es = [NSMutableArray arrayWithCapacity:[edgeStyles count]]; + for (EdgeStyle *style in edgeStyles) { + [es addObject:[[style copyWithZone:zone] autorelease]]; + } + [m _setNodeStyles:ns]; + [m _setEdgeStyles:es]; + + return m; +} + @end // vi:ft=objc:ts=4:noet:sts=4:sw=4 |