diff options
author | Anthony Dong <aanthony.dong@gmail.com> | 2019-04-29 18:20:16 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-04-29 20:37:21 +0200 |
commit | 119319843106e0b98c749d8d1dc176666cf963a0 (patch) | |
tree | 5bbe7f702aacbf1a491d882186c7671cfe555d17 /ui | |
parent | quickinstall: add a quick thing (diff) | |
download | wireguard-windows-119319843106e0b98c749d8d1dc176666cf963a0.tar.xz wireguard-windows-119319843106e0b98c749d8d1dc176666cf963a0.zip |
ui: select newly created/edited tunnels
Signed-off-by: Anthony Dong <aanthony.dong@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/tunnelspage.go | 1 | ||||
-rw-r--r-- | ui/tunnelsview.go | 25 |
2 files changed, 21 insertions, 5 deletions
diff --git a/ui/tunnelspage.go b/ui/tunnelspage.go index 5df74d05..44150267 100644 --- a/ui/tunnelspage.go +++ b/ui/tunnelspage.go @@ -302,7 +302,6 @@ func (tp *TunnelsPage) onEditTunnel() { if err == nil && err2 == nil && (priorState == service.TunnelStarting || priorState == service.TunnelStarted) { tunnel.Start() } - //TODO: synchronize and select newly added tunnel }() } } diff --git a/ui/tunnelsview.go b/ui/tunnelsview.go index 4adf8902..58816d09 100644 --- a/ui/tunnelsview.go +++ b/ui/tunnelsview.go @@ -176,17 +176,34 @@ func (tv *TunnelsView) onTunnelsChange() { } } } - didAdd := false + tunnelsAdded := 0 + lastTunnelName := "" for tunnel := range newTunnels { if !oldTunnels[tunnel] { tv.model.tunnels = append(tv.model.tunnels, tunnel) - didAdd = true - //TODO: If adding a tunnel for the first time when the previously were none, select it + tunnelsAdded++ + lastTunnelName = tunnel.Name } } - if didAdd { + if tunnelsAdded > 0 { tv.model.PublishRowsReset() tv.model.Sort(tv.model.SortedColumn(), tv.model.SortOrder()) + // If adding a tunnel for the first time when the previously were none, select it + if len(tv.SelectedIndexes()) == 0 { + tv.selectTunnel(lastTunnelName) + } + } + }) +} + +// Tiny helper to select a tunnel by name. +func (tv *TunnelsView) selectTunnel(tunnelName string) { + tv.Synchronize(func() { + for i, tunnel := range tv.model.tunnels { + if tunnel.Name == tunnelName { + tv.SetCurrentIndex(i) + break + } } }) } |