diff options
author | Alex Merry <alex.merry@cs.ox.ac.uk> | 2012-12-17 17:24:26 +0000 |
---|---|---|
committer | Alex Merry <alex.merry@cs.ox.ac.uk> | 2012-12-17 17:24:26 +0000 |
commit | 410fdf146246e014f1598e1880b5326e75159c43 (patch) | |
tree | 704c4d0b1359ac6db660a325c8ee7ab0ef35a93d /tikzit/src/gtk/Application.m | |
parent | f75835e188c1bf8010fb7cc18c7526934ff19eba (diff) |
Update props window when a window's document changes
A window's document can change when opening a document from a window
that is has no backing file and no changes. The properties window was
not getting updated propertly when this happened (it still referred to
the old document). Now it is updated properly.
Diffstat (limited to 'tikzit/src/gtk/Application.m')
-rw-r--r-- | tikzit/src/gtk/Application.m | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/tikzit/src/gtk/Application.m b/tikzit/src/gtk/Application.m index 1459355..a7f1824 100644 --- a/tikzit/src/gtk/Application.m +++ b/tikzit/src/gtk/Application.m @@ -52,6 +52,11 @@ Application* app = nil; - (void) windowClosed:(NSNotification*)notification; - (void) windowGainedFocus:(NSNotification*)notification; - (void) selectedToolChanged:(NSNotification*)notification; +- (void) windowDocumentChanged:(NSNotification*)n; +@end + +@interface Application (Private) +- (void) setActiveWindow:(Window*)window; @end @implementation Application @@ -227,7 +232,9 @@ Application* app = nil; selector:@selector(windowGainedFocus:) name:@"WindowGainedFocus" object:window]; - // FIXME: focus? + if ([window hasFocus]) { + [self setActiveWindow:window]; + } } - (void) newWindow { @@ -339,11 +346,12 @@ Application* app = nil; gtk_main_quit(); } } + - (void) windowGainedFocus:(NSNotification*)notification { Window *window = [notification object]; - TikzDocument *doc = [window document]; - [propertiesWindow setDocument:doc]; + [self setActiveWindow:window]; } + - (void) selectedToolChanged:(NSNotification*)n { id<Tool> tool = [[n userInfo] objectForKey:@"tool"]; if (tool != nil) @@ -351,6 +359,26 @@ Application* app = nil; else NSLog(@"nil tool!"); } + +- (void) windowDocumentChanged:(NSNotification*)n { + [propertiesWindow setDocument:[[n userInfo] objectForKey:@"document"]]; +} +@end + +@implementation Application (Private) +- (void) setActiveWindow:(Window*)window { + [[NSNotificationCenter defaultCenter] removeObserver:self + name:@"DocumentChanged" + object:nil]; + + [propertiesWindow setDocument:[window document]]; + + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(windowDocumentChanged:) + name:@"DocumentChanged" + object:window]; +} @end // vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker |