-
Notifications
You must be signed in to change notification settings - Fork 0
/
Naja.cobra
799 lines (651 loc) · 36 KB
/
Naja.cobra
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
%%args -ref:System.Design -ref:System.Windows.Forms
use Qios.DevSuite.Components
use System.Windows.Forms from System.Windows.Forms
use ICSharpCode.TextEditor
use ICSharpCode.TextEditor.Gui.CompletionWindow
use ICSharpCode.TextEditor.Document
use System.ComponentModel
use System.ComponentModel.Design from System.Design
use System.Drawing
use System.Drawing.Design
use System.Diagnostics
use System.Text.RegularExpressions
use pF.DesignSurfaceExt from "DesignSurfaceExt2"
use pF.DesignSurfaceManagerExt from "DesignSurfaceManagerExt"
use Cobra.Lang.Compiler
class Naja is partial inherits Form
var _editorSettings as ITextEditorProperties?
var _findForm = FindAndReplaceForm()
#DONE: Test the task list load
#DONE: UNABLE TO REPRODUCE: IO Window closes when a process is done. Perhaps "Process Exited" in I/O could give the exit code.
#DONE: Add support for update of task list on save.
#DONE: Add a build.bat file
#DONE: Save as, followed by cancel complains of empty path.
#DONE: File->Open, no All Files... filter (or similar) --> Added C# as acceptable file type.
#DONE: Preserve tabs instead of replacing w/ 4 spaces
#TODO: GAC Wrapper: http://blogs.msdn.com/b/junfeng/archive/2004/09/14/229649.aspx
#TODO: ReflectionOnlyLoad for Auto Complete logic: http://msdn.microsoft.com/en-us/library/0et80c7k(v=VS.80).aspx
#
#var _properties as PropertyGrid #
var _tasks as Tasks
#var _toolStrip as ToolStrip #
var _menuStrip as QMainMenu #
var _menuFile as QMenuItem #
var _menuFileProject as QMenuItem
var _menuFileProjectSave as QMenuItem #
var _menuFileProjectSaveAs as QMenuItem #
var _menuFileProjectOpen as QMenuItem #
var _menuFileProjectNew as QMenuItem #
var _menuFileFile as QMenuItem
var _menuFileSave as QMenuItem #
var _menuFileSaveAs as QMenuItem #
var _menuFileQuit as QMenuItem #
var _menuFileClose as QMenuItem
var _menuFileOpen as QMenuItem #
var _menuFileNew as QMenuItem #
var _menuCompile as QMenuItem #
var _menuCompileBuild as QMenuItem #
var _menuCompileTest as QMenuItem #
var _menuCompileObjectExplorer as QMenuItem #
var _menuCompileRun as QMenuItem #
var _menuExperimental as QMenuItem
var _menuAddForm as QMenuItem
#var _contextMenu as QContextMenu
var _lblOut as Label
var _lblOutput as RichTextBox
var _bottomDock as QDockBar
var _rightDock as QDockBar
var _leftDock as QDockBar
var _ioWindow as QDockingWindow
var _projectTree as SolutionTree
#var _itemProperties as PropertyGrid
var _tabs as QTabControl #
var _tabTest as QTabPage #
var _tabConfig as QTabPage #
var _chkShowSpaces as CheckBox
var _chkShowEOL as CheckBox
var _chkHighlightCurrentRow as CheckBox
var _chkBracketMatching as CheckBox
var _chkEnableVirtualSpace as CheckBox
var _chkShowLineNumbers as CheckBox
var _chkConvertTabsToSpaces as CheckBox
var _cboCompileTarget as ComboBox
var _components as System.ComponentModel.IContainer? #
get _allEditors as TextEditorControl*
for tab in _tabs.controls
for ctrl in tab.controls
if ctrl.typeOf is TextEditorControl
yield ctrl to TextEditorControl
def _activeEditor as TextEditorControl?
if _tabs.controls.count == 0, return nil
if _tabs.activeTabPage == nil or _tabs.activeTabPage.controls.count == 0, return nil
return _tabs.activeTabPage.controls[0] to TextEditorControl?
#region test
cue init
base.init
.text = "Naja - Cobra IDE"
.width = 1000
.height = 800
.isMdiContainer = true
_components = System.ComponentModel.Container()
listen .formClosing, ref _formClosing
.initializeDockBars
.initializeTabs
#.initializeToolbar
.initializeMenus
#endregion
def dispose(disposing as bool) is override, protected
if disposing and _components is not nil
_components.dispose
base.dispose(disposing)
def initializeDockBars
_rightDock = QDockBar(parent=this,name="_rightDock",dock=DockStyle.Right)
projectWindow = QDockingWindow(name="projectWindow",dock=DockStyle.Top,width=200,height=400,text="Solution Explorer")
projectWindow.owner = this
_projectTree = SolutionTree(parent=projectWindow,dock=DockStyle.Fill,name="_projectTree")
listen _projectTree.doubleClick, ref .solutionDoubleClicked
_projectTree.solution = Solution()
pj = _projectTree.addProject(Project(name="New Project"))
_projectTree.addReference("mscorlib.dll",pj)
_projectTree.addReference("System.dll",pj)
_projectTree.addReference("Cobra.Lang.dll",pj)
_projectTree.addFile("New File",pj)
#propertiesWindow = QDockingWindow(name="propertiesWindow",dock=DockStyle.Bottom,width=200, text="Properties")
#propertiesWindow.canDockOnOtherControlBottom = true
#propertiesWindow.owner = this
#propertiesWindow.dockWindow(_rightDock)
projectWindow.dockWindow(_rightDock)
#projectWindow.dockWindow(propertiesWindow,QDockOrientation.Vertical,false)
#_itemProperties = PropertyGrid(parent=propertiesWindow,dock=DockStyle.Fill,name="_itemProperties")
#_itemProperties.selectedObject = projectWindow
_leftDock = QDockBar(parent=this,name="_leftDock",dock=DockStyle.Left)
_bottomDock = QDockBar(parent=this,name="_bottomDock",dock=DockStyle.Bottom)
_tasks =tasks = Tasks(name="tasks", dock=DockStyle.Fill, dock=DockStyle.Fill,height=200,text="Tasks")
listen tasks.TaskSelected, ref .taskSelected
tasks.owner = this
tasks.dockWindow(_bottomDock)
_ioWindow = ioWindow = QDockingWindow(name="IO",dock=DockStyle.Fill,height=200,text="I/O")
ioWindow.owner = this
ioWindow.dockWindow(tasks,QDockOrientation.Tabbed,false)
ioWindow.slideWindow(true,false)
_lblOutput = RichTextBox(parent=ioWindow, dock=DockStyle.Fill,name="_lblOutput",autoSize=false,backColor=Color.white, borderStyle = System.Windows.Forms.BorderStyle.FixedSingle, height=400,readOnly=true)
_lblOut = Label(parent=ioWindow, dock=DockStyle.Top,name="_lblOut",autoSize=true,text="Output:")
def taskSelected(fileName as String, lineNumber as int)
#make sure we've got the full path
#TODO: Handle scenario of multiple results. For now, it just assumes a single match.
fileNodes = _projectTree.findNodes(fileName)
if fileNodes.count ==0, return
fileNode = fileNodes[0]
fileName = fileNode.tag.toString
#TODO: Check if the file is already open
editor = .open(fileName)
editor.activeTextAreaControl.textArea.scrollTo(lineNumber)
def solutionDoubleClicked(sender, e as System.EventArgs)
if _projectTree.selectedNode == nil or _projectTree.selectedNode.tag == nil
return
if not System.IO.File.exists(_projectTree.selectedNode.tag.toString)
return
.open(_projectTree.selectedNode.tag.toString)
def _addNewEditor(title as String) as TextEditorControl
tabEditor = QTabPage(text=title)
_tabs.controls.add(tabEditor)
editor = TextEditorControl(parent=tabEditor, dock=DockStyle.Fill,name="editor",width=480)
editor.document.foldingManager.foldingStrategy = CobraFoldingStrategy()
editor.document.foldingManager.updateFoldings(nil,nil)
editor.fileName = "untitled.cobra"
_tabs.activeTabPage = tabEditor
listen editor.document.documentChanged, ref _documentChanged
listen tabEditor.enter, ref _documentTabEntered
listen editor.activeTextAreaControl.textArea.keyDown, ref _keyDown
if _editorSettings is nil
_editorSettings = editor.textEditorProperties
#_editorSettings.convertTabsToSpaces = true
.onSettingsChanged
else
editor.textEditorProperties = _editorSettings
return editor
var _settingsChanging = false
def onSettingsChanged
if _editorSettings is nil, return
if _settingsChanging, return
_settingsChanging = true
_chkShowSpaces.checked = _editorSettings.showSpaces
_chkShowEOL.checked = _editorSettings.showEOLMarker
_chkHighlightCurrentRow.checked = _editorSettings.lineViewerStyle == LineViewerStyle.FullRow
_chkBracketMatching.checked = if(_editorSettings.bracketMatchingStyle == BracketMatchingStyle.After, true,false)
_chkEnableVirtualSpace.checked = _editorSettings.allowCaretBeyondEOL
_chkShowLineNumbers.checked = _editorSettings.showLineNumbers
_chkConvertTabsToSpaces.checked = _editorSettings.convertTabsToSpaces
_settingsChanging = false
def _keyDown(sender, e as KeyEventArgs)
#simple logic to just require Ctrl + <space>
if not e.control, return
if not e.keyCode <> Keys.Space, return
e.suppressKeyPress = true
_showIntellisense(e.keyValue to char)
def _showIntellisense(value as char)
#completionDataProvider = CodeCompletionDataProvider()
pass #TODO : ADD INTELLISENSE
/#
ICompletionDataProvider completionDataProvider = new CodeCompletionDataProvider()
CodeCompletionWindow window = CodeCompletionWindow.ShowCompletionWindow(this, ActiveEditor, "",
completionDataProvider, value)
#/
def _documentTabEntered(sender, e as EventArgs)
page = sender to QTabPage
page.controls[0].focus
def _documentChanged(sender, e as DocumentEventArgs)
.setModifiedFlag(_activeEditor,true)
def initializeTabs
qFillDock = Form(dock=DockStyle.Fill,name="qFillDock")
qFillDock.mdiParent = this
qFillDock.windowState = FormWindowState.Maximized
qFillDock.show
_tabs = QTabControl(parent=qFillDock,dock=DockStyle.Fill, name="_tabs")
_tabTest = QTabPage(text="Test")
_tabConfig = QTabPage(text="Config")
_chkShowSpaces = CheckBox(parent=_tabConfig,top=10,width=200,text="Show Whitespace",name="ShowSpaces")
listen _chkShowSpaces.checkedChanged, ref _checkedSettingChanged
_chkShowEOL = CheckBox(parent=_tabConfig,top=35,width=200,text="Show New Lines", name="ShowEOL")
listen _chkShowEOL.checkedChanged, ref _checkedSettingChanged
_chkHighlightCurrentRow = CheckBox(parent=_tabConfig,top=60,width=200,text="Highlight Current Row",name="HighlightCurrentRow")
listen _chkHighlightCurrentRow.checkedChanged, ref _checkedSettingChanged
_chkBracketMatching = CheckBox(parent=_tabConfig,top=85,width=200,text="Bracket Matching",name="BracketMatching")
listen _chkBracketMatching.checkedChanged, ref _checkedSettingChanged
_chkEnableVirtualSpace = CheckBox(parent=_tabConfig,top=110,width=200,text="Enable Virtual Space",name="EnableVirtualSpace")
listen _chkEnableVirtualSpace.checkedChanged, ref _checkedSettingChanged
_chkShowLineNumbers = CheckBox(parent=_tabConfig,top=135,width=200,text="Show Line Numbers",name="ShowLineNumbers")
listen _chkShowLineNumbers.checkedChanged, ref _checkedSettingChanged
_chkConvertTabsToSpaces = CheckBox(parent=_tabConfig,top=160,width=200,text="Convert Tabs to Spaces",name="ConvertTabsToSpaces")
listen _chkConvertTabsToSpaces.checkedChanged, ref _checkedSettingChanged
lblCompileTarget=Label(parent=_tabConfig,top=185,autoSize=true,text="Compile Target:",name="lblCompileTarget")
_cboCompileTarget = ComboBox(parent=_tabConfig, top=185,width=150, left=lblCompileTarget.left + lblCompileTarget.width + 5,name="_cboCompileTarget")
_cboCompileTarget.items.addRange(@["WinEXE","EXE","Lib","Module"])
_cboCompileTarget.selectedIndex = 0
#_properties = PropertyGrid(parent=_tabConfig,dock=DockStyle.Right,name="_properties",selectedObject=_projectTree,width=300)
#_addNewEditor("New file")
_tabs.controls.add(_tabTest)
_tabs.controls.add(_tabConfig)
def _checkedSettingChanged(sender, e as EventArgs)
if _settingsChanging, return
chk = sender to CheckBox
editor as TextEditorControl?
for editor in _allEditors
break #just want AN editor, don't care which, they share the same properties.
if editor is nil, return
branch chk.name
on "ShowSpaces"
editor.showSpaces = editor.showTabs = not editor.showSpaces
on "ShowEOL"
editor.showEOLMarkers = not editor.showEOLMarkers
on "HighlightCurrentRow"
editor.lineViewerStyle = if(editor.lineViewerStyle==LineViewerStyle.None,LineViewerStyle.FullRow,LineViewerStyle.None)
on "BracketMatching"
editor.bracketMatchingStyle = if(editor.bracketMatchingStyle == BracketMatchingStyle.After, BracketMatchingStyle.Before,BracketMatchingStyle.After)
on "EnableVirtualSpace"
editor.allowCaretBeyondEOL = not editor.allowCaretBeyondEOL
on "ShowLineNumbers"
editor.showLineNumbers = not editor.showLineNumbers
on "ConvertTabsToSpaces"
editor.convertTabsToSpaces = not editor.convertTabsToSpaces
else
print "Unknown checkbox name: [chk.name]"
return
.onSettingsChanged
def initializeToolbar
pass #_toolStrip = ToolStrip(parent=this,name="_toolStrip",dock=DockStyle.Top)
def initializeMenus
_menuStrip = QMainMenu(parent=this,name="_menuStrip",dock=DockStyle.Top)
#File Menu
_menuFile = QMenuItem(itemName="_menuFile",title="File")
_menuFileFile = QMenuItem(itemName="_menuFileFile",title="File")
_menuFileProject = QMenuItem(itemName="_menuFileProject",title="Project")
_menuFileProjectSave = QMenuItem(itemName="_menuFileProjectSave",title="Save")
listen _menuFileProjectSave.menuItemActivated, ref .menuFileProjectSave_Click
_menuFileProjectSaveAs = QMenuItem(itemName="_menuFileProjectSaveAs",title="Save As")
listen _menuFileProjectSaveAs.menuItemActivated, ref .menuFileProjectSaveAs_Click
_menuFileProjectOpen = QMenuItem(itemName="_menuFileProjectOpen",title="Open")
listen _menuFileProjectOpen.menuItemActivated, ref .menuFileProjectOpen_Click
_menuFileProjectNew = QMenuItem(itemName="_menuFileProjectNew",title="New")
listen _menuFileProjectNew.menuItemActivated, ref .menuFileProjectNew_Click
_menuFileQuit = QMenuItem(itemName="_menuFileQuit",title="&Quit",shortcut=Shortcut.CtrlQ)
listen _menuFileQuit.menuItemActivated, ref .menuQuit_Click
_menuFileClose = QMenuItem(itemName="_menuFileClose",title="C&lose",shortcut=Shortcut.CtrlW)
listen _menuFileClose.menuItemActivated, ref .menuClose_Click
_menuFileOpen = QMenuItem(itemName="_menuFileOpen",title="&Open",shortcut=Shortcut.CtrlO)
listen _menuFileOpen.menuItemActivated, ref .menuOpen_Click
_menuFileNew = QMenuItem(itemName="_menuFileNew", title="&New",shortcut=Shortcut.CtrlN)
listen _menuFileNew.menuItemActivated, ref .menuNew_Click
_menuFileSaveAs = QMenuItem(itemName="_menuFileSaveAs", title="Save &As",shortcut=Shortcut.CtrlShiftS)
listen _menuFileSaveAs.menuItemActivated, ref .menuSaveAs_Click
_menuFileSave = QMenuItem(itemName="_menuFileSave", title="&Save",shortcut=Shortcut.CtrlS)
listen _menuFileSave.menuItemActivated, ref .menuSave_Click
_menuFileProject.menuItems.add(_menuFileProjectNew)
_menuFileProject.menuItems.add(_menuFileProjectOpen)
_menuFileProject.menuItems.add(_menuFileProjectSave)
_menuFileProject.menuItems.add(_menuFileProjectSaveAs)
_menuFileFile.menuItems.add(_menuFileNew)
_menuFileFile.menuItems.add(_menuFileOpen)
_menuFileFile.menuItems.add(_menuFileSave)
_menuFileFile.menuItems.add(_menuFileSaveAs)
_menuFile.menuItems.add(_menuFileProject)
_menuFile.menuItems.add(_menuFileFile)
_menuFile.menuItems.add(_menuFileQuit)
##################################################################
#Edit Menu
menuEdit = QMenuItem(itemName="_menuEdit",title="Edit")
menuEditCut = QMenuItem(itemName="_menuEditCut",title="Cut",shortcut=Shortcut.CtrlX)
listen menuEditCut.menuItemActivated, ref .menuEditCut_Click
menuEditCopy = QMenuItem(itemName="_menuEditCopy",title="Copy",shortcut=Shortcut.CtrlC)
listen menuEditCopy.menuItemActivated, ref .menuEditCopy_Click
menuEditPaste = QMenuItem(itemName="_menuEditPaste",title="Paste",shortcut=Shortcut.CtrlV)
listen menuEditPaste.menuItemActivated, ref .menuEditPaste_Click
menuEditDelete = QMenuItem(itemName="_menuEditDelete",title="Delete")
listen menuEditDelete.menuItemActivated, ref .menuEditDelete_Click
menuEditFind = QMenuItem(itemName="_menuEditFind",title="Find",shortcut=Shortcut.CtrlF)
listen menuEditFind.menuItemActivated, ref .menuEditFind_Click
menuEditReplace = QMenuItem(itemName="_menuEditReplace",title="Replace",shortcut=Shortcut.CtrlH)
listen menuEditReplace.menuItemActivated, ref .menuEditReplace_Click
menuEditFindAgain = QMenuItem(itemName="_menuEditFindAgain",title="Find Again",shortcut=Shortcut.F3)
listen menuEditFindAgain.menuItemActivated, ref .menuEditFindAgain_Click
menuEditFindAgainReverse = QMenuItem(itemName="_menuEditFindAgainReverse",title="Find Again Reverse")
listen menuEditFindAgainReverse.menuItemActivated, ref .menuEditFindAgainReverse_Click
menuEditFindAndReplace = QMenuItem(itemName="_menuEditFindAndReplace",title="Find And Replace")
menuEditFindAndReplace.menuItems.add(menuEditFind)
menuEditFindAndReplace.menuItems.add(menuEditReplace)
menuEditFindAndReplace.menuItems.add(menuEditFindAgain)
menuEditFindAndReplace.menuItems.add(menuEditFindAgainReverse)
menuEditToggleBookmark = QMenuItem(itemName="_menuEditToggleBookmark",title="Toggle Bookmark")
listen menuEditToggleBookmark.menuItemActivated, ref .menuEditToggleBookmark_Click
menuEditGoToNextBookmark = QMenuItem(itemName="_menuEditGoToNextBookmark",title="Go To Next Bookmark")
listen menuEditGoToNextBookmark.menuItemActivated, ref .menuEditGoToNextBookmark_Click
menuEditGoToPrevBookmark = QMenuItem(itemName="_menuEditGoToPreviousBookmark",title="Go To Previous Bookmark")
listen menuEditGoToPrevBookmark.menuItemActivated, ref .menuEditGoToPrevBookmark_Click
menuEditBooksmarks = QMenuItem(itemName="_menuEditBookmarks",title="Bookmarks")
menuEditBooksmarks.menuItems.add(menuEditToggleBookmark)
menuEditBooksmarks.menuItems.add(menuEditGoToNextBookmark)
menuEditBooksmarks.menuItems.add(menuEditGoToPrevBookmark)
menuEdit.menuItems.add(menuEditCut)
menuEdit.menuItems.add(menuEditCopy)
menuEdit.menuItems.add(menuEditPaste)
menuEdit.menuItems.add(menuEditDelete)
menuEdit.menuItems.add(menuEditFindAndReplace)
menuEdit.menuItems.add(menuEditBooksmarks)
#####################################################################
#Compile Menu
_menuCompile = QMenuItem(itemName="_menuCompile",title="Compile")
listen _menuCompile.menuItemActivated, ref .menuCompile_Click
_menuCompileBuild = QMenuItem(itemName="_menuCompileBuild",title="&Build",shortcut=Shortcut.CtrlB)
listen _menuCompileBuild.menuItemActivated, ref .menuCompileBuild_Click
_menuCompileTest = QMenuItem(itemName="_menuCompileTest",title="&Test",shortcut=Shortcut.CtrlT)
listen _menuCompileTest.menuItemActivated, ref .menuCompileTest_Click
_menuCompileObjectExplorer = QMenuItem(itemName="_menuCompileObjectExplorer",title="Object &Explorer",shortcut=Shortcut.CtrlE)
listen _menuCompileObjectExplorer.menuItemActivated, ref .menuCompileObjectExplorer_Click
_menuCompileRun = QMenuItem(itemName="_menuCompileRun",title="&Run",shortcut=Shortcut.F5)
listen _menuCompileRun.menuItemActivated, ref .menuCompileRun_Click
_menuCompile.menuItems.add(_menuCompileBuild)
_menuCompile.menuItems.add(_menuCompileTest)
_menuCompile.menuItems.add(_menuCompileObjectExplorer)
_menuCompile.menuItems.add(_menuCompileRun)
###############################################################
#Experimental Menu
_menuExperimental = QMenuItem(itemName="_menuExperimental",title="Experimental")
_menuAddForm = QMenuItem(itemName="_menuAddForm",title="Generate Form")
_menuExperimental.menuItems.add(_menuAddForm)
listen _menuAddForm.menuItemActivated, ref .menuAddForm_Click
_menuStrip.menuItems.add(_menuFile)
_menuStrip.menuItems.add(menuEdit)
_menuStrip.menuItems.add(_menuCompile)
_menuStrip.menuItems.add(_menuExperimental)
def menuCompile_Click(sender, e as QMenuEventArgs)
_menuCompileBuild.enabled = _p is nil
_menuCompileTest.enabled = _p is nil
_menuCompileObjectExplorer.enabled = _p is nil
_menuCompileRun.enabled = _p is nil
def menuCompileBuild_Click(sender, e as QMenuEventArgs)
.runCobraProcess(" -c -turbo ")
def menuCompileTest_Click(sender, e as QMenuEventArgs)
.runCobraProcess(" -test ")
def menuCompileObjectExplorer_Click(sender, e as QMenuEventArgs)
.runCobraProcess("")
def menuCompileRun_Click(sender, e as QMenuEventArgs)
.runCobraProcess(" -d ")
/#
'name': 'target',
419 'synonyms': ['t'],
420 'description': 'Build a specific target.',
421 'type': 'menu',
422 'choices': ['exe', 'winexe', 'lib', 'module'],
423 'args': 'exe|winexe|lib|module',
424 'platforms': ['.net'],
#/
var _p as Process?
def runCobraProcess(args as String)
if _p is not nil, return #can't run a second compile process!
if _projectTree.solution is nil or _projectTree.solution.projects.count ==0, return
_p = p = Process()
_ioWindow.slideWindow(false,true)
_ioWindow.swapDockMode
p.startInfo.useShellExecute = false
p.startInfo.redirectStandardOutput = true
p.startInfo.redirectStandardError = true
p.startInfo.fileName = r"C:\Cobra\bin\cobra.bat"
p.enableRaisingEvents = true
fileArgs = ""
curProj = _projectTree.solution.projects[0]
if _activeEditor == nil or curProj.files.contains(_activeEditor.fileName)
fileArgs = String.join(" ", curProj.files.toArray) to !
refArgs = String.join(" -ref:",curProj.references.toArray) to !
if refArgs.length > 0
refArgs = " -ref:" + refArgs
fileArgs += refArgs
else
if _activeEditor.fileName == nil
if not .saveChanges(_activeEditor to !), return
fileArgs = _activeEditor.fileName to !
args += " -t:" + _cboCompileTarget.selectedItem.toString.toLower
p.startInfo.arguments = args + " " + fileArgs
System.IO.File.writeAllText(System.IO.Path.combine(System.IO.Path.getDirectoryName(_activeEditor.fileName),"build.bat"),p.startInfo.fileName + " " + p.startInfo.arguments)
.logIO(p.startInfo.fileName + " " + p.startInfo.arguments,Color.blue)
listen p.outputDataReceived, ref .outputDataReceived
listen p.errorDataReceived, ref .errorDataReceived
listen p.exited, ref .processExited
p.start
p.beginErrorReadLine
p.beginOutputReadLine
def outputDataReceived(sender, e as DataReceivedEventArgs)
.logIO(e.data,Color.black)
def errorDataReceived(sender, e as DataReceivedEventArgs)
.logIO(e.data,Color.maroon)
def logIO(msg as String?, color as Color)
if msg is nil, return
start = _lblOutput.textLength
_lblOutput.appendText(msg)
enda = _lblOutput.textLength
_lblOutput.select(start,enda-start)
_lblOutput.selectionColor = color
_lblOutput.selectionLength=0
_lblOutput.appendText("\r\n")
_lblOutput.selectionLength = 0
_lblOutput.selectionStart = _lblOutput.textLength
_lblOutput.scrollToCaret
def processExited(sender, e as EventArgs)
.logIO("Process Exited\r\n",Color.black)
ignore _p.outputDataReceived, ref .outputDataReceived
ignore _p.errorDataReceived, ref .errorDataReceived
ignore _p.exited, ref .processExited
_ioWindow.swapDockMode
_ioWindow.slideWindow(true,true)
_p = nil
def menuFileProjectSave_Click(sender, e as QMenuEventArgs)
_projectTree.solution.save
.updateTasks
def menuFileProjectSaveAs_Click(sender, e as QMenuEventArgs)
_projectTree.solution.fileName = "" #force Save As
_projectTree.solution.save
var _reTODO = Regex("#\s*TODO:",RegexOptions(Compiled,IgnoreCase))
def menuFileProjectOpen_Click(sender, e as QMenuEventArgs)
try
_projectTree.solution = Solution.load(NajaUtils.promptForOpenFileName("Naja Solution files|*.najasln"))
.updateTasks
catch ex as Exception
MessageBox.show(ex.toString)
def updateTasks
_tasks.clearTasks
for p in _projectTree.solution.projects
for f in p.files
if not System.IO.File.exists(f), continue
lineNum = 0
for line in System.IO.File.readAllLines(f)
lineNum +=1
if not _reTODO.isMatch(line), continue
task = _reTODO.split(line)[1]
_tasks.addTask(task,"File:[System.IO.Path.getFileName(f)], Line:[lineNum]")
def menuFileProjectNew_Click(sender, e as QMenuEventArgs)
pass
def menuSaveAs_Click(sender, e as QMenuEventArgs)
if _activeEditor is not nil
.saveAsChanges(_activeEditor to !)
.updateTasks
def menuSave_Click(sender, e as QMenuEventArgs)
editor = _activeEditor
if editor is not nil
.saveChanges(editor)
.updateTasks
def menuNew_Click(sender, e as QMenuEventArgs)
_addNewEditor("New file")
def menuOpen_Click(sender, e as QMenuEventArgs)
fileName = NajaUtils.promptForOpenFileName
if fileName <> ""
.open(fileName)
def open(fileName as String) as TextEditorControl?
editor = .setEditorText(fileName)
if _activeEditor is not nil and _activeEditor.document.textLength and String.isNullOrEmpty(_activeEditor.fileName)
_removeTextEditor(_activeEditor to !)
return editor
def menuClose_Click(sender, e as QMenuEventArgs)
if _activeEditor is not nil
_removeTextEditor(_activeEditor to !)
def _removeTextEditor(editor as TextEditorControl)
_tabs.controls.remove(editor.parent)
def menuQuit_Click(sender, e as QMenuEventArgs)
.close
def _formClosing(sender, e as FormClosingEventArgs)
for editor in _allEditors
if .isModified(editor)
result = MessageBox.show("Save changes to [editor.fileName?'new file']?","Save?",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question)
if result == DialogResult.Cancel
e.cancel = true
else if result == DialogResult.Yes
if not .saveAsChanges(editor)
e.cancel = true
def setEditorText(fileName as String) as TextEditorControl?
editor = _addNewEditor("[System.IO.Path.getFileName(fileName)]")
try
editor.loadFile(fileName)
.setModifiedFlag(editor,false)
catch ex as Exception
MessageBox.show(ex.message,ex.typeOf.name)
_removeTextEditor(editor)
return nil
#editor.tag = fileName
editor.document.foldingManager.foldingStrategy = CobraFoldingStrategy()
editor.document.foldingManager.updateFoldings(nil,nil)
return editor
def isModified(editor as TextEditorControl) as bool
return editor.parent.text.endsWith("*")
def setModifiedFlag(editor as TextEditorControl?, flag as bool)
if editor is nil, return
isModified = .isModified(editor to !)
if isModified <> flag
p = editor.parent
if isModified
p.text = p.text.substring(0,p.text.length-1)
else
p.text +="*"
def saveChanges(editor as TextEditorControl) as bool
try
if String.isNullOrEmpty(editor.fileName)
return .saveAsChanges(editor)
editor.saveFile(editor.fileName)
.setModifiedFlag(editor,false)
return true
catch ex as Exception
MessageBox.show(ex.message,ex.typeOf.name)
return false
def saveAsChanges(editor as TextEditorControl) as bool
fileName = NajaUtils.promptForSaveAsFileName(editor.fileName?"")
if fileName.length <> 0 and fileName.trim <> ""
try
editor.saveFile(fileName)
editor.parent.text = Path.getFileName(editor.fileName)
.setModifiedFlag(editor,false)
editor.document.highlightingStrategy = HighlightingStrategyFactory.createHighlightingStrategyForFile(editor.fileName)
return true
catch ex as Exception
MessageBox.show(ex.message, ex.typeOf.name)
return false
#this following function / logic is 100% port from the TextEditorForm sample on CodeProject
#in fact the Editor Menu is pretty much a port of the TextEditorForm sample
def _doEditAction(editor as TextEditorControl?, action as ICSharpCode.TextEditor.Actions.IEditAction?)
if editor is nil or action is nil, return
area = editor.activeTextAreaControl.textArea
editor.beginUpdate
try
lock editor.document
action.execute(area)
if area.selectionManager.hasSomethingSelected and area.autoClearSelection
if area.document.textEditorProperties.documentSelectionMode == DocumentSelectionMode.Normal
area.selectionManager.clearSelection
finally
editor.endUpdate
area.caret.updateCaretPosition
def menuEditCut_Click(sender, e as QMenuEventArgs)
if _haveSelection
_doEditAction(_activeEditor,Actions.Cut())
def menuEditCopy_Click(sender, e as QMenuEventArgs)
if _haveSelection
_doEditAction(_activeEditor,Actions.Copy())
def menuEditPaste_Click(sender, e as QMenuEventArgs)
_doEditAction(_activeEditor,Actions.Paste())
def menuEditDelete_Click(sender, e as QMenuEventArgs)
if _haveSelection
_doEditAction(_activeEditor,Actions.Delete())
def _haveSelection as bool
return _activeEditor is not nil and _activeEditor.activeTextAreaControl.textArea.selectionManager.hasSomethingSelected
def menuEditFind_Click(sender, e as QMenuEventArgs)
if _activeEditor is nil, return
if _findForm.isDisposed, _findForm = FindAndReplaceForm()
_findForm.showFor(_activeEditor to !,false)
def menuEditReplace_Click(sender, e as QMenuEventArgs)
if _activeEditor is nil, return
if _findForm.isDisposed, _findForm = FindAndReplaceForm()
_findForm.showFor(_activeEditor to !,true)
def menuEditFindAgain_Click(sender, e as QMenuEventArgs)
if _activeEditor is nil, return
if _findForm.isDisposed, _findForm = FindAndReplaceForm()
_findForm.findNext(true,false,"Search text '[_findForm.lookFor]' not found.")
def menuEditFindAgainReverse_Click(sender, e as QMenuEventArgs)
if _activeEditor is nil, return
if _findForm.isDisposed, _findForm = FindAndReplaceForm()
_findForm.findNext(true,true,"Search text '[_findForm.lookFor]' not found.")
def menuEditToggleBookmark_Click(sender, e as QMenuEventArgs)
if _activeEditor is nil, return
_doEditAction(_activeEditor to !,Actions.ToggleBookmark())
_activeEditor.isIconBarVisible = _activeEditor.document.bookmarkManager.marks.count > 0
def menuEditGoToNextBookmark_Click(sender, e as QMenuEventArgs)
if _activeEditor is nil, return
_doEditAction(_activeEditor to !,Actions.GotoNextBookmark(do(bookmark as Bookmark)=true))
def menuEditGoToPrevBookmark_Click(sender, e as QMenuEventArgs)
if _activeEditor is nil, return
_doEditAction(_activeEditor to !,Actions.GotoPrevBookmark(do(bookmark as Bookmark)=true))
enum CompilerValue
NotSet
Set
HasValue
enum BackEnd
None
CLR
JVM
ObjC
class CodeCompletionDataProvider implements ICompletionDataProvider is public
var _imageList as ImageList
pro imageList as ImageList
get
return _imageList
set
_imageList = value
get preSelection as String?
return nil
get defaultIndex as int
return -1
cue init
base.init
_imageList = ImageList()
def processKey(key as char) as CompletionDataProviderKeyResult
if key.isLetterOrDigit or key == c'_'
return CompletionDataProviderKeyResult.NormalKey
return CompletionDataProviderKeyResult.InsertionKey
def insertAction(data as ICompletionData, textArea as TextArea, insertionOffset as int, key as char) as bool
textArea.caret.position = textArea.document.offsetToPosition(Math.min(insertionOffset, textArea.document.textLength))
return data.insertAction(textArea,key)
def generateCompletionData(fileName as String, textArea as TextArea, charType as char) as ICompletionData[]
result = List<of ICompletionData>()
return result.toArray
class Program
var errorFile as String? is shared
def main is shared
has STAThread
Application.enableVisualStyles
Application.setCompatibleTextRenderingDefault(false)
Application.setUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
.errorFile = System.IO.Path.combine(Application.startupPath,"Naja.Errors.log")
listen Application.threadException, ref .application_threadException
listen AppDomain.currentDomain.unhandledException, ref .currentDomain_unhandledException
Application.run(Naja())
def application_threadException(sender, e as System.Threading.ThreadExceptionEventArgs) is shared
.log(e.exception to !)
def currentDomain_unhandledException(sender, e as UnhandledExceptionEventArgs) is shared
.log(e.exceptionObject to Exception)
def log(ex as Exception) is shared
System.IO.File.appendAllText(.errorFile,ex.toString)