summaryrefslogtreecommitdiff
path: root/tikzit/src/gtk/GraphInputHandler.m
diff options
context:
space:
mode:
authorAlex Merry <dev@randomguy3.me.uk>2012-06-29 15:12:49 +0100
committerAlex Merry <dev@randomguy3.me.uk>2012-06-29 15:12:49 +0100
commit7b4db7aa75f8e60702fe7828e4be9b06ef7c5fc9 (patch)
tree6b136cdd1b8161fe6eb53d0f9269ffccc57aeb6a /tikzit/src/gtk/GraphInputHandler.m
parent626622b7e570015f5f49e327dfe24660fb221411 (diff)
Be helpful about which panes are visible
If only one property/style pane is visible, auto-switch between them depending on the tool.
Diffstat (limited to 'tikzit/src/gtk/GraphInputHandler.m')
-rw-r--r--tikzit/src/gtk/GraphInputHandler.m66
1 files changed, 65 insertions, 1 deletions
diff --git a/tikzit/src/gtk/GraphInputHandler.m b/tikzit/src/gtk/GraphInputHandler.m
index caaadeb..aec0b7b 100644
--- a/tikzit/src/gtk/GraphInputHandler.m
+++ b/tikzit/src/gtk/GraphInputHandler.m
@@ -18,15 +18,25 @@
#import "GraphInputHandler.h"
#import <gdk/gdkkeysyms.h>
+#import "MainWindow.h"
#import "Edge+Render.h"
static const InputMask unionSelectMask = ShiftMask;
+@interface GraphInputHandler (Notifications)
+- (void) nodeSelectionChanged:(NSNotification*)n;
+- (void) edgeSelectionChanged:(NSNotification*)n;
+@end
+
@implementation GraphInputHandler
- (id) initWithGraphRenderer:(GraphRenderer*)r {
+ return [self initWithGraphRenderer:r window:nil];
+}
+- (id) initWithGraphRenderer:(GraphRenderer*)r window:(MainWindow*)w {
self = [super init];
if (self) {
+ window = w;
renderer = r;
mode = SelectMode;
state = QuietState;
@@ -35,11 +45,26 @@ static const InputMask unionSelectMask = ShiftMask;
modifyEdge = nil;
selectionBoxContents = [[NSMutableSet alloc] initWithCapacity:10];
currentResizeHandle = NoHandle;
+ // FIXME: listen only to the doc's PickSupport
+ // (need to track document changes)
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(nodeSelectionChanged:)
+ name:@"NodeSelectionChanged" object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(edgeSelectionChanged:)
+ name:@"EdgeSelectionChanged" object:nil];
}
return self;
}
+- (void) dealloc {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [selectionBoxContents release];
+
+ [super dealloc];
+}
+
- (TikzDocument*) doc {
return [renderer document];
}
@@ -98,8 +123,23 @@ static const InputMask unionSelectMask = ShiftMask;
}
mode = m;
[self deselectAll];
- if (m == BoundingBoxMode) {
+ if (mode == BoundingBoxMode) {
[renderer setBoundingBoxHandlesShown:YES];
+ [window favourGraphControls];
+ } else if (mode == CreateNodeMode) {
+ [window favourNodeControls];
+ } else if (mode == DrawEdgeMode) {
+ [window favourEdgeControls];
+ } else if (mode == HandMode) {
+ [window favourGraphControls];
+ } else if (mode == SelectMode) {
+ // FIXME: also change on selection change
+ if ([[[[self doc] pickSupport] selectedNodes] count])
+ [window favourNodeControls];
+ else if ([[[[self doc] pickSupport] selectedEdges] count])
+ [window favourEdgeControls];
+ else
+ [window favourGraphControls];
}
}
}
@@ -445,4 +485,28 @@ static const InputMask unionSelectMask = ShiftMask;
@end
+@implementation GraphInputHandler (Notifications)
+- (void) nodeSelectionChanged:(NSNotification*)n {
+ if (mode == SelectMode) {
+ if ([[[[self doc] pickSupport] selectedNodes] count])
+ [window favourNodeControls];
+ else if ([[[[self doc] pickSupport] selectedEdges] count])
+ [window favourEdgeControls];
+ else
+ [window favourGraphControls];
+ }
+}
+
+- (void) edgeSelectionChanged:(NSNotification*)n {
+ if (mode == SelectMode) {
+ if ([[[[self doc] pickSupport] selectedNodes] count])
+ [window favourNodeControls];
+ else if ([[[[self doc] pickSupport] selectedEdges] count])
+ [window favourEdgeControls];
+ else
+ [window favourGraphControls];
+ }
+}
+@end
+
// vim:ft=objc:ts=8:et:sts=4:sw=4