summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Merry <dev@randomguy3.me.uk>2013-04-09 19:48:02 +0100
committerAlex Merry <dev@randomguy3.me.uk>2013-05-07 09:36:54 +0100
commiteb55df536af97d65365f920f7e35e6534a24056c (patch)
treea1791f0c2f9b37f58224726d7309613223c1e6fb
parenta707ec228ff39d0df26d78f715561952d2f8c0b9 (diff)
GTK+: One preview window per main window
Each document window has its own preview window, allowing multiple ones to be open at once.
-rw-r--r--tikzit/src/gtk/Application.h9
-rw-r--r--tikzit/src/gtk/Application.m24
-rw-r--r--tikzit/src/gtk/GraphEditorPanel.h13
-rw-r--r--tikzit/src/gtk/GraphEditorPanel.m5
-rw-r--r--tikzit/src/gtk/Menu.m2
-rw-r--r--tikzit/src/gtk/PreviewWindow.m2
-rw-r--r--tikzit/src/gtk/Window.h11
-rw-r--r--tikzit/src/gtk/Window.m41
8 files changed, 65 insertions, 42 deletions
diff --git a/tikzit/src/gtk/Application.h b/tikzit/src/gtk/Application.h
index c17a523..1b48a79 100644
--- a/tikzit/src/gtk/Application.h
+++ b/tikzit/src/gtk/Application.h
@@ -49,7 +49,6 @@ extern Application* app;
ToolBox *toolBox;
PreambleEditor *preambleWindow;
- PreviewWindow *previewWindow;
ContextWindow *contextWindow;
SettingsDialog *settingsDialog;
@@ -135,14 +134,6 @@ extern Application* app;
*/
- (void) presentContextWindow;
/**
- * Show or update the preview window.
- */
-- (void) presentPreviewForDocument:(TikzDocument*)doc;
-/**
- * Show or update the preview window without it grabbing focus
- */
-- (void) previewDocument:(TikzDocument*)doc;
-/**
* Show the settings dialog.
*/
- (void) presentSettingsDialog;
diff --git a/tikzit/src/gtk/Application.m b/tikzit/src/gtk/Application.m
index 99ad24d..e9935bd 100644
--- a/tikzit/src/gtk/Application.m
+++ b/tikzit/src/gtk/Application.m
@@ -34,7 +34,6 @@
#ifdef HAVE_POPPLER
#import "Preambles.h"
#import "Preambles+Storage.h"
-#import "PreviewWindow.h"
#endif
#import "BoundingBoxTool.h"
@@ -186,7 +185,6 @@ Application* app = nil;
[lastOpenFolder release];
[lastSaveAsFolder release];
[preambleWindow release];
- [previewWindow release];
[settingsDialog release];
[openWindows release];
[tools release];
@@ -276,28 +274,6 @@ Application* app = nil;
[contextWindow present];
}
-- (void) presentPreviewForDocument:(TikzDocument*)doc {
-#ifdef HAVE_POPPLER
- if (previewWindow == nil) {
- previewWindow = [[PreviewWindow alloc] initWithPreambles:preambles config:configFile];
- //[previewWindow setParentWindow:mainWindow];
- [previewWindow setDocument:doc];
- }
- [previewWindow present];
-#endif
-}
-
-- (void) previewDocument:(TikzDocument*)doc {
-#ifdef HAVE_POPPLER
- if (previewWindow == nil) {
- previewWindow = [[PreviewWindow alloc] initWithPreambles:preambles config:configFile];
- //[previewWindow setParentWindow:mainWindow];
- [previewWindow setDocument:doc];
- }
- [previewWindow show];
-#endif
-}
-
- (void) presentSettingsDialog {
if (settingsDialog == nil) {
settingsDialog = [[SettingsDialog alloc] initWithConfiguration:configFile
diff --git a/tikzit/src/gtk/GraphEditorPanel.h b/tikzit/src/gtk/GraphEditorPanel.h
index 857b0ba..2b93259 100644
--- a/tikzit/src/gtk/GraphEditorPanel.h
+++ b/tikzit/src/gtk/GraphEditorPanel.h
@@ -24,15 +24,20 @@
@class TikzDocument;
@class WidgetSurface;
+@protocol PreviewHandler <NSObject>
+- (void) showPreview;
+@end
@interface GraphEditorPanel : NSObject {
- GraphRenderer *renderer;
- WidgetSurface *surface;
- GraphInputHandler *inputHandler;
- id<Tool> tool;
+ GraphRenderer *renderer;
+ WidgetSurface *surface;
+ GraphInputHandler *inputHandler;
+ id<PreviewHandler> previewHandler;
+ id<Tool> tool;
}
@property (retain) TikzDocument *document;
@property (readonly) GtkWidget *widget;
@property (retain) id<Tool> activeTool;
+@property (assign) id<PreviewHandler> previewHandler;
- (id) init;
- (id) initWithDocument:(TikzDocument*)document;
diff --git a/tikzit/src/gtk/GraphEditorPanel.m b/tikzit/src/gtk/GraphEditorPanel.m
index fc50afc..c87e53e 100644
--- a/tikzit/src/gtk/GraphEditorPanel.m
+++ b/tikzit/src/gtk/GraphEditorPanel.m
@@ -39,6 +39,9 @@
@end
@implementation GraphEditorPanel
+
+@synthesize previewHandler;
+
- (id) init {
return [self initWithDocument:nil];
}
@@ -194,7 +197,7 @@
- (void) keyReleased:(unsigned int)keyVal withMask:(InputMask)mask {
if (keyVal == GDK_KEY_space && !mask) {
- [app previewDocument:[panel document]];
+ [[panel previewHandler] showPreview];
}
if (![app activateToolForKey:keyVal withMask:mask]) {
id<Tool> tool = [panel activeTool];
diff --git a/tikzit/src/gtk/Menu.m b/tikzit/src/gtk/Menu.m
index 0eb8ba8..feac6b8 100644
--- a/tikzit/src/gtk/Menu.m
+++ b/tikzit/src/gtk/Menu.m
@@ -316,7 +316,7 @@ static void send_to_back_cb (GtkAction *action, Window *window) {
#ifdef HAVE_POPPLER
static void show_preview_cb (GtkAction *action, Window *window) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- [app presentPreviewForDocument:[window document]];
+ [window presentPreview];
[pool drain];
}
#endif
diff --git a/tikzit/src/gtk/PreviewWindow.m b/tikzit/src/gtk/PreviewWindow.m
index cb61ee3..fc0e7a3 100644
--- a/tikzit/src/gtk/PreviewWindow.m
+++ b/tikzit/src/gtk/PreviewWindow.m
@@ -126,9 +126,9 @@
}
- (void) dealloc {
+ gtk_widget_destroy (GTK_WIDGET (window));
[previewer release];
[surface release];
- gtk_widget_destroy (GTK_WIDGET (window));
[super dealloc];
}
diff --git a/tikzit/src/gtk/Window.h b/tikzit/src/gtk/Window.h
index 62af643..a3ce8a4 100644
--- a/tikzit/src/gtk/Window.h
+++ b/tikzit/src/gtk/Window.h
@@ -48,6 +48,8 @@
Menu *menu;
GraphEditorPanel *graphPanel;
+ PreviewWindow *previewWindow;
+
// state variables
BOOL suppressTikzUpdates;
BOOL hasParseError;
@@ -166,6 +168,15 @@
- (void) zoomOut;
- (void) zoomReset;
+/**
+ * Show or update the preview window.
+ */
+- (void) presentPreview;
+/**
+ * Show or update the preview window without it grabbing focus
+ */
+- (void) updatePreview;
+
@end
// vim:ft=objc:ts=8:et:sts=4:sw=4
diff --git a/tikzit/src/gtk/Window.m b/tikzit/src/gtk/Window.m
index dd9ee3c..7cb1e65 100644
--- a/tikzit/src/gtk/Window.m
+++ b/tikzit/src/gtk/Window.m
@@ -31,6 +31,10 @@
#import "SupportDir.h"
#import "TikzDocument.h"
+#ifdef HAVE_POPPLER
+#import "PreviewWindow.h"
+#endif
+
enum {
GraphInfoStatus,
ParseStatus
@@ -79,7 +83,7 @@ static void update_paste_action (GtkClipboard *clipboard, GdkEvent *event, GtkAc
- (void) _connectSignals;
@end
-@interface Window (Private)
+@interface Window (Private) <PreviewHandler>
- (BOOL) _askCanClose;
/** Open a document, dealing with errors as necessary */
- (TikzDocument*) _openDocument:(NSString*)path;
@@ -95,6 +99,7 @@ static void update_paste_action (GtkClipboard *clipboard, GdkEvent *event, GtkAc
/** Update the undo and redo actions to match the active document's
* undo stack. */
- (void) _updateUndoActions;
+- (void) showPreview;
@end
// }}}
@@ -130,11 +135,14 @@ static void update_paste_action (GtkClipboard *clipboard, GdkEvent *event, GtkAc
}
- (void) dealloc {
+ // The GTK+ window has already been destroyed at this point
+
[[NSNotificationCenter defaultCenter] removeObserver:self];
g_signal_handler_disconnect (
gtk_clipboard_get (GDK_SELECTION_CLIPBOARD),
clipboard_handler_id);
+ [previewWindow release];
[menu release];
[graphPanel release];
[document release];
@@ -159,6 +167,7 @@ static void update_paste_action (GtkClipboard *clipboard, GdkEvent *event, GtkAc
document = [newDoc retain];
[graphPanel setDocument:document];
+ [previewWindow setDocument:document];
[self _updateTikz];
[self _updateTitle];
[self _updateStatus];
@@ -336,7 +345,6 @@ static void update_paste_action (GtkClipboard *clipboard, GdkEvent *event, GtkAc
if (![[NSFileManager defaultManager] ensureDirectoryExists:userShapeDir error:&error]) {
[self presentError:error withMessage:@"Could not create user shape directory"];
} else {
- NSLog (@"Saving shape to %@", file);
if (![document saveCopyToPath:file error:&error]) {
[self presentError:error withMessage:@"Could not save shape file"];
} else {
@@ -452,6 +460,30 @@ static void update_paste_action (GtkClipboard *clipboard, GdkEvent *event, GtkAc
[graphPanel zoomReset];
}
+- (void) presentPreview {
+#ifdef HAVE_POPPLER
+ if (previewWindow == nil) {
+ previewWindow = [[PreviewWindow alloc] initWithPreambles:[app preambles]
+ config:[app mainConfiguration]];
+ //[previewWindow setParentWindow:self];
+ [previewWindow setDocument:document];
+ }
+ [previewWindow present];
+#endif
+}
+
+- (void) updatePreview {
+#ifdef HAVE_POPPLER
+ if (previewWindow == nil) {
+ previewWindow = [[PreviewWindow alloc] initWithPreambles:[app preambles]
+ config:[app mainConfiguration]];
+ //[previewWindow setParentWindow:self];
+ [previewWindow setDocument:document];
+ }
+ [previewWindow show];
+#endif
+}
+
@end
// }}}
@@ -541,6 +573,7 @@ static void update_paste_action (GtkClipboard *clipboard, GdkEvent *event, GtkAc
gtk_box_pack_start (mainLayout, GTK_WIDGET (tikzPaneSplitter), TRUE, TRUE, 0);
graphPanel = [[GraphEditorPanel alloc] initWithDocument:document];
+ [graphPanel setPreviewHandler:self];
GtkWidget *graphEditorWidget = [graphPanel widget];
gtk_widget_show (graphEditorWidget);
GtkWidget *graphFrame = gtk_frame_new (NULL);
@@ -806,6 +839,10 @@ static void update_paste_action (GtkClipboard *clipboard, GdkEvent *event, GtkAc
return graphPanel;
}
+- (void) showPreview {
+ [self updatePreview];
+}
+
@end
// }}}