-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathQuincyFrame.cpp
5048 lines (4729 loc) · 204 KB
/
QuincyFrame.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
/* Quincy IDE for the Pawn scripting language
*
* Copyright CompuPhase, 2009-2024
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Version: $Id: QuincyFrame.cpp 7205 2024-08-02 18:38:54Z thiadmer $
*/
#define _CRT_SECURE_NO_DEPRECATE
#include "wxQuincy.h"
#include <wx/busyinfo.h>
#include <wx/clipbrd.h>
#include <wx/filename.h>
#include <wx/mimetype.h>
#include <wx/numdlg.h>
#include <wx/print.h>
#include <wx/printdlg.h>
#include <wx/textfile.h>
#include <wx/tokenzr.h>
#include <wx/html/htmprint.h>
#include "QuincyFrame.h"
#include "QuincyReplaceDlg.h"
#include "QuincyReplacePrompt.h"
#include "QuincySearchDlg.h"
#include "QuincySampleBrowser.h"
#include "QuincySettingsDlg.h"
#include "QuincyDirPicker.h"
#include <amx.h>
#include <amxdbg.h>
#include "svnrev.h"
#if defined __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#endif
#if !defined wxSTC_MARK_BOOKMARK
#if defined SC_MARK_BOOKMARK
#define wxSTC_MARK_BOOKMARK SC_MARK_BOOKMARK
#else
#define wxSTC_MARK_BOOKMARK wxSTC_MARK_ARROW
#endif
#endif
#if wxCHECK_VERSION(2, 9, 0)
#define GetActiveEdit(ctrl) dynamic_cast<wxStyledTextCtrl*>(((ctrl)->GetSelection() >= 0 && (ctrl)->GetSelection() < (int)(ctrl)->GetPageCount()) ? (ctrl)->GetCurrentPage() : 0)
#else
#define GetActiveEdit(ctrl) dynamic_cast<wxStyledTextCtrl*>(((ctrl)->GetSelection() >= 0 && (ctrl)->GetSelection() < (int)(ctrl)->GetPageCount()) ? (ctrl)->GetPage((ctrl)->GetSelection()) : 0)
#endif
#include "res/Quincy16.xpm"
#include "res/Quincy32.xpm"
#include "res/Quincy48.xpm"
#include "res/filemodified.xpm"
#include "res/tb_new.xpm"
#include "res/tb_open.xpm"
#include "res/tb_save.xpm"
#include "res/tb_saveas.xpm"
#include "res/tb_saveall.xpm"
#include "res/tb_close.xpm"
#include "res/tb_print.xpm"
#include "res/tb_quit.xpm"
#include "res/tb_undo.xpm"
#include "res/tb_redo.xpm"
#include "res/tb_cut.xpm"
#include "res/tb_copy.xpm"
#include "res/tb_paste.xpm"
#include "res/tb_columnfill.xpm"
#include "res/tb_find.xpm"
#include "res/tb_findnext.xpm"
#include "res/tb_replace.xpm"
#include "res/tb_bracematch.xpm"
#include "res/tb_compile.xpm"
#include "res/tb_transfer.xpm"
#include "res/tb_device.xpm"
#include "res/tb_debug.xpm"
#include "res/tb_run.xpm"
#include "res/tb_stop.xpm"
#include "res/tb_stepover.xpm"
#include "res/tb_stepinto.xpm"
#include "res/tb_stepout.xpm"
#include "res/tb_runtocursor.xpm"
#include "res/tb_breakpoint.xpm"
#include "res/tb_settings.xpm"
#include "res/tb_help.xpm"
#include "res/tb_contexthelp.xpm"
#include "res/tb_pawn.xpm"
#if !defined wxStyledTextEventHandler
#define wxStyledTextEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxStyledTextEventFunction, &func)
#endif
#if !defined sizearray
#define sizearray(a) (sizeof(a) / sizeof((a)[0]))
#endif
#if defined _WIN32
#define MIN_PANE_SIZE 24
#else
#define MIN_PANE_SIZE 32
#endif
static const wxChar debug_prefix[] = wxT("}%`");
static const wxChar PawnKeyWords[] = wxT("assert break case const continue default defined ")
wxT("do else exit for forward goto if native new ")
wxT("operator public return sizeof sleep state static ")
wxT("stock switch tagof var while true false");
QuincyFrame::QuincyFrame(const wxString& title, const wxSize& size)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, size)
{
int idx;
for (idx = 0; idx < MAX_EDITORS; idx++) {
Editor[idx] = NULL;
Filename[idx] = wxEmptyString;
EditorDirty[idx] = false;
FileTimeStamp[idx] = 0;
}
/* default "current" directory is the one with the examples */
strCurrentDirectory = theApp->GetExamplesPath();
SetSizeHints(wxDefaultSize, wxDefaultSize);
SetIcon(wxIcon(Quincy32_xpm));
Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(QuincyFrame::OnCloseWindow));
Connect(wxEVT_ACTIVATE, wxActivateEventHandler(QuincyFrame::OnActivate));
/* create the bitmaps that are shared for the menu and the toolbar */
wxBitmap tb_new(tb_new_xpm);
wxBitmap tb_open(tb_open_xpm);
wxBitmap tb_save(tb_save_xpm);
wxBitmap tb_saveas(tb_saveas_xpm);
wxBitmap tb_saveall(tb_saveall_xpm);
wxBitmap tb_close(tb_close_xpm);
wxBitmap tb_print(tb_print_xpm);
wxBitmap tb_quit(tb_quit_xpm);
wxBitmap tb_undo(tb_undo_xpm);
wxBitmap tb_redo(tb_redo_xpm);
wxBitmap tb_cut(tb_cut_xpm);
wxBitmap tb_copy(tb_copy_xpm);
wxBitmap tb_paste(tb_paste_xpm);
wxBitmap tb_columnfill(tb_columnfill_xpm);
wxBitmap tb_find(tb_find_xpm);
wxBitmap tb_findnext(tb_findnext_xpm);
wxBitmap tb_replace(tb_replace_xpm);
wxBitmap tb_bracematch(tb_bracematch_xpm);
wxBitmap tb_compile(tb_compile_xpm);
wxBitmap tb_transfer(tb_transfer_xpm);
wxBitmap tb_devicetool(tb_device_xpm);
wxBitmap tb_debug(tb_debug_xpm);
wxBitmap tb_run(tb_run_xpm);
wxBitmap tb_abort(tb_stop_xpm);
wxBitmap tb_stepinto(tb_stepinto_xpm);
wxBitmap tb_stepover(tb_stepover_xpm);
wxBitmap tb_stepout(tb_stepout_xpm);
wxBitmap tb_runtocursor(tb_runtocursor_xpm);
wxBitmap tb_breakpoint(tb_breakpoint_xpm);
wxBitmap tb_settings(tb_settings_xpm);
wxBitmap tb_help(tb_help_xpm);
wxBitmap tb_contexthelp(tb_contexthelp_xpm);
#define AppendIconItem(menu,_id,label,bitmap) \
do { \
wxMenuItem *item = new wxMenuItem((menu), (_id), (label)); \
item->SetBitmap(bitmap); \
(menu)->Append(item); \
} while (0)
/* create the menu */
#define MENU_ENTRY(label) theApp->Shortcuts.FormatShortCut(label, true)
menuBar = new wxMenuBar;
menuFile = new wxMenu;
AppendIconItem(menuFile, wxID_NEW, MENU_ENTRY("New"), tb_new);
AppendIconItem(menuFile, wxID_OPEN, MENU_ENTRY("Open"), tb_open);
AppendIconItem(menuFile, wxID_SAVE, MENU_ENTRY("Save"), tb_save);
AppendIconItem(menuFile, wxID_SAVEAS, MENU_ENTRY("SaveAs"), tb_saveas);
AppendIconItem(menuFile, IDM_SAVEALL, MENU_ENTRY("SaveAll"), tb_saveall);
AppendIconItem(menuFile, wxID_CLOSE, MENU_ENTRY("Close"), tb_close);
menuFile->AppendSeparator();
menuFile->Append(IDM_LOADWORKSPACE, MENU_ENTRY("OpenWorkspace"));
menuFile->Append(IDM_SAVEWORKSPACE, MENU_ENTRY("SaveWorkspace"));
menuFile->Append(IDM_CLOSEWORKSPACE, MENU_ENTRY("CloseWorkspace"));
menuFile->AppendSeparator();
AppendIconItem(menuFile, wxID_PRINT, MENU_ENTRY("Print"), tb_print);
menuFile->AppendSeparator();
menuRecentFiles = new wxMenu; /* the "recent files/workspaces" menus are filled later */
menuRecentWorkspaces = new wxMenu;
menuFile->Append(-1, "Recent files", menuRecentFiles);
menuFile->Append(-1, "Recent workspaces", menuRecentWorkspaces);
menuFile->AppendSeparator();
AppendIconItem(menuFile, wxID_EXIT, MENU_ENTRY("Quit"), tb_quit);
menuBar->Append(menuFile, "&File");
menuEdit = new wxMenu;
AppendIconItem(menuEdit, wxID_UNDO, MENU_ENTRY("Undo"), tb_undo);
AppendIconItem(menuEdit, wxID_REDO, MENU_ENTRY("Redo"), tb_redo);
AppendIconItem(menuEdit, wxID_CUT, MENU_ENTRY("Cut"), tb_cut);
AppendIconItem(menuEdit, wxID_COPY, MENU_ENTRY("Copy"), tb_copy);
AppendIconItem(menuEdit, wxID_PASTE, MENU_ENTRY("Paste"), tb_paste);
menuEdit->AppendSeparator();
AppendIconItem(menuEdit, wxID_FIND, MENU_ENTRY("Find"), tb_find);
AppendIconItem(menuEdit, IDM_FINDNEXT, MENU_ENTRY("FindNext"), tb_findnext);
AppendIconItem(menuEdit, wxID_REPLACE, MENU_ENTRY("Replace"), tb_replace);
menuEdit->AppendSeparator();
menuEdit->Append(wxID_INDEX, MENU_ENTRY("GotoLine"));
menuEdit->Append(IDM_GOTOSYMBOL, MENU_ENTRY("GotoSymbol"));
AppendIconItem(menuEdit, IDM_MATCHBRACE, MENU_ENTRY("MatchBrace"), tb_bracematch);
menuBookmarks = new wxMenu;
menuBookmarks->Append(IDM_BOOKMARKTOGGLE, MENU_ENTRY("ToggleBookmark"));
menuBookmarks->Append(IDM_BOOKMARKNEXT, MENU_ENTRY("NextBookmark"));
menuBookmarks->Append(IDM_BOOKMARKPREV, MENU_ENTRY("PrevBookmark"));
//??? list bookmarks (in all files)
menuEdit->Append(-1, "Bookmarks", menuBookmarks);
menuEdit->AppendSeparator();
menuEdit->Append(IDM_AUTOCOMPLETE, MENU_ENTRY("Autocomplete"));
AppendIconItem(menuEdit, IDM_FILLCOLUMN, MENU_ENTRY("FillColumn"), tb_columnfill);
menuBar->Append(menuEdit, "&Edit");
menuView = new wxMenu;
menuView->AppendCheckItem(IDM_VIEWWHITESPACE, MENU_ENTRY("ViewWhitespace"));
menuView->AppendCheckItem(IDM_VIEWINDENTGUIDES, MENU_ENTRY("ViewIndentGuides"));
menuBar->Append(menuView, "&View");
menuBuild = new wxMenu;
AppendIconItem(menuBuild, IDM_COMPILE, MENU_ENTRY("Compile"), tb_compile);
AppendIconItem(menuBuild, IDM_TRANSFER, MENU_ENTRY("Transfer"), tb_transfer);
menuBuild->AppendSeparator();
AppendIconItem(menuBuild, IDM_DEBUG, MENU_ENTRY("Debug"), tb_debug);
AppendIconItem(menuBuild, IDM_RUN, MENU_ENTRY("Run"), tb_run);
AppendIconItem(menuBuild, IDM_ABORT, MENU_ENTRY("Stop"), tb_abort);
menuBuild->AppendSeparator();
AppendIconItem(menuBuild, IDM_STEPINTO, MENU_ENTRY("StepInto"), tb_stepinto);
AppendIconItem(menuBuild, IDM_STEPOVER, MENU_ENTRY("StepOver"), tb_stepover);
AppendIconItem(menuBuild, IDM_STEPOUT, MENU_ENTRY("StepOut"), tb_stepout);
AppendIconItem(menuBuild, IDM_RUNTOCURSOR, MENU_ENTRY("RunToCursor"), tb_runtocursor);
menuBuild->AppendSeparator();
menuBreakpoints = new wxMenu;
AppendIconItem(menuBreakpoints, IDM_BREAKPOINTTOGGLE, MENU_ENTRY("ToggleBreakpoint"), tb_breakpoint);
menuBreakpoints->Append(IDM_BREAKPOINTCLEAR, MENU_ENTRY("ClearBreakpoints"));
//??? list all breakpoints
menuBuild->Append(-1, "Breakpoints", menuBreakpoints);
menuBar->Append(menuBuild, "&Build/Run");
menuTools = new wxMenu;
AppendIconItem(menuTools, wxID_PROPERTIES, MENU_ENTRY("Options"), tb_settings);
AppendIconItem(menuTools, IDM_SAMPLEBROWSER, MENU_ENTRY("SampleBrowser"), tb_pawn);
menuTabSpace = new wxMenu;
menuTabSpace->Append(IDM_TABSTOSPACES, MENU_ENTRY("TabToSpace"));
menuTabSpace->Append(IDM_INDENTSTOTABS, MENU_ENTRY("IndentToTab"));
menuTabSpace->Append(IDM_SPACESTOTABS, MENU_ENTRY("SpaceToTab"));
menuTabSpace->AppendSeparator();
menuTabSpace->Append(IDM_TRIMTRAILING, MENU_ENTRY("TrimTrailing"));
menuTools->Append(-1, "Whitespace conversions", menuTabSpace);
menuBar->Append(menuTools, "&Tools");
menuHelp = new wxMenu;
AppendIconItem(menuHelp, wxID_HELP, MENU_ENTRY("GeneralHelp"), tb_help);
AppendIconItem(menuHelp, IDM_CONTEXTHELP, MENU_ENTRY("ContextHelp"), tb_contexthelp);
menuHelp->AppendSeparator();
menuHelp->Append(wxID_ABOUT/*, "&About"*/);
menuBar->Append(menuHelp, "&Help");
SetMenuBar(menuBar);
RebuildRecentMenus();
/* selection events */
Connect(wxID_NEW, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnNewFile));
Connect(wxID_OPEN, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnOpen));
Connect(wxID_SAVE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnSave));
Connect(wxID_SAVEAS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnSaveAs));
Connect(IDM_SAVEALL, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnSaveAll));
Connect(wxID_CLOSE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnClose));
Connect(IDM_LOADWORKSPACE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnLoadWorkSpace));
Connect(IDM_SAVEWORKSPACE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnSaveWorkSpace));
Connect(IDM_CLOSEWORKSPACE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnCloseWorkSpace));
Connect(wxID_PRINT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnPrint));
Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnQuit));
Connect(wxID_UNDO, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnUndo));
Connect(wxID_REDO, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnRedo));
Connect(wxID_CUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnCut));
Connect(wxID_COPY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnCopy));
Connect(wxID_PASTE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnPaste));
Connect(wxID_FIND, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnFindDlg));
Connect(IDM_FINDNEXT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnFindNext));
Connect(wxID_REPLACE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnReplaceDlg));
Connect(wxID_INDEX, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnGotoDlg));
Connect(IDM_GOTOSYMBOL, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnGotoSymbol));
Connect(IDM_BOOKMARKTOGGLE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnBookmarkToggle));
Connect(IDM_BOOKMARKNEXT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnBookmarkNext));
Connect(IDM_BOOKMARKPREV, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnBookmarkPrevious));
Connect(IDM_MATCHBRACE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnMatchBrace));
Connect(IDM_FILLCOLUMN, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnFillColumn));
Connect(IDM_VIEWWHITESPACE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnViewWhiteSpace));
Connect(IDM_VIEWINDENTGUIDES, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnViewIndentGuides));
Connect(IDM_COMPILE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnCompile));
Connect(IDM_TRANSFER, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnTransfer));
Connect(IDM_DEBUG, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnDebug));
Connect(IDM_RUN, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnRun));
Connect(IDM_ABORT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnAbort));
Connect(IDM_STEPINTO, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnStepInto));
Connect(IDM_STEPOVER, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnStepOver));
Connect(IDM_STEPOUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnStepOut));
Connect(IDM_RUNTOCURSOR, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnRunToCursor));
Connect(IDM_BREAKPOINTTOGGLE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnBreakpointToggle));
Connect(IDM_BREAKPOINTCLEAR, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnBreakpointClear));
Connect(wxID_PROPERTIES, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnSettings));
Connect(IDM_SAMPLEBROWSER, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnSampleBrowser));
Connect(IDM_TABSTOSPACES, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnTabsToSpaces));
Connect(IDM_SPACESTOTABS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnSpacesToTabs));
Connect(IDM_INDENTSTOTABS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnIndentsToTabs));
Connect(IDM_TRIMTRAILING, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnTrimTrailing));
Connect(wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnAbout));
Connect(wxID_HELP, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnHelp));
Connect(IDM_CONTEXTHELP, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnContextHelp));
Connect(IDM_AUTOCOMPLETE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QuincyFrame::OnAutoComplete));
/* UI update events */
Connect(IDM_CLOSEWORKSPACE, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuincyFrame::OnUIWorkSpace));
Connect(wxID_UNDO, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuincyFrame::OnUIUndo));
Connect(wxID_REDO, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuincyFrame::OnUIUndo));
Connect(wxID_CUT, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuincyFrame::OnUICutCopy));
Connect(wxID_COPY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuincyFrame::OnUICutCopy));
Connect(wxID_PASTE, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuincyFrame::OnUIPaste));
Connect(IDM_FINDNEXT, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuincyFrame::OnUIFind));
Connect(IDM_RUN, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuincyFrame::OnUIRun));
Connect(IDM_STEPINTO, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(QuincyFrame::OnUIStepInto));
/* find dialog events */
Connect(wxID_ANY, wxEVT_COMMAND_FIND, wxFindDialogEventHandler(QuincyFrame::OnFindAction));
Connect(wxID_ANY, wxEVT_COMMAND_FIND_NEXT, wxFindDialogEventHandler(QuincyFrame::OnFindAction));
Connect(wxID_ANY, wxEVT_COMMAND_FIND_REPLACE, wxFindDialogEventHandler(QuincyFrame::OnReplace));
Connect(wxID_ANY, wxEVT_COMMAND_FIND_REPLACE_ALL, wxFindDialogEventHandler(QuincyFrame::OnReplaceAll));
Connect(wxID_ANY, wxEVT_COMMAND_FIND_CLOSE, wxFindDialogEventHandler(QuincyFrame::OnFindClose));
/* frame events */
Connect(wxEVT_IDLE, wxIdleEventHandler(QuincyFrame::OnIdle));
Connect(wxEVT_END_PROCESS, wxProcessEventHandler(QuincyFrame::OnTerminateApp));
/* add a status bar */
CreateStatusBar(2);
int widths[2] = { -1, 180 };
SetStatusWidths(2, widths);
/* main view (toolbar is part of the main view) */
wxBoxSizer* bSizerFrame = new wxBoxSizer(wxVERTICAL);
#define TB_SHORTCUT(label) theApp->Shortcuts.FormatShortCut(label, false, true)
ToolBar = new wxAuiToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_TB_HORZ_LAYOUT);
ToolBar->SetToolBitmapSize(wxSize(16, 16));
ToolBar->AddTool(wxID_NEW, "New", tb_new, "New file" + TB_SHORTCUT("New"));
ToolBar->AddTool(wxID_OPEN, "Open", tb_open, "Open file" + TB_SHORTCUT("Open"));
ToolBar->AddTool(wxID_SAVE, "Save", tb_save, "Save active file" + TB_SHORTCUT("Save"));
ToolBar->AddTool(IDM_SAVEALL, "Save all", tb_saveall, "Save all modified files" + TB_SHORTCUT("SaveAll"));
ToolBar->AddSeparator();
ToolBar->AddTool(wxID_PRINT, "Print", tb_print, "Print file" + TB_SHORTCUT("Print"));
ToolBar->AddSeparator();
ToolBar->AddTool(wxID_CUT, "Cut", tb_cut, "Cut to clipboard" + TB_SHORTCUT("Cut"));
ToolBar->AddTool(wxID_COPY, "Copy", tb_copy, "Copy to clipboard" + TB_SHORTCUT("Copy"));
ToolBar->AddTool(wxID_PASTE, "Paste", tb_paste, "Paste from clipboard" + TB_SHORTCUT("Paste"));
ToolBar->AddSeparator();
ToolBar->AddTool(wxID_UNDO, "Undo", tb_undo, "Undo last operation" + TB_SHORTCUT("Undo"));
ToolBar->AddTool(wxID_REDO, "Redo", tb_redo, "Redo last undo" + TB_SHORTCUT("Redo"));
ToolBar->AddSeparator();
ToolBar->AddTool(IDM_COMPILE, "Build", tb_compile, "Compile the current script" + TB_SHORTCUT("Compile"));
ToolBar->AddTool(IDM_TRANSFER, "Transfer", tb_transfer, "Transfer the compiled script to an external host" + TB_SHORTCUT("Transfer"));
ToolBar->AddTool(IDM_DEBUG, "Debug", tb_debug, "Debug the script" + TB_SHORTCUT("Debug"));
ToolBar->AddTool(IDM_RUN, "Run", tb_run, "Run the script" + TB_SHORTCUT("Run"));
ToolBar->AddTool(IDM_ABORT, "Stop", tb_abort, "Abort the running script" + TB_SHORTCUT("Stop"));
ToolBar->AddTool(IDM_STEPINTO, "Step Into", tb_stepinto, "Step into functions" + TB_SHORTCUT("StepInto"));
ToolBar->AddTool(IDM_STEPOVER, "Step Over", tb_stepover, "Step over functions" + TB_SHORTCUT("StepOver"));
ToolBar->AddTool(IDM_STEPOUT, "Step Out", tb_stepout, "Run up to the function return" + TB_SHORTCUT("StepOut"));
ToolBar->AddTool(IDM_RUNTOCURSOR, "Run to cursor", tb_runtocursor, "Run up to the current line" + TB_SHORTCUT("RunToCursor"));
ToolBar->AddSeparator();
ToolBar->AddTool(IDM_DEVICETOOL, "Device", tb_devicetool, "Configure the device" + TB_SHORTCUT("DeviceTool"));
ToolBar->AddSeparator();
FunctionList = new wxChoice(ToolBar, IDM_SELECTCONTEXT, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_SORT);
FunctionList->SetMinSize(wxSize(200, -1));
FunctionList->SetToolTip("The function name at the current cursor position.");
ToolBar->AddControl(FunctionList, "Context");
ToolBar->Realize();
ToolBar->Refresh(false);
bSizerFrame->Add(ToolBar, 0, wxEXPAND, 5);
Connect(wxID_NEW, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnNewFile));
Connect(wxID_OPEN, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnOpen));
Connect(wxID_SAVE, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnSave));
Connect(IDM_SAVEALL, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnSaveAll));
Connect(wxID_PRINT, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnPrint));
Connect(wxID_CUT, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnCut));
Connect(wxID_COPY, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnCopy));
Connect(wxID_PASTE, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnPaste));
Connect(wxID_UNDO, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnUndo));
Connect(wxID_REDO, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnRedo));
Connect(IDM_COMPILE, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnCompile));
Connect(IDM_TRANSFER, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnTransfer));
Connect(IDM_DEBUG, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnDebug));
Connect(IDM_RUN, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnRun));
Connect(IDM_ABORT, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnAbort));
Connect(IDM_STEPINTO, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnStepInto));
Connect(IDM_STEPOVER, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnStepOver));
Connect(IDM_STEPOUT, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnStepOut));
Connect(IDM_RUNTOCURSOR, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnRunToCursor));
Connect(IDM_DEVICETOOL, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(QuincyFrame::OnDeviceTool));
Connect(IDM_SELECTCONTEXT, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(QuincyFrame::OnSelectContext));
/* splitter window */
SplitterFrame = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3D);
SplitterFrame->SetMinimumPaneSize(MIN_PANE_SIZE);
/* add a notebook control with tabs for the editors */
pnlEdit = new wxPanel(SplitterFrame, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
wxBoxSizer* bSizerEdit = new wxBoxSizer(wxVERTICAL);
EditTab = new wxAuiNotebook(pnlEdit, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_CLOSE_ON_ACTIVE_TAB|wxAUI_NB_SCROLL_BUTTONS|wxAUI_NB_TAB_MOVE|wxAUI_NB_TOP);
bSizerEdit->Add(EditTab, 1, wxEXPAND | wxTOP, 5);
pnlEdit->SetSizer(bSizerEdit);
pnlEdit->Layout();
bSizerEdit->Fit(pnlEdit);
EditTab->Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler(QuincyFrame::OnTabChange), NULL, this );
EditTab->Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEventHandler(QuincyFrame::OnTabClose), NULL, this );
/* add a notebook with tabs for compiler information and log windows
note: the pages must be added in the order of the TAB_xxx constants */
pnlPane = new wxPanel(SplitterFrame, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
wxBoxSizer* bSizerPane = new wxBoxSizer(wxVERTICAL);
PaneTab = new wxAuiNotebook(pnlPane, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_BOTTOM);
#if defined _WIN32
wxFont font(9, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, "Courier New");
#else
wxFont font(9, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, "Monospace");
#endif
BuildLog = new wxListView(PaneTab, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_NO_HEADER | wxLC_REPORT | wxLC_SINGLE_SEL);
BuildLog->SetFont(font);
BuildLog->InsertColumn(0, wxEmptyString);
PaneTab->AddPage(BuildLog, "Build", false); /* TAB_BUILD */
ErrorLog = new wxListView(PaneTab, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_NO_HEADER | wxLC_REPORT | wxLC_SINGLE_SEL);
ErrorLog->SetFont(font);
ErrorLog->InsertColumn(0, wxEmptyString);
ErrorLog->Connect(wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler(QuincyFrame::OnErrorSelect), NULL, this);
PaneTab->AddPage(ErrorLog, "Messages", false); /* TAB_MESSAGES */
BrowserTree = new wxTreeCtrl(PaneTab, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS|wxTR_FULL_ROW_HIGHLIGHT|wxTR_HIDE_ROOT|wxTR_NO_LINES|wxTR_SINGLE|wxTR_DEFAULT_STYLE);
BrowserTree->SetFont(font);
BrowserTree->Connect(wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler(QuincyFrame::OnSymbolSelect), NULL, this);
PaneTab->AddPage(BrowserTree, "Symbols", false); /* TAB_SYMBOLS */
WatchLog = new wxListView(PaneTab, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_EDIT_LABELS);
WatchLog->SetFont(font);
WatchLog->InsertColumn(0, "Symbol");
WatchLog->InsertColumn(1, "Value");
WatchLog->Connect(wxEVT_COMMAND_LIST_END_LABEL_EDIT, wxListEventHandler(QuincyFrame::OnWatchEdited), NULL, this);
WatchLog->Connect(wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxListEventHandler(QuincyFrame::OnWatchActivated), NULL, this);
WatchLog->Connect(wxEVT_COMMAND_LIST_DELETE_ITEM, wxListEventHandler(QuincyFrame::OnWatchDelete), NULL, this);
PaneTab->AddPage(WatchLog, "Watches", false); /* TAB_WATCHES */
Terminal = new wxTextCtrl(PaneTab, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxHSCROLL | wxTE_LEFT | wxTE_MULTILINE | wxTE_READONLY);
Terminal->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
Terminal->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
Terminal->SetFont(font);
Terminal->Connect(wxEVT_CHAR, wxKeyEventHandler(QuincyFrame::OnTerminalChar), NULL, this);
PaneTab->AddPage(Terminal, "Output", false); /* TAB_OUTPUT */
PaneTab->Layout();
bSizerPane->Add(PaneTab, 1, wxEXPAND | wxBOTTOM, 5);
pnlPane->SetSizer(bSizerPane);
pnlPane->Layout();
bSizerPane->Fit(pnlPane);
SearchLog = 0; /* this panel is optionally set */
SplitterFrame->SplitHorizontally(pnlEdit, pnlPane, 0);
bSizerFrame->Add(SplitterFrame, 1, wxEXPAND);
this->SetSizer(bSizerFrame);
this->Layout();
/* set initial splitter position, centre the application window */
minIni* ini = theApp->GetConfigFile();
long pos = ini->getl("Position", "Splitter", 0);
SplitterFrame->SetSashPosition(pos);
SplitterFrame->SetSashGravity(1.0);
Centre();
/* Find settings */
FindDlg = NULL;
unsigned flags = wxFR_DOWN | (theApp->SearchFlags & (wxFR_MATCHCASE | wxFR_WHOLEWORD));
FindData.SetFlags(flags);
PrepareSearchLog();
/* drag & drop target */
SetDropTarget(new DragAndDropFile(this));
/* a timer for delayed events */
Timer = new wxTimer(this, IDM_TIMER);
wxASSERT(Timer);
Connect(IDM_TIMER, wxEVT_TIMER, wxTimerEventHandler(QuincyFrame::OnTimer));
/* see whether there are initial files to load */
RectSelectChkSum = 0;
HelpIndex = 0;
strWorkspace = ini->gets("Session", "Workspace");
LoadSession();
if (EditTab->GetPageCount() == 0)
AddEditor(); /* no files in the session, create an empty file */
context.SetControl(FunctionList);
UIDisabledTools = 0;
VisibleWhiteSpace = false;
IgnoreChangeEvent = false;
PendingFlags = 0;
ExecPID = 0;
ExecProcess = 0;
DebugMode = false;
WatchLog->Enable(DebugMode);
WatchUpdateList.Clear();
}
void QuincyFrame::OnCloseWindow(wxCloseEvent& /* event */)
{
if (!SaveAllFiles(true))
return;
Disconnect(wxEVT_ACTIVATE, wxActivateEventHandler(QuincyFrame::OnActivate));
if (ExecPID != 0 && wxProcess::Exists(ExecPID)) {
wxProcess::Kill(ExecPID, wxSIGTERM);
wxProcess::Kill(ExecPID, wxSIGKILL);
}
SaveSession(); /* save all options */
IgnoreChangeEvent = true;
/* optionally copy search options from the "FindData" structure to the main
options */
if (!theApp->SearchAdvanced)
theApp->SearchFlags = FindData.GetFlags();
/* save application window size and other options */
wxSize size = GetSize();
long splitterpos = SplitterFrame->GetSashPosition();
theApp->SaveSettings(size, splitterpos);
this->Destroy();
}
void QuincyFrame::OnActivate(wxActivateEvent& event)
{
static bool recurse = false;
if (!recurse && event.GetActive()) {
for (unsigned page = 0; page < EditTab->GetPageCount(); page++) {
wxStyledTextCtrl *edit = dynamic_cast<wxStyledTextCtrl*>(EditTab->GetPage(page));
wxASSERT(edit);
int index;
for (index = 0; index < MAX_EDITORS && Editor[index] != edit; index++)
/* nothing */;
wxASSERT(index < MAX_EDITORS);
if (index < MAX_EDITORS) {
wxString path = Filename[index];
bool exists = wxFileExists(path);
time_t t = exists ? wxFileModificationTime(path) : 0;
if (exists && t != FileTimeStamp[index]) {
recurse = true;
wxString msg = "The file " + path.AfterLast(DIRSEP_CHAR)
+ " was changed outside the editor.\nReload?";
if (EditorDirty[index])
msg += "\n\nNota Bene: the file has local changes. These are lost on a reload.";
int reply = wxMessageBox(msg, "Notice", wxYES_NO);
if (reply == wxYES) {
LoadFile(path, edit);
SetChanged(index, false);
}
FileTimeStamp[index] = t; /* so it isn't asked again */
recurse = false;
}
}
}
}
}
void QuincyFrame::AdjustTitle()
{
wxString title = "Pawn";
/* add current target */
if (strTargetHost.Length() > 0) {
title += " [" + strTargetHost + "]";
}
/* add current file */
wxASSERT(EditTab);
int sel = EditTab->GetSelection();
if (sel >= 0)
title += " - " + EditTab->GetPageText(sel);
if (strWorkspace.Length() > 0) {
wxString project = strWorkspace;
if (project.Find(DIRSEP_CHAR) >= 0)
project = project.AfterLast(DIRSEP_CHAR);
title += " (" + project + ")";
}
SetTitle(title);
}
void QuincyFrame::OnQuit(wxCommandEvent& /* event */)
{
if (!SaveAllFiles(true))
return;
Disconnect(wxEVT_ACTIVATE, wxActivateEventHandler(QuincyFrame::OnActivate));
SaveSession();
IgnoreChangeEvent = true;
while (EditTab->GetPageCount() > 0)
RemoveEditor(0, true);
Close(true);
}
void QuincyFrame::OnTabChange(wxAuiNotebookEvent& /* event */)
{
/* user has clicked on a TAB to select a different file */
AdjustTitle();
wxStyledTextCtrl *edit = GetActiveEdit(EditTab);
context.ScanContext(edit, CTX_RESET);
}
void QuincyFrame::OnTabClose(wxAuiNotebookEvent& event)
{
CloseCurrentFile(false);
event.Skip();
}
bool DragAndDropFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString& filenames)
{
size_t nFiles = filenames.GetCount();
for (size_t n = 0; n < nFiles; n++) {
if (wxFile::Exists(filenames[n])) {
/* check whether this is a project file, if so, change to the project */
wxASSERT(m_pOwner->EditTab);
if (filenames[n].Right(4).CmpNoCase(".prj")==0) {
/* close all current files (query for save), also save the session */
if (!m_pOwner->SaveAllFiles(true))
return true;
m_pOwner->SaveSession();
while (m_pOwner->EditTab->GetPageCount() > 0)
m_pOwner->RemoveEditor(0);
/* load the new workspace */
m_pOwner->strWorkspace = filenames[n];
m_pOwner->LoadSession();
/* no files in the session, create an empty file */
if (m_pOwner->EditTab->GetPageCount() == 0)
m_pOwner->AddEditor();
} else {
/* if there is only one editor, with a default filename, close that one */
if (m_pOwner->EditTab->GetPageCount() == 1 && m_pOwner->Filename[0].Length() == 0)
m_pOwner->RemoveEditor(0);
if (m_pOwner->AddEditor(filenames[n]))
m_pOwner->AdjustTitle();
}
}
}
return true;
}
void QuincyFrame::OnErrorSelect(wxListEvent& event)
{
wxString line = ErrorLog->GetItemText(event.GetIndex());
line.Trim(false);
/* line is filename(line1[-line2]): warning|error|fatal error errno: text */
wxString filename = line.BeforeFirst('(');
line = line.AfterFirst('(');
wxString linenrs = line.BeforeFirst(')');
long first, last;
linenrs.ToLong(&first);
linenrs = linenrs.AfterLast('-');
if (linenrs.length() == 0)
last = first;
else
linenrs.ToLong(&last);
/* find the file, or load it */
wxStyledTextCtrl* edit = 0;
filename.Trim();
for (int idx = 0; idx < MAX_EDITORS && !edit; idx++)
if (Filename[idx].Cmp(filename) == 0)
edit = Editor[idx];
if (!edit) {
/* compare the base names only if no full path on the match is found */
for (int idx = 0; idx < MAX_EDITORS && !edit; idx++) {
wxString basename = Filename[idx].AfterLast(DIRSEP_CHAR);
if (basename.Cmp(filename) == 0)
edit = Editor[idx];
}
}
if (!edit) {
/* try to open the file (and find it) */
AddEditor(filename);
for (int idx = 0; idx < MAX_EDITORS && !edit; idx++)
if (Filename[idx].Cmp(filename) == 0)
edit = Editor[idx];
}
if (!edit) {
wxMessageBox("Could not open " + filename, "Pawn IDE", wxOK | wxICON_ERROR);
return;
}
/* find the TAB page to activate */
for (unsigned page = 0; page < EditTab->GetPageCount(); page++) {
if (EditTab->GetPage(page) == edit) {
EditTab->SetSelection(page);
break;
}
}
/* scroll to the position */
long firstpos = edit->PositionFromLine(first - 1);
long lastpos = edit->PositionFromLine(last);
edit->GotoPos(firstpos);
edit->SetSelection(firstpos, lastpos);
PendingFlags |= PEND_SWITCHEDIT;
if (!Timer->IsRunning()) /* delayed switch focus (because calling edit->SetFocus() here does not work) */
Timer->Start(100, true);
}
void QuincyFrame::OnSymbolSelect(wxTreeEvent& event)
{
/* see which item it is */
BrowserItemData* data = dynamic_cast<BrowserItemData*>(BrowserTree->GetItemData(event.GetItem()));
if (!data)
return;
const CSymbolEntry* symbol = data->Symbol();
if (!symbol)
return;
/* set a temporary bookmark on the current position */
wxStyledTextCtrl* edit = GetActiveEdit(EditTab);
if (edit) {
int line = edit->GetCurrentLine();
if ((edit->MarkerGet(line) & ((1 << MARKER_BOOKMARK) | (1 << MARKER_NAVIGATE))) == 0) {
IgnoreChangeEvent = true;
edit->MarkerAdd(line, MARKER_NAVIGATE);
IgnoreChangeEvent = false;
}
}
GotoSymbol(symbol);
}
bool QuincyFrame::AddEditor(const wxString &name)
{
/* Scintilla only supports UTF-8 when compiled for Unicode, and this
is the default for the most wxWidgets distributions */
if (name.length() > 0 && wxFileExists(name) && !ScanUTF8(name)) {
int reply = wxMessageBox("The file " + name.AfterLast(DIRSEP_CHAR)
+ " uses characters outside the ASCII range and needs to be converted to UTF-8.\n"
"Do you wish to do that now?", "Notice", wxYES_NO);
if (reply != wxYES)
return false;
if (!Latin1ToUTF8(name)) {
wxMessageBox("Conversion of " + name.AfterLast(DIRSEP_CHAR) + " to UTF-8 has failed.",
"Pawn IDE", wxOK | wxICON_ERROR);
return false;
}
}
/* find an empty spot */
int idx;
for (idx = 0; idx < MAX_EDITORS && Editor[idx] != NULL; idx++)
/* nothing */;
if (idx >= MAX_EDITORS)
return false;
/* the editor */
wxStyledTextCtrl *edit = new wxStyledTextCtrl(EditTab, IDC_EDIT + idx, wxPoint(-1, -1), wxSize(-1, -1), wxTE_MULTILINE);
Editor[idx] = edit;
SetEditorsStyle(edit);
edit->SetIndentationGuides(false);
edit->SetCaretLineVisible(true);
edit->SetMarginType(1, wxSTC_MARGIN_SYMBOL);
edit->SetMarginWidth(1, 16);
edit->SetMarginMask(1,~wxSTC_MASK_FOLDERS);
edit->MarkerDefine(MARKER_BOOKMARK, wxSTC_MARK_BOOKMARK, wxColour(0, 0, 0), wxColour(0, 160, 0));
edit->MarkerDefine(MARKER_NAVIGATE, wxSTC_MARK_BOOKMARK, wxColour(0, 0, 0), wxColour(0, 0, 160));
edit->MarkerDefine(MARKER_BREAKPOINT, wxSTC_MARK_CIRCLE, wxColour(192, 192, 192), wxColour(160, 0, 0));
edit->MarkerDefine(MARKER_CURRENTLINE, wxSTC_MARK_SHORTARROW, wxColour(0, 0, 0), wxColour(240, 192, 0));
if (name.Length() == 0 || IsPawnFile(name)) {
edit->SetLexer(wxSTC_LEX_CPP);
edit->SetProperty("lexer.cpp.track.preprocessor", "0"); /* this is too complex with Pawn, because Pawn can also check definitions of variables & functions */
edit->SetKeyWords(0, PawnKeyWords);
edit->SetWordChars("_@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
}
edit->SetCodePage(wxSTC_CP_UTF8); /* required for the Unicode build of wxWidgets, which is now standard */
edit->SetTabIndents(true);
edit->SetBackSpaceUnIndents(true);
edit->SetMouseDwellTime(500);
edit->AutoCompStops("[]{}<>`~!#$%^&*-+|\\;:'\",./?");
edit->AutoCompSetDropRestOfWord(true);
edit->AutoCompSetChooseSingle(true);
edit->AutoCompSetSeparator('|');
/* make sure special keys are not not handled by scintilla */
edit->CmdKeyClear('[', wxSTC_KEYMOD_CTRL); /* CmdKeyClear blocks the key from propagating */
edit->CmdKeyClear(']', wxSTC_KEYMOD_CTRL);
for (int i = 0; i < theApp->Shortcuts.Count(); i++) {
KbdShortcut* shortcut = theApp->Shortcuts.GetItem(i);
wxAcceleratorEntry entry;
if (entry.FromString(shortcut->GetShortcut())) {
int flags = wxSTC_KEYMOD_NORM; /* wxWidgets flags and Scintilla flags are not the same */
if (entry.GetFlags() & wxACCEL_SHIFT)
flags |= wxSTC_KEYMOD_SHIFT;
if (entry.GetFlags() & wxACCEL_CTRL)
flags |= wxSTC_KEYMOD_CTRL;
if (entry.GetFlags() & wxACCEL_ALT)
flags |= wxSTC_KEYMOD_ALT;
edit->CmdKeyAssign(entry.GetKeyCode(), flags, 0); /* propagate to parent window */
}
}
Connect(IDC_EDIT + idx, wxEVT_STC_CHANGE, wxStyledTextEventHandler(QuincyFrame::OnEditorChange));
Connect(IDC_EDIT + idx, wxEVT_STC_CHARADDED, wxStyledTextEventHandler(QuincyFrame::OnEditorCharAdded));
Connect(IDC_EDIT + idx, wxEVT_STC_UPDATEUI, wxStyledTextEventHandler(QuincyFrame::OnEditorPosition));
Connect(IDC_EDIT + idx, wxEVT_STC_DWELLSTART, wxStyledTextEventHandler(QuincyFrame::OnEditorDwellStart));
Connect(IDC_EDIT + idx, wxEVT_STC_DWELLEND, wxStyledTextEventHandler(QuincyFrame::OnEditorDwellEnd));
edit->SetDropTarget(new DragAndDropFile(this));
wxASSERT(EditTab);
wxString str;
if (name.Length() == 0) {
Filename[idx] = wxEmptyString;
FileTimeStamp[idx] = 0;
str = "(new)";
} else {
Filename[idx] = name;
FileTimeStamp[idx] = wxFileModificationTime(name);
str = name.AfterLast(DIRSEP_CHAR);
}
EditTab->AddPage(edit, str, false);
unsigned count = EditTab->GetPageCount();
EditTab->SetSelection(count - 1); /* activate the page just added */
EditTab->Layout();
this->Layout();
this->Refresh();
if (name.Length() > 0) {
if (!LoadFile(name, edit))
wxMessageBox("Failed to load file " + str, "Pawn IDE", wxOK | wxICON_ERROR);
} else {
edit->ClearAll();
}
edit->SetFocus();
edit->EnsureCaretVisible();
SetChanged(idx, false);
SetStatusText(wxEmptyString, 0);
return true;
}
bool QuincyFrame::RemoveEditor(int index, bool deletecontrol)
{
wxASSERT(EditTab);
if (EditTab->GetPageCount() == 0)
return false;
wxStyledTextCtrl *edit;
if (index == -1) {
/* get the active editor */
edit = GetActiveEdit(EditTab);
} else {
wxASSERT(index >= 0 && index < MAX_EDITORS);
edit = dynamic_cast<wxStyledTextCtrl*>(EditTab->GetPage(index));
}
wxASSERT(edit);
/* find the editor in the list */
for (index = 0; index < MAX_EDITORS && Editor[index] != edit; index++)
/* nothing */;
if (index >= MAX_EDITORS || edit == NULL)
return false;
Editor[index] = NULL;
Filename[index] = wxEmptyString;
FileTimeStamp[index] = 0;
/* optionally find the tab page and delete it */
if (deletecontrol) {
wxASSERT(EditTab);
for (index = 0; index < (int)EditTab->GetPageCount(); index++)
if (EditTab->GetPage(index) == edit)
EditTab->DeletePage(index);
}
return true;
}
/* adapted from the functions in the Pawn compiler */
bool QuincyFrame::ScanUTF8(const wxString& filename)
{
FILE *fp = fopen(filename.utf8_str(), "r");
if (!fp)
return false;
bool utf8 = true;
bool bom_found = false;
bool firstchar = true;
unsigned char line[512];
while (utf8 && fgets((char*)line, sizeof(line), fp) != NULL) {
const unsigned char *ptr = line;
if (firstchar) {
/* check whether the very first character on the very first line
starts with a byte order mark (BOM) */
if (line[0] == 0xef && line[1] == 0xbb && line[2] == 0xbf) {
bom_found = true;
ptr += 3;
}
firstchar = false;
}
/* run over one line */
long lowmark = 0;
int follow = 0;
long code = 0;
while (utf8 && *ptr != '\0') {
unsigned char ch = *ptr++;
if (follow > 0 && (ch & 0xc0) == 0x80) {
/* leader code is active, combine with earlier code */
code = (code << 6) | (ch & 0x3f);
if (--follow == 0) {
/* encoding a character in more bytes than is strictly
needed, is not really valid UTF-8; if no BOM is found,
we are strict in order to increase the chance of heuristic
dectection of non-UTF-8 text (JAVA writes zero bytes as
a 2-byte code UTF-8, which is invalid) */
if (code < lowmark && !bom_found)
utf8 = false;
/* the code positions 0xd800--0xdfff and 0xfffe & 0xffff do
not exist in UCS-4 (and hence, they do not exist in Unicode) */
if (code >= 0xd800 && code <= 0xdfff || code == 0xfffe || code == 0xffff)
utf8 = false;
}
} else if (follow == 0 && (ch & 0x80) == 0x80) {
/* UTF-8 leader code */
if ((ch & 0xe0) == 0xc0) {
/* 110xxxxx 10xxxxxx */
follow = 1;
lowmark = 0x80L;
code = ch & 0x1f;
} else if ((ch & 0xf0) == 0xe0) {
/* 1110xxxx 10xxxxxx 10xxxxxx (16 bits, BMP plane) */
follow = 2;
lowmark = 0x800L;
code = ch & 0x0f;
} else if ((ch & 0xf8) == 0xf0) {
/* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
follow = 3;
lowmark = 0x10000L;
code = ch & 0x07;
} else if ((ch & 0xfc) == 0xf8) {
/* 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */
follow = 4;
lowmark = 0x200000L;
code = ch & 0x03;
} else if ((ch & 0xfe) == 0xfc) {
/* 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx (32 bits) */
follow = 5;
lowmark = 0x4000000L;
code = ch & 0x01;
} else {
/* this is invalid UTF-8 */
utf8 = false;
} /* if */
} else if (follow == 0 && (ch & 0x80) == 0x00) {
/* 0xxxxxxx (US-ASCII), which is valid UTF8 */
code = ch;
} else {
/* this is invalid UTF-8 */
utf8 = false;
}
}
}
fclose(fp);
return utf8;
}
bool QuincyFrame::Latin1ToUTF8(const wxString& filename)
{
/* Nota Bene:
* 1) no check is made to verify whether the file is already in UTF8
* 2) worse: the file is simply assumed to be in Latin-1
*/
FILE *fp = fopen(filename.utf8_str(), "r");
if (!fp)
return false;
/* get the file length, then read it in memory completely */
fseek(fp, 0, SEEK_END);
long size = ftell(fp);
unsigned char *buffer = (unsigned char*)malloc(size * sizeof(char));
if (!buffer) {
fclose(fp);
return false;
}
fseek(fp, 0, SEEK_SET);
fread(buffer, sizeof(char), size, fp);
fclose(fp);
/* re-open the file for writing */
fp = fopen(filename.utf8_str(), "w");
if (!fp) {