aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/ViewController
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-04 20:09:28 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:32 +0530
commitefb64b195966d876e9b9b2f2d4bba7872e5b02de (patch)
tree37332036d6c3ebfd727f8b69c64e51ccbfa84624 /WireGuard/WireGuard/UI/macOS/ViewController
parentmacOS: Manage tunnels: Update tunnels list on changes (diff)
downloadwireguard-apple-efb64b195966d876e9b9b2f2d4bba7872e5b02de.tar.xz
wireguard-apple-efb64b195966d876e9b9b2f2d4bba7872e5b02de.zip
macOS: Manage tunnels: Remove tunnel
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift37
1 files changed, 31 insertions, 6 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
index c7d691f..643529c 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
@@ -61,7 +61,7 @@ class TunnelsListTableViewController: NSViewController {
override func loadView() {
tableView.dataSource = self
tableView.delegate = self
- selectFirstTunnel()
+ selectTunnel(at: 0)
let scrollView = NSScrollView()
scrollView.hasVerticalScroller = true
@@ -140,7 +140,30 @@ class TunnelsListTableViewController: NSViewController {
}
@objc func removeTunnelClicked() {
- print("removeTunnelClicked")
+ guard let window = view.window else { return }
+ let selectedTunnelIndex = tableView.selectedRow
+ let selectedTunnel = tunnelsManager.tunnel(at: selectedTunnelIndex)
+ let alert = NSAlert()
+ alert.messageText = tr(format: "macDeleteTunnelConfirmationAlertMessage (%@)", selectedTunnel.name)
+ alert.informativeText = tr("macDeleteTunnelConfirmationAlertInfo")
+ alert.addButton(withTitle: tr("macDeleteTunnelConfirmationAlertButtonTitleDelete"))
+ alert.addButton(withTitle: tr("macDeleteTunnelConfirmationAlertButtonTitleCancel"))
+ alert.beginSheetModal(for: window) { [weak self] response in
+ guard response == .alertFirstButtonReturn else { return }
+ self?.buttonBar.setEnabled(false, forSegment: 1)
+ self?.tunnelsManager.remove(tunnel: selectedTunnel) { [weak self] error in
+ guard let self = self else { return }
+ self.buttonBar.setEnabled(true, forSegment: 1)
+ if let error = error {
+ ErrorPresenter.showErrorAlert(error: error, from: self)
+ return
+ }
+ let tunnelIndex = min(selectedTunnelIndex, self.tunnelsManager.numberOfTunnels() - 1)
+ if tunnelIndex > 0 {
+ self.selectTunnel(at: tunnelIndex)
+ }
+ }
+ }
}
@objc func exportLogClicked() {
@@ -199,10 +222,12 @@ class TunnelsListTableViewController: NSViewController {
}
@discardableResult
- private func selectFirstTunnel() -> Bool {
- guard tunnelsManager.numberOfTunnels() > 0 else { return false }
- tableView.selectRowIndexes(IndexSet(integer: 0), byExtendingSelection: false)
- return true
+ private func selectTunnel(at index: Int) -> Bool {
+ if index < tunnelsManager.numberOfTunnels() {
+ tableView.selectRowIndexes(IndexSet(integer: index), byExtendingSelection: false)
+ return true
+ }
+ return false
}
}