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
|
package main
import (
"fmt"
"os"
"strings"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
)
const (
appId = "org.buetow.quicklogger"
placeholderText = "Enter text here..."
)
var (
defaultDirectory = "."
defaultTagItems = []string{
"log",
"share",
"share:li",
"share:ma",
"track",
"track 10",
"track 15",
"track 20",
"track 25",
"track 30",
"track 5",
"work",
}
defaultWhatItems = []string{
"Breathing",
"Bulgarian",
"Ema",
"Exercise",
"Meditation",
"Music",
"Reading Articles",
"Reading Books",
"Stretching",
"Tech",
}
)
var windowSize = fyne.NewSize(400, 100)
func createPreferenceWindow(a fyne.App) fyne.Window {
window := a.NewWindow("Preferences")
directoryPreference := widget.NewEntry()
directoryPreference.SetText(a.Preferences().StringWithFallback("Directory", defaultDirectory))
tagDropdownPreference := widget.NewEntry()
tagDropdownPreference.SetText(a.Preferences().StringWithFallback("Tags", strings.Join(defaultTagItems, ",")))
whatDropdownPreference := widget.NewEntry()
whatDropdownPreference.SetText(a.Preferences().StringWithFallback("Whats", strings.Join(defaultWhatItems, ",")))
window.SetContent(container.NewVBox(
container.NewVBox(
widget.NewLabel("Directory:"),
directoryPreference,
widget.NewLabel("Tags:"),
tagDropdownPreference,
widget.NewLabel("Whats:"),
whatDropdownPreference,
),
container.NewHBox(
widget.NewButton("Save", func() {
a.Preferences().SetString("Directory", directoryPreference.Text)
a.Preferences().SetString("Tags", tagDropdownPreference.Text)
a.Preferences().SetString("Whats", whatDropdownPreference.Text)
window.Hide()
}),
widget.NewButton("Reset dropdowns", func() {
// directoryPreference.SetText(defaultDirectory)
tagDropdownPreference.SetText(strings.Join(defaultTagItems, ","))
whatDropdownPreference.SetText(strings.Join(defaultWhatItems, ","))
},
),
)))
window.Resize(windowSize)
return window
}
func createMainWindow(a fyne.App) fyne.Window {
// Create main window
window := a.NewWindow("Quick logger")
input := widget.NewMultiLineEntry()
input.Wrapping = fyne.TextWrapWord
input.SetPlaceHolder(placeholderText)
input.SetMinRowsVisible(30)
// Dropdown with pre-selectable items
daysDropdown := widget.NewSelect([]string{"0", "1", "3", "7", "14", "30", "60", "99"}, func(selected string) {
input.SetText(selected + " ")
window.Canvas().Focus(input)
})
daysDropdown.PlaceHolder = "Days"
tagDropdownItems := strings.Split(a.Preferences().StringWithFallback("Tags", strings.Join(defaultTagItems, ",")), ",")
tagDropdown := widget.NewSelect(tagDropdownItems, func(selected string) {
input.Append(selected + " ")
window.Canvas().Focus(input)
})
tagDropdown.PlaceHolder = "Tag"
whatDropdownItems := strings.Split(a.Preferences().StringWithFallback("Whats", strings.Join(defaultWhatItems, ",")), ",")
whatDropdown := widget.NewSelect(whatDropdownItems, func(selected string) {
input.Append(selected + " ")
window.Canvas().Focus(input)
input.Cursor()
})
whatDropdown.PlaceHolder = "What"
logTextButton := widget.NewButton("Log text", func() {
filename := fmt.Sprintf("%s/ql-%s.md",
a.Preferences().StringWithFallback("Directory", defaultDirectory),
time.Now().Format("060102-150405"),
)
if err := os.WriteFile(filename, []byte(input.Text), 0644); err != nil {
dialog.ShowError(err, window)
return
}
input.SetText("")
input.SetPlaceHolder(placeholderText)
})
window.SetContent(container.NewVBox(
container.NewHBox(daysDropdown, tagDropdown, whatDropdown, logTextButton),
input,
widget.NewButton("Preferences", func() {
createPreferenceWindow(a).Show()
}),
))
window.Resize(windowSize)
window.Canvas().Focus(input)
return window
}
func main() {
createMainWindow(app.NewWithID(appId)).ShowAndRun()
}
|