]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
osx: Subclass NSApplication to implement keyboard copy/paste commands
authorMartin Willi <martin@revosec.ch>
Wed, 24 Aug 2016 18:28:00 +0000 (20:28 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 24 Aug 2016 18:40:39 +0000 (20:40 +0200)
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.

src/frontends/osx/strongSwan.xcodeproj/project.pbxproj
src/frontends/osx/strongSwan/Application.h [new file with mode: 0644]
src/frontends/osx/strongSwan/Application.m [new file with mode: 0644]
src/frontends/osx/strongSwan/strongSwan-Info.plist

index ce23e8f1d71f4ec7156a9cd47ce83a361563eff6..7319adb84a4fb1c74c4804af279e578f2bf2a06c 100644 (file)
@@ -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 = "<group>"; };
                5B04A7201747800F00A13BDC /* icon-alt.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon-alt.png"; sourceTree = "<group>"; };
                5B313F9917A93D590055C86A /* icon-large.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = "icon-large.icns"; sourceTree = "<group>"; };
+               5B3BD2541D6E144F002C4030 /* Application.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Application.h; sourceTree = "<group>"; };
+               5B3BD2551D6E144F002C4030 /* Application.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Application.m; sourceTree = "<group>"; };
                5B74984C172AA3550041971E /* xpc_dispatch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xpc_dispatch.c; sourceTree = "<group>"; };
                5B74984E172AA3670041971E /* xpc_dispatch.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = xpc_dispatch.h; sourceTree = "<group>"; };
                5B74989017311AFC0041971E /* xpc_channels.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = xpc_channels.h; sourceTree = "<group>"; };
                                5B8D87A41A409E6D008E5702 /* PasswordWindow.xib */,
                                5B8D87991A406572008E5702 /* Helper.h */,
                                5B8D879A1A40658B008E5702 /* Helper.m */,
+                               5B3BD2541D6E144F002C4030 /* Application.h */,
+                               5B3BD2551D6E144F002C4030 /* Application.m */,
                        );
                        path = strongSwan;
                        sourceTree = "<group>";
                                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 (file)
index 0000000..c032019
--- /dev/null
@@ -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 <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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 <Cocoa/Cocoa.h>
+
+@interface Application : NSApplication
+
+@end
diff --git a/src/frontends/osx/strongSwan/Application.m b/src/frontends/osx/strongSwan/Application.m
new file mode 100644 (file)
index 0000000..e1616e8
--- /dev/null
@@ -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 <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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
index cd02dd48fb0d9c410c5ef3ee842c8783b3fc796e..03572eff243e5ac2cc7d10f55fa418008cad8a40 100644 (file)
@@ -33,7 +33,7 @@
        <key>NSMainNibFile</key>
        <string>MainMenu</string>
        <key>NSPrincipalClass</key>
-       <string>NSApplication</string>
+       <string>Application</string>
        <key>SMPrivilegedExecutables</key>
        <dict>
                <key>org.strongswan.charon-xpc</key>