/
MainForm.cs
executable file
·3621 lines (3374 loc) · 139 KB
/
MainForm.cs
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
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using NETXP.Controls.Docking;
using NETXP.Controls.TaskPane;
using NETXP.Controls.Bars;
using QWEditor;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Reflection;
using System.Diagnostics;
using System.Threading;
namespace MegaIDE
{
/// <summary>
/// MainForm Class . Contains the IDE code and the file functions(e.g. Open,Close,Save etc) . Links with the ProjectManager Class for complete implementation.
/// </summary>
public sealed class MainFormClass : System.Windows.Forms.Form
{
#region Singleton Implementation
private static MainFormClass mainForm;
/// <summary>
/// Gets the singleton form variable.
/// </summary>
public static MainFormClass MainForm
{
get
{
return mainForm;
}
}
/// <summary>
/// Sets the singleton form variable.
/// </summary>
public static MainFormClass MainFormInitializer
{
set
{
mainForm = value;
}
}
#endregion
#region Form Variables
private NETXP.Controls.Bars.CommandBarManager commandBarManager;
private NETXP.Controls.Bars.CommandBarDock commandBarDockLeft;
private NETXP.Controls.Bars.CommandBarDock commandBarDockRight;
private NETXP.Controls.Bars.CommandBarDock commandBarDockTop;
private NETXP.Controls.Bars.CommandBarDock commandBarDockBottom;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem1;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem2;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem3;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem4;
private NETXP.Controls.Bars.CommandBarButtonItem fileMenu;
private NETXP.Controls.Bars.CommandBarButtonItem editMenu;
private NETXP.Controls.Bars.CommandBarButtonItem viewMenu;
private NETXP.Controls.Bars.CommandBarButtonItem optionsMenu;
private NETXP.Controls.Bars.CommandBarButtonItem aboutMenu;
private NETXP.Controls.Bars.StatusBar statusBar;
private NETXP.Controls.Docking.DockingManagerExtender dockingManagerExtender;
private NETXP.Controls.Bars.CommandBarButtonItem viewToolBox;
private System.ComponentModel.IContainer components;
private NETXP.Controls.Bars.CommandBarButtonItem viewResetLayout;
private RichTextBoxEx outputWindow;
private NETXP.Controls.Bars.ListBar toolBox;
private NETXP.Controls.Bars.CommandBarButtonItem viewOutputWindow;
private NETXP.Controls.Bars.CommandBarButtonItem viewPropertiesWindow;
private System.Windows.Forms.Panel dockingPanel;
private NETXP.Controls.Bars.CommandBarButtonItem viewProjectFiles;
private System.Windows.Forms.ImageList treeImageList;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem5;
private System.Windows.Forms.PropertyGrid propertyGrid;
private System.Windows.Forms.Panel propertiesWindow;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarBuild;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarProgram;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarSimulate;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarOpen;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarSave;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarSaveAll;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarCut;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarPaste;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarCopy;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarRedo;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarUndo;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarSearch;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarReplace;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarQuickSearch;
private NETXP.Controls.Bars.CommandBar buildToolbar;
private NETXP.Controls.Bars.CommandBarDock toolbarHolder;
private NETXP.Controls.Bars.CommandBar menuBar;
private NETXP.Controls.Bars.CommandBarButtonItem viewToolbars;
private NETXP.Controls.Bars.CommandBarButtonItem viewFileToolbar;
private NETXP.Controls.Bars.CommandBarButtonItem viewBuildToolbar;
private NETXP.Controls.Bars.CommandBar fileToolbar;
private NETXP.Controls.Docking.TabbedGroups tabbedGroups;
private QWEditor.Parser parser;
private System.Windows.Forms.ContextMenu tabContextMenu;
private NETXP.Components.Extenders.MenuImageExtender contextMenuImageExtender;
private NETXP.Controls.Bars.CommandBarButtonItem editRedo;
private NETXP.Controls.Bars.CommandBarButtonItem editUndo;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem6;
private NETXP.Controls.Bars.CommandBarButtonItem editCut;
private NETXP.Controls.Bars.CommandBarButtonItem editCopy;
private NETXP.Controls.Bars.CommandBarButtonItem editPaste;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem7;
private NETXP.Controls.Bars.CommandBarButtonItem editFind;
private NETXP.Controls.Bars.CommandBarButtonItem editReplace;
private NETXP.Controls.Bars.CommandBarButtonItem editGotoLine;
private NETXP.Controls.Bars.CommandBarButtonItem editSelectAll;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem9;
private NETXP.Controls.Docking.TabGroupNode tabNode;
private NETXP.Controls.Bars.CommandBarButtonItem filePageSetup;
private NETXP.Controls.Bars.CommandBarButtonItem filePrint;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem8;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem10;
private NETXP.Controls.Bars.CommandBarButtonItem fileExit;
private NETXP.Controls.Bars.CommandBarButtonItem fileNew;
private NETXP.Controls.Bars.CommandBarButtonItem fileOpen;
private NETXP.Controls.Bars.CommandBarButtonItem fileClose;
private NETXP.Controls.Bars.CommandBarButtonItem fileNewProject;
private NETXP.Controls.Bars.CommandBarButtonItem fileNewFile;
private NETXP.Controls.Bars.CommandBarButtonItem fileOpenProject;
private NETXP.Controls.Bars.CommandBarButtonItem fileOpenFile;
private System.Windows.Forms.OpenFileDialog openDialog;
private System.Windows.Forms.SaveFileDialog saveDialog;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarOpenFile;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarOpenProject;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarNew;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarNewProject;
private NETXP.Controls.Bars.CommandBarButtonItem toolBarNewFile;
private NETXP.Controls.Bars.CommandBarButtonItem fileSave;
private NETXP.Controls.Bars.CommandBarButtonItem fileSaveAll;
private NETXP.Controls.Bars.CommandBarButtonItem fileSaveAs;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem11;
private NETXP.Controls.Bars.CommandBarButtonItem fileRecentFiles;
private NETXP.Controls.Bars.CommandBarButtonItem fileRecentProjects;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem12;
private System.Windows.Forms.ComboBox propertiesComboBox;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarSaveFile;
private NETXP.Controls.Bars.CommandBarButtonItem toolBarSaveProject;
private NETXP.Controls.Bars.CommandBarButtonItem projectMenu;
private NETXP.Controls.Bars.CommandBarButtonItem projectAddNewFile;
private NETXP.Controls.Bars.CommandBarButtonItem projectAddExistingFile;
private NETXP.Controls.Bars.CommandBarButtonItem projectAddNewFolder;
private NETXP.Controls.Bars.CommandBarButtonItem projectCloseProject;
private NETXP.Controls.Bars.CommandBarButtonItem projectOptions;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem13;
private NETXP.Controls.Bars.CommandBarButtonItem toolsEditorOptions;
private NETXP.Controls.Bars.CommandBarButtonItem projectBuild;
private NETXP.Controls.Bars.CommandBarButtonItem projectProgram;
private NETXP.Controls.Bars.CommandBarButtonItem projectSimulate;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem14;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem15;
private System.Windows.Forms.MenuItem tabContextMenuUndo;
private System.Windows.Forms.MenuItem tabContextMenuRedo;
private System.Windows.Forms.MenuItem tabContextMenuCut;
private System.Windows.Forms.MenuItem tabContextMenuCopy;
private System.Windows.Forms.MenuItem tabContextMenuPaste;
private System.Windows.Forms.MenuItem tabContextMenuGoto;
private System.Windows.Forms.MenuItem tabContextMenuSetup;
private System.Windows.Forms.MenuItem tabContextMenuPrint;
private System.Windows.Forms.MenuItem menuSeperator1;
private System.Windows.Forms.MenuItem menuSeperator2;
private System.Windows.Forms.MenuItem menuSeperator3;
private System.Windows.Forms.ToolTip toolBoxToolTip;
private NETXP.Controls.XPButton errorStatusBarPanel;
private NETXP.Controls.XPButton warningStatusBarPanel;
private ErrorListView errorList;
private bool showErrors;
private bool showWarnings;
private ArrayList tempErrorList;
#endregion
#region Project and File Variables
private QWEditor.SyntaxSettings globalSyntaxSettings;
private string appDirectory;
private NETXP.Controls.TreeViewEx projectFilesTree;
private NETXP.Controls.Bars.CommandBarButtonItem projectSaveProject;
private NETXP.Controls.Bars.CommandBarButtonItem viewErrorList;
private System.Windows.Forms.ComboBox toolbarQuickCombo;
private System.Windows.Forms.StatusBarPanel lncolStatusBarPanel;
private System.Windows.Forms.StatusBarPanel statusBarButtonsHolder;
private System.Windows.Forms.ContextMenu outputWindowContextMenu;
private System.Windows.Forms.MenuItem outputWindowClearMenuItem;
private System.Windows.Forms.MenuItem outputWindowCopyMenuItem;
private System.Windows.Forms.MenuItem menuItem1;
private NETXP.Controls.Bars.CommandBarLabelItem quickSearchComboHolder;
private NETXP.Controls.Bars.ProgressPanel statusBarProgressPanel;
private NETXP.Controls.Bars.CommandBarButtonItem aboutMegaIDE;
private NETXP.Controls.Bars.CommandBarSeparatorItem commandBarSeparatorItem16;
private NETXP.Controls.Bars.CommandBarButtonItem toolsResetEditorSettings;
private NETXP.Controls.Bars.CommandBarButtonItem toolsAutoComplete;
private NETXP.Controls.Bars.CommandBarButtonItem toolbarReset;
private bool isProjectOpen;
#endregion
#region Properties
/// <summary>
/// Sets the errors count in the status bar. Reviewed . To be changed after next version.
/// </summary>
public int Errors
{
set
{
if(value == 1)
{
errorStatusBarPanel.Text = "1 Error";
errorStatusBarPanel.Size = new Size(70,21);
warningStatusBarPanel.Location = new Point(76,2);
statusBarButtonsHolder.Width = 168;
}
else
{
string errorsNum = value.ToString();
errorStatusBarPanel.Size = new Size(75+(errorsNum.Length-1)*5,21);
warningStatusBarPanel.Location = new Point(errorStatusBarPanel.Size.Width+6,2);
statusBarButtonsHolder.Width = errorStatusBarPanel.Size.Width+warningStatusBarPanel.Width+6;
errorStatusBarPanel.Text = value.ToString()+" Errors";
}
}
get{return int.Parse(errorStatusBarPanel.Text.Split(' ')[0]);}
}
/// <summary>
/// Sets the warnings count in the status bar. Reviewed . To be changed after next version.
/// </summary>
public int Warnings
{
set
{
if(value == 1)
{
warningStatusBarPanel.Text = "1 Warning";
warningStatusBarPanel.Size = new Size(87,21);
statusBarButtonsHolder.Width = errorStatusBarPanel.Size.Width+93;
}
else
{
string warNum = value.ToString();
warningStatusBarPanel.Size = new Size(92+(warNum.Length-1)*5,21);
warningStatusBarPanel.Text = value.ToString()+" Warnings";
statusBarButtonsHolder.Width = errorStatusBarPanel.Size.Width+warningStatusBarPanel.Width+6;
}
}
get{return int.Parse(warningStatusBarPanel.Text.Split(' ')[0]);}
}
/// <summary>
/// Gets or Sets the
/// </summary>
public int PercentDone
{
get{return statusBarProgressPanel.Value;}
set{statusBarProgressPanel.Value = value;}
}
/// <summary>
/// Gets the application directory path.
/// </summary>
public string AppDirectory
{
get{return appDirectory;}
}
/// <summary>
/// Gets the treeview control associated with project tree.
/// </summary>
public NETXP.Controls.TreeViewEx ProjectFilesTree
{
get { return projectFilesTree;}
}
/// <summary>
/// Gets the error list listview control.
/// </summary>
public ErrorListView ErrorList
{
get{return errorList;}
}
/// <summary>
/// Gets the output window RichTextBox.
/// </summary>
public RichTextBoxEx OutputWindow
{
get{return outputWindow;}
}
/// <summary>
/// Gets or Sets the isProject open bool variable.
/// </summary>
public bool IsProjectOpen
{
get{return isProjectOpen;}
set
{
if(value == false)
{
foreach(CommandBarItem toolbarItem in buildToolbar.Items)
toolbarItem.Enabled=false;
projectMenu.Visible = false;
}
else
{
projectMenu.Visible = true;
foreach(CommandBarItem toolbarItem in buildToolbar.Items)
toolbarItem.Enabled=true;
}
isProjectOpen = value;
}
}
/// <summary>
/// Gets or Sets the property to display errors in Error List.
/// </summary>
public bool ShowErrors
{
get{return showErrors;}
}
/// <summary>
/// Gets the property to display warnings in Error List.
/// </summary>
public bool ShowWarnings
{
get{return showWarnings;}
}
/// <summary>
/// Stores the temporary objects of the errorList.
/// </summary>
public ArrayList TempErrorList
{
get{return tempErrorList;}
}
#endregion
#region File Operations
/// <summary>
/// Applies the syntax settings to all the open pages.
/// </summary>
private void ApplySyntaxSettings()
{
if(tabbedGroups.RootSequence.Count != 0)
{
foreach(NETXP.Controls.Docking.TabPage page in tabNode.TabPages)
{
globalSyntaxSettings.ApplyToEdit(page.Control as SyntaxEdit);
}
}
}
/// <summary>
/// Moves the cursor to particular line in specified file. Reviewed . To be changed after next version.
/// </summary>
/// <param name="fileName">
/// Path of the file.
/// </param>
/// <param name="lineNumber">
/// Line Number to go to.
/// </param>
public void GotoFileLine(string fileName,int lineNumber)
{
if(!System.IO.File.Exists(fileName))
{
MessageBox.Show(fileName+" does not exist!","MegaIDE",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Warning);
RecentDocuments.RemoveFromRecentFiles(fileName);
UpdateRecentDocumentsList();
return;
}
SyntaxEdit syntaxEdit;
// Search in already opened files.
if(tabbedGroups.RootSequence.Count != 0)
{
foreach(NETXP.Controls.Docking.TabPage selectedPage in tabNode.TabPages)
{
if(selectedPage.ToolTipText.Equals(fileName))
{
tabNode.TabControl.SelectedTab=selectedPage;
syntaxEdit=(selectedPage.Control as SyntaxEdit);
syntaxEdit.Source.MoveToLine(lineNumber-1);
syntaxEdit.LineSeparator.Options=QWEditor.SeparatorOptions.HighlightCurrentLine;
syntaxEdit.MouseDown+=new MouseEventHandler(SourceTabPage_MouseDown);
syntaxEdit.Refresh();
return;
}
}
}
// Create a new tab if file does not exist.
syntaxEdit=new SyntaxEdit();
// Loading syntax highlighter is the file is a source file.
if(Path.GetExtension(fileName).ToLower()==".c" || Path.GetExtension(fileName).ToLower()==".h")
syntaxEdit.Lexer=parser;
syntaxEdit.SourceStateChanged+=new NotifyEvent(syntaxEdit_SourceStateChanged);
// Code completion event handler declaration.
if(ProjectManagerClass.ProjectManager.GetFileNode(fileName) != null)
syntaxEdit.NeedCodeCompletion+=new CodeCompletionEvent(syntaxEdit_NeedCodeCompletion);
syntaxEdit.CodeCompletionHint.Images=treeImageList;
syntaxEdit.CodeCompletionBox.Images=treeImageList;
syntaxEdit.Selection.Options=QWEditor.SelectionOptions.UseColors;
syntaxEdit.Gutter.Options=QWEditor.GutterOptions.PaintLinesOnGutter;
syntaxEdit.Selection.InActiveBackColor=System.Drawing.Color.Yellow;
syntaxEdit.Selection.InActiveForeColor=System.Drawing.Color.Black;
syntaxEdit.Anchor=((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)| System.Windows.Forms.AnchorStyles.Left)| System.Windows.Forms.AnchorStyles.Right)));
globalSyntaxSettings.ApplyToEdit(syntaxEdit);
syntaxEdit.Scrolling.UpdateScroll();
syntaxEdit.ShowScrollHint(10);
syntaxEdit.ContextMenu=tabContextMenu;
syntaxEdit.Source.FileName=fileName;
syntaxEdit.Source.LoadFile(fileName);
// Creating new tab page
NETXP.Controls.Docking.TabPage newTabPage=new NETXP.Controls.Docking.TabPage(Path.GetFileName(fileName));
newTabPage.ToolTipText=fileName;
newTabPage.Control=syntaxEdit;
newTabPage.Tag=false; // false means file not modified
// Check for readonly file. To be reviewed and removed with next QWEditor version.
if((((byte)System.IO.File.GetAttributes(fileName))&7)>0)
{
syntaxEdit.Source.ReadOnly=true;
newTabPage.Title+="(Read Only)";
}
if(tabbedGroups.RootSequence.Count==0)
{
tabNode=tabbedGroups.RootSequence.AddNewNode();
tabNode.TabControl.SelectionChanged+=new EventHandler(TabControl_SelectionChanged);
}
tabNode.TabControl.SelectedIndex=tabNode.TabPages.Add(newTabPage);
// Update recent files list.
RecentDocuments.AddToRecentFiles(fileName);
UpdateRecentDocumentsList();
// Move to specified line.
syntaxEdit.Source.MoveToLine(lineNumber-1);
syntaxEdit.LineSeparator.Options=QWEditor.SeparatorOptions.HighlightCurrentLine;
syntaxEdit.MouseDown+=new MouseEventHandler(SourceTabPage_MouseDown);
syntaxEdit.Refresh();
}
/// <summary>
/// Creates a new tab displaying the text content of the specified file.
/// </summary>
/// <param name="fileName">
/// Path of the file.
/// </param>
public void OpenFile(string fileName)
{
//Check for file existence
if(!System.IO.File.Exists(fileName))
{
MessageBox.Show(fileName+" does not exist!","MegaIDE",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Warning);
RecentDocuments.RemoveFromRecentFiles(fileName);
UpdateRecentDocumentsList();
return;
}
SyntaxEdit syntaxEdit;
//Check if already open
if(tabbedGroups.RootSequence.Count != 0)
{
foreach(NETXP.Controls.Docking.TabPage selectedPage in tabNode.TabPages)
{
if(selectedPage.ToolTipText.ToLower().Equals(fileName.ToLower()))
{
tabNode.TabControl.SelectedTab=selectedPage;
syntaxEdit=(selectedPage.Control as SyntaxEdit);
syntaxEdit.Refresh();
/*if(!(bool)selectedPage.Tag)
{
syntaxEdit=(selectedPage.Control as SyntaxEdit);
syntaxEdit.Source.LoadFile(fileName);
syntaxEdit.Refresh();
}*/
return;
}
}
}
//Create a new tab
syntaxEdit=new SyntaxEdit();
// Loading syntax highlighter is the file is a source file.
if(Path.GetExtension(fileName).ToLower()==".c" || Path.GetExtension(fileName).ToLower()==".h")
syntaxEdit.Lexer=parser;
syntaxEdit.SourceStateChanged+=new NotifyEvent(syntaxEdit_SourceStateChanged);
// Code completion event handler declaration.
if(isProjectOpen && ProjectManagerClass.ProjectManager.GetFileNode(fileName) != null)
syntaxEdit.NeedCodeCompletion+=new CodeCompletionEvent(syntaxEdit_NeedCodeCompletion);
// Initialization of syntaxEdit
syntaxEdit.CodeCompletionHint.Images=treeImageList;
syntaxEdit.CodeCompletionBox.Images=treeImageList;
syntaxEdit.Selection.Options=QWEditor.SelectionOptions.UseColors;
syntaxEdit.Gutter.Options=QWEditor.GutterOptions.PaintLinesOnGutter;
syntaxEdit.Selection.InActiveBackColor=System.Drawing.Color.Yellow;
syntaxEdit.Selection.InActiveForeColor=System.Drawing.Color.Black;
syntaxEdit.Anchor=((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)| System.Windows.Forms.AnchorStyles.Left)| System.Windows.Forms.AnchorStyles.Right)));
globalSyntaxSettings.ApplyToEdit(syntaxEdit);
syntaxEdit.Scrolling.UpdateScroll();
syntaxEdit.ShowScrollHint(10);
syntaxEdit.ContextMenu=tabContextMenu;
syntaxEdit.Source.FileName=fileName;
syntaxEdit.Source.LoadFile(fileName);
// Creating new tab page
NETXP.Controls.Docking.TabPage newTabPage=new NETXP.Controls.Docking.TabPage(Path.GetFileName(fileName));
newTabPage.ToolTipText=fileName;
newTabPage.Control=syntaxEdit;
newTabPage.Tag=false; // false means file not modified
// Check for readonly file. To be reviewed and removed with next QWEditor version.
if((((byte)System.IO.File.GetAttributes(fileName))&7)>0)
{
syntaxEdit.Source.ReadOnly=true;
newTabPage.Title+="(Read Only)";
}
if(tabbedGroups.RootSequence.Count==0)
{
tabNode=tabbedGroups.RootSequence.AddNewNode();
tabNode.TabControl.SelectionChanged+=new EventHandler(TabControl_SelectionChanged);
}
tabNode.TabControl.SelectedIndex=tabNode.TabPages.Add(newTabPage);
// Update recent files list.
RecentDocuments.AddToRecentFiles(fileName);
UpdateRecentDocumentsList();
}
/// <summary>
/// Closes an open tab for a particular file.
/// </summary>
/// <param name="fileName">
/// Full path of the file.
/// </param>
public void CloseOpenTab(string fileName)
{
if(tabbedGroups.RootSequence.Count != 0)
{
NETXP.Controls.Docking.TabPageCollection tabPageCollection=new TabPageCollection();
foreach(NETXP.Controls.Docking.TabPage selectedTabPage in tabNode.TabPages)
if(selectedTabPage.ToolTipText.ToLower().Equals(fileName.ToLower()))
{
tabNode.TabPages.Remove(selectedTabPage);
break;
}
}
}
/// <summary>
/// Closes open tabs with files starting with a particular path(e.g folder).
/// </summary>
/// <param name="path">
/// Path of the folder.
/// </param>
public void CloseOpenTabs(string path)
{
if(tabbedGroups.RootSequence.Count != 0)
{
NETXP.Controls.Docking.TabPageCollection tabPageCollection=new TabPageCollection();
foreach(NETXP.Controls.Docking.TabPage selectedTabPage in tabNode.TabPages)
if(selectedTabPage.ToolTipText.ToLower().StartsWith(path.ToLower()))
{
tabPageCollection.Add(selectedTabPage);
}
foreach(NETXP.Controls.Docking.TabPage tabPage in tabPageCollection)
{
tabNode.TabPages.Remove(tabPage);
}
}
}
/// <summary>
/// Saves all the project files if the project is open.
/// </summary>
public void SaveProjectFiles()
{
if(tabbedGroups.RootSequence.Count != 0 && isProjectOpen)
{
foreach(NETXP.Controls.Docking.TabPage selectedTabPage in tabNode.TabPages)
{
if(ProjectManagerClass.ProjectManager.GetFileNode(selectedTabPage.ToolTipText) != null)
{
SaveFile(selectedTabPage);
}
}
}
}
/// <summary>
/// Closes all the tabs which have project files opened.
/// </summary>
public void CloseProjectFiles()
{
if(tabbedGroups.RootSequence.Count != 0)
{
NETXP.Controls.Docking.TabPageCollection tabPageCollection=new TabPageCollection();
foreach(NETXP.Controls.Docking.TabPage selectedTabPage in tabNode.TabPages)
{
if(ProjectManagerClass.ProjectManager.GetFileNode(selectedTabPage.ToolTipText) != null)
{
tabPageCollection.Add(selectedTabPage);
}
}
foreach(NETXP.Controls.Docking.TabPage selectedTabPage in tabPageCollection)
{
tabNode.TabPages.Remove(selectedTabPage);
}
}
}
/// <summary>
/// Gets for the tabs a list of unsaved project files.
/// </summary>
/// <returns>
/// Arraylist containing the path of the unsaved files.
/// </returns>
public ArrayList GetUnsavedProjectFiles()
{
ArrayList filesList=new ArrayList(4);
if(tabbedGroups.RootSequence.Count != 0 && isProjectOpen)
{
foreach(NETXP.Controls.Docking.TabPage selectedTabPage in tabNode.TabPages)
{
if(ProjectManagerClass.ProjectManager.GetFileNode(selectedTabPage.ToolTipText) != null)
if((bool)selectedTabPage.Tag)
filesList.Add(selectedTabPage.ToolTipText);
}
}
filesList.TrimToSize();
return filesList;
}
/// <summary>
/// Returns a list of all unsaved files currently opened.
/// </summary>
/// <returns>
/// Arraylist containing the paths of the unsaved files.
/// </returns>
public ArrayList GetUnsavedFiles()
{
ArrayList filesList=new ArrayList(4);
if(tabbedGroups.RootSequence.Count != 0)
{
foreach(NETXP.Controls.Docking.TabPage selectedTabPage in tabNode.TabPages)
{
if((bool)selectedTabPage.Tag)
filesList.Add(selectedTabPage.ToolTipText);
}
}
filesList.TrimToSize();
return filesList;
}
/// <summary>
/// Returns all the currently opened project files.
/// </summary>
/// <returns>
/// Arraylist containing the relative paths of the opened project files.
/// </returns>
public ArrayList GetOpenProjectFilesList()
{
ArrayList filesList=new ArrayList(4);
string openedFile="";
if(tabbedGroups.RootSequence.Count != 0)
{
foreach(NETXP.Controls.Docking.TabPage selectedTabPage in tabNode.TabPages)
{
TreeNode fileNode=ProjectManagerClass.ProjectManager.GetFileNode(selectedTabPage.ToolTipText);
if(fileNode != null)
{
string relativePath=fileNode.FullPath.Replace(projectFilesTree.Nodes[0].Nodes[0].FullPath+"\\","");
filesList.Add(relativePath);
if(tabNode.TabControl.SelectedTab==selectedTabPage)
openedFile=relativePath;
}
}
}
if(filesList.Count != 0 && openedFile.Length != 0)
filesList.Add(openedFile);
filesList.TrimToSize();
return filesList;
}
/// <summary>
/// Opens multiple files as specified.
/// </summary>
/// <param name="filesList">
/// List of file paths to be opened.
/// </param>
public void OpenFiles(ArrayList filesList)
{
foreach(string fileName in filesList)
OpenFile(fileName);
}
/// <summary>
/// Opens multiple project files as specified.
/// </summary>
/// <param name="projectFolder">
/// Project folder path.
/// </param>
/// <param name="filesList">
/// Relative paths of files in the project.
/// </param>
public void OpenProjectFiles(string projectFolder,ArrayList filesList)
{
foreach(string fileName in filesList)
OpenFile(projectFolder+"\\"+fileName);
}
/// <summary>
/// Renames an open tab .
/// </summary>
/// <param name="oldFileName">
/// Path containing old file name.
/// </param>
/// <param name="newFileName">
/// Path containing the new file name.
/// </param>
public void RenameTab(string oldFileName,string newFileName)
{
try
{
foreach(NETXP.Controls.Docking.TabPage selectedTabPage in tabNode.TabPages)
if(selectedTabPage.ToolTipText.Equals(oldFileName))
{
SyntaxEdit syntaxEdit=selectedTabPage.Control as SyntaxEdit;
selectedTabPage.Title=Path.GetFileName(newFileName);
syntaxEdit.Source.FileName=newFileName;
selectedTabPage.ToolTipText=newFileName;
if(((bool)selectedTabPage.Tag)==true)
selectedTabPage.Title+="*";
tabNode.TabControl.SelectedTab=selectedTabPage;
return;
}
}
catch{}
}
/// <summary>
/// Saves an opened file.
/// </summary>
/// <param name="fileName">
/// Path of the file.
/// </param>
public void SaveFile(string fileName)
{
if(tabbedGroups.RootSequence.Count != 0)
{
foreach(NETXP.Controls.Docking.TabPage selectedTabPage in tabNode.TabPages)
{
if(selectedTabPage.ToolTipText.ToLower()==fileName.ToLower())
{
SaveFile(selectedTabPage);
return;
}
}
}
}
/// <summary>
/// Shows the Save File As dialog and saves the file.
/// </summary>
/// <param name="fileName">
/// Path of the file.
/// </param>
public void SaveFileAs(string fileName)
{
string saveFilter="";
string fileExtension=Path.GetExtension(fileName);
if(fileExtension.Equals(".c"))
saveFilter="C Files (*.c)|*.c|";
else if(fileExtension.Equals(".h"))
saveFilter="Header Files (*.h)|*.h|";
else if(fileExtension.Equals(".txt"))
saveFilter="Text Files (*.txt)|*.txt|";
saveDialog.Filter=saveFilter+"All Files (*.*)|*.*";
saveDialog.Title="Save "+Path.GetFileName(fileName)+" As";
if(saveDialog.ShowDialog()==DialogResult.OK)
{
if(System.IO.File.Exists(saveDialog.FileName))
if((((byte)System.IO.File.GetAttributes(saveDialog.FileName))&7)>0)
{
MessageBox.Show("Cannot overwrite a system , hidden or read-only file !","MegaIDE",MessageBoxButtons.OK,MessageBoxIcon.Hand);
return;
}
try
{
File.Copy(fileName,saveDialog.FileName);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"MegaIDE",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
/// <summary>
/// Saves the file opened by a specified tab page.
/// </summary>
/// <param name="selectedTabPage">
/// Tabpage selected.
/// </param>
private void SaveFile(NETXP.Controls.Docking.TabPage selectedTabPage)
{
try
{
if((bool)selectedTabPage.Tag)
{
SyntaxEdit syntaxEdit=selectedTabPage.Control as SyntaxEdit;
if(syntaxEdit.Source.ReadOnly)
{
MessageBox.Show("Cannot overwrite a system , hidden or read-only file !","MegaIDE",MessageBoxButtons.OK,MessageBoxIcon.Hand);
return;
}
syntaxEdit.Source.SaveFile(syntaxEdit.Source.FileName);
selectedTabPage.Title=Path.GetFileName(syntaxEdit.Source.FileName);
selectedTabPage.Tag=false;
}
}
catch{}
}
/// <summary>
/// Shows the Save file As dialog before saving the file opened by the specified tab page.
/// </summary>
/// <param name="selectedTabPage">
/// Tabpage selected.
/// </param>
private void SaveFileAs(NETXP.Controls.Docking.TabPage selectedTabPage)
{
if(tabbedGroups.RootSequence.Count != 0)
{
SyntaxEdit syntaxEdit=selectedTabPage.Control as SyntaxEdit;
string currentFileName=syntaxEdit.Source.FileName;
string saveFilter="";
string fileExtension=Path.GetExtension(syntaxEdit.Source.FileName);
if(fileExtension.Equals(".c"))
saveFilter="C Files (*.c)|*.c|";
else if(fileExtension.Equals(".h"))
saveFilter="Header Files (*.h)|*.h|";
else if(fileExtension.Equals(".txt"))
saveFilter="Text Files (*.txt)|*.txt|";
saveDialog.Filter=saveFilter+"All Files (*.*)|*.*";
saveDialog.Title="Save "+Path.GetFileName(syntaxEdit.Source.FileName)+" As";
if(saveDialog.ShowDialog()==DialogResult.OK)
{
if(System.IO.File.Exists(saveDialog.FileName))
if((((byte)System.IO.File.GetAttributes(saveDialog.FileName))&7)>0)
{
MessageBox.Show("Cannot overwrite a system , hidden or read-only file !","MegaIDE",MessageBoxButtons.OK,MessageBoxIcon.Hand);
return;
}
if(syntaxEdit.Source.FileName != saveDialog.FileName)
{
RecentDocuments.AddToRecentFiles(saveDialog.FileName);
UpdateRecentDocumentsList();
}
syntaxEdit.Source.SaveFile(saveDialog.FileName);
selectedTabPage.Title=Path.GetFileName(saveDialog.FileName);
syntaxEdit.Source.FileName=saveDialog.FileName;
selectedTabPage.ToolTipText=saveDialog.FileName;
selectedTabPage.Tag=false;
}
}
}
#endregion
#region Form Functions
/// <summary>
/// Constructor without parameters.
/// </summary>
private MainFormClass()
{
//
// Required for Windows Form Designer support
//
WaitCallback callbackFunc = new WaitCallback(LoadSettings);
InitializeComponent();
FormLoad();
//Loader thread
ThreadPool.QueueUserWorkItem(callbackFunc);
//new MethodInvoker(LoadSettings).BeginInvoke(null,null);
Height=System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
Width=System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
// Initialization of the singleton variable
MainFormClass.MainFormInitializer=this;
}
/// <summary>
/// Constructor with parameters
/// </summary>
/// <param name="fileName">
/// File to open
/// </param>
private MainFormClass(string fileName)
{
//
// Required for Windows Form Designer support
//
WaitCallback callbackFunc = new WaitCallback(LoadSettings);
InitializeComponent();
FormLoad();
//LoadSettings(new object());
Height=System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
Width=System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
MainFormClass.MainFormInitializer=this;
ThreadPool.QueueUserWorkItem(callbackFunc,fileName);
//new MethodInvoker(LoadSettings).BeginInvoke(null,null);
//Opening the command line filepath.
/*if(Path.GetExtension(fileName).ToLower()==".mbp")
{
ProjectManagerClass.ProjectManager.Refresh();
ProjectManagerClass.ProjectManager.OpenProject(fileName);
}
else
{
OpenFile(fileName);
}*/
}
//TODO:Review
/// <summary>
/// Load the settings from the saved files.
/// </summary>
private void LoadSettings(object pathString)
{
RecentDocuments.LoadListFromRegistry();
UpdateRecentDocumentsList();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(GetType());
// parser
//
this.parser.Strings = null;
this.parser.ReadSchemeFromResource(typeof(MainFormClass), "parser.XmlScheme");
// Syntax Settings
globalSyntaxSettings=new QWEditor.SyntaxSettings();
if(System.IO.File.Exists(appDirectory+@"\Syntax.xml"))
{
globalSyntaxSettings.LoadFile(appDirectory+@"\Syntax.xml");
}
else
{
globalSyntaxSettings.AllowOutlining=false;
globalSyntaxSettings.ShowMargin=false;
globalSyntaxSettings.ScrollBars=RichTextBoxScrollBars.Both;
globalSyntaxSettings.WordWrap=false;
globalSyntaxSettings.GutterWidth=20;
}
if(pathString!=null)
{
string fileName = pathString as string;
//Opening the command line filepath.