forked from mipstian/catch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CTCApplication.m
38 lines (34 loc) · 1.63 KB
/
CTCApplication.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#import "CTCApplication.h"
@implementation CTCApplication
/**
@brief Reimplement basic cut/copy/paste/undo/select all events
@see http://stackoverflow.com/questions/970707/cocoa-keyboard-shortcuts-in-dialog-without-an-edit-menu
*/
- (void)sendEvent:(NSEvent *)event {
if (event.type == NSKeyDown) {
if ((event.modifierFlags & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask) {
if ([event.charactersIgnoringModifiers isEqualToString:@"x"]) {
if ([self sendAction:@selector(cut:) to:nil from:self]) return;
}
else if ([event.charactersIgnoringModifiers isEqualToString:@"c"]) {
if ([self sendAction:@selector(copy:) to:nil from:self]) return;
}
else if ([event.charactersIgnoringModifiers isEqualToString:@"v"]) {
if ([self sendAction:@selector(paste:) to:nil from:self]) return;
}
else if ([event.charactersIgnoringModifiers isEqualToString:@"z"]) {
if ([self sendAction:NSSelectorFromString(@"undo:") to:nil from:self]) return;
}
else if ([event.charactersIgnoringModifiers isEqualToString:@"a"]) {
if ([self sendAction:@selector(selectAll:) to:nil from:self]) return;
}
}
else if ((event.modifierFlags & NSDeviceIndependentModifierFlagsMask) == (NSCommandKeyMask | NSShiftKeyMask)) {
if ([event.charactersIgnoringModifiers isEqualToString:@"Z"]) {
if ([self sendAction:NSSelectorFromString(@"redo:") to:nil from:self]) return;
}
}
}
[super sendEvent:event];
}
@end