-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathevernote.ahk
2460 lines (1961 loc) · 72.3 KB
/
evernote.ahk
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
AUTOEXEC_Evernote: ; Workaround for Autohotkey's ugly auto-exec feature. Must be first line.
/* APIs:
EverTable_LaunchUI()
PreviewHtml_ShowGui(html)
ColorMatrix_ShowGui()
;
Evernote_PopupInlinePasteMenu()
Evernote_PopupBlockPasteMenu()
Evernote_PasteSingleLineCode(bgcolor, is_monofont, keep_orig_clipboard)
Evernote_PasteSingleLineWithHtmlDeco(str_decofunc)
*/
; User can define g_evtblColorCustoms[] to append custom colors to g_evtblColorPresets
global g_evtblColorPresets := [ "#f0f0f0,清淡灰"
, "#e0e0e0,代码灰"
, "#c6e2ff,多云蓝"
, "#ecf8ff,晴空蓝"
, "#e0f0f0,灰蓝"
, "#f0e0f0,暗紫"
, "#f0f0ff,灰紫"
, "#fefedc,淡雅黄"
, "#fff8e0,淡橙"
, "#f0e0e0,浅栗红"
, "#e0f0e0,薄荷绿"
, "#f0f0e0,药片黄"
, "#e0c0ff,罗兰紫"
, "#f8e8ff,淡紫"
, "#ffe0b0,霞光橙"
, "#deffbe,青芽绿"
, "#ffe6e6,粉饼红"
, "#EEe0c0,浅棕"
, "#f890c0,胭脂红"
, "#FFA090,石榴红"
, "#FEFE8C,明亮黄"
, "#FFE266,日落黄"
, "#F2F8b4,枯叶黄"
, "#B0E0B0,青瓷绿(celadon)"
, "#74C4C4,深海绿"
, "#C0FF00,荧光绿"
, "#40A0FF,水手蓝"
, "#AAE8FF,深空蓝"
, "#F86030,深橙色"
, "#D46262,深栗红"
, "#DC143C,深红(crimson)"
, "#704214,深褐色(sepia)"
, "#614051,茄紫色(eggplant Ubuntu)"
, "#50C878,祖母绿(Emerald)"
, "#40E0D0,绿松石(turquoise)"
, "#C8A2C8,丁香紫(lilac)"
, ""
, ""
, "#FFFFFF,Pure White" ]
; =======
global g_HwndEvtbl
global text_ColorPreview := "Color Preview"
global g_evtblComboColor
global g_evtblHwndComboColor
global g_evtblComboColor2
global g_evtblHwndComboColor2
global g_evtblPreviewBox
global g_evtblPreviewText
global g_evtblPreviewBox2
global g_evtblPreviewText2
global g_evtblPreviewMix ; embed IE html
global g_evtblIsBlackText
global g_evtblUse2ndColor
global g_evtblIsWhiteText
global g_evtblBtnColorMatrix
global g_evtblBtnColorMatrix2
global g_evtblIsDiv ; <DIV>
global g_evtblIsTable ; <TABLE>
global g_evtblIsCssTable ; This is for CssTable
global g_evtblIsSpan ; <span> inline text with bgcolor
global g_evtblSpanText ; User text that will appear in resulting html <span> tag
global g_evtblIsSpanMono ; Whether use monospaced text in <span>
;
global Evtbl_OnTableDivSwitch
;
global g_evtblEdtCsstableRows
global g_evtblLblCsstableRows
global g_evtblChkboxCsstableHead
global g_evtblDivFullWidth
global g_evtblDivLeftSide
global g_evtblDivRightSide
global g_evtblDivQAstyle
global lbl_TableColumnSpec, lbl_TableCellPadding, lbl_TableBorderPx
global g_evtblTableColumnSpec
global g_evtblCssTableColumnSpec ; This is for CssTable
global g_evtblIsFirstColumnColor
global g_evtblBorder1px
global g_evtblBorder2px
global g_evtblIsPaddingSparse
global g_evtblIsPaddingDense
global g_evtblBtnOK
global g_evtblChkboxTSV
global g_evtblHwndToPaste
global g_HwndPreviewHtml ; GuiName: PvHtml
global g_PvhtmlEdit
global g_PvhtmlClipboard
global g_PvhtmlMsg
global g_HwndColorMatrix
; global gar_ColorCellHwnd:=[]
global gar_colordict := [] ; to be filled according to g_evtblColorPresets
global COLORCELLs_perline := 5
global COLORCELL_width := 130
global COLORCELL_xgap := 20 ; exp with 60
global COLORCELL_xmargin := 10 ; exp with 40
global COLORCELL_xspan := (COLORCELL_width+COLORCELL_xgap)
global COLORCELL_height := 30
global COLORCELL_ygap := 10
global COLORCELL_ymarginTop := 36
global g_HiddenCtrlYD
global COLORCELL_yspan := (COLORCELL_height+COLORCELL_ygap)
global g_colormatrixIsWhiteText
;
global g_varnameComboColorOut := "" ; output-target for color-matrix GUI (just like a return value)
global g_evtblBox1HalfPos := {} ; Box x,y,w,h when only 1st color is used.
global g_evtblBox1FullPos := {} ; Box x,y,w,h when 1st and 2nd color is used.
global g_evtblIdxDefaultColor1 := 2
global g_evtblIdxDefaultColor2 := 1
global g_evtbl_IE11_ok := false
global g_matrixColor1, g_matrixColor2, g_matrixColor3, g_matrixColor4, g_matrixColor5, g_matrixColor6, g_matrixColor7, g_matrixColor8, g_matrixColor9, g_matrixColor10
global g_matrixColor11, g_matrixColor12, g_matrixColor13, g_matrixColor14, g_matrixColor15, g_matrixColor16, g_matrixColor17, g_matrixColor18, g_matrixColor19, g_matrixColor20
global g_matrixColor21, g_matrixColor22, g_matrixColor23, g_matrixColor24, g_matrixColor25, g_matrixColor26, g_matrixColor27, g_matrixColor28, g_matrixColor29, g_matrixColor30
global g_matrixColor31, g_matrixColor32, g_matrixColor33, g_matrixColor34, g_matrixColor35, g_matrixColor36, g_matrixColor37, g_matrixColor38, g_matrixColor39, g_matrixColor40
global g_matrixColor41, g_matrixColor42, g_matrixColor43, g_matrixColor44, g_matrixColor45, g_matrixColor46, g_matrixColor47, g_matrixColor48, g_matrixColor49, g_matrixColor50
global g_matrixColor51, g_matrixColor52, g_matrixColor53, g_matrixColor54, g_matrixColor55, g_matrixColor56, g_matrixColor57, g_matrixColor58, g_matrixColor59, g_matrixColor60
global g_matrixColor61, g_matrixColor62, g_matrixColor63, g_matrixColor64, g_matrixColor65, g_matrixColor66, g_matrixColor67, g_matrixColor68, g_matrixColor69, g_matrixColor70
global g_matrixColor71, g_matrixColor72, g_matrixColor73, g_matrixColor74, g_matrixColor75, g_matrixColor76, g_matrixColor77, g_matrixColor78, g_matrixColor79, g_matrixColor80
global g_matrixColor81, g_matrixColor82, g_matrixColor83, g_matrixColor84, g_matrixColor85, g_matrixColor86, g_matrixColor87, g_matrixColor88, g_matrixColor89, g_matrixColor90
; ======
global g_HwndSupsub
global g_SupsubBaseText
global g_SupsubSupText
global g_SupsubSubText
; ======
global g_evernotePopLinksFile := "EvernotePopupLinks.csv.txt"
; -- In customize.ahk, you can override this global var to point to your own file.
Evernote_InitThisModule()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
return ; End of auto-execute section.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#Include %A_LineFile%\..\libs\CtlColorStatic.ahk
#Include %A_LineFile%\..\libs\Gdip_All.ahk
#Include %A_LineFile%\..\libs\GenHtmlSnippet.ahk
#Include %A_LineFile%\..\libs\ClipboardMonitor.ahk
#Include %A_LineFile%\..\libs\AHKhttp.ahk
#Include %A_LineFile%\..\libs\chjfuncs.ahk
class Evnt
{
static pastecode_start_numline := 1
static pastecode_retry_delaymsec := 200
static pastecode_restore_plaintext_delaymsec := 500
}
Evernote_InitThisModule()
{
evernote_InlinePaste_InitMenu()
evernote_InitHotkeys()
}
evernote_InitHotkeys()
{
QSA_DefineActivateSingle_Caps("m", "ENMainFrame", "Evernote")
QSA_DefineActivateGroupFlex_Caps("n", "ENSingleNoteView", QSA_NO_WNDCLS_REGEX, "^(?!#ENS).+", "Evernote Single-note")
; Match any single note whose title does NOT starts with #ENS
; App+t to callup EverTable UI
fxhk_DefineComboHotkeyCond("AppsKey", "t", "Evernote_IsMainFrameOrSingleActive", "EverTable_LaunchUI")
}
; ========================= EverTable(Evtbl) code starts =========================
EverTable_LaunchUI()
{
Evtbl_FixIE(11) ; gradient background is supported only in IE11.
; Remember current active window, will be paste target later
g_evtblHwndToPaste := dev_GetActiveHwnd()
Evtbl_ShowGui()
}
Evtbl_FixIE(Version=0, ExeName="")
{
; https://autohotkey.com/board/topic/93660-embedded-ie-shellexplorer-render-issues-fix-force-it-to-use-a-newer-render-engine/
static Key := "Software\Microsoft\Internet Explorer"
. "\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"
, Versions := {7:7000, 8:8888, 9:9999, 10:10001, 11:11001}
if Versions.HasKey(Version)
Version := Versions[Version]
if !ExeName
{
if A_IsCompiled
ExeName := A_ScriptName
else
SplitPath, A_AhkPath, ExeName
}
RegRead, PreviousValue, HKCU, %Key%, %ExeName%
if (Version = "")
RegDelete, HKCU, %Key%, %ExeName%
else
RegWrite, REG_DWORD, HKCU, %Key%, %ExeName%, %Version%
return PreviousValue
}
Evtbl_ShowGui()
{
if(!g_HwndEvtbl) {
Evtbl_CreateGui()
}
Gui, EVTBL:Show, , % "EverTable"
; Always set keyboard focus to color Combobox on GUI showing.
GuiControl, EVTBL:Focus, g_evtblComboColor
Evtbl_SyncUserInputToColorPreview()
; Initially turn off these checkbox:
GuiControl, EVTBL:, g_evtblChkboxTSV, 0
; SetTimer, timer_EvtblSyncColor, 200
OnMessage(0x200, Func("Evtbl_WM_MOUSEMOVE")) ; add message hook
OnMessage(0x111, Func("Evtbl_WM_COMMAND")) ; to get WM_COMMAND -> EN_KILLFOCUS notification
}
Evtbl_HideGui(html_clipboard:="")
{
; SetTimer, timer_EvtblSyncColor, Off
Gui, EVTBL:Hide
OnMessage(0x200, Func("Evtbl_WM_MOUSEMOVE"), 0) ; remove message hook
OnMessage(0x111, Func("Evtbl_WM_COMMAND"), 0)
tooltip ; turn off possible dangling tooltip
if(html_clipboard)
{
; We should do clipboard paste *after* Evtbl GUI has been hidden,
; otherwise, the selected-text in Combobox may probably be cleared.
dev_ClipboardSetHTML(html_clipboard, true, g_evtblHwndToPaste)
}
}
Evtbl_CreateGui()
{
Gui, EVTBL:New ;Destroy old window if any
Gui, EVTBL:+Hwndg_HwndEvtbl
;
; Global Windows Dialog options
;
Gui, EVTBL:Color, white ; Set whole GUI background color, bcz Evernote evclip's background is always white.
Gui, EVTBL:Font, s9 c909090, Tahoma
Gui, EVTBL:Add, Text, w500, % "EverTable generates visually appealing <TABLE> and <DIV> HTML snippets for Evernote."
Gui, EVTBL:Font, s9 cBlack, Tahoma
;
; Background color: Text color:
; [combobox selecting color ] (x)Black ( )White [~]
; [combobox selecting 2nd color] [x]Second color [~]
; [[ Color Preview ]]
;
Gui, EVTBL:Add, Text, xm w320 , % "Background &color:"
Gui, EVTBL:Add, Text, X+10 w160 , % "Text color:"
;
; Add a Combobox with fixed-width font(Consolas), and set its event handler:
Gui, EVTBL:Font, s9 cBlack, Consolas
Gui, EVTBL:Add, ComboBox, xm w320 vg_evtblComboColor Hwndg_evtblHwndComboColor gEvtbl_OnComboColorChange
;
Gui, EVTBL:Font, s9 cBlack, Tahoma
Gui, EVTBL:Add, Radio, X+10 yp+4 Group Checked vg_evtblIsBlackText gEvtbl_procTextColor, % "&Black"
Gui, EVTBL:Add, Radio, X+10 vg_evtblIsWhiteText gEvtbl_procTextColor, % "&White"
Gui, EVTBL:Add, Button, xm+470 yp-4 vg_evtblBtnColorMatrix gEvtbl_ShowColorMatrix, % "~"
; 2nd color combobox + [x]checkbox + [~]
Gui, EVTBL:Font, s9 cBlack, Consolas
Gui, EVTBL:Add, ComboBox, xm y+10 w320 vg_evtblComboColor2 Hwndg_evtblHwndComboColor2 gEvtbl_OnComboColorChange,
Gui, EVTBL:Font, s9 cBlack, Tahoma
Gui, EVTBL:Add, Checkbox, x+10 yp+4 w118 vg_evtblUse2ndColor gEvtbl_SyncUserInputToColorPreview, % "&Use second color"
Gui, EVTBL:Add, Button, xm+470 yp-4 vg_evtblBtnColorMatrix2 gEvtbl_ShowColorMatrix2, % "~"
;
; Add "Preview" labels with a bit larger font:
; Note: A preview-label is a Progress-bar overlayed with a transparent Text label.
; We use Progress-bar bcz we can set its background color individually.
Gui, EVTBL:Font, s12 cBlack, Tahoma
Gui, EVTBL:Add, Progress, xm y+15 w160 vg_evtblPreviewBox
Gui, EVTBL:Add, Text, xp yp wp hp Center +Border BackgroundTrans vg_evtblPreviewText, % text_ColorPreview
; -- Center: Text at control center; xs ys: x,y@saved position ; xp yp wp hp: x,y,width,height same as previous
; 2nd color:
Gui, EVTBL:Add, Progress, x+10 w160 hp vg_evtblPreviewBox2
Gui, EVTBL:Add, Text, xp yp wp hp Center +Border BackgroundTrans vg_evtblPreviewText2, % text_ColorPreview
; 3rd, mix color with IE ActiveX ctrl
Gui, EVTBL:Add, ActiveX, x+10 yp w160 hp vg_evtblPreviewMix, Shell.Explorer ; demo code uses vWB
Evtbl_HtmlInitContent(g_evtblPreviewMix)
; Restore default font size for GUI
Gui, EVTBL:Font, s9 cBlack, Tahoma
;
; HTML content selection: <TABLE> , <DIV> , CSS-Table , <span>
;
Gui, EVTBL:Add, Text, xm Y+15 , % "HTML content:"
Gui, EVTBL:Add, Radio, X+10 Group Checked vg_evtblIsTable gEvtbl_OnTableDivSwitch, % "<&TABLE>"
Gui, EVTBL:Add, Radio, X+10 vg_evtblIsDiv gEvtbl_OnTableDivSwitch, % "<&DIV>"
Gui, EVTBL:Add, Radio, X+25 vg_evtblIsCsstable gEvtbl_OnTableDivSwitch, % "CSS-t&able"
Gui, EVTBL:Add, Radio, X+10 vg_evtblIsSpan gEvtbl_OnTableDivSwitch, % "<spa&n>"
; // set CSS-table rows //
Gui, EVTBL:Add, Edit, xp yp-3 w30 Hidden vg_evtblEdtCsstableRows, % "3"
Gui, EVTBL:Add, Text, x+5 yp+3 Hidden vg_evtblLblCsstableRows, % "rows"
Gui, EVTBL:Add, CheckBox, x+5 Checked Hidden vg_evtblChkboxCsstableHead, % "Add header"
; 2022.03 span-text editbox
Gui, EVTBL:Add, Edit, xm y+9 w415 Hidden vg_evtblSpanText , % "span text"
Gui, EVTBL:Add, Checkbox, x+3 yp+2 w80 Hidden vg_evtblIsSpanMono, % "mono-f&ont"
;
; 2024.07 DIV talk-leftside/talk-rightside
Gui, EVTBL:Add, Radio, xm+179 yp Group Checked Hidden vg_evtblDivFullWidth, % "&Full width"
Gui, EVTBL:Add, Radio, x+10 Hidden vg_evtblDivLeftSide, % "&Left side"
Gui, EVTBL:Add, Radio, x+10 Hidden vg_evtblDivRightSide, % "&Right side"
Gui, EVTBL:Add, Radio, x+10 Hidden vg_evtblDivQAstyle, % "&Q&&A Style"
;
; Table Columns: ____24,360,540____ [x] First column in color // reuse the same position as span-text
;
Gui, EVTBL:Add, Text, xm yp+2 vlbl_TableColumnSpec, % "Table Column&s:"
Gui, EVTBL:Add, Edit, x+10 yp-2 w240 vg_evtblTableColumnSpec, % "24:#,360:Brief,540:Detail"
Gui, EVTBL:Add, Edit, xp yp wp Hidden vg_evtblCssTableColumnSpec, % "30%,30%,30%" ; yes, overlap with previous
Gui, EVTBL:Add, Checkbox, x+20 yp+4 vg_evtblIsFirstColumnColor, % "&First column in color"
; Gui, EVTBL:Add, Text, x+10 yp+2, % "Table width(%):"
; Gui, EVTBL:Add, Edit, x+10 yp-2 w40, % "100"
;
; Table border: (x)1px ( )2px Table cell padding: (x)sparse ( )dense
;
Gui, EVTBL:Add, Text, xm y+12 vlbl_TableCellPadding, % "Table cell &padding:"
Gui, EVTBL:Add, Radio, x+10 Group Checked vg_evtblIsPaddingSparse, % "Sparse"
Gui, EVTBL:Add, Radio, x+10 vg_evtblIsPaddingDense , % "Dense"
;
Gui, EVTBL:Add, Text, x+22 vlbl_TableBorderPx, % "Table borde&r:"
Gui, EVTBL:Add, Radio, x+10 Group vg_evtblBorder1px, % "1px"
Gui, EVTBL:Add, Radio, x+10 Checked vg_evtblBorder2px, % "2px"
; [ Paste HTML ] ... [ Preview HTML ]
Gui, EVTBL:Add, Button, xm Y+10 Default vg_evtblBtnOK gEvtbl_BtnOK, % "Paste HTML (Enter)"
Gui, EVTBL:Add, Checkbox, x+10 yp+6 vg_evtblChkboxTSV, % "fro&m TSV/CSV"
Gui, EVTBL:Add, Button, x420 yp-6 gEvtbl_BtnPreviewHtml, % "Preview &HTML"
Evtbl_ComboboxFillColorPresets("g_evtblComboColor", g_evtblIdxDefaultColor1)
Evtbl_ComboboxFillColorPresets("g_evtblComboColor2", g_evtblIdxDefaultColor2)
; Special: Save Preview box's position for later use.
GuiControlGet, box1, EVTBL:Pos, g_evtblPreviewBox
GuiControlGet, box3, EVTBL:Pos, g_evtblPreviewMix
;
g_evtblBox1HalfPos.x := box1X
g_evtblBox1HalfPos.y := box1Y
g_evtblBox1HalfPos.w := box1W
g_evtblBox1HalfPos.h := box1H
; dev_TooltipAutoClear( Format("box1: {} {} {} {}", box1X, box1Y, box1W, box1H))
g_evtblBox1FullPos.x := box1X
g_evtblBox1FullPos.y := box1Y
g_evtblBox1FullPos.w := box3X+box3W - box1X
g_evtblBox1FullPos.h := box3H
return
;timer_EvtblSyncColor:
; Evtbl_SyncUserInputToColorPreview()
; return
}
Evtbl_OnTableDivSwitch()
{
; Memo: Initial hidden ctrls is controlled in Evtbl_CreateGui() ;
all_ctls := [ "g_evtblEdtCsstableRows", "g_evtblLblCsstableRows", "g_evtblChkboxCsstableHead"
, "g_evtblIsSpan"
, "lbl_TableColumnSpec", "g_evtblTableColumnSpec", "g_evtblCssTableColumnSpec", "g_evtblIsFirstColumnColor"
, "g_evtblSpanText", "g_evtblIsSpanMono", "g_evtblDivFullWidth", "g_evtblDivLeftSide", "g_evtblDivRightSide", "g_evtblDivQAstyle"
, "lbl_TableCellPadding", "g_evtblIsPaddingSparse", "g_evtblIsPaddingDense"
, "lbl_TableBorderPx", "g_evtblBorder1px", "g_evtblBorder2px" ]
; ------------------------------------------------------------------------------------------
table_ctls := [ "_", "_", "_"
, "g_evtblIsSpan"
, "lbl_TableColumnSpec", "g_evtblTableColumnSpec", "_", "g_evtblIsFirstColumnColor"
, "_", "_" , "_", "_", "_"
, "lbl_TableCellPadding", "g_evtblIsPaddingSparse", "g_evtblIsPaddingDense"
, "lbl_TableBorderPx", "g_evtblBorder1px", "g_evtblBorder2px" ]
; ------------------------------------------------------------------------------------------
csstbl_ctls := [ "g_evtblEdtCsstableRows", "g_evtblLblCsstableRows", "g_evtblChkboxCsstableHead"
, "_"
, "lbl_TableColumnSpec", "", "_", "g_evtblCssTableColumnSpec", "g_evtblIsFirstColumnColor"
, "_", "_", "_", "_", "_"
, "_", "_", "_"
, "_", "_", "_" ]
; ------------------------------------------------------------------------------------------
div_ctls := [ "_", "_", "_"
, "g_evtblIsSpan"
, "_", "_", "_", "_"
, "_", "_", "g_evtblDivFullWidth", "g_evtblDivLeftSide", "g_evtblDivRightSide", "g_evtblDivQAstyle"
, "_", "_", "_"
, "_", "_", "_" ]
; ------------------------------------------------------------------------------------------
span_ctls := [ "_", "_", "_"
, "g_evtblIsSpan"
, "_", "_", "_", "_"
, "g_evtblSpanText", "g_evtblIsSpanMono", "_", "_", "_"
, "_", "_", "_"
, "_", "_", "_" ]
Gui, EVTBL:Submit, NoHide
if(g_evtblIsTable)
need_ctls := table_ctls
else if(g_evtblIsDiv)
need_ctls := div_ctls
else if(g_evtblIsCssTable)
need_ctls := csstbl_ctls
else if(g_evtblIsSpan)
need_ctls := span_ctls
else
dev_assert(0)
Loop, % all_ctls.Length()
{
ctlvar := all_ctls[A_Index]
isshow := dev_IsEleInArray(ctlvar, need_ctls)
hideORshow := isshow ? "Show" : "Hide"
GuiControl, EVTBL:%hideORshow%, %ctlvar%
; Disable a Uic, so to make its Alt-hotchar in-effective.
; This is beneficial when two Uic-s share a single hotchar.
; If one is disabled, the other will get instant response on that hotchar.
dis_enable := isshow ? "Enable" : "Disable"
GuiControl, EVTBL:%dis_enable%, %ctlvar%
}
GuiControl, % "EVTBL:" (g_evtblIsTable?"Show":"Hide"), g_evtblChkboxTSV
}
Evtbl_ParseTableColumnWidth(ColumnSpec)
{
; ColumnSpec is like: "24,360,540" or "24:#,360:Brief,540:Detail"
token := StrSplit(ColumnSpec, ",")
if (token.Length() == 0) {
return
}
ar_colinfo := []
Loop, PARSE, ColumnSpec, `,
{
; A_LoopField will be "24" or "360:Brief" etc
tkn := [ "" , "#" A_Index ]
; -- tkn[2] : set default column header text #1, #2, #3 ...
tkn := StrSplit(A_LoopField, ":")
ar_colinfo.Push({ "width_px" : tkn[1], "text" : tkn[2] })
}
return ar_colinfo
}
make_css_bg_rule(hexcolor1, hexcolor2)
{
if(hexcolor2)
css_bg_rule := Format("background: linear-gradient(15deg, {}, {});", hexcolor1, hexcolor2)
else
css_bg_rule := Format("background-color: {};", hexcolor1)
return css_bg_rule
}
Evtbl_GenHtml_Table(hexcolor1, hexcolor2)
{
ar_colinfo := Evtbl_ParseTableColumnWidth(g_evtblTableColumnSpec)
if(!ar_colinfo) {
MsgBox, % "Wrong input: Empty table columns assignment."
return
}
/*
html_table_complete_sample =
(
+<table border="2" style="border-collapse:collapse; border-color:#3C965A; width:100%;">
<colgroup><col style="width:24px;"></col><col style="width:360px;"></col><col style="width:540px;"></col></colgroup>
<thead>
<tr> <!-- 20190722: Do NOT use <th> inside <thead>, which will cause column widths skew after typing words into cells. -->
<td style="padding:0.5em; background-color:#50C878; color:black; text-align:center; font-weight:bold; border-color:#3C965A;">#</td>
<td style="padding:0.5em; background-color:#50C878; color:black; text-align:center; font-weight:bold; border-color:#3C965A;">Brief</td>
<td style="padding:0.5em; background-color:#50C878; color:black; text-align:center; font-weight:bold; border-color:#3C965A;">Detail</td>
</tr>
</thead>
<tbody>
<tr>
<td style="vertical-align:top; padding:0.5em; border-color:#3C965A;">20190722</td>
<td style="vertical-align:top; padding:0.5em; border-color:#3C965A;">.</td>
<td style="vertical-align:top; padding:0.5em; border-color:#3C965A;">.</td>
</tr>
</tbody>
</table>~
)
*/
htmline_colgroup := "" ; {1}
colwidth_count := ar_colinfo.Length()
css_bg_rule := make_css_bg_rule(hexcolor1, hexcolor2) ; maybe pure color or color gradient
Loop, %colwidth_count%
{
ptn_colgroup =
(
<col style="width: {1}px;"></col>
)
htmline_colgroup .= Format(ptn_colgroup, ar_colinfo[A_Index].width_px)
}
padding_em := g_evtblIsPaddingSparse ? "0.5" : "0.2"
tableborder := g_evtblBorder1px ? "1" : "2"
bordercolor := Evtbl_CalBorderColorFromBgColor(hexcolor1)
pb_text_color := g_evtblIsWhiteText ? "white" : "black" ; text-color for those background-painted cells
thead_tds := "" ; the <td>s inside <thead><tr>
Loop, %colwidth_count%
{
ptn_tds =
(
<td style="padding:{1}em; {2}; color:{3}; text-align:center; font-weight:bold; border-color:{4};">{5}</td>
)
thead_tds .= Format(ptn_tds, padding_em, css_bg_rule, pb_text_color, bordercolor, ar_colinfo[A_Index].text)
}
tbody_tds := "" ; the <td>s inside <tbody><tr>
Loop, %colwidth_count%
{
ptn_tds =
(
<td style="vertical-align:top; padding:{1}em; border-color:{2}; color:{3}; {4}">{5}</td>
)
cell_bgcolor := ""
cell_textcolor := "black"
datestr := ""
if(A_Index==1)
{
if(g_evtblIsFirstColumnColor)
{
cell_bgcolor := css_bg_rule
cell_textcolor := pb_text_color
}
FormatTime, datestr, , % "yyyyMMdd"
}
tbody_tds .= Format(ptn_tds, padding_em, bordercolor, cell_textcolor, cell_bgcolor, datestr)
}
html_ptn =
(
+<table border="{4}" style="border-collapse:collapse; border-color:{5}; width:100`%; chjid:{6};">
<colgroup>{1}</colgroup>
<thead>
<tr> <!-- 20190722: Do NOT use <th> inside <thead>, which will cause column widths skew after typing words into cells. -->
{2}
</tr>
</thead>
<tbody>
<tr>
{3}
</tr>
</tbody>
</table>~
) ; memo: The leading + and trailing ~ is for Evernote 6.13's sane purpose.
html := Format(html_ptn
, htmline_colgroup, thead_tds, tbody_tds
, tableborder, bordercolor
, "evertbl_" dev_GetDateTimeStrCompact())
; [2022-10-30] Embed `chjid` timestamp into <table>, so that Evernote 6.5.4 preserves it.
; Note: I have to use chjid inside style="...", instead of regular id attribute of <table>,
; bcz Evernote 6.5.4 will drop the "id=... " when I export the clip to .enex.
; Caution: Editing the <table> with Evernote 6.6+ will ruin chjid .
return html
}
Evtbl_GenHtml_Div_once(hexcolor1, hexcolor2, align:="FullWidth", add_tail_dash:=true)
{
cssmargin := ""
if(align=="LeftSide")
cssmargin := "margin-right: 20`%;"
else if(align=="RightSide")
cssmargin := "margin-left: 20`%;"
htmlptn =
(
-<div style="padding: 0.8em; {1} border: 1px solid rgb(220, 220, 220); {2};"><span>DIV</span></div>
) ; will be feed to Format(), {1} will be replaced
if(add_tail_dash)
htmlptn .= "<div>-</div>"
css_bg_rule := make_css_bg_rule(hexcolor1, hexcolor2)
html := Format(htmlptn, cssmargin, css_bg_rule)
return html
}
Evtbl_GenHtml_Div(hexcolor1, hexcolor2, align:="FullWidth")
{
is_QAstyle := (align=="QAstyle")
if(not is_QAstyle)
{
return Evtbl_GenHtml_Div_once(hexcolor1, hexcolor2, align)
}
else
{
Qhtml := Evtbl_GenHtml_Div_once(hexcolor1, "", "LeftSide", false)
if(not hexcolor2)
hexcolor2 := hexcolor1
Ahtml := Evtbl_GenHtml_Div_once(hexcolor2, "", "RightSide")
return Qhtml . Ahtml
}
}
Evtbl_GenHtml()
{
GuiControlGet, colortext, EVTBL:, g_evtblComboColor
hexcolor1 := Evtbl_GetHexcolorFromStr(colortext) ; -- e.g. hexcolor="#f0f0ff"
if(!hexcolor1)
{
MsgBox, % "Invalid hex color1 input, cannot generate HTML."
return
}
hexcolor2 := "" ; assume no 2nd color
GuiControlGet, g_evtblUse2ndColor, EVTBL:
if(g_evtblUse2ndColor)
{
GuiControlGet, colortext, EVTBL:, g_evtblComboColor2
hexcolor2 := Evtbl_GetHexcolorFromStr(colortext)
if(!hexcolor2) {
MsgBox, % "Invalid hex color2 input, cannot generate HTML."
return
}
}
Gui, EVTBL:Submit, NoHide
if(g_evtblIsTable)
{
if(!g_evtblChkboxTSV)
html := Evtbl_GenHtml_Table(hexcolor1, hexcolor2)
else
html := Evtbl_GenHtml_FromTSV(hexcolor1, hexcolor2)
}
else if(g_evtblIsDiv)
{
align := ""
if(g_evtblDivLeftSide)
align := "LeftSide"
else if(g_evtblDivRightSide)
align := "RightSide"
else if(g_evtblDivQAstyle)
align := "QAstyle"
html := Evtbl_GenHtml_Div(hexcolor1, hexcolor2, align)
}
else if(g_evtblIsCssTable)
{
rows := g_evtblEdtCsstableRows + 0
GuiControlGet, g_evtblChkboxCsstableHead, EVTBL:
isAddHead := g_evtblChkboxCsstableHead ? 1 : 0
html := Evtbl_GenHtml_CssTable(rows, isAddHead, hexcolor1, hexcolor2)
}
else if(g_evtblIsSpan)
{
GuiControlGet, spantext, EVTBL:, g_evtblSpanText
if (spantext=="")
spantext := "~~"
GuiControlGet, g_evtblIsSpanMono, EVTBL:
html := Evtbl_GenHtml_Span(hexcolor1, hexcolor2, spantext, g_evtblIsSpanMono)
}
return html
}
Evtbl_GenHtml_CssTable(rows, isAddHead, hexcolor1, hexcolor2)
{
/* This function enables embedding nesting "tables" into an Evernote <table>. Great idea!
But since CSS-table in Evernote is a tweak, so it has limitations:
* We cannot add or delete rows and columns.
* We cannot drag CSS-table cell border to adjust their width.
So plan carefully before you insert one. If you find the layout unsatisfied, you have to re-insert the
whole csstable and fill its content from the beginning.
*/
; Parsing ColumnSpec. If logic changes here,
; tooltip for `g_evtblCssTableColumnSpec` in Evtbl_WM_MOUSEMOVE() should be updated accordingly.
ColumnSpec := g_evtblCssTableColumnSpec
if( Instr(ColumnSpec, ",") )
{
ar_colinfo := Evtbl_ParseTableColumnWidth(ColumnSpec)
if(!ar_colinfo) {
MsgBox, % "Wrong input: Empty table columns assignment."
return
}
}
else
{
; No separator in ColumnSpec, so we think it a column count.
; In this case we do not set "width:30%" as table-cell style, so we have "auto fit-width" effect,
; i.e. column width ajusted automatically according to text amount in cell.
columns := ColumnSpec + 0
if(columns<=0) {
MsgBox, % "Wrong input: Empty table columns assignment. If no comma, should be a integer."
return
}
ar_colinfo := {}
Loop, %columns% {
ar_colinfo.Push({ "width_px":"any", "text":"any" })
}
}
/*
html_csstable_complete_sample =
(
+<div style="display:table; border:1px solid lightgray;">
<div style="display:table-row">
<div style="display:table-cell; padding:3px; border:1px solid lightgray; width:50%; background-color:#fefe8c;">Cell</div>
<div style="display:table-cell; padding:3px; border:1px solid lightgray; width:50%; background-color:#fefe8c;">Cell</div>
</div>
<div style="display:table-row">
<div style="display:table-cell; padding:3px; border:1px solid lightgray; background-color:#fefe8c;">Cell</div>
<div style="display:table-cell; padding:3px; border:1px solid lightgray;">-</div>
</div>
</div>~
)
*/
css_bg_rule := make_css_bg_rule(hexcolor1, hexcolor2) ; maybe pure color or color gradient
html_tablerows := ""
Loop, % rows+isAddHead
{
is_first_line := A_Index==1
is_color_row := is_first_line && isAddHead
html_onerow := Evtbl_GenHtml_CssTable_OneRow(ar_colinfo, css_bg_rule, is_first_line, is_color_row)
html_tablerows .= html_onerow
}
fmt_html =
(
+<div style="display:table; border:1px solid lightgray;">
{1}
</div>~
)
html := Format(fmt_html, html_tablerows)
return html
}
;
Evtbl_GenHtml_CssTable_OneRow(ar_colinfo, css_bg_rule, is_first_line, is_color_row)
{
fmt_tablecell =
(
<div style="display:table-cell; padding:3px; border:1px solid lightgray; width:{1}; vertical-align:top; {2}; {3}">{4}</div>
)
colwidth_count := ar_colinfo.Length()
tablecells_onerow := ""
Loop, %colwidth_count%
{
bg_rule := (is_color_row || (A_Index==1 && g_evtblIsFirstColumnColor)) ? css_bg_rule : ""
width_value := ar_colinfo[A_Index].width_px
if(!StrIsEndsWith(width_value, "%"))
width_value .= "%" ; turn 30 into 30%, etc
tablecells_onerow .= Format(fmt_tablecell
, width_value
, (is_first_line && is_color_row) ? "text-align:center" : ""
, bg_rule
, is_first_line ? Format("Column{1}", A_Index) : "-")
}
fmt_tablerow =
(
<div style="display:table-row">
{1}
</div>
)
tablerow := Format(fmt_tablerow, tablecells_onerow)
return tablerow
}
Evtbl_GenHtml_Span(hexcolor1, hexcolor2, spantext, is_monofont)
{
htmlptn =
(
<span style="{1}; color:{2}; {3}">{4}</span>
) ; Note: an extra " " at tail, so that user's continued typing after the <span> is in normal text style.
; But a little drawback: If there has already been normal text after pasting the <span>, there will be TWO space-chars after <span>.
spanhtml := dev_EscapeHtmlChars(spantext)
; spanhtml := "<tt>" spanhtml "</tt>" ; This renders extra borders on span text, not good.
monofont := is_monofont ? "font-family:consolas,monospace;" : ""
css_bg_rule := make_css_bg_rule(hexcolor1, hexcolor2)
html := Format(htmlptn
, css_bg_rule
, g_evtblIsWhiteText?"white":"black"
, monofont
, spanhtml)
return html
}
Evtbl_BtnOK()
{
; dev_TooltipAutoClear("Evtbl_BtnOK", 1000)
html := Evtbl_GenHtml()
if(html) ; if html is null, leave the GUI on so that user can do fix.
{
Evtbl_HideGui(html)
}
}
Evtbl_OnComboColorChange()
{
Evtbl_SyncUserInputToColorPreview()
}
EVTBLGuiEscape() ; The GuiEscape hook
{
; msgbox, % "EVTBLGuiEscape()"
Evtbl_HideGui(html)
}
EVTBLGuiClose() ; The GuiClose hook
{
; msgbox, % "EVTBLGuiClose()"
Evtbl_HideGui()
}
Evtbl_BtnPreviewHtml()
{
html := Evtbl_GenHtml()
PreviewHtml_ShowGui(html)
}
Evtbl_procTextColor()
{
Evtbl_SyncUserInputToColorPreview()
}
_validate_color_triple(cobj)
{
if(cobj.red>=0 && cobj.red<=255 && cobj.green>=0 && cobj.green<=255 && cobj.blue>=0 && cobj.blue<=255)
return cobj
else
return
}
util_GetRgbTripleFromStr(colortext)
{
; colortext can be "#f0f0f0...", or "rgb(0,128,255)..." // should not be "f0f0f0..."
; note: "#f0f0f0a" or "#f0f0f011..." is not valid
; Return an object with three members of .red .green .blue
cobj := {}
; Check for "#f0f0f0"
;
RegExMatch(colortext, "^#[0-9a-fA-F]{6}(?!\w)", hexcolor)
; -- hexcolor will be "#f0f0f0" etc if colortext is valid.
if(hexcolor)
{
cobj.red := dev_Hex2Num(SubStr(hexcolor, 2, 2))
cobj.green := dev_Hex2Num(SubStr(hexcolor, 4, 2))
cobj.blue := dev_Hex2Num(SubStr(hexcolor, 6, 2))
return _validate_color_triple(cobj)
}
; Check for "rgb(...)"
;
RegExMatch(colortext, "i)^rgb\(([0-9]{1,3})[ ,]+([0-9]{1,3})[ ,]+([0-9]{1,3})\)", subpat)
if(subpat)
{
cobj.red := subpat1
cobj.green := subpat2
cobj.blue := subpat3
return _validate_color_triple(cobj)
}
}
util_ColorTripleToHex(ctriple, is_prefix_sharp:=false)
{
rgbstr := Format("{:02X}{:02X}{:02X}", ctriple.red, ctriple.green, ctriple.blue)
return (is_prefix_sharp ? "#" : "") . rgbstr
}
util_ColorTripleToRGB(ctriple, is_prefix_sharp:=false)
{
rgbstr := Format("rgb({},{},{})", ctriple.red, ctriple.green, ctriple.blue)
return rgbstr
}
Evtbl_GetHexcolorFromStr(colortext)
{
ctriple := util_GetRgbTripleFromStr(colortext)
if(!ctriple)
{ ; if colortext contains invalid RGB values, will return null
return ""
}
hexcolor := util_ColorTripleToHex(ctriple, true)
return hexcolor
}
Evtbl_GetColorDicts()
{
ar_colordict := []
presets := g_evtblColorPresets.Length()
arinput := []
arinput.Push(g_evtblColorPresets*)