summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Merry <alex.merry@cs.ox.ac.uk>2013-02-04 14:45:56 +0000
committerAlex Merry <alex.merry@cs.ox.ac.uk>2013-02-04 14:45:56 +0000
commit19e555267a2170d38e77e563192bfafe20d2f5c5 (patch)
tree526dff96fc68289ba6ff932f16dfe748b8991f11
parentfe1b43c7b7c83e392b60ffc71ac29f7e63810f58 (diff)
Only change style settings when OK is clicked
If the user clicks Cancel, nothing changes.
-rw-r--r--tikzit/src/common/EdgeStyle.h1
-rw-r--r--tikzit/src/common/EdgeStyle.m10
-rw-r--r--tikzit/src/common/NodeStyle.h5
-rw-r--r--tikzit/src/common/NodeStyle.m10
-rw-r--r--tikzit/src/common/StyleManager.h4
-rw-r--r--tikzit/src/common/StyleManager.m42
-rw-r--r--tikzit/src/gtk/SettingsDialog.h1
-rw-r--r--tikzit/src/gtk/SettingsDialog.m14
8 files changed, 81 insertions, 6 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
diff --git a/tikzit/src/gtk/SettingsDialog.h b/tikzit/src/gtk/SettingsDialog.h
index 9c1582d..0f687b3 100644
--- a/tikzit/src/gtk/SettingsDialog.h
+++ b/tikzit/src/gtk/SettingsDialog.h
@@ -26,6 +26,7 @@
@interface SettingsDialog: NSObject {
Configuration *configuration;
StyleManager *styleManager;
+ StyleManager *tempStyleManager;
NodeStylesPalette *nodePalette;
EdgeStylesPalette *edgePalette;
diff --git a/tikzit/src/gtk/SettingsDialog.m b/tikzit/src/gtk/SettingsDialog.m
index 096cca3..c45ab53 100644
--- a/tikzit/src/gtk/SettingsDialog.m
+++ b/tikzit/src/gtk/SettingsDialog.m
@@ -20,6 +20,7 @@
#import "Configuration.h"
#import "EdgeStylesPalette.h"
#import "NodeStylesPalette.h"
+#import "StyleManager.h"
// {{{ Internal interfaces
// {{{ Signals
@@ -53,6 +54,7 @@ static void cancel_button_clicked_cb (GtkButton *widget, SettingsDialog *dialog)
if (self) {
configuration = [c retain];
styleManager = [m retain];
+ tempStyleManager = [m copy];
}
return self;
@@ -67,6 +69,7 @@ static void cancel_button_clicked_cb (GtkButton *widget, SettingsDialog *dialog)
}
[configuration release];
+ [tempStyleManager release];
[styleManager release];
[nodePalette release];
[edgePalette release];
@@ -93,9 +96,6 @@ static void cancel_button_clicked_cb (GtkButton *widget, SettingsDialog *dialog)
[m retain];
[styleManager release];
styleManager = m;
-
- [nodePalette setStyleManager:m];
- [edgePalette setStyleManager:m];
}
- (GtkWindow*) parentWindow {
@@ -163,8 +163,8 @@ static void cancel_button_clicked_cb (GtkButton *widget, SettingsDialog *dialog)
return;
}
- nodePalette = [[NodeStylesPalette alloc] initWithManager:styleManager];
- edgePalette = [[EdgeStylesPalette alloc] initWithManager:styleManager];
+ nodePalette = [[NodeStylesPalette alloc] initWithManager:tempStyleManager];
+ edgePalette = [[EdgeStylesPalette alloc] initWithManager:tempStyleManager];
window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL));
gtk_window_set_default_size (window, 570, -1);
@@ -278,6 +278,8 @@ static void cancel_button_clicked_cb (GtkButton *widget, SettingsDialog *dialog)
}
#endif
+ [styleManager updateFromManager:tempStyleManager];
+
[[NSNotificationCenter defaultCenter]
postNotificationName:@"ConfigurationChanged"
object:configuration];
@@ -293,6 +295,8 @@ static void cancel_button_clicked_cb (GtkButton *widget, SettingsDialog *dialog)
withDefault:@"pdflatex"];
gtk_entry_set_text (pdflatexPathEntry, [path UTF8String]);
#endif
+
+ [tempStyleManager updateFromManager:styleManager];
}
@end