summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Merry <alex.merry@cs.ox.ac.uk>2012-12-12 12:57:25 +0000
committerAlex Merry <alex.merry@cs.ox.ac.uk>2012-12-12 12:57:25 +0000
commit4ee50a8cf2b592c2ac98a45da63bde6466a9ee9f (patch)
tree1462a0245783ef25427803d8d67a2af8f2e0cabe
parentad869704e6dd52315bff174070e570727e7e8d98 (diff)
Implement (single-key) tool shortcuts
-rw-r--r--tikzit/src/gtk/Application.h3
-rw-r--r--tikzit/src/gtk/Application.m13
-rw-r--r--tikzit/src/gtk/GraphEditorPanel.m8
3 files changed, 24 insertions, 0 deletions
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> 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