macOS: Remove custom key event handling

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2019-05-06 11:12:47 +05:30
parent 5e5481b69b
commit 6d8965e97d
2 changed files with 0 additions and 53 deletions

View File

@ -5,18 +5,6 @@ import Cocoa
class Application: NSApplication {
private let characterKeyCommands = [
"x": #selector(NSText.cut(_:)),
"c": #selector(NSText.copy(_:)),
"v": #selector(NSText.paste(_:)),
"z": #selector(UndoActionRespondable.undo(_:)),
"a": #selector(NSResponder.selectAll(_:)),
"Z": #selector(UndoActionRespondable.redo(_:)),
"w": #selector(NSWindow.performClose(_:)),
"m": #selector(NSWindow.performMiniaturize(_:)),
"q": #selector(AppDelegate.quit)
]
private var appDelegate: AppDelegate? //swiftlint:disable:this weak_delegate
override init() {
@ -28,21 +16,4 @@ class Application: NSApplication {
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 = characterKeyCommands[event.charactersIgnoringModifiers ?? ""] {
sendAction(selector, to: nil, from: self)
} else {
super.sendEvent(event)
}
}
}
@objc protocol UndoActionRespondable {
func undo(_ sender: AnyObject)
func redo(_ sender: AnyObject)
}

View File

@ -115,27 +115,3 @@ extension ManageTunnelsRootViewController: TunnelsListTableViewControllerDelegat
self.tunnelDetailVC = nil
}
}
extension ManageTunnelsRootViewController {
override func keyDown(with event: NSEvent) {
let modifierFlags = event.modifierFlags.rawValue & NSEvent.ModifierFlags.deviceIndependentFlagsMask.rawValue
let isCmdOrCmdShiftDown = (modifierFlags == NSEvent.ModifierFlags.command.rawValue || modifierFlags == NSEvent.ModifierFlags.command.rawValue | NSEvent.ModifierFlags.shift.rawValue)
if event.specialKey == .delete {
tunnelsListVC?.handleRemoveTunnelAction()
} else if isCmdOrCmdShiftDown {
switch event.charactersIgnoringModifiers {
case "n":
tunnelsListVC?.handleAddEmptyTunnelAction()
case "o":
tunnelsListVC?.handleImportTunnelAction()
case "t":
tunnelDetailVC?.handleToggleActiveStatusAction()
case "e":
tunnelDetailVC?.handleEditTunnelAction()
default:
break
}
}
}
}