aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/tunnelsview.go
diff options
context:
space:
mode:
authorAnthony Dong <aanthony.dong@gmail.com>2019-04-29 18:20:16 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-04-29 20:37:21 +0200
commit119319843106e0b98c749d8d1dc176666cf963a0 (patch)
tree5bbe7f702aacbf1a491d882186c7671cfe555d17 /ui/tunnelsview.go
parentquickinstall: add a quick thing (diff)
downloadwireguard-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/tunnelsview.go')
-rw-r--r--ui/tunnelsview.go25
1 files changed, 21 insertions, 4 deletions
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
+ }
}
})
}