This repository has been archived by the owner on Apr 26, 2021. It is now read-only.
/
searchWindow.go
88 lines (80 loc) · 2.31 KB
/
searchWindow.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
// searchWindow.go
/// +build OMIT
package main
import "github.com/andlabs/ui"
// Make dialog box with callback functions to allow or deny action. fyes give entry.text value
func DialogBoxEntrySearch(mainwin *ui.Window, title, yes, no string, fyes func(entry string, cs, ww, rx bool), fno func(), text ...string) {
if mainwin == nil {
panic("mainwin not present !!!")
}
mainwin.Disable()
dialogWindow := ui.NewWindow(title, 10, 10, false)
dialogWindow.OnClosing(func(*ui.Window) bool {
mainwin.Enable() // Make MAINWIN enaled
return true
})
ui.OnShouldQuit(func() bool {
dialogWindow.Destroy()
return true
})
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
// Display given message
for _, txt := range text {
vbox.Append(ui.NewLabel(txt), false) // Label with txt
}
// Add Option search
hbox := ui.NewHorizontalBox()
vbox.Append(hbox, true)
chkWholeWord := ui.NewCheckbox("Whole word")
chkCaseSensitive := ui.NewCheckbox("Case sensitive")
chkRegex := ui.NewCheckbox("Use regex")
chkWholeWord.OnToggled(func(*ui.Checkbox) {
chkRegex.SetChecked(false)
})
chkRegex.OnToggled(func(*ui.Checkbox) {
chkWholeWord.SetChecked(false)
})
hbox.Append(chkWholeWord, true)
hbox.Append(chkCaseSensitive, true)
hbox.Append(chkRegex, true)
// Add entry control
entry := ui.NewEntry()
vbox.Append(entry, true)
// Make a grid to set position of buttons
grid := ui.NewGrid()
grid.SetPadded(true)
vbox.Append(grid, false)
// Implement button "Yes"
okButton := ui.NewButton(yes)
okButton.OnClicked(func(*ui.Button) {
toSearch := entry.Text() // Catch entry before destroying window ...
cs := chkCaseSensitive.Checked()
ww := chkWholeWord.Checked()
rx := chkRegex.Checked()
dialogWindow.Destroy()
fyes(toSearch, cs, ww, rx)
mainwin.Enable()
})
// Implement button "No"
noButton := ui.NewButton(no)
noButton.OnClicked(func(*ui.Button) {
dialogWindow.Destroy()
fno()
mainwin.Enable()
})
// Add buttons
grid.Append(ui.NewLabel(""), // Fake controle to align buttons at right end.
1, 2, 1, 1,
true, ui.AlignFill, false, ui.AlignEnd)
grid.Append(okButton,
2, 2, 1, 1,
false, ui.AlignEnd, false, ui.AlignEnd)
grid.Append(noButton,
3, 2, 1, 1,
false, ui.AlignEnd, false, ui.AlignEnd)
// Let's show result
dialogWindow.SetChild(vbox)
dialogWindow.SetMargined(true)
dialogWindow.Show()
}