-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
415 lines (349 loc) · 12.6 KB
/
Copy pathmain.go
File metadata and controls
415 lines (349 loc) · 12.6 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
package main
import (
"encoding/csv"
"fmt"
"os"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
type Task struct {
name string
description string
text string
status string
lastChanged string
}
func main() {
a := app.New()
a.Settings().SetTheme(theme.DarkTheme())
w := a.NewWindow("Task Manager")
toggleEdit := false
toggleNew := false
statuses := []string{"Open", "Closed"}
// adding Edit shortcut
ctrlE := &desktop.CustomShortcut{KeyName: fyne.KeyE, Modifier: fyne.KeyModifierControl}
// ading New shorcut
ctrlW := &desktop.CustomShortcut{KeyName: fyne.KeyW, Modifier: fyne.KeyModifierControl}
// adding Save current text shortcut
ctrlS := &desktop.CustomShortcut{KeyName: fyne.KeyS, Modifier: fyne.KeyModifierControl}
// adding Delete current task shortcut
ctrlD := &desktop.CustomShortcut{KeyName: fyne.KeyD, Modifier: fyne.KeyModifierControl}
// adding Delete current task shortcut
lightMode := false
ctrlL := &desktop.CustomShortcut{KeyName: fyne.KeyL, Modifier: fyne.KeyModifierControl}
ctrlOne := &desktop.CustomShortcut{KeyName: fyne.Key1, Modifier: fyne.KeyModifierControl}
ctrlTwo := &desktop.CustomShortcut{KeyName: fyne.Key2, Modifier: fyne.KeyModifierControl}
ctrlThree := &desktop.CustomShortcut{KeyName: fyne.Key3, Modifier: fyne.KeyModifierControl}
ctrlFour := &desktop.CustomShortcut{KeyName: fyne.Key4, Modifier: fyne.KeyModifierControl}
//adding to canvas and defining function for the ctrl E shortcut
file, err := os.Open("tasks.csv")
if err != nil {
os.Create("tasks.csv")
}
reader := csv.NewReader(file)
records, _ := reader.ReadAll()
// Initializing list
var data = []string{}
// Intialing selected task to be handled later
var currTask = new(Task)
currTask.name = ""
currTask.description = ""
currTask.text = ""
currTask.status = ""
currTask.lastChanged = ""
var currId int
currId = -1
fmt.Println(records)
// Passing names to the sidebar
for i := 0; i < len(records); i++ {
fmt.Println(records[i][0])
data = append(data, records[i][0])
}
taskList := widget.NewList(
func() int {
return len(data)
},
func() fyne.CanvasObject {
return widget.NewLabel("template")
},
func(i widget.ListItemID, o fyne.CanvasObject) {
o.(*widget.Label).SetText(data[i])
})
headerContent := "# Select a task or create a new one (Ctrl+W)"
taskHeader := widget.NewRichTextFromMarkdown(" ")
taskHeader.ParseMarkdown(headerContent)
notes := widget.NewMultiLineEntry()
notes.SetText(currTask.text)
saveBtn := widget.NewButtonWithIcon("Save", theme.DocumentSaveIcon(), func() {
// Deal on how to save the textbox to the file
// Must change commas in user text to "," or find other way to handle it
fmt.Println("Pressionado")
currTask.text = notes.Text
records[currId][2] = currTask.text
records[currId][4] = time.Now().String()[0:19]
fmt.Println(records[currId])
fileW, e := os.OpenFile("tasks.csv", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
writer := csv.NewWriter(fileW)
e = writer.WriteAll(records)
if e != nil {
fmt.Println(e)
}
fmt.Println(time.Now().String()[0:19])
})
bottomContent := container.NewVBox(saveBtn)
taskList.OnSelected = func(id widget.ListItemID) {
fmt.Println(id)
currId = id
currTask.name = records[currId][0]
currTask.description = records[currId][1]
currTask.text = records[currId][2]
currTask.status = records[currId][3]
currTask.lastChanged = records[currId][4]
headerContent = "# " + currTask.name + "\n## " + currTask.description + "\n ### Status: " + currTask.status + " - Changed on: " + currTask.lastChanged
fmt.Println(headerContent)
taskHeader.ParseMarkdown(headerContent)
// Setting the text in the editor for the current task
notes.SetText(currTask.text)
content := container.NewBorder(taskHeader, bottomContent, taskList, nil, notes)
w.SetContent(content)
}
// Setting edit window
editName := widget.NewEntry()
editDescription := widget.NewEntry()
editStatus := widget.NewSelect(statuses, func(s string) {
fmt.Println(s)
})
saveEditBtn := widget.NewButtonWithIcon("Save Task", theme.DocumentSaveIcon(), func() {
// Deal on how to save the textbox to the file
// Must change commas in user text to "," or find other way to handle it
fmt.Println("Pressionado")
//editName.Text = currTask.name
//editDescription.Text = currTask.description
//editStatus.Selected = currTask.status
records[currId][0] = editName.Text
records[currId][1] = editDescription.Text
records[currId][3] = editStatus.Selected
records[currId][4] = time.Now().String()[0:19]
fmt.Println(records[currId])
fileW, e := os.OpenFile("tasks.csv", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
writer := csv.NewWriter(fileW)
e = writer.WriteAll(records)
if e != nil {
fmt.Println(e)
}
// Redefining the sidebar so it can pickup name changes
file, err = os.Open("tasks.csv")
if err != nil {
os.Create("tasks.csv")
}
// Clearing data array so it can be populated again
data = []string{}
reader = csv.NewReader(file)
records, _ = reader.ReadAll()
for i := 0; i < len(records); i++ {
fmt.Println(records[i][0])
data = append(data, records[i][0])
}
// Now must refresh top header and go back to main window
currTask.name = records[currId][0]
currTask.description = records[currId][1]
currTask.status = records[currId][3]
currTask.lastChanged = records[currId][4]
headerContent = "# " + currTask.name + "\n## " + currTask.description + "\n ### Status: " + currTask.status + " - Changed on: " + currTask.lastChanged
taskHeader.ParseMarkdown(headerContent)
taskHeader.Refresh()
taskList.Refresh()
content := container.NewBorder(taskHeader, bottomContent, taskList, nil, notes)
w.SetContent(content)
toggleEdit = false
})
editContent := container.NewVBox(widget.NewLabel("Task Name"), editName, widget.NewLabel("Task Description"), editDescription, widget.NewLabel("Task Status"), editStatus, saveEditBtn)
w.Canvas().AddShortcut(ctrlE, func(shortcut fyne.Shortcut) {
// Flip between true and false to toggle edit mdoe or not
fmt.Println("Ctrl+E")
if currId == -1 {
dialog.ShowInformation("Error", "Select a task before editing.", w)
return
}
toggleEdit = !toggleEdit
if toggleEdit {
toggleNew = false
editName.Text = currTask.name
editDescription.Text = currTask.description
editStatus.Selected = currTask.status
editContent = container.NewVBox(widget.NewLabel("Task Name"), editName, widget.NewLabel("Task Description"), editDescription, widget.NewLabel("Task Status"), editStatus, saveEditBtn)
editContent.Refresh()
content := container.NewBorder(taskHeader, bottomContent, taskList, nil, editContent)
w.SetContent(content)
} else {
content := container.NewBorder(taskHeader, bottomContent, taskList, nil, notes)
w.SetContent(content)
}
})
// Setting New task window
newName := widget.NewEntry()
newDescription := widget.NewEntry()
newStatus := widget.NewSelect(statuses, func(s string) {
fmt.Println(s)
})
saveNewBtn := widget.NewButtonWithIcon("Add New Task", theme.DocumentSaveIcon(), func() {
// Deal on how to save the textbox to the file
// Must change commas in user text to "," or find other way to handle it
fmt.Println("Novo - Pressionado")
// SELECT A NEW ID MAX + 1 AND APPEND TO THE RECORDS SLICE
if newName.Text == "" {
newName.Text = "(new task)"
}
if newStatus.Selected == "" {
newStatus.Selected = statuses[0]
}
newRecord := []string{newName.Text, newDescription.Text, "Insert notes here...", newStatus.Selected, time.Now().String()[0:19]}
records = append(records, newRecord)
fileW, e := os.OpenFile("tasks.csv", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
writer := csv.NewWriter(fileW)
e = writer.WriteAll(records)
if e != nil {
fmt.Println(e)
}
// Redefining the sidebar
file, err = os.Open("tasks.csv")
if err != nil {
os.Create("tasks.csv")
}
// Clearing data array so it can be populated again
data = []string{}
reader = csv.NewReader(file)
records, _ = reader.ReadAll()
for i := 0; i < len(records); i++ {
fmt.Println(records[i][0])
data = append(data, records[i][0])
}
// Now must refresh the sidebar and go back to main window
taskList.Refresh()
content := container.NewBorder(taskHeader, bottomContent, taskList, nil, notes)
content.Refresh()
w.SetContent(content)
toggleNew = false
})
newContent := container.NewVBox(widget.NewLabel("New Task Name"), newName, widget.NewLabel("New Task Description"), newDescription, widget.NewLabel("New Task Status"), newStatus, saveNewBtn)
w.Canvas().AddShortcut(ctrlW, func(shortcut fyne.Shortcut) {
// Flip between true and false to toggle edit mdoe or not
fmt.Println("Ctrl+W")
toggleNew = !toggleNew
if toggleNew {
toggleEdit = false
content := container.NewBorder(taskHeader, bottomContent, taskList, nil, newContent)
w.SetContent(content)
} else {
content := container.NewBorder(taskHeader, bottomContent, taskList, nil, notes)
w.SetContent(content)
}
})
w.Canvas().AddShortcut(ctrlS, func(shortcut fyne.Shortcut) {
// Flip between true and false to toggle mode or not
fmt.Println("Ctrl+S")
// Deal on how to save the textbox to the file
// Must change commas in user text to "," or find other way to handle it
fmt.Println("Pressionado")
currTask.text = notes.Text
records[currId][2] = currTask.text
records[currId][4] = time.Now().String()[0:19]
fmt.Println(records[currId])
fileW, e := os.OpenFile("tasks.csv", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
writer := csv.NewWriter(fileW)
e = writer.WriteAll(records)
if e != nil {
fmt.Println(e)
}
// Updating Header
fmt.Println(time.Now().String()[0:19])
currTask.lastChanged = records[currId][4]
headerContent = "# " + currTask.name + "\n## " + currTask.description + "\n ### Status: " + currTask.status + " - Changed on: " + currTask.lastChanged
taskHeader.ParseMarkdown(headerContent)
taskHeader.Refresh()
content := container.NewBorder(taskHeader, bottomContent, taskList, nil, notes)
w.SetContent(content)
})
w.Canvas().AddShortcut(ctrlD, func(shortcut fyne.Shortcut) {
fmt.Println("Ctrl+D")
if toggleEdit == true || toggleNew == true {
return
}
if currId == -1 {
return
}
records = append(records[:currId], records[currId+1:]...)
fileW, e := os.OpenFile("tasks.csv", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
writer := csv.NewWriter(fileW)
e = writer.WriteAll(records)
if e != nil {
fmt.Println(e)
}
// Redefining the sidebar
file, err = os.Open("tasks.csv")
if err != nil {
os.Create("tasks.csv")
}
// Clearing data array so it can be populated again
data = []string{}
reader = csv.NewReader(file)
records, _ = reader.ReadAll()
for i := 0; i < len(records); i++ {
fmt.Println(records[i][0])
data = append(data, records[i][0])
}
// Reseting list
currId = -1
taskList.UnselectAll()
// Now must refresh the sidebar and go back to main window
taskList.Refresh()
headerContent = "# Select a task or create a new one (Ctrl+W)"
taskHeader.ParseMarkdown(headerContent)
taskHeader.Refresh()
content := container.NewBorder(taskHeader, bottomContent, taskList, nil, notes)
content.Refresh()
w.SetContent(content)
})
w.Canvas().AddShortcut(ctrlL, func(shortcut fyne.Shortcut) {
fmt.Println("Ctrl+L")
if lightMode == true {
a.Settings().SetTheme(theme.DarkTheme())
lightMode = false
return
}
a.Settings().SetTheme(theme.LightTheme())
lightMode = true
})
// Numeric shortcuts
// Ctrl + 1
w.Canvas().AddShortcut(ctrlOne, func(shortcut fyne.Shortcut) {
fmt.Println("Ctrl+1")
taskList.Select(0)
})
// Ctrl + 2
w.Canvas().AddShortcut(ctrlTwo, func(shortcut fyne.Shortcut) {
fmt.Println("Ctrl+2")
taskList.Select(1)
})
// Ctrl + 3
w.Canvas().AddShortcut(ctrlThree, func(shortcut fyne.Shortcut) {
fmt.Println("Ctrl+3")
taskList.Select(2)
})
// Ctrl + 4
w.Canvas().AddShortcut(ctrlFour, func(shortcut fyne.Shortcut) {
fmt.Println("Ctrl+4")
taskList.Select(3)
})
content := container.NewBorder(taskHeader, bottomContent, taskList, nil, notes)
w.SetContent(content)
w.CenterOnScreen()
w.Resize(fyne.NewSize(1280, 720))
w.ShowAndRun()
}