From 814372e88b23ce7956b2322d6f382742e2277ea5 Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Wed, 13 Feb 2013 13:31:08 +0000 Subject: GTK: Add shortcuts for changing selection mode Now when the graph has focus, shift+n will choose node selection, shift+e edge selection and shift+b both. --- tikzit/src/gtk/Application.h | 5 ++++- tikzit/src/gtk/Application.m | 5 +++-- tikzit/src/gtk/GraphEditorPanel.m | 13 ++++++++++++- tikzit/src/gtk/SelectTool.m | 18 +++++++++++++++--- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/tikzit/src/gtk/Application.h b/tikzit/src/gtk/Application.h index b364c5e..e82d2b1 100644 --- a/tikzit/src/gtk/Application.h +++ b/tikzit/src/gtk/Application.h @@ -150,7 +150,10 @@ extern Application* app; */ - (void) saveConfiguration; -- (void) activateToolForKey:(unsigned int)keyVal withMask:(InputMask)mask; +/** + * @result YES if key event was processed, NO otherwise + */ +- (BOOL) activateToolForKey:(unsigned int)keyVal withMask:(InputMask)mask; @end diff --git a/tikzit/src/gtk/Application.m b/tikzit/src/gtk/Application.m index 4c696a2..bfde140 100644 --- a/tikzit/src/gtk/Application.m +++ b/tikzit/src/gtk/Application.m @@ -209,7 +209,7 @@ Application* app = nil; } } -- (void) activateToolForKey:(unsigned int)keyVal withMask:(InputMask)mask { +- (BOOL) activateToolForKey:(unsigned int)keyVal withMask:(InputMask)mask { // FIXME: cache the accel info, rather than reparsing it every time? for (id tool in tools) { guint toolKey = 0; @@ -217,9 +217,10 @@ Application* app = nil; gtk_accelerator_parse ([[tool shortcut] UTF8String], &toolKey, &toolMod); if (toolKey != 0 && toolKey == keyVal && (int)mask == (int)toolMod) { [self setActiveTool:tool]; - return; + return YES; } } + return NO; } - (void) _addWindow:(Window*)window { diff --git a/tikzit/src/gtk/GraphEditorPanel.m b/tikzit/src/gtk/GraphEditorPanel.m index 4c7312a..553f261 100644 --- a/tikzit/src/gtk/GraphEditorPanel.m +++ b/tikzit/src/gtk/GraphEditorPanel.m @@ -176,10 +176,21 @@ } - (void) keyPressed:(unsigned int)keyVal withMask:(InputMask)mask { - [app activateToolForKey:keyVal withMask:mask]; + if (![app activateToolForKey:keyVal withMask:mask]) { + id tool = [panel activeTool]; + if ([panel hasTool] && [tool respondsToSelector:@selector(keyPressed:withMask:)]) { + [tool keyPressed:keyVal withMask:mask]; + } + } } - (void) keyReleased:(unsigned int)keyVal withMask:(InputMask)mask { + if (![app activateToolForKey:keyVal withMask:mask]) { + id tool = [panel activeTool]; + if ([panel hasTool] && [tool respondsToSelector:@selector(keyReleased:withMask:)]) { + [tool keyReleased:keyVal withMask:mask]; + } + } } @end diff --git a/tikzit/src/gtk/SelectTool.m b/tikzit/src/gtk/SelectTool.m index 6f3ceeb..d5c482f 100644 --- a/tikzit/src/gtk/SelectTool.m +++ b/tikzit/src/gtk/SelectTool.m @@ -23,6 +23,8 @@ #import "TikzDocument.h" #import "tzstockitems.h" +#import + #define DRAG_SELECT_MODE_KEY "tikzit-drag-select-mode" static const InputMask unionSelectMask = ShiftMask; @@ -73,7 +75,7 @@ static void drag_select_mode_cb (GtkToggleButton *button, SelectTool *tool); FALSE, 0); - GtkWidget *nodeOpt = gtk_radio_button_new_with_label (NULL, "nodes"); + GtkWidget *nodeOpt = gtk_radio_button_new_with_label (NULL, "nodes (N)"); g_object_set_data (G_OBJECT (nodeOpt), DRAG_SELECT_MODE_KEY, (gpointer)DragSelectsNodes); @@ -89,7 +91,7 @@ static void drag_select_mode_cb (GtkToggleButton *button, SelectTool *tool); GtkWidget *edgeOpt = gtk_radio_button_new_with_label ( gtk_radio_button_get_group (GTK_RADIO_BUTTON (nodeOpt)), - "edges"); + "edges (E)"); g_object_set_data (G_OBJECT (edgeOpt), DRAG_SELECT_MODE_KEY, (gpointer)DragSelectsEdges); @@ -105,7 +107,7 @@ static void drag_select_mode_cb (GtkToggleButton *button, SelectTool *tool); GtkWidget *bothOpt = gtk_radio_button_new_with_label ( gtk_radio_button_get_group (GTK_RADIO_BUTTON (edgeOpt)), - "both"); + "both (B)"); g_object_set_data (G_OBJECT (bothOpt), DRAG_SELECT_MODE_KEY, (gpointer)DragSelectsBoth); @@ -359,6 +361,16 @@ static void drag_select_mode_cb (GtkToggleButton *button, SelectTool *tool); } } +- (void) keyPressed:(unsigned int)keyVal withMask:(InputMask)mask { + if (keyVal == GDK_KEY_N && mask == ShiftMask) { + [self setDragSelectMode:DragSelectsNodes]; + } else if (keyVal == GDK_KEY_E && mask == ShiftMask) { + [self setDragSelectMode:DragSelectsEdges]; + } else if (keyVal == GDK_KEY_B && mask == ShiftMask) { + [self setDragSelectMode:DragSelectsBoth]; + } +} + - (void) renderWithContext:(id)context onSurface:(id)surface { if (!NSIsEmptyRect (selectionBox)) { [context saveState]; -- cgit v1.2.3