-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEditor.cpp
More file actions
5221 lines (4703 loc) · 155 KB
/
Copy pathEditor.cpp
File metadata and controls
5221 lines (4703 loc) · 155 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
/*#*******************************************************************************
# COPYRIGHT NOTES
# ---------------
# This is a part of VinaText Project
# Copyright(C) - free open source
# This source code can be used, distributed or modified under MIT license
#*******************************************************************************/
#include "stdafx.h"
#include "Editor.h"
#include "LexerParser.h"
#include "EditorDatabase.h"
#include "AppSettings.h"
#include "TemporarySettings.h"
#include "VinaTextApp.h"
#include "StringHelper.h"
#include "Debugger.h"
#include "SmartHandle.h"
#include "MultiThreadWorker.h"
#include "Hpsutils.h"
#include "GuiUtils.h"
#include "PathUtil.h"
#include "OSUtil.h"
#include "AppUtil.h"
#include "UnicodeUtils.h"
#include "TextFile.h"
#include "EditorLexerDark.h"
#include "EditorLexerLight.h"
#include "EditorColorDark.h"
#include "EditorColorLight.h"
#include "UserCustomizeData.h"
CEditorCtrl::CEditorCtrl()
{
m_wideBuf = std::make_unique<wchar_t[]>(m_wideBufSize);
m_charBuf = std::make_unique<char[]>(m_charBufSize);
}
CEditorCtrl::~CEditorCtrl()
{
if (PathFileExists(m_strFilePath))
{
VinaTextDebugger.RemoveBreakPointDataInFile(m_strFilePath);
}
m_CreateLexerFunc = NULL;
m_GetLexerNameFromID = NULL;
}
void CEditorCtrl::ReleaseDocument()
{
DoCommand(SCI_SETDOCPOINTER, 0, 0);
if (m_DocumentID > 0)
{
DoCommand(SCI_RELEASEDOCUMENT, 0, m_DocumentID);
}
}
BOOL CEditorCtrl::Create(const CString& strWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
{
if (!CWnd::CreateEx(WS_EX_CLIENTEDGE | WS_EX_COMPOSITED, STR_SCINTILLAWND, strWindowName, dwStyle, rect, pParentWnd, (UINT)nID))
{
return FALSE;
}
// load dll lexers
CVinaTextApp* pApp = AppUtils::GetVinaTextApp();
if (pApp)
{
FARPROC pFunCreateLexer = GetProcAddress(pApp->m_hDllLexer, LEXILLA_CREATELEXER);
m_CreateLexerFunc = (Lexilla::CreateLexerFn)(pFunCreateLexer);
if (!m_CreateLexerFunc)
{
ASSERT(m_CreateLexerFunc); return FALSE;
}
#if 0
FARPROC pFunGetLexerNameFromID = GetProcAddress(pApp->m_hDllLexer, LEXILLA_LEXERNAMEFROMID);
m_GetLexerNameFromID = (Lexilla::LexerNameFromIDFn)(pFunGetLexerNameFromID);
#endif
}
// retrieve a pointer to the message handling function of the Scintilla Edit Control and call it directly to execute a command
m_DirectFunc = (DirectFunc)::SendMessage(this->m_hWnd, SCI_GETDIRECTFUNCTION, 0, 0);
m_pDirectPtr = (DirectPtr)::SendMessage(this->m_hWnd, SCI_GETDIRECTPOINTER, 0, 0);
if (!m_DirectFunc)
{
ASSERT(m_DirectFunc); return FALSE;
}
if (!m_pDirectPtr)
{
ASSERT(m_pDirectPtr); return FALSE;
}
// bind Delete key to clear selected text or delete character at caret
//SendMessage(SCI_ASSIGNCMDKEY, (SCK_DELETE + (SCMOD_NORM << 16)), SCI_CLEAR);
return TRUE;
}
void CEditorCtrl::InitilizeSetting(CLanguageDatabase* pDatabase)
{
DoCommand(SCI_SETIMEINTERACTION, SC_IME_WINDOWED);
// Preset theme colors
if (IS_LIGHT_THEME)
{
m_AppThemeColorSet._lineNumberColor = EditorColorLight::linenumber;
m_AppThemeColorSet._selectionTextColor = EditorColorLight::black;
m_AppThemeColorSet._editorTextColor = EditorColorLight::editorTextColor;
m_AppThemeColorSet._editorMarginBarColor = EditorColorLight::editorMarginBarColor;
m_AppThemeColorSet._editorFolderBackColor = EditorColorLight::editorFolderBackColor;
m_AppThemeColorSet._editorFolderForeColor = EditorColorLight::editorFolderForeColor;
m_AppThemeColorSet._editorCaretColor = EditorColorLight::editorCaretColor;
m_AppThemeColorSet._editorIndicatorColor = EditorColorLight::editorIndicatorColor;
m_AppThemeColorSet._editorSpellCheckColor = EditorColorLight::editorSpellCheckColor;
m_AppThemeColorSet._editorTagMatchColor = EditorColorLight::editorTagMatchColor;
}
else
{
m_AppThemeColorSet._lineNumberColor = EditorColorDark::linenumber;
m_AppThemeColorSet._selectionTextColor = EditorColorDark::white;
m_AppThemeColorSet._editorTextColor = EditorColorDark::editorTextColor;
m_AppThemeColorSet._editorMarginBarColor = EditorColorDark::editorMarginBarColor;
m_AppThemeColorSet._editorFolderBackColor = EditorColorDark::editorFolderBackColor;
m_AppThemeColorSet._editorFolderForeColor = EditorColorDark::editorFolderForeColor;
m_AppThemeColorSet._editorCaretColor = EditorColorDark::editorCaretColor;
m_AppThemeColorSet._editorIndicatorColor = EditorColorDark::editorIndicatorColor;
m_AppThemeColorSet._editorSpellCheckColor = EditorColorDark::editorSpellCheckColor;
m_AppThemeColorSet._editorTagMatchColor = EditorColorDark::editorTagMatchColor;
}
// Editor font settings
SetColorForStyle(STYLE_DEFAULT,
m_AppThemeColorSet._editorTextColor,
AppSettingMgr.m_AppThemeColor,
AppSettingMgr.m_EditorFontSetting._iPointSize,
AppUtils::CStringToStd(AppSettingMgr.m_EditorFontSetting._lfFaceName).c_str());
DoCommand(SCI_STYLESETBOLD, STYLE_DEFAULT, AppSettingMgr.m_EditorFontSetting._isBold);
DoCommand(SCI_STYLESETITALIC, STYLE_DEFAULT, AppSettingMgr.m_EditorFontSetting._isItalic);
DoCommand(SCI_STYLESETUNDERLINE, STYLE_DEFAULT, AppSettingMgr.m_EditorFontSetting._isUnderline);
// This message sets all styles to have the same attributes as STYLE_DEFAULT.
// If you are setting up Scintilla for syntax colouring, it is likely that the
// lexical styles you set will be very similar.
DoCommand(SCI_STYLECLEARALL);
// init lexer editor
if (m_strLexerName.IsEmpty()) {
m_strLexerName = LEXER_PLAIN_TEXT;
}
// if user choose lexers from app menu then we wont load default lexer
if (m_bUseUserLexer) {
m_strLexerName = m_strUserLexerName;
}
AppSettingMgr.m_AppThemeColor == THEME_BACKGROUND_COLOR_LIGHT ?
EditorLexerLight::LoadLexer(pDatabase, this, m_strLexerName) :
EditorLexerDark::LoadLexer(pDatabase, this, m_strLexerName);
if (AppSettingMgr.m_bUseUserIndentationSettings) { // use user customize settings
SetTabSettings(AppSettingMgr.m_editorIndentationType, AppSettingMgr.m_nEditorIndentationWidth);
m_tabSpace = AppSettingMgr.m_editorIndentationType;
}
else SetTabSettings(m_tabSpace, SC_DEFAUFT_TAB_WIDTH); // default from file
SetDisplayLinenumbers(TRUE);
SetColorForStyle(STYLE_LINENUMBER,
m_AppThemeColorSet._lineNumberColor,
m_AppThemeColorSet._editorMarginBarColor,
AppSettingMgr.m_EditorFontSetting._iPointSize,
AppUtils::CStringToStd(AppSettingMgr.m_EditorFontSetting._lfFaceName).c_str());
// folding
DoCommand(SCI_SETPROPERTY, (WPARAM)"fold", reinterpret_cast<LPARAM>("1"));
DoCommand(SCI_SETPROPERTY, (WPARAM)"fold.compact", reinterpret_cast<LPARAM>("0"));
DoCommand(SCI_SETPROPERTY, (WPARAM)"fold.html", reinterpret_cast<LPARAM>("1"));
DoCommand(SCI_SETPROPERTY, (WPARAM)"fold.html.preprocessor", reinterpret_cast<LPARAM>("1"));
DoCommand(SCI_SETPROPERTY, (WPARAM)"fold.comment", reinterpret_cast<LPARAM>("1"));
DoCommand(SCI_SETPROPERTY, (WPARAM)"fold.at.else", reinterpret_cast<LPARAM>("1"));
DoCommand(SCI_SETPROPERTY, (WPARAM)"fold.flags", reinterpret_cast<LPARAM>("1"));
DoCommand(SCI_SETPROPERTY, (WPARAM)"fold.preprocessor", reinterpret_cast<LPARAM>("1"));
DoCommand(SCI_SETPROPERTY, (WPARAM)"styling.within.preprocessor", reinterpret_cast<LPARAM>("1"));
DoCommand(SCI_SETPROPERTY, (WPARAM)"asp.default.language", reinterpret_cast<LPARAM>("1"));
if (AppSettingMgr.m_bDrawFoldingLineUnderLineStyle)
{
DoCommand(SCI_SETFOLDFLAGS, SC_FOLDFLAG_LINEAFTER_CONTRACTED, 0);
}
DoCommand(SCI_FOLDDISPLAYTEXTSETSTYLE, SC_FOLDDISPLAYTEXT_BOXED, 0);
if (m_strLexerName == _T("cpp") || m_strLexerName == _T("c") || m_strLexerName == _T("cs")
|| m_strLexerName == _T("java") || m_strLexerName == _T("javascript") || m_strLexerName == _T("typescript")
|| m_strLexerName == _T("phpscript") || m_strLexerName == _T("rust") || m_strLexerName == _T("kix")
|| m_strLexerName == _T("markdown") || m_strLexerName == _T("css") || m_strLexerName == _T("bash"))
{
DoCommand(SCI_SETDEFAULTFOLDDISPLAYTEXT, 0, reinterpret_cast<LPARAM>(FOLDED_MARKER_CPP));
}
else if (m_strLexerName == _T("hypertext") || m_strLexerName == _T("xml"))
{
DoCommand(SCI_SETDEFAULTFOLDDISPLAYTEXT, 0, reinterpret_cast<LPARAM>(FOLDED_MARKER_HTML));
}
else
{
DoCommand(SCI_SETDEFAULTFOLDDISPLAYTEXT, 0, reinterpret_cast<LPARAM>(FOLDED_MARKER_TEXT));
}
if (m_strLexerName == _T("python"))
{
DoCommand(SCI_SETINDENTATIONGUIDES, SC_IV_LOOKFORWARD, 0);
}
else
{
DoCommand(SCI_SETINDENTATIONGUIDES, SC_IV_LOOKBOTH, 0);
}
//There are 32 markers available, and numbers 0 to 24 have no pre - defined use.The numbers 25 to 31 are used for folding, but if you don't need that, you could use those numbers as well.
//The first step is to choose a number for each of the markers you want to set up : let's say 4 for arrows, and 5 for circles (probably some constants should be defined for these).
//The margin mask is a 32 - bit value.To set it, you need to flip the bit that corresponds with each of the marker numbers that should be enabled for that margin :
//There are 32 markers available, and numbers 0 to 24 have no pre - defined use.The numbers 25 to 31 are used for folding
//Then you need to define the markers themselves
//So we have 3 types of margin are line number, breakpoint, foldding from left to right 2, 1 ,0
DoCommand(SCI_SETMARGINS, VINATEXT_MAXIMUM_MARGIN);
DoCommand(SCI_SETMARGINTYPEN, SC_SETMARGINTYPE_LINENUM, SC_MARGIN_NUMBER);
DoCommand(SCI_SETMARGINTYPEN, SC_SETMARGINTYPE_MAKER, SC_MARGIN_SYMBOL);
DoCommand(SCI_SETMARGINTYPEN, SC_SETMARGINTYPE_FOLDING, SC_MARGIN_SYMBOL);
DoCommand(SCI_SETMARGINMASKN, SC_SETMARGINTYPE_LINENUM, ~SC_MASK_FOLDERS);
DoCommand(SCI_SETMARGINMASKN, SC_SETMARGINTYPE_MAKER, ~SC_MASK_FOLDERS);
DoCommand(SCI_SETMARGINMASKN, SC_SETMARGINTYPE_MAKER, // multiple maker in one margin number 2
(1 << SC_MARKER_ENABLE_BREAKPOINT)
| (1 << SC_MARKER_DISABLE_BREAKPOINT)
| (1 << SC_MARKER_INSTRUCTION_POINTER)
| (1 << SC_MARKER_BOOKMARK));
DoCommand(SCI_SETMARGINMASKN, SC_SETMARGINTYPE_FOLDING, 1 << SC_MARKER_FOLDING);
DoCommand(SCI_SETMARGINMASKN, SC_SETMARGINTYPE_LINENUM, 1 << SC_MARKER_LINE_NUMBER);
DoCommand(SCI_SETMARGINMASKN, SC_SETMARGINTYPE_FOLDING, SC_MASK_FOLDERS);
//Register Enable breakpoint maker
DoCommand(SCI_MARKERDEFINE, SC_MARKER_ENABLE_BREAKPOINT, SC_MARK_CIRCLE);
DoCommand(SCI_MARKERSETFORE, SC_MARKER_ENABLE_BREAKPOINT, RGB(255, 255, 255));
DoCommand(SCI_MARKERSETBACK, SC_MARKER_ENABLE_BREAKPOINT, RGB(255, 0, 0));
//Register Disable breakpoint maker
DoCommand(SCI_MARKERDEFINE, SC_MARKER_DISABLE_BREAKPOINT, SC_MARK_CIRCLE);
DoCommand(SCI_MARKERSETFORE, SC_MARKER_DISABLE_BREAKPOINT, RGB(255, 0, 0));
//Register Debug Pointer maker
DoCommand(SCI_MARKERDEFINE, SC_MARKER_INSTRUCTION_POINTER, SC_MARK_SHORTARROW);
DoCommand(SCI_MARKERSETFORE, SC_MARKER_INSTRUCTION_POINTER, RGB(0, 0, 0));
DoCommand(SCI_MARKERSETBACK, SC_MARKER_INSTRUCTION_POINTER, RGB(255, 255, 0));
//Register Enable bookmark maker
DoCommand(SCI_MARKERDEFINE, SC_MARKER_BOOKMARK, SC_MARK_BOOKMARK);
DoCommand(SCI_MARKERSETFORE, SC_MARKER_BOOKMARK, RGB(255, 0, 0));
DoCommand(SCI_MARKERSETBACK, SC_MARKER_BOOKMARK, RGB(255, 255, 255));
DoCommand(SCI_SETMARGINSENSITIVEN, SC_SETMARGINTYPE_FOLDING, TRUE);
DoCommand(SCI_SETMARGINSENSITIVEN, SC_SETMARGINTYPE_MAKER, TRUE);
if (AppSettingMgr.m_bUseFolderMarginClassic)
{
DoCommand(SCI_SETFOLDMARGINCOLOUR, 1, RGB(0, 0, 0));
DoCommand(SCI_SETFOLDMARGINHICOLOUR, 1, RGB(96, 96, 96));
}
else
{
DoCommand(SCI_SETFOLDMARGINCOLOUR, 1, m_AppThemeColorSet._editorMarginBarColor);
DoCommand(SCI_SETFOLDMARGINHICOLOUR, 1, m_AppThemeColorSet._editorMarginBarColor);
}
// folder style
if (AppSettingMgr.m_FolderMarginStyle == FOLDER_MARGIN_STYPE::STYLE_ARROW)
{
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_ARROWDOWN);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_ARROW);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_EMPTY);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_EMPTY);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_EMPTY);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_EMPTY);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_EMPTY);
}
else if (AppSettingMgr.m_FolderMarginStyle == FOLDER_MARGIN_STYPE::STYLE_PLUS_MINUS)
{
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_MINUS);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_PLUS);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_EMPTY);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_EMPTY);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_EMPTY);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_EMPTY);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_EMPTY);
}
else if (AppSettingMgr.m_FolderMarginStyle == FOLDER_MARGIN_STYPE::STYLE_TREE_CIRCLE)
{
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_CIRCLEMINUS);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_CIRCLEPLUS);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_VLINE);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_LCORNERCURVE);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_CIRCLEPLUSCONNECTED);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_CIRCLEMINUSCONNECTED);
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_TCORNERCURVE);
}
else if (AppSettingMgr.m_FolderMarginStyle == FOLDER_MARGIN_STYPE::STYLE_TREE_BOX)
{
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_BOXMINUS);
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDEROPEN, RGB(255, 255, 255));
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDEROPEN, RGB(128, 128, 128));
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_BOXPLUS);
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDER, RGB(255, 255, 255));
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDER, RGB(128, 128, 128));
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_VLINE);
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDERSUB, RGB(255, 255, 255));
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDERSUB, RGB(128, 128, 128));
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_LCORNER);
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDERTAIL, RGB(255, 255, 255));
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDERTAIL, RGB(0, 0, 0));
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_BOXPLUSCONNECTED);
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDEREND, RGB(255, 255, 255));
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDEREND, RGB(0, 0, 0));
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_BOXMINUSCONNECTED);
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDEROPENMID, RGB(255, 255, 255));
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDEROPENMID, RGB(0, 0, 0));
DoCommand(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_TCORNER);
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDERMIDTAIL, RGB(255, 255, 255));
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDERMIDTAIL, RGB(0, 0, 0));
}
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDEROPEN, m_AppThemeColorSet._editorFolderForeColor);
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDEROPEN, m_AppThemeColorSet._editorFolderBackColor);
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDER, m_AppThemeColorSet._editorFolderForeColor);
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDER, m_AppThemeColorSet._editorFolderBackColor);
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDERSUB, m_AppThemeColorSet._editorFolderForeColor);
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDERSUB, m_AppThemeColorSet._editorFolderBackColor);
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDERTAIL, m_AppThemeColorSet._editorFolderForeColor);
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDERTAIL, m_AppThemeColorSet._editorFolderBackColor);
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDEREND, m_AppThemeColorSet._editorFolderForeColor);
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDEREND, m_AppThemeColorSet._editorFolderBackColor);
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDEROPENMID, m_AppThemeColorSet._editorFolderForeColor);
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDEROPENMID, m_AppThemeColorSet._editorFolderBackColor);
DoCommand(SCI_MARKERSETFORE, SC_MARKNUM_FOLDERMIDTAIL, m_AppThemeColorSet._editorFolderForeColor);
DoCommand(SCI_MARKERSETBACK, SC_MARKNUM_FOLDERMIDTAIL, m_AppThemeColorSet._editorFolderBackColor);
if (AppSettingMgr.m_bEnableHightLightFolder)
{
DoCommand(SCI_MARKERENABLEHIGHLIGHT, 1);
}
else
{
DoCommand(SCI_MARKERENABLEHIGHLIGHT, 0);
}
DoCommand(SCI_MARKERDEFINE, 1, SC_MARK_BOOKMARK);
SetDisplayLinenumbers(TRUE);
SetDisplaySelection(TRUE);
m_strLexerName == LEXER_PLAIN_TEXT ? SetDisplayFolding(FALSE) : SetDisplayFolding(TRUE);
// change cursor when hover margin bar
DoCommand(SCI_SETMARGINCURSORN, SC_SETMARGINTYPE_LINENUM, SC_CURSOR_RIGHT_HAND);
DoCommand(SCI_SETMARGINCURSORN, SC_SETMARGINTYPE_MAKER, SC_CURSOR_RIGHT_HAND);
DoCommand(SCI_SETMARGINCURSORN, SC_SETMARGINTYPE_FOLDING, SC_CURSOR_RIGHT_HAND);
// auto complete options
if (AppSettingMgr.m_bAutoCompleteIgnoreCase)
{
DoCommand(SCI_AUTOCSETIGNORECASE, 1);
}
DoCommand(SCI_AUTOCSETSEPARATOR, WORD_AUTOCSETSEPARATOR);
DoCommand(SCI_AUTOCSETTYPESEPARATOR, IMAGE_AUTOCSETSEPARATOR);
DoCommand(SCI_AUTOCSETMAXWIDTH, 100);
// set icon for auto complete list box
int iconWidth = GetSystemMetrics(SM_CXSMICON);
int iconHeight = GetSystemMetrics(SM_CYSMICON);
DoCommand(SCI_RGBAIMAGESETWIDTH, iconWidth);
DoCommand(SCI_RGBAIMAGESETHEIGHT, iconHeight);
HICON hIcon = GuiUtils::LoadIconWithSize(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDR_AUTO_COMPLETE), iconWidth, iconHeight);
std::unique_ptr<UINT[]> pImageBytes = GuiUtils::HIconToImageByte(hIcon);
DoCommand(SCI_REGISTERRGBAIMAGE, 0, reinterpret_cast<sptr_t>(pImageBytes.get()));
// ensure that all of the lines currently displayed can be completely scrolled
DoCommand(SCI_SETSCROLLWIDTHTRACKING, 1);
// Now the horizontal scroll bars should only appear if anydisplayed lines exceed the width of the window
DoCommand(SCI_SETSCROLLWIDTH, 1);
// Setting this to 0 allows scrolling one page below the last line.
DoCommand(SCI_SETENDATLASTLINE, 0);
if (!m_bEditorInitiated)
{
DoCommand(SCI_SETWRAPMODE, SC_WRAP_NONE);
}
DoCommand(SCI_SETWRAPVISUALFLAGS, SC_WRAPVISUALFLAG_END);
DoCommand(SCI_SETCARETFORE, m_AppThemeColorSet._editorCaretColor);
DoCommand(SCI_SETADDITIONALCARETFORE, m_AppThemeColorSet._editorCaretColor);
if (AppSettingMgr.m_bDrawCaretLineFrame)
{
DoCommand(SCI_SETCARETLINEFRAME, 1);
}
else
{
DoCommand(SCI_SETCARETLINEFRAME, 0);
}
DoCommand(SCI_SETCARETLINEVISIBLE, 1);
DoCommand(SCI_SETCARETLINEVISIBLEALWAYS, 1);
DoCommand(SCI_SETCARETLINEBACK, m_AppThemeColorSet._editorTextColor);
DoCommand(SCI_SETCARETLINEBACKALPHA, 100);
DoCommand(SCI_SETCARETWIDTH, 2);
if (AppSettingMgr.m_bEnableUrlHighlight)
{
RenderHotSpotForUrlLinks();
}
// menu pop up
DoCommand(SCI_USEPOPUP, 0, 0);
// long line checker
DoCommand(SCI_SETEDGECOLUMN, AppSettingMgr.m_nLongLineMaximum);
// selection
SetSelectionTextColor(m_AppThemeColorSet._selectionTextColor, 60);
if (AppSettingMgr.m_bEnableCaretBlink)
{
DoCommand(SCI_SETCARETPERIOD, 500, 0);
DoCommand(SCI_SETADDITIONALCARETSBLINK, TRUE);
}
else
{
DoCommand(SCI_SETCARETPERIOD, 0, 0);
DoCommand(SCI_SETADDITIONALCARETSBLINK, FALSE);
}
EnableMultiCursorMode(AppSettingMgr.m_bEnableMultipleCursor);
// set dwell timer, change to 0 if we want to use feature showhide folding bar
DoCommand(SCI_SETMOUSEDWELLTIME, SC_TIME_FOREVER);
// disable SCEN_CHANGE to avoid averhead
DoCommand(SCI_SETCOMMANDEVENTS, 0);
// set space line ascent
DoCommand(SCI_SETEXTRAASCENT, AppSettingMgr.m_nLineSpaceAbove);
DoCommand(SCI_SETEXTRADESCENT, AppSettingMgr.m_nLineSpaceBelow);
DoCommand(SCI_SETMOUSEWHEELCAPTURES, 0);
// set indicator styles (foreground and alpha maybe overridden by style settings)
DoCommand(SCI_INDICSETSTYLE, STYLE_BRACELIGHT, INDIC_FULLBOX);
DoCommand(SCI_STYLESETFORE, STYLE_BRACELIGHT, BasicColors::red);
DoCommand(SCI_INDICSETALPHA, STYLE_BRACELIGHT, 120);
DoCommand(SCI_INDICSETOUTLINEALPHA, STYLE_BRACELIGHT, 120);
DoCommand(SCI_STYLESETBOLD, STYLE_BRACELIGHT, 1);
DoCommand(SCI_INDICSETSTYLE, STYLE_BRACEBAD, INDIC_FULLBOX);
DoCommand(SCI_STYLESETFORE, STYLE_BRACEBAD, BasicColors::blue);
DoCommand(SCI_INDICSETALPHA, STYLE_BRACEBAD, 120);
DoCommand(SCI_INDICSETOUTLINEALPHA, STYLE_BRACEBAD, 120);
DoCommand(SCI_STYLESETBOLD, STYLE_BRACEBAD, 1);
//DoCommand(SCI_INDICSETSTYLE, INDIC_BRACEMATCH, INDIC_ROUNDBOX);
//DoCommand(SCI_INDICSETALPHA, INDIC_BRACEMATCH, 30);
//DoCommand(SCI_INDICSETOUTLINEALPHA, INDIC_BRACEMATCH, 0);
//DoCommand(SCI_INDICSETUNDER, INDIC_BRACEMATCH, true);
//DoCommand(SCI_INDICSETFORE, INDIC_BRACEMATCH, RGB(0, 150, 0));
DoCommand(SCI_INDICSETFORE, INDIC_TAGMATCH, m_AppThemeColorSet._editorTagMatchColor);
DoCommand(SCI_INDICSETFORE, INDIC_TAGATTR, m_AppThemeColorSet._editorTagMatchColor);
DoCommand(SCI_INDICSETSTYLE, INDIC_TAGMATCH, INDIC_DASH);
DoCommand(SCI_INDICSETSTYLE, INDIC_TAGATTR, INDIC_DASH);
DoCommand(SCI_INDICSETALPHA, INDIC_TAGMATCH, 50);
DoCommand(SCI_INDICSETALPHA, INDIC_TAGATTR, 50);
DoCommand(SCI_INDICSETUNDER, INDIC_TAGMATCH, 1);
DoCommand(SCI_INDICSETUNDER, INDIC_TAGATTR, 1);
// spell checker inicator
DoCommand(SCI_INDICSETSTYLE, INDIC_SPELL_CHECKER, INDIC_SQUIGGLELOW);
DoCommand(SCI_INDICSETFORE, INDIC_SPELL_CHECKER, m_AppThemeColorSet._editorSpellCheckColor);
// set saved zoom factor
DoCommand(SCI_SETZOOM, AppSettingMgr.m_nEditorZoomFactor);
}
void CEditorCtrl::ResetUndoSavePoint()
{
DoCommand(SCI_EMPTYUNDOBUFFER);
DoCommand(SCI_SETSAVEPOINT, 0, 0);
}
void CEditorCtrl::LoadExternalSettings(CLanguageDatabase* pDatabase)
{
CString strLanguageSettingFilePath = PathUtils::GetLanguageSettingFilePath(pDatabase->GetLanguageName());
if (!PathFileExists(strLanguageSettingFilePath)) return;
CStdioFile stdFile;
if (stdFile.Open(strLanguageSettingFilePath, CFile::modeRead))
{
CString strLine;
BOOL bStartReadCompilerPathSession = FALSE;
BOOL bStartReadDebuggerPathSession = FALSE;
BOOL bStartReadAutoCompleteSession = FALSE;
CString strCompilerPath;
CString strDebuggerPath;
CString strAutoCompletes;
while (stdFile.ReadString(strLine))
{
if (strLine.IsEmpty()) continue;
if (strLine.Find(_T("@@ compiler path:")) != -1)
{
bStartReadCompilerPathSession = TRUE;
continue;
}
else if (strLine.Find(_T("@@ debugger path:")) != -1)
{
bStartReadCompilerPathSession = FALSE;
bStartReadDebuggerPathSession = TRUE;
bStartReadAutoCompleteSession = FALSE;
continue;
}
else if (strLine.Find(_T("@@ auto complete:")) != -1)
{
bStartReadDebuggerPathSession = FALSE;
bStartReadAutoCompleteSession = TRUE;
bStartReadCompilerPathSession = FALSE;
continue;
}
if (bStartReadCompilerPathSession)
{
strCompilerPath += strLine.Trim();
}
else if (bStartReadDebuggerPathSession)
{
strDebuggerPath += strLine.Trim();
}
else if (bStartReadAutoCompleteSession)
{
strAutoCompletes += CSTRING_SPACE + strLine.Trim();
}
}
pDatabase->SetLanguageAutoComplete(strAutoCompletes);
pDatabase->SetCompilerPath(strCompilerPath);
pDatabase->SetDebuggerPath(strDebuggerPath);
}
stdFile.Close();
}
void CEditorCtrl::SetColorForStyle(int style, COLORREF fore, COLORREF back, int size, const char* face)
{
DoCommand(SCI_STYLESETFORE, style, fore);
DoCommand(SCI_STYLESETBACK, style, back);
if (size >= 1)
{
DoCommand(SCI_STYLESETSIZE, style, size);
}
if (face)
{
DoCommand(SCI_STYLESETFONT, style, reinterpret_cast<LPARAM>(face));
}
}
void CEditorCtrl::SetTextToEditor(const CString& strText)
{
if (IsReadOnlyEditor()) return;
CT2A bufferUTF8(strText, TF_UTF8);
LPCTSTR szUTF8 = (LPCTSTR)bufferUTF8.m_psz;
if (szUTF8 != NULL)
{
DoCommand(SCI_SETTEXT, 0, reinterpret_cast<LPARAM>(szUTF8));
}
SetFocus();
}
void CEditorCtrl::GetText(CString& strText)
{
auto GetTextFromEditor = [&]() -> char*
{
int lLen = (int)DoCommand(SCI_GETLENGTH) + 1;
if (lLen > 0)
{
char* pReturn = new char[lLen + 1];
if (pReturn != NULL)
{
*pReturn = '\0';
DoCommand(SCI_GETTEXT, lLen, reinterpret_cast<LPARAM>(pReturn));
return pReturn;
}
}
return NULL;
};
std::unique_ptr<char> szText;
szText.reset(GetTextFromEditor());
if (szText != NULL)
{
auto uiCodePage = AppUtils::GetCurrentCodePage();
AppUtils::SetCurrentCodePage(TF_UTF8);
CString str = AppUtils::ArrayCharToCString(szText.get());
AppUtils::SetCurrentCodePage(uiCodePage);
strText = str;
}
}
void CEditorCtrl::GetTextRange(Sci_TextRange* txtRange)
{
DoCommand(SCI_GETTEXTRANGE, 0, sptr_t(txtRange));
}
void CEditorCtrl::AddText(const CString& strText)
{
if (strText.GetLength() <= 0) return;
char* bufUtf8 = NULL;
CREATE_BUFFER_FROM_CSTRING(bufUtf8, strText);
if (bufUtf8 != NULL)
{
DoCommand(SCI_INSERTTEXT, 0, reinterpret_cast<LPARAM>(bufUtf8));
}
DELETE_POINTER_CPP_ARRAY(bufUtf8);
}
void CEditorCtrl::InsertText(const CString& strText, int pos)
{
if (strText.GetLength() <= 0) return;
CT2A bufferUTF8(strText, TF_UTF8);
LPCTSTR szUTF8 = (LPCTSTR)bufferUTF8.m_psz;
if (szUTF8 != NULL)
{
DoCommand(SCI_INSERTTEXT, pos, reinterpret_cast<LPARAM>(szUTF8));
}
}
void CEditorCtrl::InsertTextAtCurrentPos(const CString& strText)
{
if (strText.GetLength() <= 0) return;
int nSelections = GetSelectionNumber();
if (nSelections > SINGLE_SELECTION) return;
CT2A bufferUTF8(strText, TF_UTF8);
LPCTSTR szUTF8 = (LPCTSTR)bufferUTF8.m_psz;
if (szUTF8 != NULL)
{
DoCommand(SCI_INSERTTEXT, GetCurrentPosition(), reinterpret_cast<LPARAM>(szUTF8));
SetCurrentPosition(GetCurrentPosition() + strText.GetLength());
}
}
void CEditorCtrl::InsertTextAtSelectionNumber(const CString& strText, int lSelectionCaretPosN)
{
CT2A bufferUTF8(strText, TF_UTF8);
LPCTSTR szUTF8 = (LPCTSTR)bufferUTF8.m_psz;
if (szUTF8 != NULL)
{
DoCommand(SCI_INSERTTEXT, lSelectionCaretPosN, reinterpret_cast<LPARAM>(szUTF8));
}
}
int CEditorCtrl::GetSelectionNumberCaret(int nSelectionNumber)
{
return (int)DoCommand(SCI_GETSELECTIONNCARET, nSelectionNumber);
}
int CEditorCtrl::GetSelectionNumberAnchor(int nSelectionNumber)
{
return (int)DoCommand(SCI_GETSELECTIONNANCHOR, nSelectionNumber);
}
void CEditorCtrl::InsertTextInMultiSelectionMode(const CString& strText, int nSelections, BOOL bIsBracket)
{
std::vector<int> vecCaret;
vecCaret.reserve(nSelections);
for (int i = 0; i < nSelections; ++i)
{
int lSelectionCaretPosN = GetSelectionNumberCaret(i);
vecCaret.push_back(lSelectionCaretPosN);
InsertTextAtSelectionNumber(strText, lSelectionCaretPosN + strText.GetLength());
}
if (bIsBracket)
{
for (int i = 0; i < vecCaret.size(); ++i)
{
if (i == 0)
{
DoCommand(SCI_SETSELECTION, vecCaret[i] + strText.GetLength() - 1, vecCaret[i] + strText.GetLength() - 1);
}
else
{
DoCommand(SCI_ADDSELECTION, vecCaret[i] + strText.GetLength() - 1, vecCaret[i] + strText.GetLength() - 1);
}
}
}
else
{
for (int i = 0; i < vecCaret.size(); ++i)
{
if (i == 0)
{
DoCommand(SCI_SETSELECTION, vecCaret[i] + strText.GetLength(), vecCaret[i] + strText.GetLength());
}
else
{
DoCommand(SCI_ADDSELECTION, vecCaret[i] + strText.GetLength(), vecCaret[i] + strText.GetLength());
}
}
}
}
void CEditorCtrl::AppendText(const CString& strText, int pos)
{
if (strText.GetLength() <= 0) return;
CT2A bufferUTF8(strText, TF_UTF8);
LPCTSTR szUTF8 = (LPCTSTR)bufferUTF8.m_psz;
if (szUTF8 != NULL)
{
DoCommand(SCI_APPENDTEXT, pos, reinterpret_cast<LPARAM>(szUTF8));
}
}
void CEditorCtrl::ReplaceSelectionWithText(const CString& strText)
{
CT2A bufferUTF8(strText, TF_UTF8);
LPCTSTR szUTF8 = (LPCTSTR)bufferUTF8.m_psz;
if (szUTF8 != NULL)
{
size_t start = GetSelectionStartPosition();
DoCommand(SCI_REPLACESEL, 0, (LPARAM)"");
DoCommand(SCI_ADDTEXT, strText.GetLength(), reinterpret_cast<LPARAM>(szUTF8));
DoCommand(SCI_SETSEL, start, start + strText.GetLength());
}
}
void CEditorCtrl::ReplaceSelectionNWithText(const CString& strText, int nSel)
{
int anchorPos = GetSelectionNumberAnchor(nSel);
int curPos = GetSelectionNumberCaret(nSel);
CString strSelectedText;
if (anchorPos > curPos)
{
RemoveTextRange(curPos, anchorPos - curPos);
}
else if (anchorPos < curPos)
{
RemoveTextRange(anchorPos, curPos - anchorPos);
}
else
{
int lLine = GetLineFromPosition(curPos);
RemoveLine(lLine);
}
}
void CEditorCtrl::ReplaceCurrentWord(const CString& strNewWord)
{
int currentPos = int(DoCommand(SCI_GETCURRENTPOS));
int startPos = int(DoCommand(SCI_WORDSTARTPOSITION, currentPos, 1));
int endPos = int(DoCommand(SCI_WORDENDPOSITION, currentPos, true));
SetSelectionRange(startPos, endPos);
ReplaceSelectionWithText(strNewWord);
}
void CEditorCtrl::ReplaceLine(int lLine, const CString& strText)
{
if (lLine < 0) return;
int StartLinePos = GetLineStartPosition(lLine);
int EndLinePos = GetLineEndPosition(lLine);
SetStartSelection(StartLinePos);
SetEndSelection(EndLinePos);
ReplaceSelectionWithText(strText);
}
void CEditorCtrl::RemoveLine(int lLine)
{
if (lLine < 0) return;
int StartLinePos = GetLineStartPosition(lLine);
int EndLinePos = GetLineEndPosition(lLine);
RemoveTextRange(StartLinePos, GetLineLength(lLine));
}
void CEditorCtrl::RemoveTextRange(int lStart, int lLengthDelete)
{
DoCommand(SCI_DELETERANGE, lStart, lLengthDelete);
}
void CEditorCtrl::RemoveSelectionText()
{
DoCommand(SCI_TARGETFROMSELECTION, 0, 0);
DoCommand(SCI_REPLACETARGET, 0, reinterpret_cast<LPARAM>(""));
}
void CEditorCtrl::GetTextFromLine(int nline, CString& strText)
{
auto GetTextFromEditor = [&]() -> char*
{
int lLen = (int)DoCommand(SCI_LINELENGTH, nline - 1);
if (lLen > 0)
{
char* pReturn = new char[lLen + 1];
if (pReturn != NULL)
{
*pReturn = '\0';
DoCommand(SCI_GETLINE, nline - 1, reinterpret_cast<LPARAM>(pReturn));
pReturn[lLen] = '\0';
return pReturn;
}
}
return NULL;
};
std::unique_ptr<char> szText;
szText.reset(GetTextFromEditor());
if (szText != NULL)
{
auto uiCodePage = AppUtils::GetCurrentCodePage();
AppUtils::SetCurrentCodePage(TF_UTF8);
CString st = AppUtils::ArrayCharToCString(szText.get());
st.Replace(EDITOR_NEW_LINE_CR, _T(""));
st.Replace(EDITOR_NEW_LINE_LF, _T(""));
AppUtils::SetCurrentCodePage(uiCodePage);
strText = st;
}
}
CString CEditorCtrl::GetTextFromCurrentLine()
{
CString strLine;
GetTextFromLine(GetCurrentLine(), strLine);
return strLine;
}
CString CEditorCtrl::GetRecentAddedText()
{
CString strWord;
int curPos = int(DoCommand(SCI_GETCURRENTPOS));
int startPos = int(DoCommand(SCI_WORDSTARTPOSITION, curPos, 1));
if (curPos == startPos) return strWord;
GetTextRange(strWord, startPos, curPos);
return strWord;
}
CString CEditorCtrl::GetCurrentWord()
{
int currentPos = int(DoCommand(SCI_GETCURRENTPOS));
int startPos = int(DoCommand(SCI_WORDSTARTPOSITION, currentPos, 1));
int endPos = int(DoCommand(SCI_WORDENDPOSITION, currentPos, true));
CString strWord;
GetTextRange(strWord, startPos, endPos);
return strWord;
}
void CEditorCtrl::Cut()
{
DoCommand(SCI_CUT);
}
void CEditorCtrl::CutLine()
{
int nCurrentLine = GetCurrentLine();
SetStartSelection(GetLineStartPosition(nCurrentLine - 1));
SetEndSelection(GetLineEndPosition(nCurrentLine - 1));
DoCommand(SCI_CUT);
}
void CEditorCtrl::Copy()
{
DoCommand(SCI_COPY);
}
void CEditorCtrl::CopyLine()
{
DoCommand(SCI_COPYALLOWLINE);
}
void CEditorCtrl::CopyText(const CString& strText, int length)
{
char* bufUtf8 = NULL;
CREATE_BUFFER_FROM_CSTRING(bufUtf8, strText);
if (bufUtf8 != NULL)
{
DoCommand(SCI_COPYTEXT, length, reinterpret_cast<LPARAM>(bufUtf8));
}
DELETE_POINTER_CPP_ARRAY(bufUtf8);
}
void CEditorCtrl::CopyRange(int posStart, int posEnd)
{
DoCommand(SCI_COPYRANGE, posStart, posEnd);
}
void CEditorCtrl::Paste()
{
DoCommand(SCI_PASTE);
}
void CEditorCtrl::Clear()
{
DoCommand(SCI_CLEAR);
}
void CEditorCtrl::SelectAll()
{
DoCommand(SCI_SELECTALL);
}
void CEditorCtrl::ClearSelection(int lCaret)
{
DoCommand(SCI_SETEMPTYSELECTION, lCaret);
}
void CEditorCtrl::DropSelections()
{
int anchorPos = GetSelectionNumberAnchor(0);
int curPos = GetSelectionNumberCaret(0);
ClearSelection(curPos);
SetCurrentAnchor(anchorPos);
SetCurrentPosition(curPos);
}
int CEditorCtrl::GetSelectionStartPosition()
{
return (int)DoCommand(SCI_GETSELECTIONSTART);
}
int CEditorCtrl::GetSelectionEndPosition()
{
return (int)DoCommand(SCI_GETSELECTIONEND);
}
CString CEditorCtrl::GetSelectedText()
{
int nSelections = GetSelectionNumber();
if (nSelections == 1)
{
int lLen = (GetSelectionEndPosition() - GetSelectionStartPosition()) + 1;
if (lLen > 0)
{
char* pReturn = new char[lLen + 1];
if (pReturn != NULL)
{
*pReturn = '\0';
DoCommand(SCI_GETSELTEXT, 0, reinterpret_cast<LPARAM>(pReturn));
auto uiCodePage = AppUtils::GetCurrentCodePage();
AppUtils::SetCurrentCodePage(TF_UTF8);
CString strReturn = AppUtils::ArrayCharToCString(pReturn);
AppUtils::SetCurrentCodePage(uiCodePage);
DELETE_POINTER_CPP_ARRAY(pReturn)
return strReturn;
}
}
}
return _T("");
}
CString CEditorCtrl::GetSelectedTextAtSelection(int nSel)
{
int anchorPos = GetSelectionNumberAnchor(nSel);
int curPos = GetSelectionNumberCaret(nSel);
CString strSelectedText;
if (anchorPos > curPos)
{
GetTextRange(strSelectedText, curPos, anchorPos);
}
else if (anchorPos < curPos)
{
GetTextRange(strSelectedText, anchorPos, curPos);
}
else
{
int lLine = GetLineFromPosition(curPos);
GetTextFromLine(lLine + 1, strSelectedText);
}
return strSelectedText;
}
CString CEditorCtrl::GetFileExtension()
{
return m_strFileExtension;
}
CString CEditorCtrl::GetLexerName()
{
return m_strLexerName;
}
BOOL CEditorCtrl::CanPaste()
{
return DoCommand(SCI_CANPASTE) != 0;
}
void CEditorCtrl::SetLexer(const char* m_strLexerNameName)
{
if (m_strLexerNameName != NULL)
{
void* pLexer = m_CreateLexerFunc(m_strLexerNameName);
DoCommand(SCI_SETILEXER, 0, reinterpret_cast<LPARAM>(pLexer));
}
}
void CEditorCtrl::SetKeywords(const char* keywords, int nKeyWordSet)
{
DoCommand(SCI_SETKEYWORDS, nKeyWordSet, reinterpret_cast<LPARAM>(keywords));
}
int CEditorCtrl::GetLineIndentPos(int nLine)
{
int nIndPos = (int)DoCommand(SCI_GETLINEINDENTPOSITION, (WPARAM)nLine);