macOS: Tunnels list: Double-click to activate / deactivate

This commit is contained in:
Roopesh Chander 2019-03-18 11:57:09 +05:30
parent 6766644d80
commit 2a7dcac258
1 changed files with 13 additions and 0 deletions

View File

@ -78,6 +78,8 @@ class TunnelsListTableViewController: NSViewController {
tableView.dataSource = self
tableView.delegate = self
tableView.doubleAction = #selector(listDoubleClicked(sender:))
let isSelected = selectTunnelInOperation() || selectTunnel(at: 0)
if !isSelected {
delegate?.tunnelsListEmpty()
@ -242,6 +244,17 @@ class TunnelsListTableViewController: NSViewController {
}
}
@objc func listDoubleClicked(sender: AnyObject) {
let tunnelIndex = tableView.clickedRow
guard tunnelIndex >= 0 && tunnelIndex < tunnelsManager.numberOfTunnels() else { return }
let tunnel = tunnelsManager.tunnel(at: tunnelIndex)
if tunnel.status == .inactive {
tunnelsManager.startActivation(of: tunnel)
} else if tunnel.status == .active {
tunnelsManager.startDeactivation(of: tunnel)
}
}
@discardableResult
private func selectTunnel(at index: Int) -> Bool {
if index < tunnelsManager.numberOfTunnels() {