-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconfig.go
More file actions
84 lines (73 loc) · 1.98 KB
/
Copy pathconfig.go
File metadata and controls
84 lines (73 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
)
var (
selectedID string
// selectedOption service
selectedLogin func(string, fyne.App)
)
func (u *ui) addLogin(w fyne.Window, a fyne.App) {
content := u.loginContent(a)
d := dialog.NewCustomConfirm("Choose server to add", "OK", "Cancel",
content, func(ok bool) {
if !ok {
return
}
count := a.Preferences().Int(prefServerCountKey)
prefix := fmt.Sprintf(prefServerPrefix, count)
a.Preferences().SetInt(prefServerCountKey, count+1)
a.Preferences().SetString(prefix+prefServerTypeKey, selectedID)
go selectedLogin(prefix, a)
}, w)
d.Resize(fyne.NewSize(375, 240))
d.Show()
}
func (u *ui) loginContent(a fyne.App) fyne.CanvasObject {
var opts []struct {
id string
srv service
content fyne.CanvasObject
login func(string, fyne.App)
}
for id, data := range services {
srv := data(a)
content, save := srv.configure(u)
opts = append(opts, struct {
id string
srv service
content fyne.CanvasObject
login func(string, fyne.App)
}{id, srv, content, save})
}
details := container.NewStack(widget.NewLabel("and add your login details"))
title := widget.NewLabelWithStyle("Choose a server type", fyne.TextAlignLeading, fyne.TextStyle{Bold: true})
list := widget.NewList(
func() int {
return len(opts)
},
func() fyne.CanvasObject {
return widget.NewLabel("service...")
},
func(id widget.ListItemID, o fyne.CanvasObject) {
o.(*widget.Label).SetText(opts[id].id)
})
list.OnSelected = func(id widget.ListItemID) {
opt := opts[id]
title.SetText(fmt.Sprintf("Add %s reflector", strings.Title(opt.id)))
details.Objects = []fyne.CanvasObject{
opts[id].content,
}
details.Refresh()
selectedID = opt.id
// selectedOption = opt.srv
selectedLogin = opt.login
}
return container.NewBorder(nil, nil, list, nil,
container.NewBorder(title, nil, nil, nil, details))
}