]> granicus.if.org Git - graphviz/commitdiff
graph display updates when underlying file is changed; GVWindowController and GVAttri...
authorglenlow <devnull@localhost>
Tue, 27 May 2008 06:50:13 +0000 (06:50 +0000)
committerglenlow <devnull@localhost>
Tue, 27 May 2008 06:50:13 +0000 (06:50 +0000)
macosx/GVAttributeInspectorController.h
macosx/GVAttributeInspectorController.m

index a5b6c49e74e0e9fa89c6dc67ced6d69bab772526..67655a6cc2c6588eec6cbf741b5df9b5189ef937 100644 (file)
@@ -18,7 +18,7 @@
 #import <AppKit/AppKit.h>
 #import <WebKit/WebKit.h>
 
-@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;
index 45fe94f7a53755eedac2560ce3c55edc72f17225..0a7dc91e0b80c05a95269bd3f44b099f917a74c4 100644 (file)
@@ -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;
 - (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
                        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];
 
 - (void)dealloc
 {
+       [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidBecomeMainNotification object:nil];
        [_allSchemas release];
        [_allAttributes release];
        
-       [_inspectedGraph release];
-       
        [super dealloc];
 }