From 4ee50a8cf2b592c2ac98a45da63bde6466a9ee9f Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Wed, 12 Dec 2012 12:57:25 +0000 Subject: Implement (single-key) tool shortcuts --- tikzit/src/gtk/Application.h | 3 +++ tikzit/src/gtk/Application.m | 13 +++++++++++++ tikzit/src/gtk/GraphEditorPanel.m | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/tikzit/src/gtk/Application.h b/tikzit/src/gtk/Application.h index 1e5ab97..eb9dbbf 100644 --- a/tikzit/src/gtk/Application.h +++ b/tikzit/src/gtk/Application.h @@ -16,6 +16,7 @@ */ #import "TZFoundation.h" +#import "InputDelegate.h" @class Application; @class Configuration; @@ -149,6 +150,8 @@ extern Application* app; */ - (void) saveConfiguration; +- (void) activateToolForKey:(unsigned int)keyVal withMask:(InputMask)mask; + @end // vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/Application.m b/tikzit/src/gtk/Application.m index 4096fe9..11d0cd7 100644 --- a/tikzit/src/gtk/Application.m +++ b/tikzit/src/gtk/Application.m @@ -198,6 +198,19 @@ Application* app = nil; } } +- (void) 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; + GdkModifierType toolMod = 0; + gtk_accelerator_parse ([[tool shortcut] UTF8String], &toolKey, &toolMod); + if (toolKey != 0 && toolKey == keyVal && (int)mask == (int)toolMod) { + [self setActiveTool:tool]; + return; + } + } +} + - (void) _addWindow:(Window*)window { [window setActiveTool:activeTool]; [openWindows addObject:window]; diff --git a/tikzit/src/gtk/GraphEditorPanel.m b/tikzit/src/gtk/GraphEditorPanel.m index 542dba1..d2a1831 100644 --- a/tikzit/src/gtk/GraphEditorPanel.m +++ b/tikzit/src/gtk/GraphEditorPanel.m @@ -17,6 +17,7 @@ #import "GraphEditorPanel.h" +#import "Application.h" #import "GraphRenderer.h" #import "HandTool.h" #import "InputDelegate.h" @@ -168,6 +169,13 @@ [tool mouseScrolledAt:pos inDirection:dir withMask:mask]; } } + +- (void) keyPressed:(unsigned int)keyVal withMask:(InputMask)mask { + [app activateToolForKey:keyVal withMask:mask]; +} + +- (void) keyReleased:(unsigned int)keyVal withMask:(InputMask)mask { +} @end // vim:ft=objc:ts=8:et:sts=4:sw=4 -- cgit v1.2.3