aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/Application.swift
diff options
context:
space:
mode:
authorEric Kuck <eric@bluelinelabs.com>2019-01-10 11:21:20 +0200
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:36 +0530
commit321b88864c0101cda2185d048e409ca252382678 (patch)
tree94704cd4bc770409df94f2aae2ba4898c9b5f8d5 /WireGuard/WireGuard/UI/macOS/Application.swift
parentResync highlighter (diff)
downloadwireguard-apple-321b88864c0101cda2185d048e409ca252382678.tar.xz
wireguard-apple-321b88864c0101cda2185d048e409ca252382678.zip
Cut/copy/paste now work
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/macOS/Application.swift42
1 files changed, 36 insertions, 6 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/Application.swift b/WireGuard/WireGuard/UI/macOS/Application.swift
index 9f7b810..fba0ac6 100644
--- a/WireGuard/WireGuard/UI/macOS/Application.swift
+++ b/WireGuard/WireGuard/UI/macOS/Application.swift
@@ -3,15 +3,45 @@
import Cocoa
-var appDelegate: AppDelegate?
-
class Application: NSApplication {
+
+ private let editorCommands = [
+ "x": #selector(NSText.cut(_:)),
+ "c": #selector(NSText.copy(_:)),
+ "v": #selector(NSText.paste(_:)),
+ "z": #selector(UndoActionRespondable.undo(_:)),
+ "a": #selector(NSResponder.selectAll(_:)),
+ "Z": #selector(UndoActionRespondable.redo(_:))
+ ]
+
+ private var appDelegate: AppDelegate? //swiftlint:disable:this weak_delegate
+
// We use a custom Application class to be able to set the app delegate
// before app.run() gets called in NSApplicationMain().
- override class var shared: NSApplication {
- let app = NSApplication.shared
+ override init() {
+ super.init()
appDelegate = AppDelegate() // Keep a strong reference to the app delegate
- app.delegate = appDelegate
- return app
+ delegate = appDelegate
+ }
+
+ required init?(coder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
}
+
+ override func sendEvent(_ event: NSEvent) {
+ let modifierFlags = event.modifierFlags.rawValue & NSEvent.ModifierFlags.deviceIndependentFlagsMask.rawValue
+
+ if event.type == .keyDown,
+ (modifierFlags == NSEvent.ModifierFlags.command.rawValue || modifierFlags == NSEvent.ModifierFlags.command.rawValue | NSEvent.ModifierFlags.shift.rawValue),
+ let selector = editorCommands[event.charactersIgnoringModifiers ?? ""] {
+ sendAction(selector, to: nil, from: self)
+ } else {
+ super.sendEvent(event)
+ }
+ }
+}
+
+@objc protocol UndoActionRespondable {
+ func undo(_ sender: AnyObject)
+ func redo(_ sender: AnyObject)
}