-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhistory.go
59 lines (49 loc) · 1.06 KB
/
history.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
package main
import (
"errors"
)
// historical record
type hRecord struct {
screen activeScreen
id int
}
func historyInit() {
addMessage(message{isError: false, message: "History system intialized"})
}
func historyAdd(rec hRecord) {
app.hist = append(app.hist, rec)
}
// go to the last projects or items screen we were on
func historyGoToLast(screens activeScreen) error {
for i := len(app.hist) - 1; i >= 0; i-- {
rec := app.hist[i]
if rec.screen&screens != 0 {
return historyGoTo(rec)
}
}
return errors.New("Screen not found")
}
func historyGoTo(rec hRecord) error {
switch rec.screen {
case items:
// set the project via its ID
if rec.id == -1 {
app.ui.project = getToday()
} else if rec.id == -2 {
app.ui.project = getTomorrow()
} else {
for key, value := range app.todoist.Projects {
if value.ID == rec.id {
app.ui.project = &app.todoist.Projects[key]
break
}
}
}
showScreen(rec.screen)
return nil
case projects:
showScreen(rec.screen)
return nil
}
return errors.New("Unable to go to history")
}