-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMainWindow.monkey2
More file actions
2176 lines (1592 loc) · 52.4 KB
/
MainWindow.monkey2
File metadata and controls
2176 lines (1592 loc) · 52.4 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
Namespace ted2go
#Import "assets/about.html@/ted2"
#Import "assets/aboutTed2Go.html@/ted2"
#Import "assets/themes/@/themes"
#Import "assets/newfiles/@/ted2/newfiles"
#Import "assets/fonts/@/fonts"
Global MainWindow:MainWindowInstance
Class MainWindowInstance Extends Window
Field SizeChanged:Void()
Field Rendered:Void( canvas:Canvas )
Method New( title:String,rect:Recti,flags:WindowFlags,jobj:JsonObject )
Super.New( title,rect,flags )
MainWindow=Self
UpdateToolsPaths()
LiveTemplates.Load()
_tabsWrap=New DraggableTabs
_docsTabView=Di.Resolve<DocsTabView>()
_recentFilesMenu=New MenuExt( "Recent files" )
_recentProjectsMenu=New MenuExt( "Recent projects" )
_closeProjectMenu=New MenuExt( "Close project" )
_docBrowser=Di.Resolve<DocBrowserView>()
_docsManager=Di.Resolve<DocumentManager>()
_docsManager.CurrentDocumentChanged+=Lambda()
UpdateKeyView()
CodeDocument.HideAllPopups()
Local doc:=Cast<CodeTextView>( _docsManager.CurrentTextView )
Local mode:=doc ? doc.OverwriteMode Else False
OverwriteTextMode=mode
_findReplaceView.CodeView=Cast<CodeTextView>( _docsManager.CurrentTextView )
If _fullscreenState=FullscreenState.Editor
SwapFullscreenEditor( False,1 )
Endif
' show current file in project view
If _docsManager.CurrentDocument And Prefs.MainProjectAutoscrollToFile
_projectView.JumpToFile( _docsManager.CurrentDocument?.Path )
Endif
End
_docsManager.DocumentDoubleClicked+=Lambda( doc:Ted2Document )
_docsManager.LockBuildFile()
End
App.FileDropped+=Lambda( path:String )
OnFileDropped( path )
End
_docsManager.DocumentAdded+=Lambda( doc:Ted2Document )
AddRecentFile( doc.Path )
Local codeDoc:=Cast<CodeDocument>( doc )
If codeDoc
codeDoc.AnalyzeIndentation()
If _projectView.ActiveProject?.MainFilePath=codeDoc.Path
_docsManager.SetAsMainFile( codeDoc.Path,True )
Endif
Endif
SaveState()
End
_docsManager.DocumentRemoved+=Lambda( doc:Ted2Document )
If IsTmpPath( doc.Path ) DeleteFile( doc.Path )
SaveState()
End
_recentViewedFiles=New RecentFiles( _docsManager )
'Build tab
_buildConsole=Di.Resolve<BuildConsole>()
' jump to errors etc.
_buildConsole.RequestJumpToFile+=Lambda( path:String,line:Int )
' emulate build error
Local err:=New BuildError( path,line,"" )
_buildActions.GotoError( err )
End
'Output tab
_outputConsole=Di.Resolve<OutputConsole>()
Local bar:=New ToolBarExt
bar.MaxSize=New Vec2i( 300,30 )
Local label:=New Label( "Filter:" )
bar.AddView( label,"left" )
Local editFilter:=New TextFieldExt
editFilter.Style=GetStyle( "TextFieldBordered" )
editFilter.CursorType=CursorType.Line
editFilter.CursorBlinkRate=2.5
bar.AddView( editFilter,"left",200 )
editFilter.TextChanged+=Lambda()
Local t:=editFilter.Text
_outputConsole.SetFilter( t )
End
bar.AddSeparator()
bar.AddIconicButton(
ThemeImages.Get( "outputbar/clean.png" ),
Lambda()
_outputConsole.ClearAll()
End,
"Clear all" )
Local it:=bar.AddIconicButton(
ThemeImages.Get( "outputbar/wrap.png" ),
Lambda()
_outputConsole.WordWrap=Not _outputConsole.WordWrap
End,
"Word wrap" )
it.ToggleMode=True
Local tbAct:=New Action( " \r " )
tbAct.Triggered+=Lambda()
_outputConsole.ProcessingRtChar=Not _outputConsole.ProcessingRtChar
End
Local tb:=New ToolButtonExt( tbAct,"Processing \r char at the beginning of lines" )
tb.ToggleMode=True
bar.AddView( tb )
_outputConsoleView=New DockingView
_outputConsoleView.AddView( bar,"top" )
_outputConsoleView.ContentView=_outputConsole
'Find tab
_findConsole=New TreeViewExt
_findConsole.SingleClickExpanding=True
_findConsole.NodeClicked+=Lambda( node:TreeView.Node )
Local n:=Cast<NodeWithData<FileJumpData>>( node )
If Not n Return
Local data:=n.data
Local pos:=New Vec2i( data.line,data.posInLine )
GotoCodePosition( data.path,pos,data.len )
End
'Help tab
_helpView=Di.Resolve<HelpView>()
_docsConsole=New DockingView
bar=New ToolBarExt
bar.MaxSize=New Vec2i( 300,30 )
_helpSwitcher=New ToolButtonExt( New Action( ">" ) )
bar.AddView( _helpSwitcher,"left" )
bar.AddView( New SpacerView( 30,0 ),"left" ) ' right offset
_helpSwitcher.Clicked=Lambda()
_helpTree.Visible=Not _helpTree.Visible
_helpSwitcher.Text=_helpTree.Visible ? "<" Else ">"
_helpSwitcher.Hint=_helpTree.Visible ? "Hide docs index" Else "Show docs index"
End
bar.AddIconicButton(
ThemeImages.Get( "docbar/home.png" ),
Lambda()
_helpView.ClearHistory()
_helpView.Navigate( AboutPagePath )
End,
"Home" )
bar.AddIconicButton(
ThemeImages.Get( "docbar/back.png" ),
Lambda()
_helpView.Back()
End,
"Back" )
bar.AddIconicButton(
ThemeImages.Get( "docbar/forward.png" ),
Lambda()
_helpView.Forward()
End,
"Forward" )
Local explorerAct:=New Action( " [*] " )
explorerAct.Triggered+=Lambda()
Local url:=_helpView.Url
OpenInExplorer( url )
End
Local explorerBtn:=New ToolButtonExt( explorerAct,GetShowInExplorerTitle() )
bar.AddView( explorerBtn )
bar.AddSeparator()
bar.AddSeparator()
label=New Label
label.Style=App.Theme.GetStyle( "HelpPageAddress" )
bar.ContentView=label
_helpView.Navigated+=Lambda( url:String )
label.Text=url
End
_helpTree=Di.Resolve<HelpTreeView>()
_docsConsole.AddView( _helpTree,"left",200,True )
_docsConsole.AddView( bar,"top" )
_docsConsole.ContentView=_helpView
_helpTree.Visible=False
_helpSwitcher.Clicked() 'show at startup
_helpView.Navigate( AboutPagePath )
_debugView=Di.Resolve<DebugView>()
_buildActions=Di.Resolve<BuildActions>()
_buildActions.ErrorsOccured+=Lambda( errors:BuildError[] )
ShowBuildConsole( True )
_buildActions.GotoError( errors[0] )
End
' ExamplesView
'
_examplesView=Di.Resolve<ExamplesView>()
' ProjectView
'
_projectView=Di.Resolve<ProjectView>()
' project opened
_projectView.ProjectOpened+=Lambda( path:String )
AddRecentProject( path )
SaveState()
End
' project closed
_projectView.ProjectClosed+=OnProjectClosed
' find in folder
_projectView.RequestedFindInFolder+=Lambda( folder:String )
_findActions.FindInFiles( folder )
End
_codeParsing=Di.Resolve<CodeParsing>()
_projectView.MainFileChanged+=Lambda( path:String,prevPath:String )
_docsManager.SetAsMainFile( prevPath,False )
_docsManager.SetAsMainFile( path,True )
End
_projectView.FileRenamed+=Lambda( path:String,prevPath:String )
Local doc:=_docsManager.FindDocument( prevPath )
If doc Then _docsManager.RenameDocument( doc,path )
End
_projectView.FolderRenamed+=Lambda( path:String,prevPath:String )
Local docs:=_docsManager.OpenDocuments
For Local doc:=Eachin docs
If doc.Path.StartsWith( prevPath )
_docsManager.RenameDocument( doc,doc.Path.Replace( prevPath,path ) )
Endif
Next
End
_fileActions=New FileActions( _docsManager )
_editActions=New EditActions( _docsManager )
_findActions=New FindActions( _docsManager,_projectView,_findConsole )
_helpActions=New HelpActions
_gotoActions=New GotoActions( _docsManager )
_tabActions=New TabActions( _tabsWrap.AllDocks )
_tabMenu=New Menu
_tabMenu.AddAction( _fileActions.close )
_tabMenu.AddAction( _fileActions.closeOthers )
_tabMenu.AddAction( _fileActions.closeToRight )
_tabMenu.AddAction( _fileActions.closeAll )
_tabMenu.AddSeparator()
_tabMenu.AddAction( _fileActions.save )
_tabMenu.AddAction( _fileActions.saveAs )
_tabMenu.AddSeparator()
_tabMenu.AddAction( _buildActions.lockBuildFile )
_tabMenu.AddAction( _projectView.setMainFile )
_tabMenu.AddSeparator()
_tabMenu.AddAction( GetShowInExplorerTitle() ).Triggered=Lambda()
Local path:=_docsManager.CurrentDocument?.Path
If path
OpenInExplorer( ExtractDir( path ) )
Endif
End
_tabMenu.AddAction( "Copy path" ).Triggered=Lambda()
Local path:=_docsManager.CurrentDocument?.Path
If path
App.ClipboardText=path
Endif
End
_docsTabView.RightClicked+=Lambda()
_tabMenu.Open()
End
_docsTabView.CloseClicked+=Lambda( index:Int )
Local doc:=_docsManager.FindDocument( _docsTabView.TabView( index ) )
If Not doc.Dirty And Not IsTmpPath( doc.Path )
doc.Close()
Return
Endif
_docsManager.CurrentDocument=doc
_fileActions.close.Trigger()
End
'File menu
'
_templateFiles=New MenuExt( "Templates" )
Local p:=AssetsDir()+"ted2/newfiles/"
For Local f:=Eachin LoadDir( p )
Local src:=stringio.LoadString( p+f )
_templateFiles.AddAction( StripExt( f.Replace( "_"," " ) ) ).Triggered=Lambda()
Local path:=AllocTmpPath( "untitled",ExtractExt( f ) )
If Not path Return
SaveString( src,path )
OpenDocument( path,True )
End
Next
_fileMenu=New MenuExt( "File" )
_fileMenu.AddAction( _fileActions.new_ )
_fileMenu.AddAction( _fileActions.open )
_fileMenu.AddSubMenu( _recentFilesMenu )
_fileMenu.AddSubMenu( _templateFiles )
_fileMenu.AddSeparator()
_fileMenu.AddAction( _fileActions.close )
_fileMenu.AddAction( _fileActions.closeOthers )
_fileMenu.AddAction( _fileActions.closeToRight )
_fileMenu.AddAction( _fileActions.closeAll )
_fileMenu.AddSeparator()
_fileMenu.AddAction( _fileActions.save )
_fileMenu.AddAction( _fileActions.saveAs )
_fileMenu.AddAction( _fileActions.saveAll )
_fileMenu.AddSeparator()
_fileMenu.AddAction( _projectView.openProjectFolder )
_fileMenu.AddAction( _projectView.openProjectFile )
_fileMenu.AddSubMenu( _recentProjectsMenu )
_fileMenu.AddSubMenu( _closeProjectMenu )
_fileMenu.AddSeparator()
_fileMenu.AddAction( _fileActions.prefs )
_fileMenu.AddSeparator()
_fileMenu.AddAction( _fileActions.quit )
'Edit menu
'
_editMenu=New MenuExt( "Edit" )
_editMenu.AddAction( _editActions.undo )
_editMenu.AddAction( _editActions.redo )
_editMenu.AddSeparator()
_editMenu.AddAction( _editActions.cut )
_editMenu.AddAction( _editActions.copy )
_editMenu.AddAction( _editActions.paste )
_editMenu.AddSeparator()
_editMenu.AddAction( _editActions.selectAll )
_editMenu.AddAction( _editActions.expandSelection )
_editMenu.AddSeparator()
' Edit -- Text
Local subText:=New MenuExt( "Text" )
subText.AddAction( _editActions.textDeleteWordForward )
subText.AddAction( _editActions.textDeleteWordBackward )
subText.AddAction( _editActions.textDeleteLine )
subText.AddAction( _editActions.textDeleteToEnd )
subText.AddAction( _editActions.textDeleteToBegin )
_editMenu.AddSubMenu( subText )
' Edit -- Comment
Local subComment:=New MenuExt( "Comment" )
subComment.AddAction( _editActions.comment )
subComment.AddAction( _editActions.uncomment )
_editMenu.AddSubMenu( subComment )
' Edit -- Convert case
Local subCase:=New MenuExt( "Convert case" )
subCase.AddAction( _editActions.textUppercase )
subCase.AddAction( _editActions.textLowercase )
subCase.AddAction( _editActions.textSwapCase )
_editMenu.AddSubMenu( subCase )
'
_editMenu.AddSeparator()
_editMenu.AddAction( _editActions.wordWrap )
'Find menu
'
_findMenu=New MenuExt( "Find" )
_findMenu.AddAction( _findActions.find )
_findMenu.AddAction( _findActions.replace )
_findMenu.AddAction( _findActions.findNext )
_findMenu.AddAction( _findActions.findPrevious )
_findMenu.AddSeparator()
_findMenu.AddAction( _findActions.findInFiles )
'Goto menu
'
_gotoMenu=New MenuExt( "Goto" )
_gotoMenu.AddAction( _gotoActions.gotoLine )
_gotoMenu.AddAction( _gotoActions.gotoDeclaration )
_gotoMenu.AddSeparator()
_gotoMenu.AddAction( _gotoActions.goBack )
_gotoMenu.AddAction( _gotoActions.goForward )
_gotoMenu.AddSeparator()
_gotoMenu.AddAction( _gotoActions.prevScope )
_gotoMenu.AddAction( _gotoActions.nextScope )
'View menu
'
_viewMenu=New MenuExt( "View" )
Local m:=New MenuExt( "Docks" )
TabActions.CreateMenu( m )
_viewMenu.AddSubMenu( m )
_viewMenu.AddSeparator()
m=New MenuExt( "Folding" )
Local foldActions:=New FoldingActions
m.AddAction( foldActions.foldCurrent )
m.AddAction( foldActions.unfoldCurrent )
m.AddSeparator()
m.AddAction( foldActions.foldScope )
m.AddAction( foldActions.unfoldScope )
m.AddSeparator()
m.AddAction( foldActions.foldAll )
m.AddAction( foldActions.unfoldAll )
_viewMenu.AddSubMenu( m )
_viewMenu.AddSeparator()
Local showRecent:=ActionById( ActionId.RecentlyViewedFiles )
showRecent.Triggered=Lambda()
Local path:=_recentViewedFiles.ShowDialog()
If path Then OpenDocument( path )
End
_viewMenu.AddAction( showRecent )
'Build menu
'
_forceStop=_buildActions.forceStop
'
_buildActions.PreBuild+=OnPreBuild
_buildActions.PreSemant+=OnPreSemant
_buildActions.PreBuildModules+=OnPreBuildModules
_buildMenu=New MenuExt( "Build" )
_buildMenu.AddAction( _buildActions.buildAndRun )
_buildMenu.AddAction( _buildActions.build )
_buildMenu.AddAction( _buildActions.semant )
_buildMenu.AddAction( _buildActions.debugApp )
_buildMenu.AddSeparator()
_buildMenu.AddSubMenu( _buildActions.targetMenu )
_buildMenu.AddSeparator()
_buildMenu.AddAction( _forceStop )
_buildMenu.AddAction( _buildActions.nextError )
_buildMenu.AddSeparator()
_buildMenu.AddAction( _buildActions.lockBuildFile )
_buildMenu.AddSeparator()
_buildMenu.AddAction( _buildActions.updateModules )
_buildMenu.AddAction( _buildActions.moduleManager )
'Window menu
'
Local windowActions:=New WindowActions( _docsManager )
_windowMenu=New MenuExt( "Window" )
_windowMenu.AddAction( windowActions.nextTab )
_windowMenu.AddAction( windowActions.prevTab )
_windowMenu.AddSeparator()
_windowMenu.AddAction( windowActions.fullscreenWindow )
_windowMenu.AddAction( windowActions.fullscreenEditor )
_windowMenu.AddSeparator()
_windowMenu.AddAction( windowActions.zoomIn )
_windowMenu.AddAction( windowActions.zoomOut )
_windowMenu.AddAction( windowActions.zoomDefault )
_windowMenu.AddSeparator()
_themesMenu=CreateThemesMenu( "Themes" )
_windowMenu.AddSubMenu( _themesMenu )
'Help menu
'
_helpMenu=New MenuExt( "Help" )
_helpMenu.AddAction( _helpActions.quickHelp )
_helpMenu.AddAction( _helpActions.viewManuals )
If IsBananasShowcaseAvailable() Then _helpMenu.AddAction( _helpActions.bananas )
_helpMenu.AddSeparator()
_helpMenu.AddAction( _buildActions.rebuildHelp )
_helpMenu.AddSeparator()
' _helpMenu.AddAction( _helpActions.onlineHelp )
_helpMenu.AddAction( _helpActions.mx2homepage )
_helpMenu.AddAction( _helpActions.uploadModules )
_helpMenu.AddSeparator()
_helpMenu.AddAction( _helpActions.about )
_helpMenu.AddAction( _helpActions.aboutTed2go )
_helpMenu.AddSeparator()
_helpMenu.AddAction( _helpActions.makeBetter )
_helpMenu.AddAction( _helpActions.joinCommunity )
'Menu bar
'
_menuBar=New MenuBarExt
_menuBar.AddMenu( _fileMenu )
_menuBar.AddMenu( _editMenu )
_menuBar.AddMenu( _findMenu )
_menuBar.AddMenu( _gotoMenu )
_menuBar.AddMenu( _viewMenu )
_menuBar.AddMenu( _buildMenu )
_menuBar.AddMenu( _windowMenu )
_menuBar.AddMenu( _helpMenu )
_buildConsoleView=New DockingView
_buildConsoleView.ContentView=_buildConsole
_statusBar=New StatusBarView( "Stop process ("+_forceStop.HotKeyText+")" )
_contentView=New DockingView
_contentView.AddView( _menuBar,"top" )
ArrangeElements()
'_helpTree.QuickHelp( "" )
ContentView=_contentView
OnCreatePlugins() 'init plugins before loadstate, to register doctypes before open last opened files
LoadState( jobj )
App.MouseEventFilter+=ThemeScaleMouseFilter
App.Idle+=OnAppIdle
CheckFirstStart()
_enableSaving=True
End
Field PrefsChanged:Void()
Method OnPrefsChanged()
ArrangeElements()
For Local doc:=Eachin _docsManager.OpenDocuments
doc.TextView?.TabStop=Prefs.EditorTabSize
Next
PrefsChanged()
_projectView.SingleClickExpanding=Prefs.MainProjectSingleClickExpanding
End
Method GainFocus()
'Local event:=New WindowEvent( EventType.WindowGainedFocus,Self )
'OnWindowEvent( event )
'SendWindowEvent( event )
'SDL_RaiseWindow( SDLWindow )
End
Method OnFileDropped( path:String )
New Fiber( Lambda()
Local ok:=_projectView.OnFileDropped( path )
If Not ok And FileExists( path ) 'file
_docsManager.OpenDocument( path,True )
Endif
End )
End
Method HideFindPanel:Bool()
If Not _findReplaceView.Visible Return False
_findReplaceView.CodeView=Null
_findReplaceView.Visible=False
UpdateKeyView()
Return True
End
Method ShowFind( what:String="" )
_findReplaceView.CodeView=Cast<CodeTextView>( _docsManager.CurrentTextView )
Local arr:=what.Split( "~n" )
If arr.Length>1
what=""
Endif
If _findReplaceView.Visible And Not what
what=_findReplaceView.FindText
Endif
_findReplaceView.Visible=True
_findReplaceView.FindText=what
_findReplaceView.Mode=FindReplaceView.Kind.Find
_findReplaceView.Activate()
End
Method ShowReplace( what:String="" )
ShowFind( what )
_findReplaceView.Mode=FindReplaceView.Kind.Replace
End
Method OnFind()
_findActions.find.Trigger()
End
Method OnFindPrev()
_findActions.findPrevious.Trigger()
End
Method OnFindNext()
_findActions.findNext.Trigger()
End
Method OnForceStop()
If _buildConsole.Running
_buildConsole.Terminate()
Endif
_debugView.KillApp()
HideStatusBarProgress()
RestoreConsoleVisibility()
If _outputConsole.Running
_outputConsole.Terminate()
Endif
End
Method OnDocumentLinesModified( doc:Ted2Document,first:Int,removed:Int,inserted:Int )
Local res:=_findActions.lastFindResults
If Not res Return
res.ProcessLinesModified( doc.Path,first,removed,inserted )
End
Property Mx2ccPath:String()
Return _mx2cc
End
Property ModsPath:String()
Return _modsDir
End
Property OverwriteTextMode:Bool()
Return _ovdMode
Setter( value:Bool )
If value=_ovdMode Return
_ovdMode=value
Local doc:=Cast<CodeTextView>( _docsManager.CurrentTextView )
If doc
doc.OverwriteMode=_ovdMode
Else
_ovdMode=False
Endif
SetStatusBarInsertMode( Not _ovdMode )
End
Property DocsManager:DocumentManager()
Return _docsManager
End
Property ProjView:ProjectView()
Return _projectView
End
Property LockedDocument:CodeDocument()
Return _docsManager.LockedDocument
End
Property IsTerminating:Bool()
Return _isTerminating
End
Property AboutPagePath:String()
Local path:=Prefs.MonkeyRootPath+"ABOUT.HTML"
' If Not IsFileExists( path )
' path="asset::ted2/about.html"
' Endif
Return path
End
Method Terminate()
_isTerminating=True
SaveState()
_enableSaving=False
OnForceStop() ' kill build process if started
' waiting for started processes if any
ParsersManager.DisableAll()
Local future:=New Future<Bool>
New Fiber( Lambda()
ProcessReader.WaitingForStopAll( future )
End )
future.Get()
CodeParsing.DeleteTempFiles()
App.Terminate()
End
'Use these as macos still seems to have problems running requesters on a fiber - stacksize?
'
Method RequestFile:String( title:String,path:String,save:Bool,filter:String="" )
Local future:=New Future<String>
If Not filter Then filter="Monkey2 files:monkey2;Text files:txt;Image files:png,jpg,jpeg;All files:*"
App.Idle+=Lambda()
Local s:=requesters.RequestFile( title,filter,save,path )
future.Set( s )
End
Return future.Get()
End
Method RequestDir:String( title:String,dir:String )
Local future:=New Future<String>
App.Idle+=Lambda()
future.Set( requesters.RequestDir( title,dir ) )
End
Return future.Get()
End
Method AllocTmpPath:String( ident:String,ext:String )
For Local i:=1 Until 100
Local path:=_tmp+ident+i+ext
If GetFileType( path )<>FileType.None Continue
If CreateFile( path ) Return path
Next
Return ""
End
Method UpdateToolsPaths()
_tmp=RealPath( "tmp/" )
#If __TARGET__="macos"
_mx2cc="bin/mx2cc_macos"
#Else If __TARGET__="windows"
_mx2cc="bin/mx2cc_windows.exe"
#Else If __TARGET__="raspbian"
_mx2cc="bin/mx2cc_raspbian"
#Else
_mx2cc="bin/mx2cc_linux"
#Endif
_mx2cc=RealPath( _mx2cc )
_modsDir=RealPath( "modules/" )
End
Method SwapFullscreenWindow()
If _fullscreenState=FullscreenState.Editor
SwapFullscreenEditor()
Return
Endif
If Not _fullscreen
_storedSize=Frame
_storedMaximized=Maximized
Endif
_fullscreen=Not _fullscreen
_fullscreenState=_fullscreen ? FullscreenState.Window Else FullscreenState.None
UpdateFullscreenMode()
End
' customState: -1 - make windowed, 1 - make fullscreen
'
Method SwapFullscreenEditor( justStarted:Bool=False,customState:Int=0 )
If Not justStarted And _docsManager.CurrentDocument=Null
Alert( "There is no editor to be fullscreened!","Fullscreen" )
Return
Endif
If Not _fullscreen
_storedSize=Frame
_storedMaximized=Maximized
Endif
' restore
If _fullscreenHelper.storedContentView<>Null
Local view:=_fullscreenHelper.editorContainer.ContentView
view.Layout="fill"
_fullscreenHelper.editorContainer.ContentView=Null
_fullscreenHelper.statusContainer.ContentView=Null
_statusBarContainer.ContentView=_statusBar
ContentView=_fullscreenHelper.storedContentView
_docsTabView.SetTabView( _fullscreenHelper.storedTabIndex,view )
_docsTabView.EnsureVisibleCurrentTab()
_docsManager.UpdateCurrentTabLabel()
_docsManager.CurrentDocument?.DirtyChanged-=_fullscreenHelper.UpdateTitle
_fullscreenHelper.storedContentView=Null
Endif
' stay in fullscreen
If _fullscreenPrevState=FullscreenState.Window
_fullscreenState=FullscreenState.Window
_fullscreenPrevState=FullscreenState.None
Return
Endif
_fullscreenPrevState=_fullscreenState
Local state:=Not _fullscreen
If customState<>0 Then state=(customState > 0)
If _fullscreenState<>FullscreenState.Window Then _fullscreen=state
_fullscreenState=_fullscreen ? FullscreenState.Editor Else FullscreenState.None
UpdateFullscreenMode()
If _fullscreen
_fullscreenHelper.storedContentView=ContentView
_fullscreenHelper.storedTabIndex=_docsTabView.CurrentIndex
_docsTabView.SetTabView( _fullscreenHelper.storedTabIndex,Null )
Local view:=_docsManager.CurrentView
view.Layout="fill-y"
view.Gravity=New Vec2f( .5,0 )
Local sz:=New Vec2i( Int(App.DesktopSize.x*.7),100000 )
view.MaxSize=sz
view.MinSize=sz
_fullscreenHelper.editorContainer.ContentView=view
_fullscreenHelper.titleLabel.Text=_docsManager.CurrentDocumentLabel
_docsManager.CurrentDocument?.DirtyChanged+=_fullscreenHelper.UpdateTitle
' status bar
_statusBarContainer.ContentView=Null
_fullscreenHelper.statusContainer.ContentView=_statusBar
'
ContentView=_fullscreenHelper.editorContainer
_docsManager.CurrentTextView?.MakeKeyView()
Endif
End
Method StoreConsoleVisibility()
'If Prefs.SiblyMode return
'_storedConsoleVisible=_consolesTabView.Visible
'_consoleVisibleCounter=0
End
Method RestoreConsoleVisibility()
'If Prefs.SiblyMode Return
'If _consoleVisibleCounter > 0 Return
'_consolesTabView.Visible=_storedConsoleVisible
'RequestRender()
End
Method IsTmpPath:Bool( path:String )
Return path.StartsWith( _tmp )
End
Method SetStatusBarActive( active:Bool )
_statusBar.SetActiveState( active )
End
Method ShowStatusBarText( text:String,append:Bool=False )
_statusBar.SetText( text,append )
End
Method SetStatusBarInsertMode( ins:Bool )
_statusBar.SetInsMode( ins )
End
Method ShowStatusBarLineInfo( tv:TextView )
Local line:=tv.Document.FindLine( tv.Cursor )
Local pos:=tv.Cursor-tv.Document.StartOfLine( line )
line+=1
pos+=1
_statusBar.SetLineInfo( "Ln : "+line+" Col : "+pos )
End
Method ShowStatusBarProgress( cancelCallback:Void(),cancelIconOnly:Bool=False )
_statusBar.Cancelled=cancelCallback
_statusBar.ShowProgress( cancelIconOnly )
End
Method HideStatusBarProgress()
_statusBar.HideProgress()
End
Private
Method GetFindDock:DockingView()
If _findReplaceView Return _findReplaceView
_findReplaceView=New FindReplaceView( _findActions )
_findReplaceView.RequestedFind+=Lambda( opt:FindOptions )
_findActions.options=opt
If opt.goNext
_findActions.findNext.Triggered()
Else
_findActions.findPrevious.Triggered()
Endif
End
_findReplaceView.RequestedReplace+=Lambda( opt:FindOptions )
_findActions.options=opt
If opt.all
_findActions.replaceAll.Triggered()
Else
_findActions.replaceNext.Triggered()
Endif
End
Return _findReplaceView
End
Method GetMainToolBar:ToolBarExt()
If _toolBar Return _toolBar
'Tool Bar
'
Local newTitle:=GetActionTextWithShortcut( _fileActions.new_ )
Local openTitle:=GetActionTextWithShortcut( _fileActions.open )
Local saveTitle:=GetActionTextWithShortcut( _fileActions.save )
Local saveAllTitle:=GetActionTextWithShortcut( _fileActions.saveAll )
Local undoTitle:=GetActionTextWithShortcut( _editActions.undo )
Local redoTitle:=GetActionTextWithShortcut( _editActions.redo )
Local runTitle:=GetActionTextWithShortcut( _buildActions.buildAndRun )
Local buildTitle:=GetActionTextWithShortcut( _buildActions.build )