-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
84 lines (72 loc) · 2.27 KB
/
settings.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
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/data/validation"
"fyne.io/fyne/v2/driver/mobile"
"fyne.io/fyne/v2/widget"
)
type Settings struct {
maxworkers uint
maxfilesize uint
includesubfolders bool
//windowsize
winx float32
winy float32
fullscreen bool
}
var DefaultSettings = Settings{
maxworkers: 8,
maxfilesize: 100,
includesubfolders: true,
}
func (s *Settings) LoadSettings() {
app := fyne.CurrentApp()
s.maxworkers = uint(app.Preferences().IntWithFallback("maxworkers", int(DefaultSettings.maxworkers)))
s.maxfilesize = uint(app.Preferences().IntWithFallback("maxfilesize", int(DefaultSettings.maxfilesize)))
s.includesubfolders = app.Preferences().BoolWithFallback("includesubfolders", DefaultSettings.includesubfolders)
//
s.winx = float32(app.Preferences().FloatWithFallback("winx", 800))
s.winy = float32(app.Preferences().FloatWithFallback("winy", 600))
s.fullscreen = app.Preferences().BoolWithFallback("fullscreen", false)
}
func (s *Settings) LoadDefaults() {
s.maxworkers = DefaultSettings.maxworkers
s.maxfilesize = DefaultSettings.maxfilesize
s.includesubfolders = DefaultSettings.includesubfolders
}
func (s *Settings) SaveSettings(winx, winy float32, fullscreen bool) {
app := fyne.CurrentApp()
app.Preferences().SetInt("maxworkers", int(s.maxworkers))
app.Preferences().SetInt("maxfilesize", int(s.maxfilesize))
app.Preferences().SetBool("includesubfolders", s.includesubfolders)
//
app.Preferences().SetFloat("winx", float64(winx))
app.Preferences().SetFloat("winy", float64(winy))
app.Preferences().SetBool("fullscreen", fullscreen)
}
func (s *Settings) ApplySettings(maxworkers, maxfilesize uint, includesubfolders bool) {
s.maxworkers = maxworkers
s.maxfilesize = maxfilesize
s.includesubfolders = includesubfolders
}
func NewFormItemWithHintText(text string, o fyne.CanvasObject, hint string) *widget.FormItem {
fi := widget.NewFormItem(text, o)
fi.HintText = hint
return fi
}
type numEntry struct {
widget.Entry
}
func (n *numEntry) Keyboard() mobile.KeyboardType {
return mobile.NumberKeyboard
}
func newNumEntry() *numEntry {
e := &numEntry{}
e.ExtendBaseWidget(e)
e.Validator = validation.NewRegexp(`\d`, "Must contain a number")
return e
}
// load
// save
// on change
// subwindowpopup