From eb55df536af97d65365f920f7e35e6534a24056c Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Tue, 9 Apr 2013 19:48:02 +0100 Subject: GTK+: One preview window per main window Each document window has its own preview window, allowing multiple ones to be open at once. --- tikzit/src/gtk/Application.h | 9 --------- tikzit/src/gtk/Application.m | 24 ----------------------- tikzit/src/gtk/GraphEditorPanel.h | 13 +++++++++---- tikzit/src/gtk/GraphEditorPanel.m | 5 ++++- tikzit/src/gtk/Menu.m | 2 +- tikzit/src/gtk/PreviewWindow.m | 2 +- tikzit/src/gtk/Window.h | 11 +++++++++++ tikzit/src/gtk/Window.m | 41 +++++++++++++++++++++++++++++++++++++-- 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; @@ -134,14 +133,6 @@ extern Application* app; * Show the context-aware window */ - (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. */ 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 +- (void) showPreview; +@end @interface GraphEditorPanel : NSObject { - GraphRenderer *renderer; - WidgetSurface *surface; - GraphInputHandler *inputHandler; - id tool; + GraphRenderer *renderer; + WidgetSurface *surface; + GraphInputHandler *inputHandler; + id previewHandler; + id tool; } @property (retain) TikzDocument *document; @property (readonly) GtkWidget *widget; @property (retain) id activeTool; +@property (assign) id 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 = [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) - (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 // }}} -- cgit v1.2.3