macOS: Manage tunnels: Keyboard shortcuts

This commit is contained in:
Roopesh Chander 2019-01-17 01:44:40 +05:30
parent 4c8c397fac
commit 3e850963fc
2 changed files with 35 additions and 0 deletions

View File

@ -7,6 +7,7 @@ class ManageTunnelsRootViewController: NSViewController {
let tunnelsManager: TunnelsManager let tunnelsManager: TunnelsManager
var tunnelsListVC: TunnelsListTableViewController? var tunnelsListVC: TunnelsListTableViewController?
var tunnelDetailVC: TunnelDetailTableViewController?
let tunnelDetailContainerView = NSView() let tunnelDetailContainerView = NSView()
var tunnelDetailContentVC: NSViewController? var tunnelDetailContentVC: NSViewController?
@ -80,10 +81,36 @@ extension ManageTunnelsRootViewController: TunnelsListTableViewControllerDelegat
func tunnelSelected(tunnel: TunnelContainer) { func tunnelSelected(tunnel: TunnelContainer) {
let tunnelDetailVC = TunnelDetailTableViewController(tunnelsManager: tunnelsManager, tunnel: tunnel) let tunnelDetailVC = TunnelDetailTableViewController(tunnelsManager: tunnelsManager, tunnel: tunnel)
setTunnelDetailContentVC(tunnelDetailVC) setTunnelDetailContentVC(tunnelDetailVC)
self.tunnelDetailVC = tunnelDetailVC
} }
func tunnelsListEmpty() { func tunnelsListEmpty() {
let noTunnelsVC = NoTunnelsDetailViewController(tunnelsManager: tunnelsManager) let noTunnelsVC = NoTunnelsDetailViewController(tunnelsManager: tunnelsManager)
setTunnelDetailContentVC(noTunnelsVC) setTunnelDetailContentVC(noTunnelsVC)
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 "i":
tunnelsListVC?.handleImportTunnelAction()
case "t":
tunnelDetailVC?.handleToggleActiveStatusAction()
case "e":
tunnelDetailVC?.handleEditTunnelAction()
default:
break
}
}
} }
} }

View File

@ -201,6 +201,14 @@ class TunnelDetailTableViewController: NSViewController {
presentAsSheet(tunnelEditVC) presentAsSheet(tunnelEditVC)
} }
@objc func handleToggleActiveStatusAction() {
if tunnel.status == .inactive {
tunnelsManager.startActivation(of: tunnel)
} else if tunnel.status == .active {
tunnelsManager.startDeactivation(of: tunnel)
}
}
@objc func statusCheckboxToggled(sender: AnyObject?) { @objc func statusCheckboxToggled(sender: AnyObject?) {
guard let statusCheckbox = sender as? NSButton else { return } guard let statusCheckbox = sender as? NSButton else { return }
if statusCheckbox.state == .on { if statusCheckbox.state == .on {