Cocoa Keyboard Shortcuts in Dialog without an Edit Menu
This commit is contained in:
@ -48,6 +48,6 @@
|
||||
<key>NSMainNibFile</key>
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<string>SWBApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
11
ShadowsocksX-NG/SWBApplication.h
Normal file
11
ShadowsocksX-NG/SWBApplication.h
Normal file
@ -0,0 +1,11 @@
|
||||
//
|
||||
// Created by clowwindy on 3/1/14.
|
||||
// Copyright (c) 2014 clowwindy. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
@import AppKit;
|
||||
|
||||
|
||||
@interface SWBApplication : NSApplication
|
||||
@end
|
49
ShadowsocksX-NG/SWBApplication.m
Normal file
49
ShadowsocksX-NG/SWBApplication.m
Normal file
@ -0,0 +1,49 @@
|
||||
//
|
||||
// Created by clowwindy on 3/1/14.
|
||||
// Copyright (c) 2014 clowwindy. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SWBApplication.h"
|
||||
|
||||
|
||||
@implementation SWBApplication {
|
||||
|
||||
}
|
||||
|
||||
// Enable Key Shortcuts
|
||||
// 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:@selector(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:@selector(redo:) to:nil from:self])
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
[super sendEvent:event];
|
||||
}
|
||||
|
||||
@end
|
Reference in New Issue
Block a user