-
Notifications
You must be signed in to change notification settings - Fork 2
/
sdpp.cpp
4200 lines (3505 loc) · 97.3 KB
/
sdpp.cpp
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
// DLIB
#include <utf>
#include <wtxta>
#include <ui64a>
#include <clip>
#include <npp.h>
#include <shlobj.h>
#include <shlwapi.h>
#define RESOURCE_FILE_INCLUDED
#include "sdpp.rc"
#pragma comment( lib, "user32" )
#pragma comment( lib, "gdi32" )
#pragma comment( lib, "shell32" )
#pragma comment( lib, "ole32" )
// TODO AppendMenuA function (winuser.h) https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-appendmenua THIS CAN INJECT CONTEXT MENU INTO NPP CONTEXT MENU! OR SPAWN A NEW MENU AND ADD ITEMS TO IT, ETC
// TODO REMOVE/DISABLE DEBUG PRINTS --> CLEAR STYLE 5 HIGHLIGHTS!
// TODO FINFILES BUGG: NOT REDRAWN WHEN MOVED OUT OF THE SCREEN
// TODO redrawMouseHov BUG!!! IF WINDOW IS SCROLLED DOWN, HIGHLIGHT IS BROKEN ::: FIXED ::: BUILD ::: TEST
// TODO Alternatively, call tips can be displayed when you leave the mouse pointer for a while over a word in response to the SCN_DWELLSTART notification andcancelled in response to SCN_DWELLEND.This method could be used in a debugger to give the value of a variable, or during editing to give information about the word under the pointer.
//SCN_DWELLSTART
//SCN_DWELLEND
//SCN_DWELLSTART is generated when the user keeps the mouse in one position for the dwell period (see SCI_SETMOUSEDWELLTIME).SCN_DWELLEND is generated after a SCN_DWELLSTART andthe mouse is moved or other activity such as key press indicates the dwell is over.Both notifications set the same fields in SCNotification :
//Field Usage
//position This is the nearest position in the document to the position where the mouse pointer was lingering.
//x, y Where the pointer lingered.The position field is set to SCI_POSITIONFROMPOINTCLOSE(x, y).
//SCI_CALLTIPSHOW(position pos, const char *definition)
//This message starts the process by displaying the call tip window.If a call tip is already active, this has no effect.
//pos is the position in the document at which to align the call tip.The call tip text is aligned to start 1 line below this character unless you have included up and/or down arrows in the call tip text in which case the tip is aligned to the right-hand edge of the rightmost arrow.The assumption is that you will start the text with something like "\001 1 of 3 \002".
//definition is the call tip text.This can contain multiple lines separated by '\n' (Line Feed, ASCII code 10) characters.Do not include '\r' (Carriage Return, ASCII code 13), as this will most likely print as an empty box. '\t' (Tab, ASCII code 9) is supported if you set a tabsize with SCI_CALLTIPUSESTYLE.
//The position of the caret is remembered here so that the call tip can be cancelled automatically if subsequent deletion moves the caret before this position.
//
//SCI_CALLTIPCANCEL
//This message cancels any displayed call tip.Scintilla will also cancel call tips for you if you use any keyboard commands that are not compatible with editing the argument list of a function.Call tips are cancelled if you delete back past the position where the caret was when the tip was triggered.
//
//SCI_CALLTIPACTIVE bool64
//This returns 1 if a call tip is active and 0 if it is not active.
//
//SCI_CALLTIPPOSSTART position
//SCI_CALLTIPSETPOSSTART(position posStart)
//This message returns or sets the value of the current position when SCI_CALLTIPSHOW started to display the tip.
//
//SCI_CALLTIPSETHLT(position highlightStart, position highlightEnd)
//This sets the region of the call tips text to display in a highlighted style.highlightStart is the zero-based index into the string of the first character to highlight and highlightEnd is the index of the first character after the highlight.highlightEnd must be greater than highlightStart; highlightEnd-highlightStart is the number of characters to highlight.Highlights can extend over line ends if this is required.
//
//Unhighlighted text is drawn in a mid grey.Selected text is drawn in a dark blue.The background is white.These can be changed with SCI_CALLTIPSETBACK, SCI_CALLTIPSETFORE, andSCI_CALLTIPSETFOREHLT.
//
//SCI_CALLTIPSETBACK(colour back)
//The background colour of call tips can be set with this message; the default colour is white.It is not a good idea to set a dark colour as the background as the default colour for normal calltip text is mid grey andthe default colour for highlighted text is dark blue.This also sets the background colour of STYLE_CALLTIP.
//
//SCI_CALLTIPSETFORE(colour fore)
//The colour of call tip text can be set with this message; the default colour is mid grey.This also sets the foreground colour of STYLE_CALLTIP.
//
//SCI_CALLTIPSETFOREHLT(colour fore)
//The colour of highlighted call tip text can be set with this message; the default colour is dark blue.
//
//SCI_CALLTIPUSESTYLE(int tabSize)
//This message changes the style used for call tips from STYLE_DEFAULT to STYLE_CALLTIP andsets a tab size in screen pixels.If tabsize is less than 1, Tab characters are not treated specially.Once this call has been used, the call tip foreground andbackground colours are also taken from the style.
//
//SCI_CALLTIPSETPOSITION(bool64 above)
//By default the calltip is displayed below the text, setting above to true (1) will display it above the text.
#define CMD_FUNCS 16
// Important commands' IDs
#define CMD_FIND_IN_FILES 6
// SEPARATOR --------- (CMD_CONSOLE + 7) -------------------------------
#define CMD_CONSOLE (CMD_FIND_IN_FILES + 2) // Cpp file parameters togglers
#define CMD_NOPT (CMD_CONSOLE + 1)
#define CMD_DBG (CMD_CONSOLE + 2)
#define CMD_NLAUNCH (CMD_CONSOLE + 3)
#define CMD_ASM (CMD_CONSOLE + 4)
// SEPARATOR --------- (CMD_CONSOLE + 5) -------------------------------
#define CMD_DBGP_DISABLED (CMD_ASM + 2) // Cpp file debug toggler
#define FIND_BEFORE 0x0
#define FIND_AFTER 0x1
#define CLOSING 0x0
#define OPENING 0x2
#define MAX_LANG_LINE_SIZE 512
#define MAX_COMMENT_TAG_SIZE 32
#define FILE_READ_BUFF_SZ 4096
#ifdef UNICODE
#define TOWSTR(x) L ## x
#else
#define TOWSTR(x) x
#endif
#define APP_GUID "-{AAA6D28F-DF14-4570-A273-21DD2708F5AD}"
#define REGISTER_MESSAGE(n) \
static const UINT n = RegisterWindowMessage(TOWSTR(#n APP_GUID))
#undef MEM_FREE
#define MEM_ALLOC(x) HeapAlloc(heap, 0, (x))
#define MEM_ZALLOC(x) HeapAlloc(heap, HEAP_ZERO_MEMORY, (x))
#define MEM_FREE(x) HeapFree(heap, 0, (x))
HANDLE heap = HeapCreate(0, 0x10000, 0); // 65 536 B, 64k granularity
struct Selection
{
ui64 beg;
ui64 end;
ui64 idx;
};
struct Lang
{
const char *n;
char c[MAX_COMMENT_TAG_SIZE];
char bcb[MAX_COMMENT_TAG_SIZE];
char bce[MAX_COMMENT_TAG_SIZE];
};
struct UserLang
{
char *n;
char c[MAX_COMMENT_TAG_SIZE];
char bcb[MAX_COMMENT_TAG_SIZE];
char bce[MAX_COMMENT_TAG_SIZE];
};
struct DebugPrintLine
{
ui64 line;
ui32 symb_n;
ui32 pos;
char **symbs;
ui64 smb_ts;
};
ui64 ulangs_s;
UserLang *user_langs;
ui64 langs_s = 87;
Lang langs[] = {
{"normal", ">>> ", "[", "]"} , // Coz, why not?
{"php", "", "", ""} ,
{"c", "", "", ""} ,
{"cpp", "", "", ""} ,
{"cs", "", "", ""} ,
{"objc", "", "", ""} ,
{"java", "", "", ""} ,
{"rc", "", "", ""} ,
{"html", "", "", ""} ,
{"xml", "", "", ""} ,
{"makefile", "", "", ""} ,
{"pascal", "", "", ""} ,
{"batch", "", "", ""} ,
{"ini", "", "", ""} ,
{"nfo", "", "", ""} , // MSDOS Style/ASCII Art
{"L_USER", "", "", ""} , // User Defined language file
{"asp", "", "", ""} ,
{"sql", "", "", ""} ,
{"vb", "", "", ""} ,
{"L_JS", "", "", ""} , // Deprecated
{"css", "", "", ""} ,
{"perl", "", "", ""} ,
{"python", "", "", ""} ,
{"lua", "", "", ""} ,
{"tex", "", "", ""} ,
{"fortran", "", "", ""} ,
{"bash", "", "", ""} ,
{"actionscript", "", "", ""} , // Flash ActionScript file
{"nsis", "", "", ""} ,
{"tcl", "", "", ""} ,
{"lisp", "", "", ""} ,
{"scheme", "", "", ""} ,
{"asm", "", "", ""} ,
{"diff", "", "", ""} ,
{"props", "", "", ""} ,
{"postscript", "", "", ""} ,
{"ruby", "", "", ""} ,
{"smalltalk", "", "", ""} ,
{"vhdl", "", "", ""} ,
{"kix", "", "", ""} ,
{"autoit", "", "", ""} ,
{"caml", "", "", ""} ,
{"ada", "", "", ""} ,
{"verilog", "", "", ""} ,
{"matlab", "", "", ""} ,
{"haskell", "", "", ""} ,
{"inno", "", "", ""} ,
{"searchResult", "", "", ""} ,
{"cmake", "", "", ""} ,
{"yaml", "", "", ""} ,
{"cobol", "", "", ""} ,
{"gui4cli", "", "", ""} ,
{"d", "", "", ""} ,
{"powershell", "", "", ""} ,
{"r", "", "", ""} ,
{"jsp", "", "", ""} ,
{"coffeescript", "", "", ""} ,
{"json", "", "", ""} ,
{"javascript", "", "", ""} ,
{"fortran77", "", "", ""} ,
{"baanc", "", "", ""} ,
{"srec", "", "", ""} ,
{"ihex", "", "", ""} ,
{"tehex", "", "", ""} ,
{"swift", "", "", ""} ,
{"asn1", "", "", ""} ,
{"avs", "", "", ""} ,
{"blitzbasic", "", "", ""} ,
{"purebasic", "", "", ""} ,
{"freebasic", "", "", ""} ,
{"csound", "", "", ""} ,
{"erlang", "", "", ""} ,
{"escript", "", "", ""} ,
{"forth", "", "", ""} ,
{"latex", "", "", ""} ,
{"mmixal", "", "", ""} ,
{"nim", "", "", ""} ,
{"nncrontab", "", "", ""} ,
{"oscript", "", "", ""} ,
{"rebol", "", "", ""} ,
{"registry", "", "", ""} ,
{"rust", "", "", ""} ,
{"spice", "", "", ""} ,
{"txt2tags", "", "", ""} ,
{"visualprolog", "", "", ""} ,
{"typescript", "", "", ""} ,
{"L_EXTERNAL", "", "", ""} , // End of language enum
};
const TCHAR *const npp_plugin_name = L"C++ Tools";
FuncItem funcs[CMD_FUNCS];
NppData npp_data;
HWND scintilla;
HINSTANCE md_inst;
bool64 dotless_thread_created;
unsigned long long draw_events;
bool64 dotless_found;
wchar_t nbuf[MAX_PATH];
unsigned long long nbuf_s;
SCNotification double_click_ntf;
//const TCHAR sectionName[] = TEXT("Insert Extension");
//const TCHAR keyName[] = TEXT("doCloseTag");
//const TCHAR configFileName[] = TEXT("pluginDemo.ini");
//TCHAR iniFilePath[MAX_PATH];
//bool64 doCloseTag = false;
const char *line_comm;
const char *block_beg;
const char *block_end;
ui64 line_comm_s;
ui64 block_beg_s;
ui64 block_end_s;
Selection *selects;
ShortcutKey toggle_comm_sh_key;
REGISTER_MESSAGE(NPP_PLUGIN_GET_SCINTILLA);
REGISTER_MESSAGE(NPP_PLUGIN_GET_CUR_FILE_NAME);
const wchar_t *plugin_msg_wnd_class = L"SdppNppPluginMsgWindow";
HWND msg_wnd;
const char *dbg_bpoint = "_DBG_SBP;";
const char *dbg_print = "_DBG_P(";
const char *dbg_prefix = "_DBG_";
bool64 cpp_console_set;
bool64 cpp_nopt_set;
bool64 cpp_dbg_set;
bool64 cpp_nlaunch_set;
bool64 cpp_asm_set;
bool64 cpp_dbg_bp_off_set;
const txt cpp_console = L(" CONSOLE");
const txt cpp_nopt = L(" NOPT");
const txt cpp_dbg = L(" DBG");
const txt cpp_nlaunch = L(" NLAUNCH");
const txt cpp_asm = L(" ASM");
const txt cpp_dbg_bp_off = L("#define _DBG_BP_OFF\r\n");
const txt cpp_sddb = L("#include <sddb>\r\n");
const txt cpp_define = L("#define");
void pluginInit(HANDLE md_inst);
void pluginCleanUp();
void commandMenuInit();
void commandMenuCleanUp();
bool64 setCommand(ui64 index, const wchar_t *cmd_name, PFUNCPLUGINCMD func_p, ShortcutKey *sk, bool64 check_on_init);
void openSmallCpp();
void toggleComment();
void toggleTabs();
void breakpoint();
void debugPrint();
void findInFiles();
void toggleCppConsole();
void toggleCppNopt();
void toggleCppDbg();
void toggleCppNlaunch();
void toggleCppAsm();
void toggleCppDisableDbgp();
void cppRemoveDbgp();
void dupeFile();
void updateCppParams();
void addToolbarButton(ui64 comm_id, ui64 ico_id);
DWORD NOTHROW dotlessStyleThread(LPVOID lp);
char *strrep(char *s, ui64 pos, ui64 n, char rep);
bool64 strCmpRng(const char *s0, const char *s1_beg, const char *s1_end);
bool64 fndValRng(const char *fnd, const char *start_range, const char **beg, const char **end);
bool64 fndValRngUser(const char *fnd, const char *start_range, const char **beg, const char **end);
void strCpyRng(char *dest, const char *s_beg, const char *s_end);
void htmlEntiti2chars(char *ent_s);
void extractUserLangInfo(const wchar_t *fn);
void extractULIdir(wchar_t *dir);
DWORD NOTHROW commDbLoadingThread(LPVOID lp);
ui64 fnd1stNonSp(ui64 line);
ui64 fnd1stNonSp(ui64 line, ui64 *h_sp);
bool64 isComment(ui64 pos);
bool64 isLineBeg(ui64 pos);
bool64 isLineEnd(ui64 pos);
bool64 isPosBegLine(ui64 pos, ui64 line);
bool64 isBlockComm(ui64 pos, ui64 mode);
void insertTabs(ui64 amount, ui64 pos);
bool64 fndInSpaceSepArr(const char *fnd, const char *arr);
void wcs2str(char *dest, const wchar_t *src);
i64 doToggleComment(ui64 sel_s, ui64 sel_e, ui64 sel_i);
i64 togSingSelLineComm(ui64 sel_s, ui64 sel_e, ui64 sel_i);
i64 togMultiSelLineComm(ui64 sel_s, ui64 sel_e, ui64 sel_i);
i64 togBlockComm(ui64 sel_s, ui64 sel_e, ui64 sel_i);
void spawnMsgWnd();
LRESULT CALLBACK msgWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
DWORD NOTHROW msgProcThread(LPVOID lp);
bool64 isSymbolChar(char c);
char *getSymbol(ui64 pos);
char *getSelection(ui64 beg, ui64 end);
ui64 countNextSymbs(ui64 *pos, const txt &t);
ui64 getSymbBeg(ui64 pos, const txt &t);
ui64 getSymbEnd(ui64 pos, const txt &t);
bool64 isFuncDecl(const txt &t, ui64 *symb_pos);
void nppGoToLine(ui64 line);
void nppGoToPos(ui64 pos);
bool64 checkTxt(char *src, const txt &t);
bool64 checkTxtHasType(char *sbeg, bool64 in_class);
bool64 semicolInLine(const char *ln);
ui64 findFuncDefin(char *doc, ui64 bpos, const txt &symb, const txt &args);
ui64 findFuncDecl(char *doc, ui64 epos, const txt &symb, const txt &args);
bool64 fileExists(const wtxt &fn);
void findFuncInOtherFile(const txt &symb, const txt &args);
bool64 hasType(const txt &line, ui64 sbeg, ui64 lpos_abs);
txt findClassName(char *doc, ui64 sbeg);
DWORD __declspec(nothrow) functionJumper(void *scn);
void toggleCppParam(bool64 &cpp_param_set, ui64 cmd_func, const txt &cmd_param_txt);
txt getLine(ui64 line_i);
txt getTextRange(ui64 b, ui64 e);
void includeSddb();
void removeDbgPrints(ui64 s, ui64 e);
void doFindInFiles(const txt &pat);
inline ui64 m2scintilla(UINT id, ui64 wp, ui64 lp)
{
return (ui64)SendMessage(scintilla, id, (WPARAM)wp, (LPARAM)lp);
}
inline ui64 m2scintilla(UINT id, ui64 wp, txt &lp)
{
return (ui64)SendMessage(scintilla, id, (WPARAM)wp, (LPARAM)(char *)lp);;
}
inline ui64 m2scintilla(UINT id, ui64 wp, const txt &lp)
{
return (ui64)SendMessage(scintilla, id, (WPARAM)wp, (LPARAM)(const char *)lp);
}
inline ui64 m2scintilla(UINT id, ui64 wp)
{
return (ui64)SendMessage(scintilla, id, (WPARAM)wp, 0);
}
inline ui64 m2scintilla(UINT id)
{
return (ui64)SendMessage(scintilla, id, 0, 0);
}
inline ui64 m2npp(UINT id, ui64 wp, ui64 lp)
{
return (ui64)SendMessage(npp_data._nppHandle, id, (WPARAM)wp, (LPARAM)lp);
}
inline ui64 m2npp(UINT id, ui64 wp, void *lp)
{
return (ui64)SendMessage(npp_data._nppHandle, id, (WPARAM)wp, (LPARAM)lp);
}
inline ui64 m2npp(UINT id, ui64 wp, const void *lp)
{
return (ui64)SendMessage(npp_data._nppHandle, id, (WPARAM)wp, (LPARAM)lp);
}
inline ui64 m2npp(UINT id, ui64 wp)
{
return (ui64)SendMessage(npp_data._nppHandle, id, (WPARAM)wp, 0);
}
inline ui64 m2npp(UINT id)
{
return (ui64)SendMessage(npp_data._nppHandle, id, 0, 0);
}
inline void updateScintillaHwnd() // Update the current scintilla
{
int scintilla_used = -1;
SendMessage(npp_data._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)&scintilla_used);
if(scintilla_used == -1) // Scintilla 0 -> Main View in multivew (Left) | 1 -> Second view (Right)
{
return;
}
scintilla = (scintilla_used == 0) ? npp_data._scintillaMainHandle : npp_data._scintillaSecondHandle;
}
BOOL APIENTRY DllMain(HANDLE hm, DWORD reason, LPVOID /*lpReserved*/)
{
switch(reason)
{
case DLL_PROCESS_ATTACH:
pluginInit(hm);
md_inst = (HINSTANCE)hm;
break;
case DLL_PROCESS_DETACH:
pluginCleanUp();
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
default:
break;
}
return TRUE;
}
extern "C" __declspec(dllexport) void setInfo(NppData notepad_plus_data)
{
npp_data = notepad_plus_data;
commandMenuInit();
}
extern "C" __declspec(dllexport) const TCHAR * getName()
{
return npp_plugin_name;
}
extern "C" __declspec(dllexport) FuncItem * getFuncsArray(int *fn)
{
*fn = CMD_FUNCS;
return funcs;
}
extern "C" __declspec(dllexport) void beNotified(SCNotification *scn)
{
switch (scn->nmhdr.code)
{
// NPP NOTIFICATIONS ==========================================
case NPPN_READY:
case NPPN_WORDSTYLESUPDATED: // User changed current theme's style
SendMessage(npp_data._scintillaMainHandle, SCI_CALLTIPSETBACK, 0xFF1E1E1E, 0);
SendMessage(npp_data._scintillaMainHandle, SCI_CALLTIPSETFORE, 0xFFF3F2F1, 0);
SendMessage(npp_data._scintillaMainHandle, SCI_CALLTIPSETFOREHLT, 0xFFD69C55, 0);
SendMessage(npp_data._scintillaSecondHandle, SCI_CALLTIPSETBACK, 0xFF1E1E1E, 0);
SendMessage(npp_data._scintillaSecondHandle, SCI_CALLTIPSETFORE, 0xFFF3F2F1, 0);
SendMessage(npp_data._scintillaSecondHandle, SCI_CALLTIPSETFOREHLT, 0xFFD69C55, 0);
break;
case NPPN_BUFFERACTIVATED:
updateCppParams();
break;
case NPPN_FILESAVED:
case NPPN_FILEBEFOREOPEN:
{
ui64 res = m2npp(NPPM_GETFULLPATHFROMBUFFERID, scn->nmhdr.idFrom);
wchar_t *full_path = (wchar_t *)MEM_ALLOC((res+1) * sizeof(wchar_t));
res = m2npp(NPPM_GETFULLPATHFROMBUFFERID, scn->nmhdr.idFrom, full_path);
bool64 dot_found = false;
unsigned long long slash = 0;
for(ui64 i = res-1; i != UI64_MAX; --i)
{
if(full_path[i] == '\\')
{
slash = i;
break;
}
else if(full_path[i] == '.')
{
dot_found = true;
break;
}
}
if(!dot_found)
{
draw_events = 0;
if(!dotless_thread_created)
{
CreateThread(NULL, 0, dotlessStyleThread, NULL, NULL, NULL);
dotless_thread_created = true;
}
dotless_found = true;
ui64 i = slash+1, j = 0;
for(; i < res; ++i, ++j)
{
nbuf[j] = full_path[i];
}
nbuf[j] = 0;
nbuf_s = j;
}
MEM_FREE(full_path);
} break;
case NPPN_TBMODIFICATION:
{
addToolbarButton(0, IDI_SMALLDOT_ICON);
addToolbarButton(1, IDI_COMMENT_ICON);
addToolbarButton(2, IDI_TABS_ICON);
addToolbarButton(3, IDI_DEBUG_BP_ICON);
addToolbarButton(4, IDI_DEBUG_DP_ICON);
addToolbarButton(5, IDI_DUPE_FILE_ICON);
// ID[6+] no buttons, context menu only or separators
} break;
case NPPN_SHUTDOWN:
commandMenuCleanUp();
break;
// SCINTILLA NOTIFICATIONS ====================================
case SCN_ZOOM: // TODO ADD TOGGLE MENU COMMAND FOR THIS ~~~~~~~~~~~~~~~~~~~~
{
updateScintillaHwnd();
//i32 zoom = (i32)m2scintilla(SCI_GETZOOM);
m2scintilla(SCI_SETZOOM, 0);
} return;
case SCN_PAINTED:
if(dotless_found)
{
++draw_events;
}
break;
case SCN_DOUBLECLICK:
double_click_ntf.position = scn->position;
double_click_ntf.line = scn->line;
CreateThread(NULL, 0, functionJumper, (void *)&double_click_ntf, 0, NULL);
break;
default:
return;
}
}
#pragma warning( suppress : 4100 )
extern "C" __declspec(dllexport) LRESULT messageProc(UINT msg, WPARAM wp, LPARAM lp)
{
return TRUE;
}
#ifdef UNICODE
extern "C" __declspec(dllexport) BOOL isUnicode()
{
return TRUE;
}
#endif // UNICODE
#pragma warning( suppress : 4100 )
void pluginInit(HANDLE module_inst)
{
CreateThread(NULL, 0, commDbLoadingThread, NULL, 0, NULL);
CreateThread(NULL, 0, msgProcThread, NULL, 0, NULL);
}
void pluginCleanUp()
{
for(ui64 i = 0; i < ulangs_s; ++i)
{
MEM_FREE(user_langs[i].n);
}
if(user_langs != NULL)
{
MEM_FREE(user_langs);
}
// Settings saving example below...
//::WritePrivateProfileString(sectionName, keyName, doCloseTag?TEXT("1"):TEXT("0"), iniFilePath);
}
void commandMenuInit()
{
toggle_comm_sh_key._isAlt = false;
toggle_comm_sh_key._isCtrl = true;
toggle_comm_sh_key._isShift = false;
toggle_comm_sh_key._key = 0x51; // VK_Q
ui64 fn = 0;
setCommand(fn, L"Open s.cpp", openSmallCpp, NULL, false);
setCommand(++fn, L"Toggle comment", toggleComment, &toggle_comm_sh_key, false);
setCommand(++fn, L"Hide/Show Tabs", toggleTabs, NULL, false);
setCommand(++fn, L"Put Breakpoint", breakpoint, NULL, false);
setCommand(++fn, L"Make Debug Print", debugPrint, NULL, false);
setCommand(++fn, L"Duplicate File", dupeFile, NULL, false);
setCommand(++fn, L"Find in Files", findInFiles, NULL, false);
setCommand(++fn, L"---", NULL, NULL, false); //-----------------------------------
setCommand(++fn, L"Console", toggleCppConsole, NULL, false); // 8
setCommand(++fn, L"No optim.", toggleCppNopt, NULL, false);
setCommand(++fn, L"Debug", toggleCppDbg, NULL, false);
setCommand(++fn, L"No launch", toggleCppNlaunch, NULL, false);
setCommand(++fn, L"ASM", toggleCppAsm, NULL, true);
setCommand(++fn, L"---", NULL, NULL, false); //-----------------------------------
setCommand(++fn, L"Disable DBGP", toggleCppDisableDbgp, NULL, false);
setCommand(++fn, L"Remove DBGP", cppRemoveDbgp, NULL, false);
}
bool64 setCommand(ui64 index, const wchar_t *cmd_name, PFUNCPLUGINCMD func_p, ShortcutKey *sk, bool64 check_on_init)
{
wcscpy(funcs[index]._itemName, cmd_name);
funcs[index]._pFunc = func_p;
funcs[index]._init2Check = (bool)check_on_init;
funcs[index]._pShKey = sk;
return true;
}
void commandMenuCleanUp()
{
// Do nothing...
}
//----------------------------------------------//
// FUNCTION DEFINITIONS //
//----------------------------------------------//
void openSmallCpp()
{
m2npp(NPPM_DOOPEN, 0, L"D:\\P\\MT\\s.cpp");
}
void toggleTabs()
{
bool64 tabs_hidden = (bool64)m2npp(NPPM_ISTABBARHIDDEN);
m2npp(NPPM_HIDETABBAR, 0, !tabs_hidden);
}
void toggleComment()
{
updateScintillaHwnd();
ui32 lang_t = L_TEXT;
m2npp(NPPM_GETCURRENTLANGTYPE, 0, &lang_t);
if(lang_t == L_USER)
{
static wchar_t fname[MAX_PATH];
m2npp(NPPM_GETFILENAME, MAX_PATH, fname);
wchar_t *ext = wcsrchr(fname, '.') + 1;
if(ext == nullptr)
{
return;
}
static char ext_str[MAX_PATH];
wcs2str(ext_str, ext);
bool64 ulang_not_found = true;
for(ui64 i = 0; i < ulangs_s; ++i)
{
if(fndInSpaceSepArr(ext_str, user_langs[i].n))
{
line_comm = user_langs[i].c;
block_beg = user_langs[i].bcb;
block_end = user_langs[i].bce;
ulang_not_found = false;
break;
}
}
if(ulang_not_found)
{
return;
}
}
else
{
line_comm = langs[lang_t].c;
block_beg = langs[lang_t].bcb;
block_end = langs[lang_t].bce;
}
line_comm_s = strlen(line_comm);
block_beg_s = strlen(block_beg);
block_end_s = strlen(block_end);
ui64 sel_n = m2scintilla(SCI_GETSELECTIONS); // There is always at least one selection
selects = (Selection *)MEM_ALLOC(sel_n * sizeof(Selection));
for(ui64 i = 0; i < sel_n; ++i)
{
selects[i].beg = m2scintilla(SCI_GETSELECTIONNSTART, i);
selects[i].end = m2scintilla(SCI_GETSELECTIONNEND, i);
selects[i].idx = i;
}
for(ui64 i = 0; i < sel_n; ++i) // Insertion sort
{
for(ui64 j = i+1; j < sel_n; ++j)
{
if(selects[j].beg < selects[i].beg)
{
Selection tmp = selects[i];
selects[i] = selects[j];
selects[j] = tmp;
}
}
}
m2scintilla(SCI_BEGINUNDOACTION); // UNDO =========================
i64 ch_ins = 0;
for(ui64 i = 0; i < sel_n; ++i)
{
ui64 ss = selects[i].beg + ch_ins;
ui64 se = selects[i].end + ch_ins;
ch_ins += doToggleComment(ss, se, i);
}
if(selects[0].end < selects[0].beg)
{
ui64 tmp = selects[0].end;
selects[0].end = selects[0].beg;
selects[0].beg = tmp;
}
m2scintilla(SCI_SETSELECTION, selects[0].end, selects[0].beg); // Good for 1st selection
for(ui64 i = 1; i < sel_n; ++i)
{
if(selects[i].end < selects[i].beg)
{
ui64 tmp = selects[i].end;
selects[i].end = selects[i].beg;
selects[i].beg = tmp;
}
m2scintilla(SCI_ADDSELECTION, selects[i].end, selects[i].beg);
}
m2scintilla(SCI_ENDUNDOACTION); // ==============================
MEM_FREE(selects);
}
void breakpoint()
{
updateScintillaHwnd();
ui64 sel_n = m2scintilla(SCI_GETSELECTIONS); // There is always at least one selection
static ui64 bp_txt_size = strlen(dbg_bpoint);
ui64 *lines = (ui64 *)MEM_ALLOC(sel_n * sizeof(ui64));
for(ui64 i = 0; i < sel_n; ++i)
{
ui64 pos = m2scintilla(SCI_GETSELECTIONNEND, i);
lines[i] = m2scintilla(SCI_LINEFROMPOSITION, pos);
}
m2scintilla(SCI_BEGINUNDOACTION); // UNDO =========================
for(ui64 i = 0; i < sel_n; ++i)
{
ui64 ins_pos = m2scintilla(SCI_GETLINEENDPOSITION, lines[i]);
m2scintilla(SCI_INSERTTEXT, ins_pos, (ui64)dbg_bpoint);
}
includeSddb();
m2scintilla(SCI_ENDUNDOACTION); // ==============================
}
void debugPrint()
{
updateScintillaHwnd();
ui64 sel_n = m2scintilla(SCI_GETSELECTIONS); // There is always at least one selection
static char to_ins[MAX_PATH];
static ui64 dp_txt_size = strlen(dbg_print);
if(to_ins[0] == 0)
{
memcpy(to_ins, dbg_print, dp_txt_size+1);
}
Selection *sels = (Selection *)MEM_ALLOC(sel_n * sizeof(Selection));
for(ui64 i = 0; i < sel_n; ++i)
{
sels[i].beg = m2scintilla(SCI_GETSELECTIONNSTART, i);
sels[i].end = m2scintilla(SCI_GETSELECTIONNEND, i);
//sels[i].idx = i;
}
for(ui64 i = 0; i < sel_n; ++i) // Insertion sort
{
for(ui64 j = i+1; j < sel_n; ++j)
{
if(sels[j].end < sels[i].end)
{
Selection tmp = sels[i];
sels[i] = sels[j];
sels[j] = tmp;
}
}
}
DebugPrintLine *dbg_lns = (DebugPrintLine *)MEM_ZALLOC(sel_n * sizeof(DebugPrintLine));
ui64 dbl_s = UI64_MAX; // +1 will give 0
ui64 prev_line = UI64_MAX;
for(ui64 i = 0; i < sel_n; ++i)
{
ui64 line = m2scintilla(SCI_LINEFROMPOSITION, sels[i].end);
if(line != prev_line)
{
prev_line = line;
dbg_lns[++dbl_s].line = line;
}
if(dbg_lns[dbl_s].symb_n == dbg_lns[dbl_s].smb_ts)
{
dbg_lns[dbl_s].smb_ts += 8;
char **tmp = (char **)MEM_ZALLOC(dbg_lns[dbl_s].smb_ts * sizeof(char **));
memcpy(tmp, dbg_lns[dbl_s].symbs, dbg_lns[dbl_s].symb_n * sizeof(char **));
MEM_FREE(dbg_lns[dbl_s].symbs);
dbg_lns[dbl_s].symbs = tmp;
}
if(sels[i].end == sels[i].beg) // Single caret, no selection
{
dbg_lns[dbl_s].symbs[dbg_lns[dbl_s].symb_n] = getSymbol(sels[i].end);
}
else // Multiple characters selected
{
dbg_lns[dbl_s].symbs[dbg_lns[dbl_s].symb_n] = getSelection(sels[i].beg, sels[i].end);
}
dbg_lns[dbl_s].symb_n += 1;
}
++dbl_s; // Change dbl_s from index to actual size
m2scintilla(SCI_BEGINUNDOACTION); // UNDO =========================
ui64 ins_pos = m2scintilla(SCI_GETLINEENDPOSITION, dbg_lns[0].line);
for(ui64 i = 0; i < dbl_s; ++i)
{
for(ui64 j = 0; j < dbg_lns[i].symb_n; ++j)
{
ins_pos = m2scintilla(SCI_GETLINEENDPOSITION, dbg_lns[i].line);
ui64 ss = strlen(dbg_lns[i].symbs[j]);
if(ss + dp_txt_size + 2 >= MAX_PATH)
{
m2scintilla(SCI_INSERTTEXT, ins_pos, (ui64)"[!!!SYMBOL_>_MAX_PATH!!!]");
continue;
}
strcpy(to_ins + dp_txt_size, dbg_lns[i].symbs[j]);
ui64 tot_s = dp_txt_size + ss + 2;
to_ins[tot_s-2] = ')';
to_ins[tot_s-1] = ';';
to_ins[tot_s] = 0;
m2scintilla(SCI_INSERTTEXT, ins_pos, (ui64)to_ins);
}
}
ins_pos = m2scintilla(SCI_GETLINEENDPOSITION, dbg_lns[dbl_s-1].line);
includeSddb();
m2scintilla(SCI_ENDUNDOACTION); // ==============================
for(ui64 i = 0; i < dbl_s; ++i)
{
for(ui64 j = 0; j < dbg_lns[i].symb_n; ++j)
{
MEM_FREE(dbg_lns[i].symbs[j]);
}
MEM_FREE(dbg_lns[i].symbs);
}
MEM_FREE(sels);
MEM_FREE(dbg_lns);
}
void findInFiles()
{
updateScintillaHwnd();
ui64 ss = m2scintilla(SCI_GETSELECTIONSTART);
ui64 se = m2scintilla(SCI_GETSELECTIONEND);
if(ss == se) // No selection
{
if(!isSymbolChar((char)m2scintilla(SCI_GETCHARAT, ss)))
{
return;
}
ui64 lnum = m2scintilla(SCI_LINEFROMPOSITION, ss);
ui64 lbeg = m2scintilla(SCI_POSITIONFROMLINE, lnum);
txt line = getLine(lnum);
ui64 pos_il = ss - lbeg; // Posiiton in line
txt symb = txtsp(line, getSymbBeg(pos_il, line), getSymbEnd(pos_il, line));
doFindInFiles(symb);
return;
}
txt pattern = getTextRange(ss, se);
doFindInFiles(pattern);
}
void toggleCppConsole()
{
toggleCppParam(cpp_console_set, CMD_CONSOLE, cpp_console);
}
void toggleCppNopt()
{
toggleCppParam(cpp_nopt_set, CMD_NOPT, cpp_nopt);
}
void toggleCppDbg()
{
toggleCppParam(cpp_dbg_set, CMD_DBG, cpp_dbg);
}
void toggleCppNlaunch()
{
toggleCppParam(cpp_nlaunch_set, CMD_NLAUNCH, cpp_nlaunch);
}
void toggleCppAsm()
{
toggleCppParam(cpp_asm_set, CMD_ASM, cpp_asm);
}
namespace toggleCppDisableDbgpFunc
{
static txt line;