From fda8a5d83b93915091ac50e028218ba716e2acda Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Thu, 3 Jan 2019 23:16:44 +0530 Subject: [PATCH] macOS: Manage tunnels: Select first tunnel on showing the window --- .../ViewController/TunnelsListTableViewController.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift index 5ceb2a1..310d13a 100644 --- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift +++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift @@ -61,6 +61,7 @@ class TunnelsListTableViewController: NSViewController { override func loadView() { tableView.dataSource = self tableView.delegate = self + selectFirstTunnel() let scrollView = NSScrollView() scrollView.hasVerticalScroller = true @@ -148,6 +149,13 @@ class TunnelsListTableViewController: NSViewController { @objc func exportTunnelsClicked() { print("exportTunnelsClicked") } + + @discardableResult + private func selectFirstTunnel() -> Bool { + guard tunnelsManager.numberOfTunnels() > 0 else { return false } + tableView.selectRowIndexes(IndexSet(integer: 0), byExtendingSelection: false) + return true + } } extension TunnelsListTableViewController: NSTableViewDataSource {