summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tikzit/src/gtk/Application.m34
-rw-r--r--tikzit/src/gtk/Window.h4
-rw-r--r--tikzit/src/gtk/Window.m20
3 files changed, 51 insertions, 7 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
diff --git a/tikzit/src/gtk/Window.h b/tikzit/src/gtk/Window.h
index 570cdf4..bac64a0 100644
--- a/tikzit/src/gtk/Window.h
+++ b/tikzit/src/gtk/Window.h
@@ -58,7 +58,9 @@
/**
* The document displayed by the window
*/
-@property (retain) TikzDocument *document;
+@property (retain) TikzDocument *document;
+
+@property (readonly) BOOL hasFocus;
/**
* Create a window with an empty document
diff --git a/tikzit/src/gtk/Window.m b/tikzit/src/gtk/Window.m
index c5e7654..d5dcf03 100644
--- a/tikzit/src/gtk/Window.m
+++ b/tikzit/src/gtk/Window.m
@@ -148,9 +148,8 @@ static void update_paste_action (GtkClipboard *clipboard, GdkEvent *event, GtkAc
[[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:[document pickSupport]];
[[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:document];
- [newDoc retain];
- [document release];
- document = newDoc;
+ TikzDocument *oldDoc = document;
+ document = [newDoc retain];
[graphPanel setDocument:document];
[self _updateTikz];
@@ -174,6 +173,21 @@ static void update_paste_action (GtkClipboard *clipboard, GdkEvent *event, GtkAc
if ([document path] != nil) {
[[RecentManager defaultManager] addRecentFile:[document path]];
}
+
+ NSDictionary *userInfo;
+ userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+ document, @"document",
+ oldDoc, @"oldDocument",
+ nil];
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:@"DocumentChanged"
+ object:self
+ userInfo:userInfo];
+ [oldDoc release];
+}
+
+- (BOOL) hasFocus {
+ return gtk_window_has_toplevel_focus (GTK_WINDOW (window));
}
- (void) present {