From 24c26ce52aa95e4dddfaceb23025a0438ed34350 Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Tue, 11 Dec 2012 18:23:29 +0000 Subject: Remove the concept of an "active style" from StyleManager It's all tool-based in the GTK+ interface now. --- tikzit/src/common/StyleManager.h | 4 --- tikzit/src/common/StyleManager.m | 60 -------------------------------------- tikzit/src/gtk/EdgeStyleSelector.h | 12 +------- tikzit/src/gtk/EdgeStyleSelector.m | 44 ++-------------------------- tikzit/src/gtk/EdgeStylesPalette.m | 1 - tikzit/src/gtk/NodeStyleSelector.h | 12 +------- tikzit/src/gtk/NodeStyleSelector.m | 44 ++-------------------------- tikzit/src/gtk/NodeStylesPalette.m | 1 - 8 files changed, 8 insertions(+), 170 deletions(-) diff --git a/tikzit/src/common/StyleManager.h b/tikzit/src/common/StyleManager.h index 406a86a..0fb2436 100644 --- a/tikzit/src/common/StyleManager.h +++ b/tikzit/src/common/StyleManager.h @@ -21,18 +21,14 @@ @interface StyleManager: NSObject { NSMutableArray *nodeStyles; - NodeStyle *activeNodeStyle; NSMutableArray *edgeStyles; - EdgeStyle *activeEdgeStyle; } + (StyleManager*) manager; - (id) init; @property (readonly) NSArray *nodeStyles; -@property (retain) NodeStyle *activeNodeStyle; @property (readonly) NSArray *edgeStyles; -@property (retain) EdgeStyle *activeEdgeStyle; // only for use by loading code - (void) _setNodeStyles:(NSMutableArray*)styles; diff --git a/tikzit/src/common/StyleManager.m b/tikzit/src/common/StyleManager.m index 1f895ea..837a094 100644 --- a/tikzit/src/common/StyleManager.m +++ b/tikzit/src/common/StyleManager.m @@ -99,9 +99,7 @@ if (self) { // we lazily load the default styles, since they may not be needed nodeStyles = nil; - activeNodeStyle = nil; edgeStyles = nil; - activeEdgeStyle = nil; } return self; @@ -198,14 +196,6 @@ [[NSNotificationCenter defaultCenter] postNotificationName:@"EdgeStylesReplaced" object:self]; } -- (void) postActiveNodeStyleChanged { - [[NSNotificationCenter defaultCenter] postNotificationName:@"ActiveNodeStyleChanged" object:self]; -} - -- (void) postActiveEdgeStyleChanged { - [[NSNotificationCenter defaultCenter] postNotificationName:@"ActiveEdgeStyleChanged" object:self]; -} - - (NSArray*) nodeStyles { if (nodeStyles == nil) { [self loadDefaultNodeStyles]; @@ -225,15 +215,10 @@ [nodeStyles release]; [styles retain]; nodeStyles = styles; - NodeStyle *oldActiveStyle = activeNodeStyle; - activeNodeStyle = nil; for (NodeStyle *style in styles) { [self listenToNodeStyle:style]; } [self postNodeStylesReplaced]; - if (oldActiveStyle != activeNodeStyle) { - [self postActiveNodeStyleChanged]; - } } - (void) _setEdgeStyles:(NSMutableArray*)styles { @@ -241,49 +226,10 @@ [edgeStyles release]; [styles retain]; edgeStyles = styles; - EdgeStyle *oldActiveStyle = activeEdgeStyle; - activeEdgeStyle = nil; for (EdgeStyle *style in styles) { [self listenToEdgeStyle:style]; } [self postEdgeStylesReplaced]; - if (oldActiveStyle != activeEdgeStyle) { - [self postActiveEdgeStyleChanged]; - } -} - -- (NodeStyle*) activeNodeStyle { - if (nodeStyles == nil) { - [self loadDefaultNodeStyles]; - } - return activeNodeStyle; -} - -- (void) setActiveNodeStyle:(NodeStyle*)style { - if (style == activeNodeStyle) { - return; - } - if (style == nil || [nodeStyles containsObject:style]) { - activeNodeStyle = style; - [self postActiveNodeStyleChanged]; - } -} - -- (EdgeStyle*) activeEdgeStyle { - if (edgeStyles == nil) { - [self loadDefaultEdgeStyles]; - } - return activeEdgeStyle; -} - -- (void) setActiveEdgeStyle:(EdgeStyle*)style { - if (style == activeEdgeStyle) { - return; - } - if (style == nil || [edgeStyles containsObject:style]) { - activeEdgeStyle = style; - [self postActiveEdgeStyleChanged]; - } } - (NodeStyle*) nodeStyleForName:(NSString*)name { @@ -309,9 +255,6 @@ if (nodeStyles == nil) { [self loadDefaultNodeStyles]; } - if (activeNodeStyle == style) { - [self setActiveNodeStyle:nil]; - } [self ignoreNodeStyle:style]; [style retain]; @@ -343,9 +286,6 @@ if (edgeStyles == nil) { [self loadDefaultEdgeStyles]; } - if (activeEdgeStyle == style) { - [self setActiveEdgeStyle:nil]; - } [self ignoreEdgeStyle:style]; [style retain]; diff --git a/tikzit/src/gtk/EdgeStyleSelector.h b/tikzit/src/gtk/EdgeStyleSelector.h index 935c9b7..1ae1f3c 100644 --- a/tikzit/src/gtk/EdgeStyleSelector.h +++ b/tikzit/src/gtk/EdgeStyleSelector.h @@ -23,8 +23,6 @@ GtkListStore *store; GtkTreeView *view; StyleManager *styleManager; - BOOL linkedToActiveStyle; - BOOL suppressSetActiveStyle; } /*! @@ -39,17 +37,9 @@ */ @property (retain) StyleManager *styleManager; -/*! - @property linkedToActiveStyles - @brief Whether the current selection should be the same as the - style manager's active style - */ -@property (getter=isLinkedToActiveStyle) BOOL linkedToActiveStyle; - /*! @property selectedStyle - @brief The selected style. If linkedToActiveStyle is YES, this - will be the same as [manager activeStyle]. + @brief The selected style. When this changes, a SelectedStyleChanged notification will be posted */ diff --git a/tikzit/src/gtk/EdgeStyleSelector.m b/tikzit/src/gtk/EdgeStyleSelector.m index c9c9780..8c4e0df 100644 --- a/tikzit/src/gtk/EdgeStyleSelector.m +++ b/tikzit/src/gtk/EdgeStyleSelector.m @@ -44,7 +44,6 @@ enum { - (void) stylesReplaced:(NSNotification*)notification; - (void) styleAdded:(NSNotification*)notification; - (void) styleRemoved:(NSNotification*)notification; -- (void) activeStyleChanged:(NSNotification*)notification; - (void) shapeDictionaryReplaced:(NSNotification*)n; - (void) selectionChanged; - (void) observeValueForKeyPath:(NSString*)keyPath @@ -60,7 +59,6 @@ enum { - (GdkPixbuf*) pixbufFromSurface:(cairo_surface_t*)surface; - (GdkPixbuf*) pixbufOfEdgeInStyle:(EdgeStyle*)style usingSurface:(cairo_surface_t*)surface; - (void) addStyle:(EdgeStyle*)style; -- (void) postSelectedStyleChanged; - (void) observeStyle:(EdgeStyle*)style; - (void) stopObservingStyle:(EdgeStyle*)style; - (void) reloadStyles; @@ -81,7 +79,6 @@ enum { if (self) { styleManager = nil; - linkedToActiveStyle = YES; store = gtk_list_store_new (STYLES_N_COLS, G_TYPE_STRING, @@ -155,10 +152,6 @@ enum { selector:@selector(styleRemoved:) name:@"EdgeStyleRemoved" object:m]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(activeStyleChanged:) - name:@"ActiveEdgeStyleChanged" - object:m]; [styleManager release]; styleManager = m; @@ -170,20 +163,6 @@ enum { return GTK_WIDGET (view); } -- (BOOL) isLinkedToActiveStyle { - return linkedToActiveStyle; -} - -- (void) setLinkedToActiveStyle:(BOOL)linked { - linkedToActiveStyle = linked; - if (linkedToActiveStyle) { - EdgeStyle *style = [self selectedStyle]; - if ([styleManager activeEdgeStyle] != style) { - [self setSelectedStyle:[styleManager activeEdgeStyle]]; - } - } -} - - (EdgeStyle*) selectedStyle { GtkTreeSelection *sel = gtk_tree_view_get_selection (view); GtkTreeIter iter; @@ -258,15 +237,6 @@ enum { } } -- (void) activeStyleChanged:(NSNotification*)notification { - if (linkedToActiveStyle) { - EdgeStyle *style = [self selectedStyle]; - if ([styleManager activeEdgeStyle] != style) { - [self setSelectedStyle:[styleManager activeEdgeStyle]]; - } - } -} - - (void) observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change @@ -301,13 +271,9 @@ enum { } - (void) selectionChanged { - if (linkedToActiveStyle) { - EdgeStyle *style = [self selectedStyle]; - if ([styleManager activeEdgeStyle] != style) { - [styleManager setActiveEdgeStyle:style]; - } - } - [self postSelectedStyleChanged]; + [[NSNotificationCenter defaultCenter] + postNotificationName:@"SelectedStyleChanged" + object:self]; } @end @@ -421,10 +387,6 @@ enum { cairo_surface_destroy (surface); } -- (void) postSelectedStyleChanged { - [[NSNotificationCenter defaultCenter] postNotificationName:@"SelectedStyleChanged" object:self]; -} - - (void) observeStyle:(EdgeStyle*)style { [style addObserver:self forKeyPath:@"name" diff --git a/tikzit/src/gtk/EdgeStylesPalette.m b/tikzit/src/gtk/EdgeStylesPalette.m index bcb631e..1d55300 100644 --- a/tikzit/src/gtk/EdgeStylesPalette.m +++ b/tikzit/src/gtk/EdgeStylesPalette.m @@ -255,7 +255,6 @@ static void add_style_button_cb (GtkButton *widget, EdgeStylesPalette *palette) EdgeStyle *newStyle = [EdgeStyle defaultEdgeStyleWithName:@"newstyle"]; [[palette styleManager] addEdgeStyle:newStyle]; - [[palette styleManager] setActiveEdgeStyle:newStyle]; [pool drain]; } diff --git a/tikzit/src/gtk/NodeStyleSelector.h b/tikzit/src/gtk/NodeStyleSelector.h index 894d71e..0c83dc0 100644 --- a/tikzit/src/gtk/NodeStyleSelector.h +++ b/tikzit/src/gtk/NodeStyleSelector.h @@ -23,8 +23,6 @@ GtkListStore *store; GtkIconView *view; StyleManager *styleManager; - BOOL linkedToActiveStyle; - BOOL suppressSetActiveStyle; } /*! @@ -39,17 +37,9 @@ */ @property (retain) StyleManager *styleManager; -/*! - @property linkedToActiveStyles - @brief Whether the current selection should be the same as the - style manager's active style - */ -@property (getter=isLinkedToActiveStyle) BOOL linkedToActiveStyle; - /*! @property selectedStyle - @brief The selected style. If linkedToActiveStyle is YES, this - will be the same as [manager activeStyle]. + @brief The selected style. When this changes, a SelectedStyleChanged notification will be posted */ diff --git a/tikzit/src/gtk/NodeStyleSelector.m b/tikzit/src/gtk/NodeStyleSelector.m index a175be4..4fd3a5e 100644 --- a/tikzit/src/gtk/NodeStyleSelector.m +++ b/tikzit/src/gtk/NodeStyleSelector.m @@ -41,7 +41,6 @@ enum { - (void) stylesReplaced:(NSNotification*)notification; - (void) styleAdded:(NSNotification*)notification; - (void) styleRemoved:(NSNotification*)notification; -- (void) activeStyleChanged:(NSNotification*)notification; - (void) shapeDictionaryReplaced:(NSNotification*)n; - (void) selectionChanged; - (void) observeValueForKeyPath:(NSString*)keyPath @@ -56,7 +55,6 @@ enum { - (GdkPixbuf*) pixbufFromSurface:(cairo_surface_t*)surface; - (GdkPixbuf*) pixbufOfNodeInStyle:(NodeStyle*)style usingSurface:(cairo_surface_t*)surface; - (void) addStyle:(NodeStyle*)style; -- (void) postSelectedStyleChanged; - (void) observeStyle:(NodeStyle*)style; - (void) stopObservingStyle:(NodeStyle*)style; - (void) clearModel; @@ -78,7 +76,6 @@ enum { if (self) { styleManager = nil; - linkedToActiveStyle = YES; store = gtk_list_store_new (STYLES_N_COLS, G_TYPE_STRING, @@ -143,10 +140,6 @@ enum { selector:@selector(styleRemoved:) name:@"NodeStyleRemoved" object:m]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(activeStyleChanged:) - name:@"ActiveNodeStyleChanged" - object:m]; [styleManager release]; styleManager = m; @@ -158,20 +151,6 @@ enum { return GTK_WIDGET (view); } -- (BOOL) isLinkedToActiveStyle { - return linkedToActiveStyle; -} - -- (void) setLinkedToActiveStyle:(BOOL)linked { - linkedToActiveStyle = linked; - if (linkedToActiveStyle) { - NodeStyle *style = [self selectedStyle]; - if ([styleManager activeNodeStyle] != style) { - [self setSelectedStyle:[styleManager activeNodeStyle]]; - } - } -} - - (NodeStyle*) selectedStyle { GList *list = gtk_icon_view_get_selected_items (view); if (!list) { @@ -251,15 +230,6 @@ enum { } } -- (void) activeStyleChanged:(NSNotification*)notification { - if (linkedToActiveStyle) { - NodeStyle *style = [self selectedStyle]; - if ([styleManager activeNodeStyle] != style) { - [self setSelectedStyle:[styleManager activeNodeStyle]]; - } - } -} - - (void) observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change @@ -294,13 +264,9 @@ enum { } - (void) selectionChanged { - if (linkedToActiveStyle) { - NodeStyle *style = [self selectedStyle]; - if ([styleManager activeNodeStyle] != style) { - [styleManager setActiveNodeStyle:style]; - } - } - [self postSelectedStyleChanged]; + [[NSNotificationCenter defaultCenter] + postNotificationName:@"SelectedStyleChanged" + object:self]; } @end @@ -399,10 +365,6 @@ enum { cairo_surface_destroy (surface); } -- (void) postSelectedStyleChanged { - [[NSNotificationCenter defaultCenter] postNotificationName:@"SelectedStyleChanged" object:self]; -} - - (void) observeStyle:(NodeStyle*)style { [style addObserver:self forKeyPath:@"name" diff --git a/tikzit/src/gtk/NodeStylesPalette.m b/tikzit/src/gtk/NodeStylesPalette.m index d5ac2e1..6964f4c 100644 --- a/tikzit/src/gtk/NodeStylesPalette.m +++ b/tikzit/src/gtk/NodeStylesPalette.m @@ -251,7 +251,6 @@ static void add_style_button_cb (GtkButton *widget, NodeStylesPalette *palette) NodeStyle *newStyle = [NodeStyle defaultNodeStyleWithName:@"newstyle"]; [[palette styleManager] addNodeStyle:newStyle]; - [[palette styleManager] setActiveNodeStyle:newStyle]; [pool drain]; } -- cgit v1.2.3