aboutsummaryrefslogtreecommitdiffstats
path: root/CopyMailto/QuitButton.m
diff options
context:
space:
mode:
authorTeddy Wing2018-09-05 23:10:18 +0200
committerTeddy Wing2018-09-05 23:10:18 +0200
commitb44d11312c8dd908a8e6d3c83e8f9773a893e15c (patch)
treef0888902dfeeacbb161e86b80dcdc9d4e99c5e15 /CopyMailto/QuitButton.m
parente9da806f26bd6a9b11aa461a3093346967ccaf52 (diff)
downloadCopy-Mailto-b44d11312c8dd908a8e6d3c83e8f9773a893e15c.tar.bz2
Make "Quit" button work on "q" or "Escape" key press
Previously I only had a key equivalent on the "Escape" key because you can only set a single key equivalent. But I wanted the "Quit" button to work on both "Escape" and "q" presses. I tried to do this by overriding `performKeyEquivalent:`: - (BOOL)performKeyEquivalent:(NSEvent *)theEvent { if ([[theEvent characters] isEqualToString:@"q"] || [theEvent keyCode] == kVK_Escape) { NSLog(@"%@", theEvent); return YES; } return [super performKeyEquivalent:theEvent]; } The method was called and it logged correctly, but the `IBAction` wouldn't run. Maybe this doesn't work for what I want it to? Can't figure out what the problem is. Didn't want to deal any more so just overrode `keyDown:` instead and got rid of the `IBAction`, just terminating the application in code.
Diffstat (limited to 'CopyMailto/QuitButton.m')
-rw-r--r--CopyMailto/QuitButton.m22
1 files changed, 22 insertions, 0 deletions
diff --git a/CopyMailto/QuitButton.m b/CopyMailto/QuitButton.m
new file mode 100644
index 0000000..8b8bb52
--- /dev/null
+++ b/CopyMailto/QuitButton.m
@@ -0,0 +1,22 @@
+//
+// QuitButton.m
+// CopyMailto
+//
+// Created by tw on 9/5/18.
+// Copyright © 2018 tw. All rights reserved.
+//
+
+#import "QuitButton.h"
+
+@implementation QuitButton
+
+// Quit the application on "q" or "Escape"
+- (void)keyDown:(NSEvent *)theEvent
+{
+ if ([[theEvent characters] isEqualToString:@"q"] ||
+ [theEvent keyCode] == kVK_Escape) {
+ [NSApp terminate:self];
+ }
+}
+
+@end