macOS: Tunnel detail: Handle deletion outside app, again
This was previously done in commitf281b93
, but the changes in commit1507a97
for handling deletion of multiple tunnels undid this capability. Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
377f2f0496
commit
4ef7afe3ca
|
@ -12,7 +12,7 @@ class TunnelsListTableViewController: NSViewController {
|
||||||
|
|
||||||
let tunnelsManager: TunnelsManager
|
let tunnelsManager: TunnelsManager
|
||||||
weak var delegate: TunnelsListTableViewControllerDelegate?
|
weak var delegate: TunnelsListTableViewControllerDelegate?
|
||||||
var isRemovingTunnels = false
|
var isRemovingTunnelsFromWithinTheApp = false
|
||||||
|
|
||||||
let tableView: NSTableView = {
|
let tableView: NSTableView = {
|
||||||
let tableView = NSTableView()
|
let tableView = NSTableView()
|
||||||
|
@ -183,8 +183,10 @@ class TunnelsListTableViewController: NSViewController {
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
self.selectTunnel(at: nextSelection)
|
self.selectTunnel(at: nextSelection)
|
||||||
let selectedTunnels = selectedTunnelIndices.map { self.tunnelsManager.tunnel(at: $0) }
|
let selectedTunnels = selectedTunnelIndices.map { self.tunnelsManager.tunnel(at: $0) }
|
||||||
|
self.isRemovingTunnelsFromWithinTheApp = true
|
||||||
self.tunnelsManager.removeMultiple(tunnels: selectedTunnels) { [weak self] error in
|
self.tunnelsManager.removeMultiple(tunnels: selectedTunnels) { [weak self] error in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
self.isRemovingTunnelsFromWithinTheApp = false
|
||||||
defer { completion() }
|
defer { completion() }
|
||||||
if let error = error {
|
if let error = error {
|
||||||
ErrorPresenter.showErrorAlert(error: error, from: self)
|
ErrorPresenter.showErrorAlert(error: error, from: self)
|
||||||
|
@ -281,9 +283,14 @@ extension TunnelsListTableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
func tunnelRemoved(at index: Int) {
|
func tunnelRemoved(at index: Int) {
|
||||||
|
let selectedIndices = tableView.selectedRowIndexes
|
||||||
|
let isSingleSelectedTunnelBeingRemoved = selectedIndices.contains(index) && selectedIndices.count == 1
|
||||||
tableView.removeRows(at: IndexSet(integer: index), withAnimation: .slideLeft)
|
tableView.removeRows(at: IndexSet(integer: index), withAnimation: .slideLeft)
|
||||||
if tunnelsManager.numberOfTunnels() == 0 {
|
if tunnelsManager.numberOfTunnels() == 0 {
|
||||||
delegate?.tunnelsListEmpty()
|
delegate?.tunnelsListEmpty()
|
||||||
|
} else if !isRemovingTunnelsFromWithinTheApp && isSingleSelectedTunnelBeingRemoved {
|
||||||
|
let newSelection = min(index, tunnelsManager.numberOfTunnels() - 1)
|
||||||
|
tableView.selectRowIndexes(IndexSet(integer: newSelection), byExtendingSelection: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue