-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.go
152 lines (134 loc) · 3.42 KB
/
gui.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package main
import (
g "github.com/AllenDang/giu"
"github.com/sirupsen/logrus"
"github.com/sqweek/dialog"
"image"
"time"
)
var (
guiConfigCopy AutomoverConfig
selectedIndex int
)
var (
sashPos1 float32 = 500
sashPos2 float32 = 500
)
func guiLoop() {
listBoxStr := make([]string, 0)
for _, folder := range guiConfigCopy.Watchlist {
listBoxStr = append(listBoxStr, folder.WatchPath+"\n -> "+folder.WatchPattern+" -> \n"+folder.DestinationPath)
}
var pathStr *string
var regexStr *string
var destinationStr *string
if selectedIndex >= 0 && selectedIndex < len(guiConfigCopy.Watchlist) {
pathStr = &guiConfigCopy.Watchlist[selectedIndex].WatchPath
regexStr = &guiConfigCopy.Watchlist[selectedIndex].WatchPattern
destinationStr = &guiConfigCopy.Watchlist[selectedIndex].DestinationPath
} else {
pathStr = new(string)
regexStr = new(string)
destinationStr = new(string)
}
log := string(logFacet.ReadLastLines(100))
g.SingleWindow().Layout(
g.SplitLayout(g.DirectionHorizontal, &sashPos1, g.Layout{
g.SplitLayout(g.DirectionVertical, &sashPos2, g.Layout{
g.Label("Watchlist"),
g.ListBox("ListBox1", listBoxStr).OnChange(func(ind int) {
selectedIndex = ind
}).Size(-1, 400),
g.Row(
g.Button("Add").OnClick(func() {
guiConfigCopy.Watchlist = append(guiConfigCopy.Watchlist, AutomoverWatchedFolder{
WatchPath: "C:\\Users\\User\\Downloads",
WatchPattern: "*",
DestinationPath: "C:\\Users\\User\\Downloads\\test",
})
}),
g.Button("Delete").OnClick(func() {
if selectedIndex >= 0 && selectedIndex < len(guiConfigCopy.Watchlist) {
guiConfigCopy.Watchlist = append(guiConfigCopy.Watchlist[:selectedIndex], guiConfigCopy.Watchlist[selectedIndex+1:]...)
selectedIndex = -1
}
}),
),
}, g.Layout{
g.Row(
g.Label("Path:"),
g.Button("Browse to select").OnClick(func() {
path, err := dialog.Directory().Browse()
if err != nil {
return
}
*pathStr = path
}),
),
g.InputText(pathStr).Size(-1),
g.Spacing(),
g.Label("Regex:"),
g.InputText(regexStr).Size(-1),
g.Spacing(),
g.Row(
g.Label("Destination:"),
g.Button("Browse to select").OnClick(func() {
path, err := dialog.Directory().Browse()
if err != nil {
return
}
*destinationStr = path
}),
),
g.InputText(destinationStr).Size(-1),
g.Spacing(),
g.Spacing(),
g.Spacing(),
g.Row(
g.Button("Save").OnClick(func() {
tmpCurrentCfg := config
config = guiConfigCopy
err := saveConfig()
if err != nil {
logrus.Info("Error saving config: ", err)
config = tmpCurrentCfg
} else {
stopWatcher()
startWatcher()
logrus.Info("Config saved, restarting watcher...")
}
}).Size(-1, 25),
),
}),
}, g.Layout{
g.Label("Logs"),
g.InputTextMultiline(&log).
Size(-1, -1).
Flags(g.InputTextFlagsReadOnly).
AutoScrollToBottom(true),
}),
)
}
func runGiu() {
guiConfigCopy = config
wnd := g.NewMasterWindow("Automover - github.com/reaganiwadha", 1000, 700, 0)
wnd.SetIcon([]image.Image{
scienceTinyIconPng,
})
done := make(chan bool)
go func() {
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
for {
select {
case <-done:
return
case <-ticker.C:
g.Update()
}
}
}()
wnd.Run(guiLoop)
close(done)
wndVisible = false
}