forked from VladimirMarkelov/clui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfselect.go
99 lines (82 loc) · 2.33 KB
/
fselect.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
package main
import (
ui "github.com/VladimirMarkelov/clui"
)
func createView() {
view := ui.AddWindow(0, 0, 30, 7, "File select")
view.SetPack(ui.Vertical)
view.SetGaps(0, 1)
view.SetPaddings(2, 2)
frmPath := ui.CreateFrame(view, 1, 1, ui.BorderNone, ui.Fixed)
frmPath.SetPack(ui.Horizontal)
ui.CreateLabel(frmPath, ui.AutoSize, ui.AutoSize, "Initial path", ui.Fixed)
edPath := ui.CreateEditField(frmPath, 16, "", 1)
frmMask := ui.CreateFrame(view, 1, 1, ui.BorderNone, ui.Fixed)
frmMask.SetPack(ui.Horizontal)
ui.CreateLabel(frmMask, ui.AutoSize, ui.AutoSize, "File masks", ui.Fixed)
edMasks := ui.CreateEditField(frmMask, 16, "*", 1)
frmOpts := ui.CreateFrame(view, 1, 1, ui.BorderNone, ui.Fixed)
frmOpts.SetPack(ui.Horizontal)
cbDir := ui.CreateCheckBox(frmOpts, ui.AutoSize, "Select directory", ui.Fixed)
cbMust := ui.CreateCheckBox(frmOpts, ui.AutoSize, "Must exists", ui.Fixed)
ui.CreateFrame(frmOpts, 1, 1, ui.BorderNone, 1)
lblSelected := ui.CreateLabel(view, 30, 5, "Selected:", ui.Fixed)
lblSelected.SetMultiline(true)
frmBtns := ui.CreateFrame(view, 1, 1, ui.BorderNone, ui.Fixed)
frmBtns.SetPack(ui.Horizontal)
btnSet := ui.CreateButton(frmBtns, ui.AutoSize, 4, "Select", ui.Fixed)
btnQuit := ui.CreateButton(frmBtns, ui.AutoSize, 4, "Quit", ui.Fixed)
ui.CreateFrame(frmBtns, 1, 1, ui.BorderNone, 1)
ui.ActivateControl(view, edMasks)
btnSet.OnClick(func(ev ui.Event) {
s := "Select "
if cbDir.State() == 1 {
s += "directory"
} else {
s += "file"
}
if cbMust.State() == 1 {
s += "[X]"
}
dlg := ui.CreateFileSelectDialog(
s,
edMasks.Title(),
edPath.Title(),
cbDir.State() == 1,
cbMust.State() == 1)
dlg.OnClose(func() {
if !dlg.Selected {
lblSelected.SetTitle("Selected:\nNothing")
return
}
var lb string
if dlg.Exists {
lb = "Selected existing"
} else {
lb = "Create new"
}
if cbDir.State() == 0 {
lb += " file:\n"
} else {
lb += " directory:\n"
}
lb += dlg.FilePath
lblSelected.SetTitle(lb)
})
})
btnQuit.OnClick(func(ev ui.Event) {
go ui.Stop()
})
}
func mainLoop() {
// Every application must create a single Composer and
// call its intialize method
ui.InitLibrary()
defer ui.DeinitLibrary()
createView()
// start event processing loop - the main core of the library
ui.MainLoop()
}
func main() {
mainLoop()
}