-
Notifications
You must be signed in to change notification settings - Fork 0
/
organizer_methods.go
226 lines (186 loc) · 3.84 KB
/
organizer_methods.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
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
package main
import (
"strings"
)
func (o *Organizer) getMode() Mode {
if len(o.rows) > 0 {
return NORMAL
} else {
return NO_ROWS
}
}
func (o *Organizer) moveAltCursor(key int) {
if len(o.altRows) == 0 {
return
}
//o.fc = 0
switch key {
case ARROW_UP, 'k':
if o.altFr > 0 {
o.altFr--
}
case ARROW_DOWN, 'j':
if o.altFr < len(o.altRows)-1 {
o.altFr++
}
}
}
func (o *Organizer) getWordUnderCursor() {
t := &o.rows[o.fr].title
delimiters := " ,.;?:()[]{}&#"
if strings.IndexAny(string((*t)[o.fc]), delimiters) != -1 {
return
}
var beg int
if o.fc != 0 {
beg = strings.LastIndexAny((*t)[:o.fc], delimiters)
if beg == -1 {
beg = 0
} else {
beg++
}
}
end := strings.IndexAny((*t)[o.fc:], delimiters)
if end == -1 {
end = len(*t) - 1
} else {
end = end + o.fc - 1
}
o.title_search_string = (*t)[beg : end+1]
}
func (o *Organizer) findNextWord() {
var n int
if o.fr < len(o.rows)-1 {
n = o.fr + 1
} else {
n = 0
}
for {
if n == len(o.rows) {
n = 0
}
pos := strings.Index(o.rows[n].title, o.title_search_string)
if pos == -1 {
continue
} else {
o.fr = n
o.fc = pos
return
}
n++
}
}
/*
func (o *Organizer) changeCase() {
t := &o.rows[o.fr].title
char := rune((*t)[o.fc])
if unicode.IsLower(char) {
char = unicode.ToUpper(char)
} else {
char = unicode.ToLower(char)
}
*t = (*t)[:o.fc] + string(char) + (*t)[o.fc+1:]
o.rows[o.fr].dirty = true
}
*/
//func (o *Organizer) insertRow(at int, s string, star bool, deleted bool, completed bool, modified string) {
func (o *Organizer) insertRow(at int, s string, star bool, deleted bool, archived bool, sort string) {
/* note since only inserting blank line at top, don't really need at, s and also don't need size_t*/
var row Row
o.rows = append(o.rows, row) //make sure there is room to expand o.rows
copy(o.rows[at+1:], o.rows[at:]) // move everything one over that will be to the right of new entry
row.title = s
row.id = -1
row.star = star
row.deleted = deleted
row.archived = archived
row.dirty = true
//row.modified = modified
row.sort = sort
row.marked = false
o.rows[at] = row
}
func (o *Organizer) scroll() {
if o.mode == ADD_CHANGE_FILTER {
o.altScroll()
return
}
if len(o.rows) == 0 {
o.fr, o.fc, o.coloff, o.rowoff, o.cx, o.cy = 0, 0, 0, 0, 0, 0
return
}
titlecols := sess.divider - TIME_COL_WIDTH - LEFT_MARGIN
if o.fr > sess.textLines+o.rowoff-1 {
o.rowoff = o.fr - sess.textLines + 1
}
if o.fr < o.rowoff {
o.rowoff = o.fr
}
if o.fc > titlecols+o.coloff-1 {
o.coloff = o.fc - titlecols + 1
}
if o.fc < o.coloff {
o.coloff = o.fc
}
o.cx = o.fc - o.coloff
o.cy = o.fr - o.rowoff
}
func (o *Organizer) altScroll() {
if len(o.altRows) == 0 {
return
}
prevRowoff := o.altRowoff
if o.altFr > sess.textLines+o.altRowoff-1 {
o.altRowoff = o.altFr - sess.textLines + 1
}
if o.altFr < o.altRowoff {
o.altRowoff = o.altFr
}
if prevRowoff != o.altRowoff {
sess.eraseRightScreen()
}
}
func (o *Organizer) insertChar(c int) {
if len(o.rows) == 0 {
return
}
t := &o.rows[o.fr].title
if *t == "" {
*t = string(c)
} else {
*t = (*t)[:o.fc] + string(c) + (*t)[o.fc:]
}
o.fc++
o.rows[o.fr].dirty = true
}
func (o *Organizer) writeTitle() {
row := &o.rows[o.fr]
if !row.dirty {
sess.showOrgMessage("Row has not been changed")
return
}
if o.view == TASK {
updateTitle()
} else {
updateContainerTitle()
}
o.command = ""
//sess.showOrgMessage("Updated id %d to %s (+fts if Entry)", row.id, truncate(row.title, 15))
o.refreshScreen()
}
func (o *Organizer) clearMarkedEntries() {
for k, _ := range o.marked_entries {
delete(o.marked_entries, k)
}
}
/*
std::string Organizer::outlineRowsToString(void) {
std::string s = "";
for (auto i: rows) {
s += i.title;
s += '\n';
}
s.pop_back(); //pop last return that we added
return s;
}
*/