-
Notifications
You must be signed in to change notification settings - Fork 13
/
dialogs.go
58 lines (48 loc) · 1.28 KB
/
dialogs.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
package main
import (
"github.com/diamondburned/gotk4-adwaita/pkg/adw"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
)
type Confirmation struct {
Heading string
Body string
Accept string
Reject string
}
func (d Confirmation) Show(a *App, res func(bool)) {
dialog := adw.NewMessageDialog(&a.win.Window, d.Heading, d.Body)
dialog.AddResponse("reject", d.Reject)
dialog.SetCloseResponse("reject")
dialog.AddResponse("accept", d.Accept)
dialog.SetResponseAppearance("accept", adw.ResponseSuggested)
dialog.SetDefaultResponse("accept")
dialog.ConnectResponse(func(response string) {
res(response == "accept")
})
dialog.Show()
}
type Prompt struct {
Heading string
Body string
}
func (d Prompt) Show(a *App, res func(val string)) {
input := gtk.NewText()
dialog := adw.NewMessageDialog(&a.win.Window, d.Heading, d.Body)
dialog.SetExtraChild(input)
dialog.AddResponse("cancel", "_Cancel")
dialog.SetCloseResponse("cancel")
dialog.AddResponse("add", "_Add")
dialog.SetResponseAppearance("add", adw.ResponseSuggested)
dialog.SetDefaultResponse("add")
dialog.ConnectResponse(func(response string) {
switch response {
case "add":
res(input.Buffer().Text())
}
})
input.ConnectActivate(func() {
defer dialog.Close()
res(input.Buffer().Text())
})
dialog.Show()
}