]> 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/GVDocument.h
macosx/GVDocument.m

index a435b8fd9567c1d4558c1cf769948e890d3792ea..8d9f22166152c639a96ef2c09dab760068ef3059 100644 (file)
@@ -38,6 +38,9 @@
 - (IBAction)exportDocument:(id)sender;
 - (void)exporterDidEnd:(GVExportViewController *)exporter;
 
+- (void)fileDidChange:(NSString *)path;
+- (void)graphDidChange:(NSNotification *)notification;
+
 - (void)dealloc;
 
 @end
index 99ecbd488d65046046fe2ff8587c5abd205ed9ba..600a3433b72a087818409b43114d5cb5592d5cf3 100644 (file)
@@ -14,8 +14,9 @@
 *              AT&T Research, Florham Park NJ             *
 **********************************************************/
 
-#import "GVExportViewController.h"
 #import "GVDocument.h"
+#import "GVExportViewController.h"
+#import "GVFileNotificationCenter.h"
 #import "GVGraph.h"
 #import "GVWindowController.h"
 
@@ -38,6 +39,9 @@
        _graph = [[GVGraph alloc] initWithURL:absoluteURL error:outError];
        [_graph.arguments setValue:@"dot" forKey:@"layout"];
        
+       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(graphDidChange:) name:@"GVGraphDidChange" object:_graph];
+       [[GVFileNotificationCenter defaultCenter] addObserver:self selector:@selector(fileDidChange:) path:[absoluteURL path]];
+       
        return _graph != nil;
 }
 
        [_graph renderWithFormat:[exporter device] toURL:[NSURL fileURLWithPath:[exporter filename]]];
 }
 
+- (void)fileDidChange:(NSString *)path
+{
+       NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
+       [defaultCenter removeObserver:self name:@"GVGraphDidChange" object:_graph];
+       
+       /* reparse the graph fresh from the file */
+       [_graph release];
+       _graph = [[GVGraph alloc] initWithURL:[self fileURL] error:nil];
+       [_graph.arguments setValue:@"dot" forKey:@"layout"];
+       [defaultCenter addObserver:self selector:@selector(graphDidChange:) name:@"GVGraphDidChange" object:_graph];
+       
+       [defaultCenter postNotificationName:@"GVGraphDocumentDidChange" object:self];
+}
+
+- (void)graphDidChange:(NSNotification *)notification
+{
+       [[NSNotificationCenter defaultCenter] postNotificationName:@"GVGraphDocumentDidChange" object:self];
+}
+
 - (void)dealloc
 {
+       [[NSNotificationCenter defaultCenter] removeObserver:self name:@"GVGraphDidChange" object:_graph];
+       [[GVFileNotificationCenter defaultCenter] removeObserver:self path:[[self fileURL] path]];
+
        [_exporter release];
        [_graph release];
        [super dealloc];