From: glenlow Date: Tue, 27 May 2008 06:50:13 +0000 (+0000) Subject: graph display updates when underlying file is changed; GVWindowController and GVAttri... X-Git-Tag: LAST_LIBGRAPH~32^2~3997 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4787970b81184b3710ab31b917048519c178e364;p=graphviz graph display updates when underlying file is changed; GVWindowController and GVAttributeInspectorController now reference document instead of graph --- diff --git a/macosx/GVAttributeInspectorController.h b/macosx/GVAttributeInspectorController.h index a5b6c49e7..67655a6cc 100644 --- a/macosx/GVAttributeInspectorController.h +++ b/macosx/GVAttributeInspectorController.h @@ -18,7 +18,7 @@ #import #import -@class GVGraph; +@class GVDocument; @interface GVAttributeInspectorController : NSWindowController { IBOutlet NSToolbar *componentToolbar; @@ -32,7 +32,7 @@ NSDictionary *_allSchemas; NSMutableDictionary *_allAttributes; - GVGraph *_inspectedGraph; + GVDocument *_inspectedDocument; BOOL _otherChangedGraph; } @@ -43,7 +43,8 @@ /* notifications */ - (IBAction)toolbarItemDidSelect:(id)sender; - (void)graphWindowDidBecomeMain:(NSNotification *)notification; -- (void)graphDidChange:(NSNotification *)notification; +- (void)graphDocumentDidChange:(NSNotification *)notification; +- (void)reloadAttributes; /* toolbar delegate methods */ - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar; diff --git a/macosx/GVAttributeInspectorController.m b/macosx/GVAttributeInspectorController.m index 45fe94f7a..0a7dc91e0 100644 --- a/macosx/GVAttributeInspectorController.m +++ b/macosx/GVAttributeInspectorController.m @@ -16,6 +16,7 @@ #import "GVAttributeInspectorController.h" #import "GVAttributeSchema.h" +#import "GVDocument.h" #import "GVGraph.h" #import "GVWindowController.h" @@ -26,7 +27,7 @@ if (self = [super initWithWindowNibName: @"Attributes"]) { _allSchemas = nil; _allAttributes = [[NSMutableDictionary alloc] init]; - _inspectedGraph = nil; + _inspectedDocument = nil; _otherChangedGraph = YES; } return self; @@ -58,39 +59,41 @@ - (void)graphWindowDidBecomeMain:(NSNotification *)notification { NSWindow* mainWindow = notification ? [notification object] : [NSApp mainWindow]; - NSWindowController* mainWindowController = [mainWindow windowController]; - if ([mainWindowController respondsToSelector:@selector(graph)]) { - GVGraph *newGraph = [(GVWindowController *)mainWindowController graph]; + GVDocument* mainWindowDocument = [[mainWindow windowController] document]; - if (_inspectedGraph != newGraph) { - /* retain the inspected graph and start observing any changes from it */ + /* update and observe referenced document */ NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; - if (_inspectedGraph) { - [defaultCenter removeObserver:self name:@"GVGraphDidChange" object:_inspectedGraph]; - [_inspectedGraph release]; - } - if (_inspectedGraph = [newGraph retain]) { - [_allAttributes setObject:newGraph.graphAttributes forKey:[graphToolbarItem itemIdentifier]]; - [_allAttributes setObject:newGraph.defaultNodeAttributes forKey:[nodeDefaultToolbarItem itemIdentifier]]; - [_allAttributes setObject:newGraph.defaultEdgeAttributes forKey:[edgeDefaultToolbarItem itemIdentifier]]; - [defaultCenter addObserver:self selector:@selector(graphDidChange:) name:@"GVGraphDidChange" object:newGraph]; - } - else - [_allAttributes removeAllObjects]; - + if (_inspectedDocument) + [defaultCenter removeObserver:self name:@"GVGraphDocumentDidChange" object:_inspectedDocument]; + _inspectedDocument = mainWindowDocument; + [defaultCenter addObserver:self selector:@selector(graphDocumentDidChange:) name:@"GVGraphDocumentDidChange" object:mainWindowDocument]; + + [self reloadAttributes]; /* update the UI */ [[self window] setTitle:[NSString stringWithFormat:@"%@ Attributes", [mainWindow title]]]; [attributeTable reloadData]; - } - } } -- (void)graphDidChange:(NSNotification *)notification +- (void)graphDocumentDidChange:(NSNotification *)notification { /* if we didn't instigate the change, update the UI */ - if (_otherChangedGraph) + if (_otherChangedGraph) { + [self reloadAttributes]; [attributeTable reloadData]; + } +} + +- (void)reloadAttributes +{ + /* reload the attributes from the inspected document's graph */ + [_allAttributes removeAllObjects]; + if ([_inspectedDocument respondsToSelector:@selector(graph)]) { + GVGraph *graph = [_inspectedDocument graph]; + [_allAttributes setObject:graph.graphAttributes forKey:[graphToolbarItem itemIdentifier]]; + [_allAttributes setObject:graph.defaultNodeAttributes forKey:[nodeDefaultToolbarItem itemIdentifier]]; + [_allAttributes setObject:graph.defaultEdgeAttributes forKey:[edgeDefaultToolbarItem itemIdentifier]]; + } } - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar @@ -149,7 +152,7 @@ NSString *attributeName = [[[_allSchemas objectForKey:selectedComponentIdentifier] objectAtIndex:rowIndex] name]; /* set or remove the key-value on the selected attributes */ - /* NOTE: to avoid needlessly reloading the table in graphDidChange:, we fence this change with _otherChangedGraph = NO */ + /* NOTE: to avoid needlessly reloading the table in graphDocumentDidChange:, we fence this change with _otherChangedGraph = NO */ _otherChangedGraph = NO; @try { [[_allAttributes objectForKey:selectedComponentIdentifier] setValue:anObject forKey:attributeName]; @@ -164,11 +167,10 @@ - (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidBecomeMainNotification object:nil]; [_allSchemas release]; [_allAttributes release]; - [_inspectedGraph release]; - [super dealloc]; }