/
NppCommands.cpp
2634 lines (2291 loc) · 74.9 KB
/
NppCommands.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
// This file is part of Notepad++ project
// Copyright (C)2003 Don HO <don.h@free.fr>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// Note that the GPL places important restrictions on "derived works", yet
// it does not provide a detailed definition of that term. To avoid
// misunderstandings, we consider an application to constitute a
// "derivative work" for the purpose of this license if it does any of the
// following:
// 1. Integrates source code from Notepad++.
// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
// installer, such as those produced by InstallShield.
// 3. Links to a library or executes a program that does any of the above.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "precompiledHeaders.h"
#include "Notepad_plus_Window.h"
#include "EncodingMapper.h"
#include "ShortcutMapper.h"
#include "TaskListDlg.h"
#include "clipboardFormats.h"
#include "VerticalFileSwitcher.h"
#include "documentMap.h"
#include "functionListPanel.h"
void Notepad_plus::macroPlayback(Macro macro)
{
_pEditView->execute(SCI_BEGINUNDOACTION);
for (Macro::iterator step = macro.begin(); step != macro.end(); ++step)
{
if (step->isPlayable())
step->PlayBack(this->_pPublicInterface, _pEditView);
else
_findReplaceDlg.execSavedCommand(step->message, step->lParameter, step->sParameter);
}
_pEditView->execute(SCI_ENDUNDOACTION);
}
void Notepad_plus::command(int id)
{
switch (id)
{
case IDM_FILE_NEW:
{
fileNew();
}
break;
case IDM_FILE_OPEN:
{
fileOpen();
}
break;
case IDM_FILE_OPEN_FOLDER:
{
Command cmd(TEXT("explorer /select,$(FULL_CURRENT_PATH)"));
cmd.run(_pPublicInterface->getHSelf());
}
break;
case IDM_FILE_OPEN_CMD:
{
Command cmd(TEXT("cmd /K cd /d $(CURRENT_DIRECTORY)"));
cmd.run(_pPublicInterface->getHSelf());
}
break;
case IDM_FILE_RELOAD:
fileReload();
break;
case IDM_FILESWITCHER_FILESCLOSE:
case IDM_FILESWITCHER_FILESCLOSEOTHERS:
if (_pFileSwitcherPanel)
{
vector<SwitcherFileInfo> files = _pFileSwitcherPanel->getSelectedFiles(id == IDM_FILESWITCHER_FILESCLOSEOTHERS);
for (size_t i = 0, len = files.size(); i < len; ++i)
{
fileClose((BufferID)files[i]._bufID, files[i]._iView);
}
if (id == IDM_FILESWITCHER_FILESCLOSEOTHERS)
{
// Get current buffer and its view
_pFileSwitcherPanel->activateItem(int(_pEditView->getCurrentBufferID()), currentView());
}
}
break;
case IDM_FILE_CLOSE:
if (fileClose())
checkDocState();
break;
case IDM_FILE_DELETE:
if (fileDelete())
checkDocState();
break;
case IDM_FILE_RENAME:
fileRename();
break;
case IDM_FILE_CLOSEALL:
fileCloseAll(true);
checkDocState();
break;
case IDM_FILE_CLOSEALL_BUT_CURRENT :
fileCloseAllButCurrent();
checkDocState();
break;
case IDM_FILE_CLOSEALL_TOLEFT :
fileCloseAllToLeft();
checkDocState();
break;
case IDM_FILE_CLOSEALL_TORIGHT :
fileCloseAllToRight();
checkDocState();
break;
case IDM_FILE_SAVE :
fileSave();
break;
case IDM_FILE_SAVEALL :
fileSaveAll();
break;
case IDM_FILE_SAVEAS :
fileSaveAs();
break;
case IDM_FILE_SAVECOPYAS :
fileSaveAs(BUFFER_INVALID, true);
break;
case IDM_FILE_LOADSESSION:
fileLoadSession();
break;
case IDM_FILE_SAVESESSION:
fileSaveSession();
break;
case IDM_FILE_PRINTNOW :
filePrint(false);
break;
case IDM_FILE_PRINT :
filePrint(true);
break;
case IDM_FILE_EXIT:
::SendMessage(_pPublicInterface->getHSelf(), WM_CLOSE, 0, 0);
break;
case IDM_EDIT_UNDO:
_pEditView->execute(WM_UNDO);
checkClipboard();
checkUndoState();
break;
case IDM_EDIT_REDO:
_pEditView->execute(SCI_REDO);
checkClipboard();
checkUndoState();
break;
case IDM_EDIT_CUT:
_pEditView->execute(WM_CUT);
checkClipboard();
break;
case IDM_EDIT_COPY:
_pEditView->execute(WM_COPY);
checkClipboard();
break;
case IDM_EDIT_COPY_BINARY:
case IDM_EDIT_CUT_BINARY:
{
int textLen = _pEditView->execute(SCI_GETSELTEXT, 0, 0) - 1;
if (!textLen)
return;
char *pBinText = new char[textLen + 1];
_pEditView->getSelectedText(pBinText, textLen + 1);
// Open the clipboard, and empty it.
if (!OpenClipboard(NULL))
return;
EmptyClipboard();
// Allocate a global memory object for the text.
HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (textLen + 1) * sizeof(unsigned char));
if (hglbCopy == NULL)
{
CloseClipboard();
return;
}
// Lock the handle and copy the text to the buffer.
unsigned char *lpucharCopy = (unsigned char *)GlobalLock(hglbCopy);
memcpy(lpucharCopy, pBinText, textLen * sizeof(unsigned char));
lpucharCopy[textLen] = 0; // null character
GlobalUnlock(hglbCopy);
// Place the handle on the clipboard.
SetClipboardData(CF_TEXT, hglbCopy);
// Allocate a global memory object for the text length.
HGLOBAL hglbLenCopy = GlobalAlloc(GMEM_MOVEABLE, sizeof(unsigned long));
if (hglbLenCopy == NULL)
{
CloseClipboard();
return;
}
// Lock the handle and copy the text to the buffer.
unsigned long *lpLenCopy = (unsigned long *)GlobalLock(hglbLenCopy);
*lpLenCopy = textLen;
GlobalUnlock(hglbLenCopy);
// Place the handle on the clipboard.
UINT f = RegisterClipboardFormat(CF_NPPTEXTLEN);
SetClipboardData(f, hglbLenCopy);
CloseClipboard();
if (id == IDM_EDIT_CUT_BINARY)
_pEditView->execute(SCI_REPLACESEL, 0, (LPARAM)"");
}
break;
case IDM_EDIT_PASTE:
{
int eolMode = int(_pEditView->execute(SCI_GETEOLMODE));
_pEditView->execute(SCI_PASTE);
_pEditView->execute(SCI_CONVERTEOLS, eolMode);
}
break;
case IDM_EDIT_PASTE_BINARY:
{
if (!IsClipboardFormatAvailable(CF_TEXT))
return;
if (!OpenClipboard(NULL))
return;
HGLOBAL hglb = GetClipboardData(CF_TEXT);
if (hglb != NULL)
{
char *lpchar = (char *)GlobalLock(hglb);
if (lpchar != NULL)
{
UINT cf_nppTextLen = RegisterClipboardFormat(CF_NPPTEXTLEN);
if (IsClipboardFormatAvailable(cf_nppTextLen))
{
HGLOBAL hglbLen = GetClipboardData(cf_nppTextLen);
if (hglbLen != NULL)
{
unsigned long *lpLen = (unsigned long *)GlobalLock(hglbLen);
if (lpLen != NULL)
{
_pEditView->execute(SCI_REPLACESEL, 0, (LPARAM)"");
_pEditView->execute(SCI_ADDTEXT, *lpLen, (LPARAM)lpchar);
GlobalUnlock(hglb);
}
}
}
else
{
_pEditView->execute(SCI_REPLACESEL, 0, (LPARAM)lpchar);
}
GlobalUnlock(hglb);
}
}
CloseClipboard();
}
break;
case IDM_EDIT_PASTE_AS_RTF:
case IDM_EDIT_PASTE_AS_HTML:
{
UINT f = RegisterClipboardFormat(id==IDM_EDIT_PASTE_AS_HTML?CF_HTML:CF_RTF);
if (!IsClipboardFormatAvailable(f))
return;
if (!OpenClipboard(NULL))
return;
HGLOBAL hglb = GetClipboardData(f);
if (hglb != NULL)
{
LPSTR lptstr = (LPSTR)GlobalLock(hglb);
if (lptstr != NULL)
{
// Call the application-defined ReplaceSelection
// function to insert the text and repaint the
// window.
_pEditView->execute(SCI_REPLACESEL, 0, (LPARAM)lptstr);
GlobalUnlock(hglb);
}
}
CloseClipboard();
}
break;
case IDM_EDIT_BEGINENDSELECT:
{
::CheckMenuItem(_mainMenuHandle, IDM_EDIT_BEGINENDSELECT, MF_BYCOMMAND | _pEditView->beginEndSelectedIsStarted()?MF_UNCHECKED:MF_CHECKED);
_pEditView->beginOrEndSelect();
}
break;
case IDM_EDIT_SORTLINES:
case IDM_EDIT_SORTLINESREVERSE:
{
// default: no selection
size_t fromLine = 0;
size_t toLine = _pEditView->execute(SCI_GETLINECOUNT) - 1;
// multi-selection is not allowed
if (_pEditView->execute(SCI_GETSELECTIONS) > 1)
return;
// retangle-selection is not allowed
if (_pEditView->execute(SCI_SELECTIONISRECTANGLE))
return;
int selStart = _pEditView->execute(SCI_GETSELECTIONSTART);
int selEnd = _pEditView->execute(SCI_GETSELECTIONEND);
bool hasSelection = selStart != selEnd;
pair<int, int> lineRange = _pEditView->getSelectionLinesRange();
if (hasSelection)
{
// one single line selection is not allowed
if ((lineRange.second - lineRange.first) == 0)
return;
fromLine = lineRange.first;
toLine = lineRange.second;
}
_pEditView->execute(SCI_BEGINUNDOACTION);
_pEditView->quickSortLines(fromLine, toLine, id == IDM_EDIT_SORTLINESREVERSE);
_pEditView->execute(SCI_ENDUNDOACTION);
if (hasSelection) // there was 1 selection, so we restore it
{
int posStart = _pEditView->execute(SCI_POSITIONFROMLINE, lineRange.first);
int posEnd = _pEditView->execute(SCI_GETLINEENDPOSITION, lineRange.second);
_pEditView->execute(SCI_SETSELECTIONSTART, posStart);
_pEditView->execute(SCI_SETSELECTIONEND, posEnd);
}
}
break;
case IDM_EDIT_BLANKLINEABOVECURRENT:
{
_pEditView->insertNewLineAboveCurrentLine();
}
break;
case IDM_EDIT_BLANKLINEBELOWCURRENT:
{
_pEditView->insertNewLineBelowCurrentLine();
}
break;
case IDM_EDIT_CHAR_PANEL:
{
launchAnsiCharPanel();
}
break;
case IDM_EDIT_CLIPBOARDHISTORY_PANEL:
{
launchClipboardHistoryPanel();
}
break;
case IDM_VIEW_FILESWITCHER_PANEL:
{
launchFileSwitcherPanel();
}
break;
case IDM_VIEW_PROJECT_PANEL_1:
{
launchProjectPanel(id, &_pProjectPanel_1, 0);
}
break;
case IDM_VIEW_PROJECT_PANEL_2:
{
launchProjectPanel(id, &_pProjectPanel_2, 1);
}
break;
case IDM_VIEW_PROJECT_PANEL_3:
{
launchProjectPanel(id, &_pProjectPanel_3, 2);
}
break;
case IDM_VIEW_DOC_MAP:
{
if (_pDocMap && (!_pDocMap->isClosed()))
{
_pDocMap->display(false);
_pDocMap->vzDlgDisplay(false);
_pDocMap->setClosed(true);
checkMenuItem(IDM_VIEW_DOC_MAP, false);
_toolBar.setCheck(IDM_VIEW_DOC_MAP, false);
_pEditView->getFocus();
}
else
{
launchDocMap();
if (_pDocMap)
{
checkMenuItem(IDM_VIEW_DOC_MAP, true);
_toolBar.setCheck(IDM_VIEW_DOC_MAP, true);
_pDocMap->setClosed(false);
}
}
}
break;
case IDM_VIEW_FUNC_LIST:
{
if (_pFuncList && (!_pFuncList->isClosed()))
{
_pFuncList->display(false);
_pFuncList->setClosed(true);
checkMenuItem(IDM_VIEW_FUNC_LIST, false);
_toolBar.setCheck(IDM_VIEW_FUNC_LIST, false);
}
else
{
checkMenuItem(IDM_VIEW_FUNC_LIST, true);
_toolBar.setCheck(IDM_VIEW_FUNC_LIST, true);
launchFunctionList();
_pFuncList->setClosed(false);
}
}
break;
case IDM_VIEW_TAB1:
case IDM_VIEW_TAB2:
case IDM_VIEW_TAB3:
case IDM_VIEW_TAB4:
case IDM_VIEW_TAB5:
case IDM_VIEW_TAB6:
case IDM_VIEW_TAB7:
case IDM_VIEW_TAB8:
case IDM_VIEW_TAB9:
{
const int index = id - IDM_VIEW_TAB1;
BufferID buf = _pDocTab->getBufferByIndex(index);
if(buf == BUFFER_INVALID)
{
// No buffer at chosen index, select the very last buffer instead.
const int last_index = _pDocTab->getItemCount() - 1;
if(last_index > 0)
switchToFile(_pDocTab->getBufferByIndex(last_index));
}
else
switchToFile(buf);
}
break;
case IDM_VIEW_TAB_NEXT:
{
const int current_index = _pDocTab->getCurrentTabIndex();
const int last_index = _pDocTab->getItemCount() - 1;
if(current_index < last_index)
switchToFile(_pDocTab->getBufferByIndex(current_index + 1));
else
switchToFile(_pDocTab->getBufferByIndex(0)); // Loop around.
}
break;
case IDM_VIEW_TAB_PREV:
{
const int current_index = _pDocTab->getCurrentTabIndex();
if(current_index > 0)
switchToFile(_pDocTab->getBufferByIndex(current_index - 1));
else
{
const int last_index = _pDocTab->getItemCount() - 1;
switchToFile(_pDocTab->getBufferByIndex(last_index)); // Loop around.
}
}
break;
case IDM_EDIT_DELETE:
_pEditView->execute(WM_CLEAR);
break;
case IDM_MACRO_STARTRECORDINGMACRO:
case IDM_MACRO_STOPRECORDINGMACRO:
case IDC_EDIT_TOGGLEMACRORECORDING:
{
if (_recordingMacro)
{
// STOP !!!
_mainEditView.execute(SCI_STOPRECORD);
_subEditView.execute(SCI_STOPRECORD);
_mainEditView.execute(SCI_SETCURSOR, (WPARAM)SC_CURSORNORMAL);
_subEditView.execute(SCI_SETCURSOR, (WPARAM)SC_CURSORNORMAL);
_recordingMacro = false;
_runMacroDlg.initMacroList();
}
else
{
_mainEditView.execute(SCI_SETCURSOR, 9);
_subEditView.execute(SCI_SETCURSOR, 9);
_macro.clear();
// START !!!
_mainEditView.execute(SCI_STARTRECORD);
_subEditView.execute(SCI_STARTRECORD);
_recordingMacro = true;
}
checkMacroState();
break;
}
case IDM_MACRO_PLAYBACKRECORDEDMACRO:
if (!_recordingMacro) // if we're not currently recording, then playback the recorded keystrokes
macroPlayback(_macro);
break;
case IDM_MACRO_RUNMULTIMACRODLG :
{
if (!_recordingMacro) // if we're not currently recording, then playback the recorded keystrokes
{
bool isFirstTime = !_runMacroDlg.isCreated();
_runMacroDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
{
_nativeLangSpeaker.changeDlgLang(_runMacroDlg.getHSelf(), "MultiMacro");
}
break;
}
}
break;
case IDM_MACRO_SAVECURRENTMACRO :
{
if (addCurrentMacro())
_runMacroDlg.initMacroList();
break;
}
case IDM_EDIT_FULLPATHTOCLIP :
case IDM_EDIT_CURRENTDIRTOCLIP :
case IDM_EDIT_FILENAMETOCLIP :
{
Buffer * buf = _pEditView->getCurrentBuffer();
if (id == IDM_EDIT_FULLPATHTOCLIP)
{
str2Cliboard(buf->getFullPathName());
}
else if (id == IDM_EDIT_CURRENTDIRTOCLIP)
{
generic_string dir(buf->getFullPathName());
PathRemoveFileSpec(dir);
str2Cliboard(dir.c_str());
}
else if (id == IDM_EDIT_FILENAMETOCLIP)
{
str2Cliboard(buf->getFileName());
}
}
break;
case IDM_SEARCH_FIND :
case IDM_SEARCH_REPLACE :
{
const int strSize = FINDREPLACE_MAXLENGTH;
TCHAR str[strSize];
bool isFirstTime = !_findReplaceDlg.isCreated();
_findReplaceDlg.doDialog((id == IDM_SEARCH_FIND)?FIND_DLG:REPLACE_DLG, _nativeLangSpeaker.isRTL());
_pEditView->getGenericSelectedText(str, strSize);
_findReplaceDlg.setSearchText(str);
setFindReplaceFolderFilter(NULL, NULL);
if (isFirstTime)
_nativeLangSpeaker.changeFindReplaceDlgLang(_findReplaceDlg);
break;
}
case IDM_SEARCH_FINDINFILES :
{
::SendMessage(_pPublicInterface->getHSelf(), NPPM_LAUNCHFINDINFILESDLG, 0, 0);
break;
}
case IDM_SEARCH_FINDINCREMENT :
{
const int strSize = FINDREPLACE_MAXLENGTH;
TCHAR str[strSize];
_pEditView->getGenericSelectedText(str, strSize, false);
if (0!=str[0]) // the selected text is not empty, then use it
_incrementFindDlg.setSearchText(str, _pEditView->getCurrentBuffer()->getUnicodeMode() != uni8Bit);
_incrementFindDlg.display();
}
break;
case IDM_SEARCH_FINDNEXT :
case IDM_SEARCH_FINDPREV :
{
if (!_findReplaceDlg.isCreated())
return;
FindOption op = _findReplaceDlg.getCurrentOptions();
op._whichDirection = (id == IDM_SEARCH_FINDNEXT?DIR_DOWN:DIR_UP);
generic_string s = _findReplaceDlg.getText2search();
FindStatus status = FSNoMessage;
_findReplaceDlg.processFindNext(s.c_str(), &op, &status);
if (status == FSEndReached)
_findReplaceDlg.setStatusbarMessage(TEXT("Find: Found the 1st occurrence from the top. The end of document has been reached."), FSEndReached);
else if (status == FSTopReached)
_findReplaceDlg.setStatusbarMessage(TEXT("Find: Found the 1st occurrence from the bottom. The begin of document has been reached."), FSTopReached);
break;
}
break;
case IDM_SEARCH_SETANDFINDNEXT :
case IDM_SEARCH_SETANDFINDPREV :
{
bool isFirstTime = !_findReplaceDlg.isCreated();
if (isFirstTime)
_findReplaceDlg.doDialog(FIND_DLG, _nativeLangSpeaker.isRTL(), false);
const int strSize = FINDREPLACE_MAXLENGTH;
TCHAR str[strSize];
_pEditView->getGenericSelectedText(str, strSize);
_findReplaceDlg.setSearchText(str);
_findReplaceDlg._env->_str2Search = str;
setFindReplaceFolderFilter(NULL, NULL);
if (isFirstTime)
_nativeLangSpeaker.changeFindReplaceDlgLang(_findReplaceDlg);
FindOption op = _findReplaceDlg.getCurrentOptions();
op._whichDirection = (id == IDM_SEARCH_SETANDFINDNEXT?DIR_DOWN:DIR_UP);
FindStatus status = FSNoMessage;
_findReplaceDlg.processFindNext(str, &op, &status);
if (status == FSEndReached)
_findReplaceDlg.setStatusbarMessage(TEXT("Find: Found the 1st occurrence from the top. The end of document has been reached."), FSEndReached);
else if (status == FSTopReached)
_findReplaceDlg.setStatusbarMessage(TEXT("Find: Found the 1st occurrence from the bottom. The begin of document has been reached."), FSTopReached);
break;
}
case IDM_SEARCH_GOTONEXTFOUND:
{
_findReplaceDlg.gotoNextFoundResult();
break;
}
case IDM_SEARCH_GOTOPREVFOUND:
{
_findReplaceDlg.gotoNextFoundResult(-1);
break;
}
case IDM_FOCUS_ON_FOUND_RESULTS:
{
if (GetFocus() == _findReplaceDlg.getHFindResults())
// focus already on found results, switch to current edit view
switchEditViewTo(currentView());
else
_findReplaceDlg.focusOnFinder();
break;
}
case IDM_SEARCH_VOLATILE_FINDNEXT :
case IDM_SEARCH_VOLATILE_FINDPREV :
{
TCHAR text2Find[MAX_PATH];
_pEditView->getGenericSelectedText(text2Find, MAX_PATH);
FindOption op;
op._isWholeWord = false;
op._whichDirection = (id == IDM_SEARCH_VOLATILE_FINDNEXT?DIR_DOWN:DIR_UP);
FindStatus status = FSNoMessage;
_findReplaceDlg.processFindNext(text2Find, &op, &status);
if (status == FSEndReached)
_findReplaceDlg.setStatusbarMessage(TEXT("Find: Found the 1st occurrence from the top. The end of document has been reached."), FSEndReached);
else if (status == FSTopReached)
_findReplaceDlg.setStatusbarMessage(TEXT("Find: Found the 1st occurrence from the bottom. The begin of document has been reached."), FSTopReached);
break;
}
case IDM_SEARCH_MARKALLEXT1 :
case IDM_SEARCH_MARKALLEXT2 :
case IDM_SEARCH_MARKALLEXT3 :
case IDM_SEARCH_MARKALLEXT4 :
case IDM_SEARCH_MARKALLEXT5 :
{
int styleID;
if (id == IDM_SEARCH_MARKALLEXT1)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT1;
else if (id == IDM_SEARCH_MARKALLEXT2)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT2;
else if (id == IDM_SEARCH_MARKALLEXT3)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT3;
else if (id == IDM_SEARCH_MARKALLEXT4)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT4;
else // (id == IDM_SEARCH_MARKALLEXT5)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT5;
const int strSize = FINDREPLACE_MAXLENGTH;
TCHAR text2Find[strSize];
TCHAR text2Find2[strSize];
_pEditView->getGenericSelectedText(text2Find, strSize, false);
_pEditView->getGenericWordOnCaretPos(text2Find2, strSize);
if (text2Find[0] == '\0')
{
_findReplaceDlg.markAll(text2Find2, styleID, true);
}
else
{
_findReplaceDlg.markAll(text2Find, styleID, lstrlen(text2Find) == lstrlen(text2Find2));
}
break;
}
case IDM_SEARCH_UNMARKALLEXT1 :
case IDM_SEARCH_UNMARKALLEXT2 :
case IDM_SEARCH_UNMARKALLEXT3 :
case IDM_SEARCH_UNMARKALLEXT4 :
case IDM_SEARCH_UNMARKALLEXT5 :
{
int styleID;
if (id == IDM_SEARCH_UNMARKALLEXT1)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT1;
else if (id == IDM_SEARCH_UNMARKALLEXT2)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT2;
else if (id == IDM_SEARCH_UNMARKALLEXT3)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT3;
else if (id == IDM_SEARCH_UNMARKALLEXT4)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT4;
else // (id == IDM_SEARCH_UNMARKALLEXT5)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT5;
_pEditView->clearIndicator(styleID);
break;
}
case IDM_SEARCH_GONEXTMARKER1 :
case IDM_SEARCH_GONEXTMARKER2 :
case IDM_SEARCH_GONEXTMARKER3 :
case IDM_SEARCH_GONEXTMARKER4 :
case IDM_SEARCH_GONEXTMARKER5 :
case IDM_SEARCH_GONEXTMARKER_DEF :
{
int styleID;
if (id == IDM_SEARCH_GONEXTMARKER1)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT1;
else if (id == IDM_SEARCH_GONEXTMARKER2)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT2;
else if (id == IDM_SEARCH_GONEXTMARKER3)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT3;
else if (id == IDM_SEARCH_GONEXTMARKER4)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT4;
else if (id == IDM_SEARCH_GONEXTMARKER5)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT5;
else // (id == IDM_SEARCH_GONEXTMARKER_DEF)
styleID = SCE_UNIVERSAL_FOUND_STYLE;
goToNextIndicator(styleID);
break;
}
case IDM_SEARCH_GOPREVMARKER1 :
case IDM_SEARCH_GOPREVMARKER2 :
case IDM_SEARCH_GOPREVMARKER3 :
case IDM_SEARCH_GOPREVMARKER4 :
case IDM_SEARCH_GOPREVMARKER5 :
case IDM_SEARCH_GOPREVMARKER_DEF :
{
int styleID;
if (id == IDM_SEARCH_GOPREVMARKER1)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT1;
else if (id == IDM_SEARCH_GOPREVMARKER2)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT2;
else if (id == IDM_SEARCH_GOPREVMARKER3)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT3;
else if (id == IDM_SEARCH_GOPREVMARKER4)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT4;
else if (id == IDM_SEARCH_GOPREVMARKER5)
styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT5;
else // (id == IDM_SEARCH_GOPREVMARKER_DEF)
styleID = SCE_UNIVERSAL_FOUND_STYLE;
goToPreviousIndicator(styleID);
break;
}
case IDM_SEARCH_CLEARALLMARKS :
{
_pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_EXT1);
_pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_EXT2);
_pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_EXT3);
_pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_EXT4);
_pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_EXT5);
break;
}
case IDM_SEARCH_GOTOLINE :
{
bool isFirstTime = !_goToLineDlg.isCreated();
_goToLineDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
_nativeLangSpeaker.changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine");
break;
}
case IDM_SEARCH_FINDCHARINRANGE :
{
bool isFirstTime = !_findCharsInRangeDlg.isCreated();
_findCharsInRangeDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
_nativeLangSpeaker.changeDlgLang(_findCharsInRangeDlg.getHSelf(), "FindCharsInRange");
break;
}
case IDM_EDIT_COLUMNMODETIP :
{
_nativeLangSpeaker.messageBox("ColumnModeTip",
_pPublicInterface->getHSelf(),
TEXT("Please use \"ALT+Mouse Selection\" or \"Alt+Shift+Arrow key\" to switch to column mode."),
TEXT("Column Mode Tip"),
MB_OK|MB_APPLMODAL);
break;
}
case IDM_EDIT_COLUMNMODE :
{
bool isFirstTime = !_colEditorDlg.isCreated();
_colEditorDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
_nativeLangSpeaker.changeDlgLang(_colEditorDlg.getHSelf(), "ColumnEditor");
break;
}
case IDM_SEARCH_GOTOMATCHINGBRACE :
case IDM_SEARCH_SELECTMATCHINGBRACES :
{
int braceAtCaret = -1;
int braceOpposite = -1;
findMatchingBracePos(braceAtCaret, braceOpposite);
if (braceOpposite != -1)
{
if(id == IDM_SEARCH_GOTOMATCHINGBRACE)
_pEditView->execute(SCI_GOTOPOS, braceOpposite);
else
_pEditView->execute(SCI_SETSEL, min(braceAtCaret, braceOpposite), max(braceAtCaret, braceOpposite) + 1); // + 1 so we always include the ending brace in the selection.
}
break;
}
case IDM_SEARCH_TOGGLE_BOOKMARK :
bookmarkToggle(-1);
break;
case IDM_SEARCH_NEXT_BOOKMARK:
bookmarkNext(true);
break;
case IDM_SEARCH_PREV_BOOKMARK:
bookmarkNext(false);
break;
case IDM_SEARCH_CLEAR_BOOKMARKS:
bookmarkClearAll();
break;
case IDM_LANG_USER_DLG :
{
bool isUDDlgVisible = false;
UserDefineDialog *udd = _pEditView->getUserDefineDlg();
if (!udd->isCreated())
{
_pEditView->doUserDefineDlg(true, _nativeLangSpeaker.isRTL());
_nativeLangSpeaker.changeUserDefineLang(udd);
if (_isUDDocked)
::SendMessage(udd->getHSelf(), WM_COMMAND, IDC_DOCK_BUTTON, 0);
}
else
{
isUDDlgVisible = udd->isVisible();
bool isUDDlgDocked = udd->isDocked();
if ((isUDDlgDocked)&&(isUDDlgVisible))
{
::ShowWindow(_pMainSplitter->getHSelf(), SW_HIDE);
if (bothActive())
_pMainWindow = &_subSplitter;
else
_pMainWindow = _pDocTab;
::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0);
udd->display(false);
_mainWindowStatus &= ~WindowUserActive;
}
else if ((isUDDlgDocked)&&(!isUDDlgVisible))
{
if (!_pMainSplitter)
{
_pMainSplitter = new SplitterContainer;
_pMainSplitter->init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf());
Window *pWindow;
if (bothActive())
pWindow = &_subSplitter;
else
pWindow = _pDocTab;
_pMainSplitter->create(pWindow, ScintillaEditView::getUserDefineDlg(), 8, RIGHT_FIX, 45);
}
_pMainWindow = _pMainSplitter;
_pMainSplitter->setWin0((bothActive())?(Window *)&_subSplitter:(Window *)_pDocTab);
::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0);
_pMainWindow->display();
_mainWindowStatus |= WindowUserActive;
}
else if ((!isUDDlgDocked)&&(isUDDlgVisible))
{
udd->display(false);
}
else //((!isUDDlgDocked)&&(!isUDDlgVisible))
udd->display();
}
checkMenuItem(IDM_LANG_USER_DLG, !isUDDlgVisible);
_toolBar.setCheck(IDM_LANG_USER_DLG, !isUDDlgVisible);
break;
}
case IDM_EDIT_SELECTALL:
_pEditView->execute(SCI_SELECTALL);
checkClipboard();
break;
case IDM_EDIT_INS_TAB:
_pEditView->execute(SCI_TAB);
break;