diff options
author | Alex Merry <alex.merry@cs.ox.ac.uk> | 2012-12-04 18:55:25 +0000 |
---|---|---|
committer | Alex Merry <dev@randomguy3.me.uk> | 2012-12-06 12:08:03 +0000 |
commit | f23a2d9daa1eb62b2afac8997f1d76eb881628f7 (patch) | |
tree | 378c1cc752b7aa1fd52f35da23bce7de855bef5d /tikzit/src/gtk/Application.m | |
parent | 134de8169993f23f2c3a733a7bf96622965e7d7d (diff) |
Refactor GraphInputHandler into Tools
Diffstat (limited to 'tikzit/src/gtk/Application.m')
-rw-r--r-- | tikzit/src/gtk/Application.m | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/tikzit/src/gtk/Application.m b/tikzit/src/gtk/Application.m index 2631bb3..ac6a451 100644 --- a/tikzit/src/gtk/Application.m +++ b/tikzit/src/gtk/Application.m @@ -27,12 +27,19 @@ #ifdef HAVE_POPPLER #import "SettingsDialog.h" #endif +#import "Shape.h" #import "StyleManager.h" #import "StyleManager+Storage.h" #import "SupportDir.h" #import "TikzDocument.h" #import "Window.h" +#import "BoundingBoxTool.h" +#import "CreateNodeTool.h" +#import "CreateEdgeTool.h" +#import "HandTool.h" +#import "SelectTool.h" + // used for args to g_mkdir_with_parents #import "stat.h" @@ -47,7 +54,7 @@ Application* app = nil; @synthesize mainConfiguration=configFile; @synthesize styleManager, preambles; @synthesize lastOpenFolder, lastSaveAsFolder; -@synthesize activeDocument; +@synthesize tools; + (Application*) app { if (app == nil) { @@ -93,6 +100,15 @@ Application* app = nil; openWindows = [[NSMutableArray alloc] init]; + tools = [[NSArray alloc] initWithObjects: + [SelectTool tool], + [CreateNodeTool tool], + [CreateEdgeTool tool], + [BoundingBoxTool tool], + [HandTool tool], + nil]; + activeTool = [[tools objectAtIndex:0] retain]; + // FIXME: toolboxes app = [self retain]; @@ -142,23 +158,25 @@ Application* app = nil; [preambles release]; [lastOpenFolder release]; [lastSaveAsFolder release]; - [activeDocument release]; [preambleWindow release]; [previewWindow release]; [settingsDialog release]; [openWindows release]; + [tools release]; + [activeTool release]; [super dealloc]; } -- (void) newWindow { - [self newWindowWithDocument:nil]; +- (id<Tool>) activeTool { return activeTool; } +- (void) setActiveTool:(id<Tool>)tool { + for (Window* window in openWindows) { + [window setActiveTool:tool]; + } } -- (void) newWindowWithDocument:(TikzDocument*)doc { - Window *window = (doc == nil) - ? [Window window] - : [Window windowWithDocument:doc]; +- (void) _addWindow:(Window*)window { + [window setActiveTool:activeTool]; [openWindows addObject:window]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowClosed:) @@ -167,6 +185,14 @@ Application* app = nil; // FIXME: focus? } +- (void) newWindow { + [self _addWindow:[Window window]]; +} + +- (void) newWindowWithDocument:(TikzDocument*)doc { + [self _addWindow:[Window windowWithDocument:doc]]; +} + - (void) quit { NSMutableArray *unsavedDocs = [NSMutableArray arrayWithCapacity:[openWindows count]]; for (Window *window in openWindows) { @@ -217,10 +243,6 @@ Application* app = nil; return configFile; } -- (TikzDocument*) activeDocument { - return activeDocument; -} - - (void) saveConfiguration { NSError *error = nil; @@ -259,8 +281,6 @@ Application* app = nil; object:window]; if ([openWindows count] == 0) { gtk_main_quit(); - } else if ([[window document] isEqual:activeDocument]) { - [self setActiveDocument:[[openWindows objectAtIndex:0] document]]; } } @end |