-
Notifications
You must be signed in to change notification settings - Fork 3
/
dialog.go
103 lines (90 loc) · 2 KB
/
dialog.go
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"github.com/chenqinghe/redis-desktop/i18n"
"github.com/chenqinghe/walk"
. "github.com/chenqinghe/walk/declarative"
)
type SimpleDialog struct {
Title string
Size Size
FixedSize bool
}
func (sd *SimpleDialog) Alert(p walk.Form, msg string) {
}
func (sd *SimpleDialog) Confirm(p walk.Form, msg string) bool {
return true
}
func (sd *SimpleDialog) Prompt(p walk.Form, msg string) string {
var dlg *walk.Dialog
var input *walk.LineEdit
var content string
if _, err := (Dialog{
AssignTo: &dlg,
Layout: VBox{Margins: Margins{}},
Children: []Widget{
LineEdit{AssignTo: &input},
Composite{
Layout: HBox{Margins: Margins{}},
Children: []Widget{
PushButton{
Text: i18n.Tr("widget.button.ok"),
OnClicked: func() {
content = input.Text()
dlg.Close(0)
},
},
PushButton{
Text: i18n.Tr("widget.button.cancel"),
OnClicked: func() {
dlg.Close(0)
},
},
},
},
},
Title: msg,
Size: sd.Size,
FixedSize: sd.FixedSize,
}).Run(p); err != nil {
return ""
}
return content
}
// Custom show a custom dialog, only the confirm button was pushed, accepted become true, otherwise
// no matter the dialog was closed or cancel button was pushed, accepted returns false.
func (sd *SimpleDialog) Custom(owner walk.Form, widget Widget) (accepted bool, err error) {
var (
dlg *walk.Dialog
)
if _, err := (Dialog{
AssignTo: &dlg,
Layout: VBox{Margins: Margins{}},
Children: []Widget{
widget,
Composite{
Layout: HBox{Margins: Margins{}},
Children: []Widget{
PushButton{
Text: i18n.Tr("widget.button.ok"),
OnClicked: func() {
// some stuff here...
dlg.Close(0)
},
},
PushButton{
Text: i18n.Tr("widget.button.cancel"),
OnClicked: func() {
dlg.Close(0)
},
},
},
},
},
Title: sd.Title,
Size: sd.Size,
FixedSize: sd.FixedSize,
}).Run(owner); err != nil {
return false, err
}
return
}