-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorganizer_cmd_line.go
More file actions
2155 lines (1931 loc) · 58.6 KB
/
organizer_cmd_line.go
File metadata and controls
2155 lines (1931 loc) · 58.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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package main
import (
"bytes"
"fmt"
"maps"
"os"
"os/exec"
"path/filepath"
"slices"
"sort"
"strconv"
"strings"
"time"
"github.com/jung-kurt/gofpdf"
"github.com/mandolyte/mdtopdf/v2"
"github.com/slzatz/vimango/auth"
"github.com/slzatz/vimango/vim"
)
func (a *App) setOrganizerExCmds(organizer *Organizer) map[string]func(*Organizer, int) {
registry := NewCommandRegistry[func(*Organizer, int)]()
// Navigation commands
// Note that the name in Register is the command that is recognized.
registry.Register("open", (*Organizer).open, CommandInfo{
Aliases: []string{"o"},
Description: "Display notes with specified context, folder or keyword (will match in that order)",
Usage: "open <name>",
Category: "Navigation",
Examples: []string{":open work", ":o work"},
})
registry.Register("opencontext", (*Organizer).openContext, CommandInfo{
Aliases: []string{"oc"},
Description: "Display notes from specified context",
Usage: "opencontext <context_name>",
Category: "Navigation",
Examples: []string{":opencontext work", ":oc personal"},
})
registry.Register("openfolder", (*Organizer).openFolder, CommandInfo{
Aliases: []string{"openfolder", "openf", "of"},
Description: "Display notes from specified folder",
Usage: "openfolder <folder_name>",
Category: "Navigation",
Examples: []string{":openfolder projects", ":of archive"},
})
registry.Register("openkeyword", (*Organizer).openKeyword, CommandInfo{
Aliases: []string{"openkeyword", "openk", "ok"},
Description: "Display notes tagged with specified keyword",
Usage: "openkeyword <keyword>",
Category: "Navigation",
Examples: []string{":openkeyword urgent", ":ok meeting"},
})
// Data Management commands
registry.Register("new", (*Organizer).newEntry, CommandInfo{
Aliases: []string{"n"},
Description: "Create new entry",
Usage: "new",
Category: "Entry Management",
Examples: []string{":new", ":n"},
})
registry.Register("write", (*Organizer).write, CommandInfo{
Aliases: []string{"w"},
Description: "Save all modified entries to database",
Usage: "write",
Category: "Entry Management",
Examples: []string{":write", ":w"},
})
registry.Register("sync", (*Organizer).synchronize, CommandInfo{
Aliases: []string{"test"},
Description: "Synchronize with remote server (test for dry-run)",
Usage: "sync",
Category: "Data Management",
Examples: []string{":sync", ":test (dry-run)"},
})
/*
registry.Register("bulkload", (*Organizer).initialBulkLoad, CommandInfo{
Name: "bulkload",
Aliases: []string{"bulktest"},
Description: "Perform initial bulk data load",
Usage: "bulkload",
Category: "Data Management",
Examples: []string{":bulkload", ":bulktest (dry-run)"},
})
registry.Register("reverseload", (*Organizer).reverse, CommandInfo{
Name: "reverseload",
Aliases: []string{"reversetest"},
Description: "Perform reverse bulk data load",
Usage: "reverseload",
Category: "Data Management",
Examples: []string{":reverseload", ":reversetest (dry-run)"},
})
*/
registry.Register("refresh", (*Organizer).refresh, CommandInfo{
Aliases: []string{"r"},
Description: "Refresh current view",
Usage: "refresh",
Category: "Entry Management",
Examples: []string{":refresh", ":r"},
})
registry.Register("convertgdrive", (*Organizer).convertGoogleDriveURLs, CommandInfo{
Aliases: []string{"cgd"},
Description: "Convert Google Drive URLs to gdrive:ID format in current note",
Usage: "convertgdrive",
Category: "Images",
Examples: []string{":convertgdrive"},
})
registry.Register("research", (*Organizer).startResearch, CommandInfo{
Aliases: []string{},
Description: "Start deep research using current note as prompt",
Usage: "research",
Category: "Research",
Examples: []string{":research"},
})
registry.Register("researchdebug", (*Organizer).startResearchDebug, CommandInfo{
Aliases: []string{"rd"},
Description: "Start deep research with full debug information",
Usage: "researchdebug",
Category: "Research",
Examples: []string{":researchdebug", ":rd"},
})
registry.Register("researchtest", (*Organizer).startResearchNotificationTest, CommandInfo{
Aliases: []string{"rtest"},
Description: "Generate sample research status notifications for testing",
Usage: "researchtest",
Category: "Research",
Examples: []string{":researchtest", ":rtest"},
})
// Search & Filter commands
registry.Register("find", (*Organizer).find, CommandInfo{
Description: "Search entries using full-text search",
Usage: "find <search_terms>",
Category: "Search & Filter",
Examples: []string{":find meeting notes", ":find urgent todo"},
})
registry.Register("contexts", (*Organizer).containers, CommandInfo{
Aliases: []string{"c"},
Description: "show contexts",
Usage: "contexts",
Category: "Container Management",
Examples: []string{":contexts", "c"},
})
registry.Register("newc", (*Organizer).newContext, CommandInfo{
//Aliases: []string{"c"},
Description: "show contexts",
Usage: "contexts",
Category: "Container Management",
Examples: []string{":contexts", "c"},
})
registry.Register("newf", (*Organizer).newFolder, CommandInfo{
//Aliases: []string{"c"},
Description: "show contexts",
Usage: "contexts",
Category: "Container Management",
Examples: []string{":contexts", "c"},
})
registry.Register("folders", (*Organizer).containers, CommandInfo{
Aliases: []string{"f"},
Description: "show folders",
Usage: "folders",
Category: "Container Management",
Examples: []string{":folders", "f"},
})
registry.Register("keywords", (*Organizer).containers, CommandInfo{
Aliases: []string{"k"},
Description: "show keywords",
Usage: "keywords",
Category: "Container Management",
Examples: []string{":keywords", "k"},
})
registry.Register("set context", (*Organizer).setContext, CommandInfo{
Aliases: []string{"set c", "setc", "sc"},
Description: "Set context for entrie(s)",
Usage: "set context <context>",
Category: "Entry Management",
Examples: []string{":set context work", ":set c work"},
})
registry.Register("set folder", (*Organizer).setFolder, CommandInfo{
Aliases: []string{"set f", "setf", "sf"},
Description: "Set folder for entrie(s)",
Usage: "set folder <folder>",
Category: "Entry Management",
Examples: []string{":set folder todo", ":set f todo"},
})
registry.Register("add keyword", (*Organizer).addKeyword, CommandInfo{
Aliases: []string{"add k"},
Description: "Add keyword to entry",
Usage: "add k <keyword>",
Category: "Entry Management",
Examples: []string{":add keyword urgent", ":add k urgent"},
})
registry.Register("recent", (*Organizer).recent, CommandInfo{
Description: "Show recently modified entries",
Usage: "recent",
Category: "Search & Filter",
Examples: []string{":recent"},
})
/*
registry.Register("log", (*Organizer).log, CommandInfo{
Name: "log",
Description: "Show synchronization log entries",
Usage: "log",
Category: "Search & Filter",
Examples: []string{":log"},
})
*/
// View Management commands
registry.Register("sort", (*Organizer).sortEntries, CommandInfo{
Description: "Sort entries by column",
Usage: "sort <column>",
Category: "View Management",
Examples: []string{":sort modified", ":sort created", ":sort priority"},
})
registry.Register("showall", (*Organizer).showAll, CommandInfo{
//Aliases: []string{"show"},
Description: "Toggle showing completed/deleted entries",
Usage: "showall",
Category: "View Management",
Examples: []string{":showall", ":show"},
})
/*
registry.Register("image", (*Organizer).setImage, CommandInfo{
Name: "image",
Aliases: []string{"images"},
Description: "Toggle image preview on/off",
Usage: "image <on|off>",
Category: "View Control",
Examples: []string{":image on", ":images off"},
})
*/
registry.Register("webview", (*Organizer).showWebView, CommandInfo{
Aliases: []string{"wv"},
Description: "Show current note in web browser",
Usage: "webview",
Category: "HTML View",
Examples: []string{":webview", ":wv"},
})
registry.Register("closewebview", (*Organizer).closeWebView, CommandInfo{
Aliases: []string{"close"},
Description: "Close webkit webview window",
Usage: "closewebview",
Category: "HTML View",
Examples: []string{":closewebview", ":cwv"},
})
registry.Register("toggleimages", (*Organizer).toggleImages, CommandInfo{
Aliases: []string{"ti"},
Description: "Toggle inline image display on/off",
Usage: "toggleimages",
Category: "Images",
Examples: []string{":toggleimages", ":ti"},
})
registry.Register("showimageinfo", (*Organizer).showImageInfo, CommandInfo{
Aliases: []string{"sii"},
Description: "Toggle display of Google Drive folder/filename above images",
Usage: "showimageinfo",
Category: "Images",
Examples: []string{":showimageinfo", ":sii"},
})
registry.Register("refreshimageinfo", (*Organizer).refreshImageInfo, CommandInfo{
Aliases: []string{"rii"},
Description: "Refresh Google Drive image metadata (currently file path) for images in current note. ! also re-download images.",
Usage: "refreshimageinfo[!]",
Category: "Images",
Examples: []string{":refreshimageinfo", ":refreshimageinfo!", ":rii", ":rii!"},
})
registry.Register("imagescale", (*Organizer).scaleImages, CommandInfo{
Aliases: []string{"is"},
Description: "Scale inline images up (+), down (-), or to specific size (N columns)",
Usage: "imagescale [+|-|N]",
Category: "Images",
Examples: []string{":imagescale +", ":imagescale -", ":imagescale 30", ":imagescale 60"},
})
registry.Register("cachewidth", (*Organizer).cacheWidth, CommandInfo{
Aliases: []string{"cw"},
Description: "Set max pixel width for cached Google Drive images (default 800)",
Usage: "cachewidth [N]",
Category: "Images",
Examples: []string{":cachewidth", ":cachewidth 800", ":cachewidth 1200", ":cw 600"},
})
registry.Register("clearcache", (*Organizer).clearImageCache, CommandInfo{
Aliases: []string{"clc"},
Description: "Clear the disk image cache (forces re-download of Google Drive images)",
Usage: "clearcache",
Category: "Images",
Examples: []string{":clearcache", ":clc"},
})
registry.Register("imagereset", (*Organizer).imageReset, CommandInfo{
Aliases: []string{"ir"},
Description: "Clear terminal image cache and rerender current note",
Usage: "imagereset",
Category: "Images",
Examples: []string{":imagereset", ":ir"},
})
registry.Register("vertical resize", (*Organizer).verticalResize, CommandInfo{
Aliases: []string{"vert res", "divider"},
Description: "Resize vertical divider",
Usage: "vertical resize <width>",
Category: "View Management",
Examples: []string{":vertical resize 80", ":vert res +10", ":divider -5"},
})
// Entry Management commands
registry.Register("e", (*Organizer).editNote, CommandInfo{
Description: "Edit the current note",
Usage: "e",
Category: "Entry Management",
Examples: []string{":e"},
})
registry.Register("copy", (*Organizer).copyEntry, CommandInfo{
Description: "Copy current entry",
Usage: "copy",
Category: "Entry Management",
Examples: []string{":copy"},
})
registry.Register("deletekeywords", (*Organizer).deleteKeywords, CommandInfo{
Aliases: []string{"delkw", "delk"},
Description: "Delete all keywords from current entry",
Usage: "deletekeywords",
Category: "Entry Management",
Examples: []string{":deletekeywords", ":delkw"},
})
registry.Register("deletemarks", (*Organizer).deleteMarks, CommandInfo{
Aliases: []string{"delmarks", "delm"},
Description: "Clear all marked entries",
Usage: "deletemarks",
Category: "Entry Management",
Examples: []string{":deletemarks", ":delm"},
})
// Container Management commands
/*
registry.Register("cc", (*Organizer).updateContainer, CommandInfo{
Name: "cc",
Description: "Update context for marked or current entry",
Usage: "cc",
Category: "Container Management",
Examples: []string{":cc"},
})
registry.Register("ff", (*Organizer).updateContainer, CommandInfo{
Name: "ff",
Description: "Update folder for marked or current entry",
Usage: "ff",
Category: "Container Management",
Examples: []string{":ff"},
})
registry.Register("kk", (*Organizer).updateContainer, CommandInfo{
Name: "kk",
Description: "Update keyword for marked or current entry",
Usage: "kk",
Category: "Container Management",
Examples: []string{":kk"},
})
*/
// Output & Export commands
registry.Register("print", (*Organizer).printDocument, CommandInfo{
Description: "Print current note as PDF",
Usage: "print",
Category: "Output & Export",
Examples: []string{":print"},
})
registry.Register("ha", (*Organizer).printList, CommandInfo{
Description: "Print current list using vim hardcopy",
Usage: "ha",
Category: "Output & Export",
Examples: []string{":ha"},
})
registry.Register("printlist", (*Organizer).printList2, CommandInfo{
Aliases: []string{"ha2", "pl"},
Description: "Print formatted list as PDF",
Usage: "printlist",
Category: "Output & Export",
Examples: []string{":printlist", ":pl"},
})
registry.Register("save", (*Organizer).save, CommandInfo{
Description: "Save current note to file",
Usage: "save <filename>",
Category: "Output & Export",
Examples: []string{":save note.txt", ":save /tmp/backup.md"},
})
/*
registry.Register("savelog", (*Organizer).savelog, CommandInfo{
Name: "savelog",
Description: "Save current sync log to database",
Usage: "savelog",
Category: "Output & Export",
Examples: []string{":savelog"},
})
*/
// System commands
registry.Register("quit", (*Organizer).quitApp, CommandInfo{
Aliases: []string{"q", "q!"},
Description: "Exit application (q! forces quit without saving)",
Usage: "quit",
Category: "System",
Examples: []string{":quit", ":q", ":q!"},
})
registry.Register("which", (*Organizer).whichVim, CommandInfo{
Description: "Show which vim implementation is active",
Usage: "which",
Category: "System",
Examples: []string{":which"},
})
// Help command
registry.Register("help", (*Organizer).help, CommandInfo{
Aliases: []string{"h"},
Description: "Show help for commands",
Usage: "help [command|category]",
Category: "Help",
Examples: []string{":help", ":help open", ":help Navigation", ":h"},
})
// Store registry in organizer for help command access
organizer.commandRegistry = registry
return registry.GetFunctionMap()
}
// help displays help information for organizer commands
func (o *Organizer) help(pos int) {
/*
if o.commandRegistry == nil {
o.ShowMessage(BL, "Help system not available")
o.mode = o.last_mode
return
}
*/
var helpText string
if pos == -1 {
// No arguments - show all ex commands
helpText = o.commandRegistry.FormatAllHelp()
} else {
// Get the argument after "help "
arg := o.command_line[pos+1:]
// Check if it's request for normal mode help
if arg == "normal" {
if o.normalCommandRegistry != nil {
helpText = o.formatNormalModeHelp()
} else {
helpText = "Normal mode help not available"
}
} else if _, exists := o.commandRegistry.GetCommandInfo(arg); exists {
// Check if it's a specific ex command
helpText = o.commandRegistry.FormatCommandHelp(arg)
} else if o.normalCommandRegistry != nil {
// Check if it's a normal mode command (by display name)
if normalInfo, exists := o.findNormalCommandByDisplayName(arg); exists {
helpText = o.normalCommandRegistry.FormatCommandHelp(normalInfo.Name)
} else {
// Check if it's a category (ex commands first, then normal)
exCategories := o.commandRegistry.GetAllCommands()
if _, exists := exCategories[arg]; exists {
helpText = o.commandRegistry.FormatCategoryHelp(arg)
} else if o.normalCommandRegistry != nil {
normalCategories := o.normalCommandRegistry.GetAllCommands()
if _, exists := normalCategories[arg]; exists {
helpText = o.normalCommandRegistry.FormatCategoryHelp(arg)
} else {
// Not found - suggest similar commands from both registries
exSuggestions := o.commandRegistry.SuggestCommand(arg)
normalSuggestions := o.normalCommandRegistry.SuggestCommand(arg)
allSuggestions := append(exSuggestions, normalSuggestions...)
if len(allSuggestions) > 0 {
helpText = fmt.Sprintf("Command or category '%s' not found.\nDid you mean: %s", arg, strings.Join(allSuggestions, ", "))
} else {
helpText = fmt.Sprintf("Command or category '%s' not found.\nUse ':help' for ex commands or ':help normal' for normal mode commands.", arg)
}
}
} else {
// Normal command registry not available
suggestions := o.commandRegistry.SuggestCommand(arg)
if len(suggestions) > 0 {
helpText = fmt.Sprintf("Command or category '%s' not found.\nDid you mean: %s", arg, strings.Join(suggestions, ", "))
} else {
helpText = fmt.Sprintf("Command or category '%s' not found.\nUse ':help' to see all available commands.", arg)
}
}
}
} else {
// Check if it's a category
categories := o.commandRegistry.GetAllCommands()
if _, exists := categories[arg]; exists {
helpText = o.commandRegistry.FormatCategoryHelp(arg)
} else {
// Not found - suggest similar commands
suggestions := o.commandRegistry.SuggestCommand(arg)
if len(suggestions) > 0 {
helpText = fmt.Sprintf("Command or category '%s' not found.\nDid you mean: %s", arg, strings.Join(suggestions, ", "))
} else {
helpText = fmt.Sprintf("Command or category '%s' not found.\nUse ':help' to see all available commands.", arg)
}
}
}
}
o.mode = HELP
o.drawNotice(helpText)
o.altRowoff = 0
o.command_line = "" // needed because not going into normal mode right away where it is cleared on typing ":"
}
func (o *Organizer) newContext(pos int) {
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) newFolder(pos int) {
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 ":"
}
// formatNormalModeHelp returns formatted help for all normal mode commands
func (o *Organizer) formatNormalModeHelp() string {
if o.normalCommandRegistry == nil {
return "Normal mode help not available"
}
var help strings.Builder
help.WriteString("# Normal Mode Commands:\n\n")
categories := o.normalCommandRegistry.GetAllCommands()
// Sort categories for consistent output
var categoryNames []string
for category := range categories {
categoryNames = append(categoryNames, category)
}
sort.Strings(categoryNames)
for _, category := range categoryNames {
commands := categories[category]
help.WriteString(fmt.Sprintf("### %s:\n", category))
for _, cmd := range commands {
help.WriteString(fmt.Sprintf("- `%-14s`%s\n", cmd.Name, cmd.Description))
}
help.WriteString("\n")
}
help.WriteString("Use ':help <key>' for detailed help on a specific normal mode command.\n")
help.WriteString("Use ':help <category>' for commands in a specific category.\n")
return help.String()
}
// findNormalCommandByDisplayName finds a normal command by its display name
func (o *Organizer) findNormalCommandByDisplayName(displayName string) (CommandInfo, bool) {
if o.normalCommandRegistry == nil {
return CommandInfo{}, false
}
allCommands := o.normalCommandRegistry.GetAllCommands()
for _, commands := range allCommands {
for _, cmd := range commands {
if cmd.Name == displayName {
return cmd, true
}
}
}
return CommandInfo{}, false
}
func (o *Organizer) openContainerSelection() {
row := o.rows[o.fr]
var ok bool
switch o.view {
case CONTEXT:
o.taskview = BY_CONTEXT
_, ok = o.Database.contextExists(row.title)
case FOLDER:
o.taskview = BY_FOLDER
_, ok = o.Database.folderExists(row.title)
case KEYWORD:
o.taskview = BY_KEYWORD
// this guard to see if synced may not be necessary for keyword
_, ok = o.Database.keywordExists(row.title)
}
if !ok {
o.showMessage("You need to sync before you can use %q", row.title)
return
}
o.filter = row.title
o.generateNoteList()
}
func (o *Organizer) generateNoteList() {
o.ShowMessage(BL, "'%s' will be opened", o.filter)
o.clearMarkedEntries()
o.view = TASK
o.fc, o.fr, o.rowoff = 0, 0, 0
o.FilterEntries(MAX)
if len(o.rows) == 0 {
o.insertRow(0, "", true, false, false, BASE_DATE)
o.rows[0].dirty = false
o.showMessage("No results were returned")
}
o.Session.imagePreview = false
o.readRowsIntoBuffer()
vim.SetCursorPosition(1, 0)
o.bufferTick = o.vbuf.GetLastChangedTick()
o.altRowoff = 0
o.displayNote()
//o.mode = NORMAL
//o.command = ""
}
func (o *Organizer) open(pos int) {
if o.view != TASK {
o.openContainerSelection()
return
}
if pos == -1 {
o.ShowMessage(BL, "You did not provide a context or folder!")
//o.mode = o.last_mode
// It might be necessary or prudent to also sendvim an <esc> here
o.mode = NORMAL
return
}
var ok bool
input := o.command_line[pos+1:]
if _, ok = o.Database.contextExists(input); ok {
o.taskview = BY_CONTEXT
}
if !ok {
if _, ok = o.Database.folderExists(input); ok {
o.taskview = BY_FOLDER
}
}
if !ok {
o.ShowMessage(BL, "%s is not a valid context or folder!", input)
if _, ok = o.Database.keywordExists(input); ok {
o.taskview = BY_KEYWORD
}
}
if !ok {
o.ShowMessage(BL, "%s is not a valid context, folder or keyword!", input)
o.mode = NORMAL
return
}
o.filter = input
o.generateNoteList()
o.mode = NORMAL
o.command = ""
}
func (o *Organizer) openContext(pos int) {
if pos == -1 {
o.ShowMessage(BL, "You did not provide a context!")
//o.mode = o.last_mode
o.mode = NORMAL
return
}
input := o.command_line[pos+1:]
if _, ok := o.Database.contextExists(input); !ok {
o.ShowMessage(BL, "%s is either not a valid context or has not been synced!", input)
o.mode = NORMAL
return
}
o.taskview = BY_CONTEXT
o.filter = input
o.generateNoteList()
o.mode = NORMAL
o.command = ""
}
func (o *Organizer) openFolder(pos int) {
if pos == -1 {
o.ShowMessage(BL, "You did not provide a folder!")
o.mode = NORMAL
return
}
input := o.command_line[pos+1:]
if _, ok := o.Database.folderExists(input); !ok {
o.ShowMessage(BL, "%s is not a valid folder!", input)
o.mode = NORMAL
o.command = ""
return
}
o.taskview = BY_FOLDER
o.filter = input
o.generateNoteList()
o.mode = NORMAL
o.command = ""
}
func (o *Organizer) openKeyword(pos int) {
if pos == -1 {
o.ShowMessage(BL, "You did not provide a keyword!")
//o.mode = o.last_mode
o.mode = NORMAL
return
}
input := o.command_line[pos+1:]
if _, ok := o.Database.keywordExists(input); !ok {
o.ShowMessage(BL, "%s is not a valid keyword!", input)
//o.mode = o.last_mode
o.mode = NORMAL
o.command = ""
return
}
o.taskview = BY_KEYWORD
o.filter = input
o.generateNoteList()
o.mode = NORMAL
o.command = ""
}
func (o *Organizer) write(pos int) {
var updated_rows []int
if o.view != TASK {
return
}
for i, r := range o.rows {
if r.dirty {
if r.id != -1 {
err := o.Database.updateTitle(&r)
if err != nil {
o.ShowMessage(BL, "Error updating title: id %d: %v", r.id, err)
continue
}
} else {
var context_uuid, folder_uuid string
switch o.taskview {
case BY_CONTEXT:
context_uuid, _ = o.Database.contextExists(o.filter)
folder_uuid = DefaultFolderUUID
case BY_FOLDER:
folder_uuid, _ = o.Database.folderExists(o.filter)
context_uuid = DefaultContextUUID
default:
context_uuid = DefaultContextUUID
folder_uuid = DefaultFolderUUID
}
err := o.Database.insertTitle(&r, context_uuid, folder_uuid)
if err != nil {
o.ShowMessage(BL, "Error inserting title id %d: %v", r.id, err)
continue
}
}
o.rows[i].dirty = false
updated_rows = append(updated_rows, r.id)
}
}
if len(updated_rows) == 0 {
o.ShowMessage(BL, "There were no rows to update")
} else {
o.ShowMessage(BL, "These ids were updated: %v", updated_rows)
}
//o.mode = o.last_mode
o.mode = NORMAL
o.command_line = ""
}
func (o *Organizer) quitApp(_ int) {
if o.command_line == "q!" {
app.Run = false
return
}
unsaved_changes := false
for _, r := range o.rows {
if r.dirty {
unsaved_changes = true
break
}
}
if unsaved_changes {
o.mode = NORMAL
o.ShowMessage(BL, "No db write since last change")
} else {
app.Run = false
}
}
func (o *Organizer) editNote(id int) {
var ae *Editor
if o.view != TASK {
o.command = ""
//o.mode = o.last_mode
o.mode = NORMAL
o.ShowMessage(BL, "Only entries have notes to edit!")
return
}
//pos is zero if no space and command modifier
if id == -1 {
id = o.getId()
}
if id == -1 {
o.ShowMessage(BL, "You need to save a note's title before you can edit it!")
o.command = ""
//o.mode = o.last_mode
o.mode = NORMAL
return
}
o.Session.editorMode = true
active := false
for _, w := range o.Session.Editors {
if w.id == id {
active = true
ae = w
break
}
}
if !active {
ae = app.NewEditor()
o.Session.Editors = append(o.Session.Editors, ae)
ae.id = id
ae.title = o.rows[o.fr].title
ae.top_margin = TOP_MARGIN + 1
note := o.Database.readNoteIntoString(id)
ae.ss = strings.Split(note, "\n")
// Make sure we have at least one line, even if the note was empty
if len(ae.ss) == 0 {
ae.ss = []string{""}
}
ae.vbuf = vim.NewBuffer(0)
vim.SetCurrentBuffer(ae.vbuf)
ae.vbuf.SetLines(0, -1, ae.ss)
//////// need to look at whether we need both buffer and save tick 10/01/2025
ae.bufferTick = ae.vbuf.GetLastChangedTick()
ae.saveTick = ae.vbuf.GetLastChangedTick()
o.Session.activeEditor = ae
}
o.Screen.positionWindows()
o.Screen.eraseRightScreen() //erases editor area + statusbar + msg
o.Screen.drawRightScreen()
ae.mode = NORMAL
o.Session.activeEditor = ae
o.command = ""
o.mode = NORMAL
}
func (o *Organizer) verticalResize(pos int) {
var newWidth int
opt := o.command_line[pos+1:]
width, err := strconv.Atoi(opt)
if err != nil {
o.ShowMessage(BL, "You need to provide a number")
return
}
if opt[0] == '+' || opt[0] == '-' {
newWidth = o.Screen.screenCols - o.Screen.divider - width
} else {
newWidth = o.Screen.screenCols - width
if newWidth < 20 || newWidth > o.Screen.screenCols-20 {
o.ShowMessage(BL, "Width must be between 20 and %d", o.Screen.screenCols-20)
return
}
}
app.moveDividerAbs(newWidth)
o.mode = NORMAL
}
/*
func (o *Organizer) verticalResize__(pos int) {
if pos == -1 {
sess.showOrgMessage("You need to provide a number 0 - 100")
return
}
pct, err := strconv.Atoi(o.command_line[pos+1:])
if err != nil {
sess.showOrgMessage("You need to provide a number 0 - 100")
//o.mode = NORMAL
o.mode = o.last_mode
return
}
moveDividerPct(pct)
//o.mode = NORMAL
o.mode = o.last_mode
}
*/
func (o *Organizer) newEntry(_ int) {
row := Row{
id: -1,
star: false,
dirty: true,
sort: time.Now().Format("3:04:05 pm"), //correct whether added, created, modified are the sort
}
o.vbuf.SetLines(0, 0, []string{""})
o.rows = append(o.rows, Row{})
copy(o.rows[1:], o.rows[0:])
o.rows[0] = row
o.fc, o.fr, o.rowoff = 0, 0, 0
o.command = ""
o.ShowMessage(BL, "\x1b[1m-- INSERT --\x1b[0m")
o.Screen.eraseRightScreen()
o.mode = INSERT
vim.SetCursorPosition(1, 0)
vim.SendInput("i")
}
// flag is -1 if called as an ex command and 0 if called by another Organizer method
func (o *Organizer) refresh(flag int) {
var err error
if o.view == TASK {
if o.taskview == BY_FIND {
o.mode = NORMAL ///////////////////////////
//o.mode = FIND ////////////////////////////////////
o.fc, o.fr, o.rowoff = 0, 0, 0
o.rows, err = o.Database.searchEntries(o.Session.fts_search_terms, o.sort, o.show_deleted, false)
if err != nil {
o.ShowMessage(BL, "Error searching for %s: %v", o.Session.fts_search_terms, err)
return
}
if len(o.rows) == 0 {
o.insertRow(0, "", true, false, false, BASE_DATE)
o.rows[0].dirty = false
o.ShowMessage(BL, "No results were returned")
}
o.Session.imagePreview = false
o.readRowsIntoBuffer()
vim.SetCursorPosition(1, 0)