-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorganizer_normal.go
More file actions
373 lines (317 loc) · 10 KB
/
organizer_normal.go
File metadata and controls
373 lines (317 loc) · 10 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
package main
import (
"fmt"
"maps"
"slices"
"sort"
"strings"
"github.com/slzatz/vimango/vim"
// "github.com/charmbracelet/glamour"
)
func (a *App) setOrganizerNormalCmds(organizer *Organizer) map[string]func(*Organizer) {
registry := NewCommandRegistry[func(*Organizer)]()
// Entry Actions commands
registry.Register(string(0x4), (*Organizer).del, CommandInfo{
Name: keyToDisplayName(string(0x4)),
Description: "Toggle delete status of current note",
Category: "Entry Actions",
})
registry.Register(string(0x1), (*Organizer).star, CommandInfo{
Name: keyToDisplayName(string(0x1)),
Description: "Toggle star status of current note",
Category: "Entry Actions",
})
registry.Register(string(0x18), (*Organizer).archive, CommandInfo{
Name: keyToDisplayName(string(0x18)),
Description: "Toggle archive status of current note",
Category: "Entry Actions",
})
registry.Register("m", (*Organizer).mark, CommandInfo{
Name: keyToDisplayName("m"),
Description: "Toggle mark on current note for batch operations",
Category: "Entry Actions",
})
// Navigation commands
registry.Register(string(ctrlKey('j')), (*Organizer).scrollPreviewDown, CommandInfo{
Name: keyToDisplayName(string(ctrlKey('j'))) + "/PgDn",
Aliases: []string{string(PAGE_DOWN)},
Description: "Scroll rendered note down",
Category: "Navigation",
})
registry.Register(string(ctrlKey('k')), (*Organizer).scrollPreviewUp, CommandInfo{
Name: keyToDisplayName(string(ctrlKey('k'))) + "/PgUp",
Aliases: []string{string(PAGE_UP)},
Description: "Scroll rendered note up",
Category: "Navigation",
})
registry.Register(string(ctrlKey('f')), (*Organizer).newFolderNormal, CommandInfo{
Name: keyToDisplayName(string(ctrlKey('f'))),
Description: "Assign a folder to the current note",
Category: "Entry Actions",
})
registry.Register(string(ctrlKey('c')), (*Organizer).newContextNormal, CommandInfo{
Name: keyToDisplayName(string(ctrlKey('c'))),
Description: "Assign a context to the current note",
Category: "Entry Actions",
})
registry.Register(string(HOME_KEY), (*Organizer).scrollPreviewHome, CommandInfo{
Name: "Home",
Description: "Scroll rendered note to top",
Category: "Navigation",
})
// Information commands
registry.Register(string(ctrlKey('i')), (*Organizer).info, CommandInfo{
Name: keyToDisplayName(string(ctrlKey('i'))),
Description: "Show detailed information about current note",
Category: "Information",
})
// Mode Switching commands
registry.Register(string(ctrlKey('l')), (*Organizer).switchToEditorMode, CommandInfo{
Name: keyToDisplayName(string(ctrlKey('l'))),
Description: "Switch to editor (if one is active)",
Category: "Mode Switching",
})
// Preview commands
registry.Register(string(ctrlKey('w')), (*Organizer).showWebView_n, CommandInfo{
Name: keyToDisplayName(string(ctrlKey('w'))),
Description: "Show current note in web browser",
Category: "Preview",
})
registry.Register(string(ctrlKey('q')), (*Organizer).closeWebView_n, CommandInfo{
Name: keyToDisplayName(string(ctrlKey('q'))),
Description: "Close webkit webview window",
Category: "Preview",
})
registry.Register(string(ctrlKey('y')), (*Organizer).showEditorWindows, CommandInfo{
Name: keyToDisplayName(string(ctrlKey('y'))),
Description: "Show open editor windows",
Category: "Preview",
})
// Store registry in organizer for help command access
organizer.normalCommandRegistry = registry
return registry.GetFunctionMap()
}
func (o *Organizer) mark() {
if o.view != TASK {
o.ShowMessage(BL, "You can only mark tasks")
return
}
if _, found := o.marked_entries[o.rows[o.fr].id]; found {
delete(o.marked_entries, o.rows[o.fr].id)
} else {
o.marked_entries[o.rows[o.fr].id] = struct{}{}
}
o.ShowMessage(BL, "Toggle mark for item %d", o.rows[o.fr].id)
}
func (o *Organizer) del() {
id := o.rows[o.fr].id
state := o.rows[o.fr].deleted
err := o.Database.toggleDeleted(id, state, o.view.String())
if err != nil {
o.ShowMessage(BL, "Error toggling %s id %d to deleted: %v", o.view, id, err)
return
}
o.rows[o.fr].deleted = !state
o.ShowMessage(BL, "Toggle deleted for %s id %d succeeded (new)", o.view, id)
}
func (o *Organizer) star() {
id := o.rows[o.fr].id
state := o.rows[o.fr].star
err := o.Database.toggleStar(id, state, o.view.String())
if err != nil {
o.showMessage("Error toggling %s id %d to star: %v", o.view, id, err)
return
}
o.rows[o.fr].star = !state
o.ShowMessage(BL, "Toggle star for %s id %d succeeded (new)", o.view, id)
}
func (o *Organizer) archive() {
id := o.rows[o.fr].id
state := o.rows[o.fr].archived
err := o.Database.toggleArchived(id, state, o.view.String())
if err != nil {
o.ShowMessage(BL, "Error toggling %s id %d to archived: %v", o.view, id, err)
return
}
o.rows[o.fr].archived = !state
o.ShowMessage(BL, "Toggle archive for %s id %d succeeded (new)", o.view, id)
}
func (o *Organizer) info() {
if o.view != TASK {
return
}
e := o.Database.getEntryInfo(o.getId())
info := o.displayEntryInfo(&e)
o.drawNotice(info)
o.altRowoff = 0
o.mode = NAVIGATE_NOTICE
}
func (o *Organizer) showEditorWindows() {
o.Screen.eraseRightScreen()
o.Screen.drawRightScreen()
}
func (o *Organizer) switchToEditorMode() {
if len(o.Session.Editors) == 0 {
o.ShowMessage(BL, "%sThere are no active editors%s", RED_BG, RESET)
return
}
o.Session.editorMode = true
ae := app.Session.activeEditor
vim.SetCurrentBuffer(ae.vbuf)
// below necessary because libvim does not set cursor column correctly
vim.SetCursorPosition(ae.fr+1, ae.fc) //ae.fr is 0-based, vim expects 1-based
o.Screen.eraseRightScreen()
o.Screen.drawRightScreen()
}
// for scrolling terminal markdown rendered note
func (o *Organizer) scrollPreviewDown() {
if o.altRowoff == len(o.note)-1 {
o.ShowMessage(BL, "Reached end of rendered note")
return
}
o.altRowoff++
o.ShowMessage(BL, "Line %d of %d", o.altRowoff, len(o.note))
o.Screen.eraseRightScreen()
o.drawRenderedNote()
}
// for scrolling terminal markdown rendered note
func (o *Organizer) scrollPreviewUp() {
if o.altRowoff > 0 {
o.altRowoff--
o.Screen.eraseRightScreen()
o.drawRenderedNote()
}
}
func (o *Organizer) scrollPreviewHome() {
o.altRowoff = 0
o.Screen.eraseRightScreen()
o.drawRenderedNote()
}
// for scrolling reports (notices) like help
func (o *Organizer) scrollNoticeDown() {
if len(o.notice) == 0 {
return
}
if o.altRowoff == len(o.notice)-2 {
o.ShowMessage(BL, "Reached end of rendered note")
return
}
o.altRowoff++
o.ShowMessage(BL, "Line %d of %d", o.altRowoff, len(o.note))
o.drawNoticeLayer()
o.drawNoticeText()
}
func (o *Organizer) scrollNoticeHome() {
if len(o.notice) == 0 {
return
}
o.altRowoff = 0
o.ShowMessage(BL, "Line %d of %d", o.altRowoff, len(o.note))
o.drawNoticeLayer()
o.drawNoticeText()
}
// for scrolling reports (notices) like help
func (o *Organizer) scrollNoticeUp() {
if len(o.notice) == 0 {
return
}
if o.altRowoff > 0 {
o.altRowoff--
o.drawNoticeLayer()
o.drawNoticeText()
}
}
func (o *Organizer) showWebView_n() {
o.showWebView(0)
}
func (o *Organizer) closeWebView_n() {
o.closeWebView(0)
}
func (o *Organizer) displayEntryInfo(e *NewEntry) string {
width := o.Screen.totaleditorcols - 10
var ab strings.Builder
fmt.Fprintf(&ab, "id: %d%s", e.id, "\n")
fmt.Fprintf(&ab, "tid: %d%s", e.tid, "\n")
title := fmt.Sprintf("title: %s", e.title)
if len(title) > width {
title = title[:width-3] + "..."
}
fmt.Fprintf(&ab, "%s%s", title, "\n")
// Use taskContext/taskFolder which join on uuid
context := o.Database.taskContext(e.id)
fmt.Fprintf(&ab, "**context**: %s%s", context, "\n")
folder := o.Database.taskFolder(e.id)
fmt.Fprintf(&ab, "folder: %s%s", folder, "\n")
fmt.Fprintf(&ab, "star: %t%s", e.star, "\n")
fmt.Fprintf(&ab, "deleted: %t%s", e.deleted, "\n")
fmt.Fprintf(&ab, "completed: %t%s", e.archived, "\n")
fmt.Fprintf(&ab, "modified: %s%s", e.modified, "\n")
fmt.Fprintf(&ab, "added: %s%s", e.added, "\n")
fmt.Fprintf(&ab, "keywords: %s%s", app.Database.getTaskKeywords(e.id), "\n")
return ab.String()
}
func (o *Organizer) displayContainerInfo() {
/*
type Container struct {
id int
tid int
title string
star bool
deleted bool
modified string
count int
}
*/
c := o.Database.getContainerInfo(o.rows[o.fr].id, o.view)
if c.id == 0 {
return
}
var ab strings.Builder
fmt.Fprintf(&ab, "id: %d%s", c.id, "\n")
fmt.Fprintf(&ab, "tid: %d%s", c.tid, "\n")
fmt.Fprintf(&ab, "title: %s%s", c.title, "\n")
//title := fmt.Sprintf("**title**: %s", c.title)
fmt.Fprintf(&ab, "star: %t%s", c.star, "\n")
fmt.Fprintf(&ab, "deleted: %t%s", c.deleted, "\n")
fmt.Fprintf(&ab, "modified: %s%s", c.modified, "\n")
fmt.Fprintf(&ab, "note count: %d%s", c.count, "\n")
o.drawNotice(ab.String())
}
func (o *Organizer) newContextNormal() {
o.altView = CONTEXT
o.command = ""
o.command_line = ""
context_map := o.Database.contextList()
context_slice := slices.Collect(maps.Keys(context_map))
sort.Strings(context_slice)
o.containerList = context_slice
var sb strings.Builder
for i, k := range context_slice {
fmt.Fprint(&sb, fmt.Sprintf("%d. %s\n", i+1, k))
}
//contexts := strings.Join(context_slice, "\n")
o.mode = CONTAINER
//o.drawNotice(contexts)
o.drawNotice(sb.String())
o.altRowoff = 0
//o.command_line = "" // needed because not going into normal mode right away where it is cleared on typing ":"
}
func (o *Organizer) newFolderNormal() {
o.altView = FOLDER
o.command = ""
o.command_line = ""
folder_map := o.Database.folderList()
folder_slice := slices.Collect(maps.Keys(folder_map))
sort.Strings(folder_slice)
o.containerList = folder_slice
var sb strings.Builder
for i, k := range folder_slice {
fmt.Fprint(&sb, fmt.Sprintf("%d. %s\n", i+1, k))
}
//contexts := strings.Join(context_slice, "\n")
o.mode = CONTAINER
//o.drawNotice(contexts)
o.drawNotice(sb.String())
o.altRowoff = 0
//o.command_line = "" // needed because not going into normal mode right away where it is cleared on typing ":"
}