From: Martin Willi Date: Wed, 24 Aug 2016 18:28:00 +0000 (+0200) Subject: osx: Subclass NSApplication to implement keyboard copy/paste commands X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=4513e54210a0fb63b087872b093440fb9946f6d6;p=thirdparty%2Fstrongswan.git osx: Subclass NSApplication to implement keyboard copy/paste commands As we have no menu for our dialogs, copy/paste using keyboard shortcuts do not work. As a workaround, subclass NSApplication and make the the principal class to receive the events. --- diff --git a/src/frontends/osx/strongSwan.xcodeproj/project.pbxproj b/src/frontends/osx/strongSwan.xcodeproj/project.pbxproj index ce23e8f1d7..7319adb84a 100644 --- a/src/frontends/osx/strongSwan.xcodeproj/project.pbxproj +++ b/src/frontends/osx/strongSwan.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 5B04A712174558F100A13BDC /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 5B04A711174558F100A13BDC /* icon.png */; }; 5B04A7211747800F00A13BDC /* icon-alt.png in Resources */ = {isa = PBXBuildFile; fileRef = 5B04A7201747800F00A13BDC /* icon-alt.png */; }; 5B313F9A17A93D590055C86A /* icon-large.icns in Resources */ = {isa = PBXBuildFile; fileRef = 5B313F9917A93D590055C86A /* icon-large.icns */; }; + 5B3BD2561D6E144F002C4030 /* Application.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B3BD2551D6E144F002C4030 /* Application.m */; }; 5B74989217311B200041971E /* xpc_channels.c in Sources */ = {isa = PBXBuildFile; fileRef = 5B74989117311B200041971E /* xpc_channels.c */; }; 5B7498B8173275D10041971E /* xpc_logger.c in Sources */ = {isa = PBXBuildFile; fileRef = 5B7498B7173275D10041971E /* xpc_logger.c */; }; 5B7FA5A11754D5DB00264BAC /* LogController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B7FA59F1754D5DB00264BAC /* LogController.m */; }; @@ -66,6 +67,8 @@ 5B04A711174558F100A13BDC /* icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon.png; sourceTree = ""; }; 5B04A7201747800F00A13BDC /* icon-alt.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon-alt.png"; sourceTree = ""; }; 5B313F9917A93D590055C86A /* icon-large.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = "icon-large.icns"; sourceTree = ""; }; + 5B3BD2541D6E144F002C4030 /* Application.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Application.h; sourceTree = ""; }; + 5B3BD2551D6E144F002C4030 /* Application.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Application.m; sourceTree = ""; }; 5B74984C172AA3550041971E /* xpc_dispatch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xpc_dispatch.c; sourceTree = ""; }; 5B74984E172AA3670041971E /* xpc_dispatch.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = xpc_dispatch.h; sourceTree = ""; }; 5B74989017311AFC0041971E /* xpc_channels.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = xpc_channels.h; sourceTree = ""; }; @@ -191,6 +194,8 @@ 5B8D87A41A409E6D008E5702 /* PasswordWindow.xib */, 5B8D87991A406572008E5702 /* Helper.h */, 5B8D879A1A40658B008E5702 /* Helper.m */, + 5B3BD2541D6E144F002C4030 /* Application.h */, + 5B3BD2551D6E144F002C4030 /* Application.m */, ); path = strongSwan; sourceTree = ""; @@ -306,6 +311,7 @@ 5BD1CCC41726DB0100587077 /* AppDelegate.m in Sources */, 5BD1CCFB1729365F00587077 /* Control.m in Sources */, 5B7FA5A11754D5DB00264BAC /* LogController.m in Sources */, + 5B3BD2561D6E144F002C4030 /* Application.m in Sources */, 5B8D879B1A40658B008E5702 /* Helper.m in Sources */, 5B7FA5B01754EBC800264BAC /* ConnController.m in Sources */, 5B7FA5B51754F5AF00264BAC /* PasswordController.m in Sources */, diff --git a/src/frontends/osx/strongSwan/Application.h b/src/frontends/osx/strongSwan/Application.h new file mode 100644 index 0000000000..c03201965c --- /dev/null +++ b/src/frontends/osx/strongSwan/Application.h @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2016 Martin Willi + * Copyright (C) 2016 revosec AG + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#import + +@interface Application : NSApplication + +@end diff --git a/src/frontends/osx/strongSwan/Application.m b/src/frontends/osx/strongSwan/Application.m new file mode 100644 index 0000000000..e1616e8bc3 --- /dev/null +++ b/src/frontends/osx/strongSwan/Application.m @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2016 Martin Willi + * Copyright (C) 2016 revosec AG + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#import "Application.h" + +@implementation Application + +- (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:@"a"]) { + if ([self sendAction:@selector(selectAll:) to:nil from:self]) + return; + } + } + } + + [super sendEvent:event]; +} + +@end diff --git a/src/frontends/osx/strongSwan/strongSwan-Info.plist b/src/frontends/osx/strongSwan/strongSwan-Info.plist index cd02dd48fb..03572eff24 100644 --- a/src/frontends/osx/strongSwan/strongSwan-Info.plist +++ b/src/frontends/osx/strongSwan/strongSwan-Info.plist @@ -33,7 +33,7 @@ NSMainNibFile MainMenu NSPrincipalClass - NSApplication + Application SMPrivilegedExecutables org.strongswan.charon-xpc