-
Notifications
You must be signed in to change notification settings - Fork 11
/
EdSharp.cs
11758 lines (10380 loc) · 357 KB
/
EdSharp.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
//EdSharp 4.0
// May 30, 2017
//Copyright 2007 - 2017 by Jamal Mazrui
// GNU Lesser General Public License (LGPL)
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.ApplicationServices;
using Microsoft.VisualBasic.Compatibility.VB6;
using MyIO = Microsoft.VisualBasic.FileIO;
using Microsoft.VisualBasic.MyServices;
using Microsoft.Win32;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Windows.Forms;
using Tektosyne.NetMail ;
using Tektosyne.Win32Api;
[assembly: AssemblyTitle("EdSharp")]
[assembly: AssemblyProduct("EdSharp")]
[assembly: AssemblyVersion("4.0.*")]
[assembly: AssemblyDescription("EdSharp editor")]
[assembly: AssemblyCompany("EmpowermentZone.com")]
[assembly: AssemblyCopyright("Copyright 2007 - 2016 by Jamal Mazrui")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
namespace EdSharp {
public class App : WindowsFormsApplicationBase {
public static App Shell;
public static MdiFrame Frame;
public static string ProgramName;
public static string NetDir;
public static string ProgramDir;
public static string DataDir;
public static string DefaultIniFile;
public static string HotkeyIniFile;
public static string IniFile;
public static string IndentModeFile;
public static string TempFile;
public static List<string> TempFiles = new List<string>();
//public static object Word = null;
public static object Boo = null;
public static object JAWS = null;
public static object Wineyes = null;
public static bool WordCreated = false;
public static bool ExtraSpeech = true;
public static bool IndentChange = true;
public static bool CaptureOutput = false;
public static string SpeechLog;
public static string MatchChunk = @"\s+";
public static string MatchParagraph = @"\n(\s*\n)+\s*";
public static string MatchSentence = @"([.?!]\s+)|(" + MatchParagraph + ")";
public static Dictionary<string, int> BomDictionary = null;
[STAThread]
public static void Main(string[] cmdLineArgs) {
// Environment.SetEnvironmentVariable("EdSharpIndent", "", EnvironmentVariableTarget.User);
if (System.IO.File.Exists(App.IndentModeFile)) System.IO.File.Delete(App.IndentModeFile);
Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(true);
Application.SetCompatibleTextRenderingDefault(false);
Application.OleRequired();
Shell = new App();
Shell.Run(cmdLineArgs);
} // Main method
public App() {
base.IsSingleInstance = true;
/*
//this.IsSingleInstance = true;
base.IsSingleInstance = true;
App.ProgramName = GetAppName();
App.NetDir = RuntimeEnvironment.GetRuntimeDirectory();
// App.ProgramDir = GetProgramDir();
App.ProgramDir = GetProgramDir();
App.DataDir = GetDataDir();
App.TempFile = GetTempFile();
App.DefaultIniFile = GetDefaultIniFile();
App.HotkeyIniFile = Path.Combine(App.ProgramDir, "Hotkeys.ini");
App.IniFile = GetIniFile();
App.BomDictionary = Util.GetBomDictionary();
SetConfigurationValues();
App.SpeechLog = Path.Combine(App.DataDir, "Speech.log");
if (File.Exists(App.SpeechLog)) File.Delete(App.SpeechLog);
App.ExtraSpeech = (App.ReadOption("E&xtraSpeech", "Y").ToLower().Substring(0, 1) == "n") ? false : true;
InitNetSdk();
InitJFW();
*/
this.Shutdown += delegate(object o, EventArgs e) {
if (App.WordCreated) {
Util.Say("Exiting Microsoft Word");
COM.WordExit();
}
if (App.Boo != null) COM.Release(ref App.Boo);
if (App.JAWS != null) COM.Release(ref App.JAWS);
if (App.Wineyes != null) COM.Release(ref App.Wineyes);
if (System.IO.File.Exists(App.IndentModeFile)) System.IO.File.Delete(App.IndentModeFile);
foreach (string sFile in App.TempFiles) if (File.Exists(sFile)) File.Delete(sFile);
};
this.UnhandledException += delegate(object sender, Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs e) {
Exception ex = (Exception) e.Exception;
string sMessage = ex.Message;
sMessage += "\n\nStack trace:\n" + ex.StackTrace;
// sMessage += "\nExit EdSharp?\n\nStack trace:\n" + ex.StackTrace;
// e.ExitApplication = Dialog.Confirm("Confirm", "Unexpected event!\n" + sMessage + ".\nExit EdSharp?", "N") == "Y";
string[] aButtons = {"&Mail to Developer", "Copy to Clipboard", "Exit EdSharp"};
string sButton = Dialog.Choose("Unexpected Event", sMessage, aButtons, 0);
switch (sButton) {
case "&Mail to Developer" :
Util.Say("Please add steps to reproduce the problem, if possible.");
string sSubject = "EdSharp error: " + ex.Message;
KeyValuePair<string, string>[] aAddresses = new KeyValuePair<string, string>[1];
string sName = "Jamal Mazrui";
string sAddress = "jamal@EmpowermentZone.com";
aAddresses[0] = new KeyValuePair<String, String>(sName, sAddress);
try {
MapiMail.SendMail(sSubject, sMessage, aAddresses, null);
}
catch {
Util.MailMessage(sAddress, sSubject, sMessage);
}
break;
case "Copy to Clipboard" :
Clipboard.SetText(sMessage);
break;
case "Exit EdSharp" :
// Application.Exit();
e.ExitApplication = true;
return;
}
e.ExitApplication = false;
};
this.Startup += delegate(object sender, Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e) {
//this.IsSingleInstance = true;
// base.IsSingleInstance = true;
App.ProgramName = GetAppName();
App.NetDir = RuntimeEnvironment.GetRuntimeDirectory();
App.ProgramDir = GetProgramDir();
App.ProgramDir = GetProgramDir();
App.DataDir = GetDataDir();
App.TempFile = GetTempFile();
App.DefaultIniFile = GetDefaultIniFile();
App.HotkeyIniFile = Path.Combine(App.ProgramDir, "Hotkeys.ini");
App.IniFile = GetIniFile();
App.IndentModeFile = Path.Combine(App.DataDir, "IndentMode.tmp");
// IniFile = GetIniFile();
App.BomDictionary = Util.GetBomDictionary();
SetConfigurationValues();
App.SpeechLog = Path.Combine(App.DataDir, "Speech.log");
if (File.Exists(App.SpeechLog)) File.Delete(App.SpeechLog);
App.ExtraSpeech = (App.ReadOption("E&xtraSpeech", "Y").ToLower().Substring(0, 1) == "n") ? false : true;
App.IndentChange = App.ReadOption("E&xtraSpeech", "Y").Contains("-") ? false : true;
InitNetSdk();
InitJFW();
Frame = new MdiFrame();
this.MainForm = Frame;
MdiChild child = new MdiChild(Frame);
if (App.ReadOption("OpenPrevious", "Y").ToLower().Substring(0, 1) != "n") {
string[] aFiles = App.ReadSectionKeys("Previous");
int iCount = 0;
foreach (string s in aFiles) {
if (!File.Exists(s)) continue;
iCount ++;
int iIndex = Int32.Parse(App.ReadValue("Previous", s, "-1"));
// App.Frame.OpenOrActivateWindow(s, 1);
App.Frame.OpenOrActivateWindow(s, App.Frame.GetViewLevel(s));
if (App.Frame.Child.RTB.Index == 0) App.Frame.Child.RTB.Index = iIndex;
}
if (iCount > 0) App.Frame.AddMessage("Opened " + iCount + " previous file" + (iCount == 1 ? "" : "s"));
}
App.DeleteSection("Previous");
ReadOnlyCollection<string> cmdLineArgs = this.CommandLineArgs;
if (cmdLineArgs.Count > 0) {
string sFile = cmdLineArgs[0];
string sLine = "";
string sColumn = "";
if (cmdLineArgs.Count > 1) sLine = cmdLineArgs[1];
if (cmdLineArgs.Count > 2) sColumn = cmdLineArgs[2];
// Frame.OpenOrActivateWindow(sFile, 1, sLine, sColumn);
App.Frame.OpenOrActivateWindow(sFile, App.Frame.GetViewLevel(sFile), sLine, sColumn);
}
};
} // App constructor
protected override void OnStartupNextInstance(StartupNextInstanceEventArgs e) {
/*
Util.ActivatePid(Process.GetCurrentProcess().Id);
Microsoft.VisualBasic.Interaction.AppActivate(App.Frame.Text);
App.Frame.Activate();
Util.ActivateTitle(App.Frame.Text);
*/
//COM.ActivateTitle(App.Frame.Text);
//System.Threading.Thread.Sleep(1000);
/*
object oAutoIt = COM.CreateObject("AutoItX3.Control");
object[] aParams = {"WinTitleMatchMode", 4};
COM.CallMethod(oAutoIt, "AutoItSetOption", aParams);
string sParam = "handle=" + App.Frame.TopLevelControl.Handle.ToString();
COM.CallMethod(oAutoIt, "WinActivate", sParam);
Win32.SetForegroundWindow(App.Frame.TopLevelControl.Handle);
*/
//Process.Start(Path.Combine(App.ProgramDir, "ForceWin.exe"), App.Frame.TopLevelControl.Handle.ToString());
Win32.ForceWindow(App.Frame.TopLevelControl.Handle);
if (e.CommandLine.Count == 0) return;
string sFile = Util.Unquote(e.CommandLine[0]);
string sLine = "";
string sColumn = "";
if (e.CommandLine.Count > 1) sLine = e.CommandLine[1];
if (e.CommandLine.Count > 2) sColumn = e.CommandLine[2];
if (sFile != null && File.Exists(sFile)) App.Frame.OpenOrActivateWindow(sFile, App.Frame.GetViewLevel(sFile), sLine, sColumn);
} // OnStartUpNextInstance handler
public static bool InitJFW() {
string sDir = Win32.GetJFWDir();
if (sDir.Length == 0) return false;
string sPath = Environment.GetEnvironmentVariable("PATH");
sDir += ";";
if (!sPath.ToLower().Contains(sDir.ToLower())) {
sPath = sDir + sPath;
Environment.SetEnvironmentVariable("PATH", sPath);
}
return true;
} // InitJFW method
public static bool InitNetSdk() {
// Does not work
// string sDir = Win32.GetNetRuntimeDir();
// string sDir = Win32.GetNetSdkDir();
string sDir = RuntimeEnvironment.GetRuntimeDirectory();
// Dialog.Show("RuntimeEnvironment", RuntimeEnvironment.GetSystemVersion() + "\r\n" + RuntimeEnvironment.GetRuntimeDirectory() + "\r\n" + RuntimeEnvironment.SystemConfigurationFile);
// Dialog.Show(sDir);
if (sDir.Length == 0) return false;
if (sDir.EndsWith(@"\")) sDir = sDir.Substring(0, sDir.Length - 2);
string sPath = Environment.GetEnvironmentVariable("PATH");
sDir += ";";
if (!sPath.ToLower().Contains(sDir.ToLower())) {
sPath = sDir + sPath;
Environment.SetEnvironmentVariable("PATH", sPath);
// Clipboard.SetText(Environment.GetEnvironmentVariable("PATH"));
}
return true;
} // InitNetSdk method
public static string GetAppName() {
string sExe = Environment.GetCommandLineArgs()[0];
string sReturn = Path.GetFileNameWithoutExtension(sExe);
sReturn = Application.ProductName;
return sReturn;
} // GetAppName method
public static string GetProgramDir() {
//string sApp = System.Reflection.Assembly.GetExecutingAssembly().Location;
//string sApp = Application.ExecutablePath;
//string sReturn = Path.GetDirectoryName(sApp);
string sReturn = Application.StartupPath;
return sReturn;
} // GetProgramDir method
public static string GetDataDir() {
string sName = GetAppName();
//string sDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
//string sDir = Application.UserAppDataPath;
//string sDir = Application.LocalUserAppDataPath
string sDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string sReturn = Path.Combine(sDir, sName);
if (!Directory.Exists(sReturn)) Directory.CreateDirectory(sReturn);
return sReturn;
} // GetDataDir method
public static string GetTempFile() {
string sName = GetAppName() + ".tmp";
string sDir = GetDataDir();
string sReturn = Path.Combine(sDir, sName);
App.TempFiles.Add(sReturn);
return sReturn;
} // GetTempFile method
public static string GetIniFile() {
string sName = GetAppName() + ".ini";
string sDir = GetDataDir();
string sReturn = Path.Combine(sDir, sName);
return sReturn;
} // GetIniFile method
public static string GetDefaultIniFile() {
string sName = GetAppName() + ".ini";
string sDir = GetProgramDir();
string sReturn = Path.Combine(sDir, sName);
return sReturn;
} // GetDefaultIniFile method
public static string ReadData(string sKey, string sDefault) {
string sSection = "Data";
return ReadValue(sSection, sKey, sDefault);
} // ReadData method
public static bool WriteData(string sKey, string sValue) {
string sSection = "Data";
//return WriteValue(sSection, sKey, sValue);
return Ini.WriteQuote(App.IniFile, sSection, sKey, sValue);
} // WriteData method
public static string ReadDefaultOption(string sKey, string sDefault) {
string sSection = "Options";
return Ini.ReadValue(App.DefaultIniFile, sSection, sKey, sDefault);
} // ReadDefaultOption method
public static string ReadOption(string sKey, string sDefault) {
string sSection = "Options";
return ReadValue(sSection, sKey, sDefault);
} // ReadOption method
public static string ReadValue(string sSection, string sKey, string sDefault) {
return Ini.ReadValue(App.IniFile, sSection, sKey, sDefault);
} // ReadValue method
public static bool WriteOption(string sKey, string sValue) {
string sSection = "Options";
return WriteValue(sSection, sKey, sValue);
} // WriteOption method
public static bool WriteValue(string sSection, string sKey, string sValue) {
// return Ini.WriteValue(App.IniFile, sSection, sKey, sValue);
return Ini.WriteQuote(App.IniFile, sSection, sKey, sValue);
} // WriteValue method
public static bool DeleteKey(string sSection, string sKey) {
return Ini.DeleteKey(App.IniFile, sSection, sKey);
} // DeleteKey method
public static bool DeleteSection(string sSection) {
return Ini.DeleteSection(App.IniFile, sSection);
} // DeleteSection method
public static string[] ReadDefaultOptions() {
string sSection = "Options";
return ReadDefaultSectionKeys(sSection);
} // ReadOptions method
public static string[] ReadDefaultSectionKeys(string sSection) {
bool bIncludeComments = false;
return ReadDefaultSectionKeys(sSection, bIncludeComments);
} // ReadDefaultSectionKeys method
public static string[] ReadDefaultSectionKeys(string sSection, bool bIncludeComments) {
return Ini.ReadSectionKeys(App.DefaultIniFile, sSection, bIncludeComments);
} // ReadDefaultSectionKeys method
public static string[] ReadSectionKeys(string sSection) {
return Ini.ReadSectionKeys(App.IniFile, sSection);
} // ReadSectionKeys method
public static string[] ReadSections() {
return Ini.ReadSections(App.IniFile);
} // ReadSections method
public static void SetConfigurationValues() {
string[] aSections = Ini.ReadSections(App.DefaultIniFile);
foreach (string sSection in aSections) {
string[] aCommands = Ini.ReadSectionKeys(App.DefaultIniFile, sSection, false);
string[] aKeys = new string[aCommands.Length];
for (int i = 0; i < aCommands.Length; i++) {
string sCommand = aCommands[i];
string sKey = Ini.ReadValue(App.DefaultIniFile, sSection, sCommand, "");
sKey = Ini.ReadValue(App.IniFile, sSection, sCommand, sKey);
aKeys[i] = sKey;
}
//Ini.DeleteSection(App.IniFile, sSection);
for (int i = 0; i < aCommands.Length; i++) {
string sCommand = aCommands[i];
string sKey = aKeys[i];
//if (sSection == "Import" || sSection == "Export") Ini.WriteValue(App.IniFile, sSection, sCommand, sKey);
//else Ini.WriteQuote(App.IniFile, sSection, sCommand, sKey);
Ini.WriteQuote(App.IniFile, sSection, sCommand, sKey);
}
}
} // SetConfigurationValues method
} // App class
public class MdiChild : Form {
public HomerRichTextBox RTB;
public Encoding YieldEncoding = null;
public bool IsUnixLineBreak = false;
public int AppendFromClipboard = 0;
public IntPtr NextClipboardViewer = (IntPtr) 0;
public int LastTickCount = 0;
public string LastClipboardText = "";
private string sFile = "";
public string File {
get {
return sFile;
}
set {
sFile = value;
}
} // File property
public DateTime FileTime;
public bool FileTimeChecked = false;
public MdiChild(MdiFrame frame) {
string sTitle = frame.GetNoNameTitle();
new MdiChild(frame, sTitle);
} // MdiChild constructor
public MdiChild(MdiFrame frame, string sTitle) {
this.SuspendLayout();
this.MdiParent = frame;
HomerRichTextBox rtb = new HomerRichTextBox();
rtb.GotFocus += CheckFileTime;
rtb.AccessibleRole = AccessibleRole.Text;
rtb.AutoWordSelection = false;
rtb.Dock = DockStyle.Fill;
rtb.Multiline = true;
string sFont = App.ReadOption("FontDefault", "");
if (sFont.Length > 0) {
string[] a = sFont.Split(',');
List<string> list = new List<string>(a);
int iCount = list.Count;
string sColor = list[iCount - 1];
try {
sColor = sColor.Split('=')[1];
rtb.ForeColor = Util.String2Color(sColor);
}
catch {}
list.RemoveAt(iCount - 1);
a = list.ToArray();
sFont = String.Join(",", a);
try {
//sFont = "Arial Unicode MS";
rtb.Font = Util.String2Font(sFont);
}
catch {}
}
string s = App.ReadOption("WordWrap", "Y").Trim().ToUpper();
if (s == "N" || s == "NO") rtb.SetWrap(false);
else rtb.SetWrap(true);
//rtb.ScrollBars = RichTextBoxScrollBars.Vertical;
rtb.ScrollBars = RichTextBoxScrollBars.Vertical | RichTextBoxScrollBars.Horizontal;
rtb.AcceptsTab = true;
rtb.FindText = "";
rtb.JumpLine = "";
rtb.GoPercent = "";
rtb.SearchTopic = "";
rtb.SelectionChanged += App.Frame.SetStatusAddress;
this.Controls.Add(rtb);
this.RTB = rtb;
//this.File = frame.GetNoNameTitle();
this.File = sTitle;
this.Text = System.IO.Path.GetFileName(this.File);
this.StartPosition = FormStartPosition.CenterParent;
this.AutoSize = true;
this.ResumeLayout();
this.KeyPreview = true;
this.Activated += delegate(object o, EventArgs e) {
frame.SetStatusAddress(this, null);
//this.WindowState = FormWindowState.Maximized;
//Win32.SetForegroundWindow(App.Frame.Handle);
//Win32.SetForegroundWindow(this.Handle);
//COM.ActivateTitle("EdSharp");
//int iPid = Process.GetCurrentProcess().Id;
//if (iPid > 0) Util.ActivatePid(iPid);
//Win32.ForceWindow(App.Frame.TopLevelControl.Handle);
};
string sText, sResult = "";
this.Shown += delegate(object o, EventArgs e) {
this.WindowState = FormWindowState.Maximized;
//Win32.ForceWindow(App.Frame.TopLevelControl.Handle);
sFile = this.File;
if (!sFile.Contains(@"\")) return;
sText = App.ReadValue("Favorites", sFile, "");
try {
string[] a = sText.Split('|');
sText = a[0];
rtb.Index = Int32.Parse(sText);
return;
}
catch {}
sText = App.ReadValue("Recent", sFile, "");
if (sText.Length == 0) return;
rtb = this.RTB;
HomerList hl = new HomerList(sText);
hl.KeepLike(@"^\d+$");
// hl.Remove("-1");
if (hl.Count == 0) {
return;
}
sResult = hl[0];
rtb.Index = Int32.Parse(sResult);
App.Frame.AddMessage("Previous percent " + rtb.Percent);
// Util.Say(rtb.RowText);
}; // Shown
this.Closing += delegate(object o, CancelEventArgs e) {
sFile = this.File;
if (!sFile.Contains(@"\")) return;
rtb = this.RTB;
int iIndex = rtb.Index;
if (iIndex == 0) return;
sText = App.ReadValue("Recent", sFile, "");
HomerList hl = new HomerList(sText);
hl.KeepLike(@"\d+");
hl.Remove("-1");
DateTime dt = DateTime.Now;
string sTime = dt.ToString("u");
sTime = sTime.Substring(0, sTime.Length - 1);
sText = sTime + "|" + iIndex + "|" + (rtb.ReadOnly ? "G" : "M") + "|" + (string) Util.If(rtb.WordWrap, "W", "U");
// hl.AddUniqueRange(sText);
// sText = hl.Segments;
App.WriteValue("Recent", sFile, sText);
}; // Closing
this.FileTime = System.IO.File.GetLastWriteTime(this.File);
this.Show();
} // child constructor
public void CheckFileTime(object sender, EventArgs e) {
if (App.Frame.KeyDescriber) {
App.Frame.SetMessage("No Key Describer");
App.Frame.KeyDescriber = false;
}
string sFile = this.File;
bool b = System.IO.File.Exists(App.IndentModeFile);
if (b && !this.RTB.IndentMode) System.IO.File.Delete(App.IndentModeFile);
else if (!b && this.RTB.IndentMode) System.IO.File.Create(App.IndentModeFile).Close();
if (this.FileTimeChecked || sFile.IndexOf(@"\") == -1 || !System.IO.File.Exists(sFile)) return;
DateTime dt = System.IO.File.GetLastWriteTime(sFile);
//if (this.FileTime >= dt || Util.File2String(sFile).Length == 0) return;
if (this.FileTime >= dt) return;
this.FileTimeChecked = true;
switch (Dialog.Confirm("Confirm", this.Text + " on disk is newer than the version opened in this window. Open Again?", "Y")) {
case "Y" :
int iIndex = this.RTB.Index;
this.LoadTextOrRtfFile(sFile);
this.RTB.Index = iIndex;
break;
case "N":
break;
default :
this.FileTimeChecked = false;
return;
}
} // CheckFileTime handler
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
const int WM_CHANGECBCHAIN = 0x30D;
const int WM_DRAWCLIPBOARD = 0x308;
//if (m.Msg == 776) {
switch (m.Msg) {
case WM_DRAWCLIPBOARD :
if ((int) this.NextClipboardViewer > 0) Win32.SendMessage(this.NextClipboardViewer, m.Msg, (int) m.LParam, (int) m.WParam);
if (this.AppendFromClipboard == -1) {
this.AppendFromClipboard = 1;
}
else if (this.AppendFromClipboard == 1) {
string sClipboard = Clipboard.GetText();
//if (sClipboard == this.LastClipboardText && ((Environment.TickCount - this.LastTickCount) < 100)) sClipboard = "";
if (sClipboard == this.LastClipboardText) sClipboard = "";
if (sClipboard.Length > 0) {
this.LastTickCount = Environment.TickCount;
this.LastClipboardText = sClipboard;
Console.Beep();
HomerRichTextBox rtb = this.RTB;
string sText = rtb.Text;
sText = sText.TrimEnd(new char[] {'\n'});
int iLength = sText.Length;
if (iLength >0) sText += "\f\n";
//if (iLength > 0 && sText.Substring(iLength - 1) != "\n") sText += "\n";
sClipboard = sClipboard.TrimEnd(new char[] {'\n'});
sText += sClipboard;
rtb.Text = sText;
rtb.Index = rtb.Text.Length - 1;
} // sClipboard.Length
} // this.AppendFromClipboard
break;
case WM_CHANGECBCHAIN :
IntPtr hNextClipboardViewer = m.WParam;
if (this.NextClipboardViewer == hNextClipboardViewer) this.NextClipboardViewer = m.LParam;
else if ((int) this.NextClipboardViewer > 0) Win32.SendMessage(hNextClipboardViewer, m.Msg, (int) m.LParam, (int) m.WParam);
break;
} // switch msg
} // WndProc event handler
public Encoding GetYieldEncoding() {
Encoding en = null;
string sEncoding = App.ReadOption("YieldEncoding", "").Trim();
if (sEncoding.Replace("-", "").ToLower() == "utf8n") {
en = new UTF8Encoding();
this.IsUnixLineBreak = true;
}
else if (sEncoding.Length > 0 ) {
try {
if (Util.IsNumeric(sEncoding)) en = Encoding.GetEncoding(Int32.Parse(sEncoding));
else en = Encoding.GetEncoding(sEncoding);
}
catch (Exception ex) {
Dialog.Show("Error", ex.Message);
en = Encoding.Default;
}
}
return en;
} // GetYieldEncoding method
public void LoadTextOrRtfFile(string sFile) {
bool bLiteral = false;
LoadTextOrRtfFile(sFile, bLiteral);
} // LoadTextOrRtfFile method
public void LoadTextOrRtfFile(string sFile, bool bLiteral) {
this.FileTimeChecked = false;
this.FileTime = System.IO.File.GetLastWriteTime(sFile);
try {
if (!bLiteral && Path.GetExtension(sFile).ToLower() == ".rtf") this.RTB.LoadFile(sFile, RichTextBoxStreamType.RichText);
//else this.RTB.LoadFile(sFile, RichTextBoxStreamType.UnicodePlainText);
else {
Encoding en = GetYieldEncoding();
string sText = Util.File2String(sFile, ref en);
this.RTB.Text = sText;
// Dialog.Show(sText.Length, this.RTB.TextLength);
if (sText.Length > 1 && this.RTB.TextLength == 1) {
en = Encoding.Unicode;
this.RTB.Text = Util.File2String(sFile, ref en);
}
this.YieldEncoding = en;
}
//else this.RTB.Text = Util.OldFile2String(sFile);
//else this.RTB.Text = System.IO.File.ReadAllText(sFile, System.Text.Encoding.UTF8);
//else this.RTB.Text = System.IO.File.ReadAllText(sFile, System.Text.Encoding.Default);
//else this.RTB.Text = System.IO.File.ReadAllText(sFile, System.Text.Encoding.GetEncoding(1252));
this.RTB.Modified = false;
this.Text = Path.GetFileName(sFile);
this.File = sFile;
}
catch {
App.Frame.AddMessage("Cannot open file! Opening temporary copy.");
if (System.IO.File.Exists(App.TempFile)) System.IO.File.Delete(App.TempFile);
System.IO.File.Copy(sFile, App.TempFile);
App.Frame.OpenOrActivateWindow(App.TempFile);
}
//Dialog.Show(this.File);
// Stop double bookmark at message
// App.Frame.ApplyFileOptions(sFile);
} // LoadTextFile method
public void SaveTextOrRtfFile(string sFile) {
if (System.IO.File.Exists(sFile)) {
string sKeepBackup = App.ReadOption("KeepBackup", "N").Trim().ToLower();
if (sKeepBackup == "y" || sKeepBackup == "yes") {
string sBak = sFile + ".bak";
if (System.IO.File.Exists(sBak)) System.IO.File.Delete(sBak);
System.IO.File.Copy(sFile, sBak);
}
}
if (Path.GetExtension(sFile).ToLower() == ".rtf") this.RTB.SaveFile(sFile, RichTextBoxStreamType.RichText);
//else if (Util.IsUnicode(this.RTB.Text)) Util.String2File(this.RTB.Text, sFile);
//else this.RTB.SaveFile(sFile, RichTextBoxStreamType.PlainText);
else {
Encoding en = this.YieldEncoding;
if (en == null) en = GetYieldEncoding();
string sText = this.RTB.Text;
if (!this.IsUnixLineBreak) sText = Util.Convert2WinLineBreak(sText);
Util.String2File(sText, sFile, ref en);
}
this.RTB.Modified = false;
App.Frame.SetRecent(sFile);
this.Text = Path.GetFileName(sFile);
this.File = sFile;
this.FileTime = System.IO.File.GetLastWriteTime(sFile);
this.FileTimeChecked = false;
} // SaveTextOrRtfFile method
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
return App.Frame.ProcessCmdKey_Helper(ref msg, keyData);
} // ProcessCmdKey handler
} // MdiChild class
public class MdiFrame : Form {
public string LastDescription = "";
public bool KeyDescriber = false;
public string KeyString = "";
public int KeyRepeat = 0;
public int KeyIndex = -1;
public MdiChild Child {
get {
MdiChild child = this.ActiveMdiChild as MdiChild;
if (child == null) {
Form[] children = this.MdiChildren;
int iLength = children.Length;
if (children.Length > 0) child = (MdiChild) children[iLength - 1];
}
return child;
}
set {
value.Activate();
}
} // Child property
public bool FindWithRegExp = false;
public bool bCommandComplete = true;
public static string CR = "\r";
public static string LF = "\n";
public static string LB = LF;
public static string LineBreak = Environment.NewLine;
public static string FF = "\f";
public static string SB = FF + LB;
public static string DD = "----------";
public static string SectionBreak = LB + DD + LB + SB;
public static string EOD = LB + DD + LB + "End of Document" + LB;
public static Dictionary<Keys, ToolStripMenuItem> hashKey = new Dictionary<Keys, ToolStripMenuItem>();
public MenuStrip menuMain;
public ToolStripMenuItem menuFile, menuFileNew, menuFileNewFromClipboard, menuFileOpen, menuFileOpenOtherFormat, menuFileOpenAgain, menuFileRecent, menuFileSetFavorite, menuFileClearFavorite, menuFileListFavorites, menuFileFind, menuFileSave, menuFileSaveAs, menuFileSaveCopy, menuFileExport, menuFileRename, menuFileProperties, menuFileMailBody, menuFileMailAttach, menuFilePrint, menuFileRun, menuFileCurrentWindows, menuFileClose, menuFileCloseAllButCurrentWindow, menuFileExit;
public ToolStripMenuItem menuEdit, menuEditSelectAll, menuEditUnselectAll, menuEditCopy, menuEditCopyAppend, menuEditCopyRichText, menuEditCut, menuEditCutAppend, menuEditPaste, menuEditPasteFile, menuEditUndo, menuEditRedo, menuEditStartSelection, menuEditCompleteSelection, menuEditReselect, menuEditCopyAll, menuEditSelectChunk, menuEditAppendFromClipboard, menuEditQuote, menuEditUnquote, menuEditUpperCase, menuEditLowerCase, menuEditProperCase, menuEditSwapCase, menuEditYieldEncoding, menuEditJoinLines, menuEditHardLineBreak, menuEditEnterNewLine, menuEditIndentNewLine, menuEditIndentNewLinePrior, menuEditIndent, menuEditOutdent, menuEditAlign, menuEditIndentMode, menuEditJustify, menuEditStyle, menuEditBaseline, menuEditSetSelectionFont;
public ToolStripMenuItem menuDelete, menuDeleteReplaceRegular, menuDeleteReplaceWithRegExp, menuDeleteHardLine, menuDeleteParagraph, menuDeleteLine, menuDeleteRight, menuDeleteLeft, menuDeleteDown, menuDeleteUp, menuDeleteFile, menuDeleteTrimBlanks;
public ToolStripMenuItem menuNavigate, menuNavigateForwardFind, menuNavigateReverseFind, menuNavigateForwardFindWithRegExp, menuNavigateReverseFindWithRegExp, menuNavigateForwardFindAtCursor, menuNavigateReverseFindAtCursor, menuNavigateForwardFindAgain, menuNavigateReverseFindAgain, menuNavigateJumpToLine, menuNavigateJumpToLineAgain, menuNavigateGoToPercent, menuNavigateGoToPercentAgain, menuNavigateGoToPart, menuNavigateSetBookmark, menuNavigateClearBookmark, menuNavigateGoToBookmark, menuNavigateHomeCharacter, menuNavigateEndCharacter, menuNavigateStartTag, menuNavigateEndTag, menuNavigateNextJustify, menuNavigatePriorJustify, menuNavigateNextStyle, menuNavigatePriorStyle, menuNavigateNextBaseline, menuNavigatePriorBaseline, menuNavigateNextFont, menuNavigatePriorFont, menuNavigateRightBrace, menuNavigateNextBlock, menuNavigatePriorBlock, menuNavigateLeftBrace, menuNavigateNextIndent, menuNavigatePriorIndent, menuNavigateNextChunk, menuNavigatePriorChunk, menuNavigateNextSentence, menuNavigatePriorSentence, menuNavigateNextParagraph, menuNavigatePriorParagraph, menuNavigateNextPart, menuNavigatePriorPart, menuNavigateNextSection, menuNavigatePriorSection, menuNavigateGoToSection, menuNavigateGoToContents, menuNavigateSearchForTopic, menuNavigateSearchForTopicAgain, menuNavigateGoToStartOfSelection;
public ToolStripMenuItem menuQuery, menuQueryAddress, menuQueryBraces, menuQueryBlock, menuQueryIndent, menuQueryPath, menuQueryTopic, menuQueryYield, menuQueryStatus, menuQueryCompiler, menuQuerySelected, menuQueryChunk, menuQueryReadAll, menuQueryWindowsOpen, menuQueryClipboard, menuQueryTime, menuQueryStyles, menuQueryFont;
public ToolStripMenuItem menuMisc, menuMiscSetDefaultFont, menuMiscConfigurationOptions, menuMiscManualOptions, menuMiscResetConfiguration, menuMiscGoToFolder, menuMiscGoToSpecialFolder, menuMiscWordWrap, menuMiscUnwrap, menuMiscExtraSpeechToggle, menuMiscExtraSpeechLog, menuMiscEnvironmentVariables, menuMiscSpellCheck, menuMiscThesaurus, menuMiscLookupTerm, menuMiscTranslateLanguage, menuMiscGuardDocument, menuMiscNoGuard, menuMiscPyBrace, menuMiscPyDent, menuMiscInferIndent, menuMiscFormatCode, menuMiscRepeatLine, menuMiscSectionBreak, menuMiscPathToClipboard, menuMiscPathList, menuMiscInsertTime, menuMiscCalculateDate, menuMiscHTMLFormat, menuMiscTextConvert, menuMiscTextCombine, menuMiscTextContents, menuMiscYieldWithRegExp, menuMiscExtractWithRegExp, menuMiscRunAtCursor, menuMiscSpecialCharacter, menuMiscEvaluateExpression, menuMiscReplaceTokens, menuMiscTransformFiles, menuMiscGoToEnvironment, menuMiscCompile, menuMiscPickCompiler, menuMiscPromptCommand, menuMiscReviewOutput, menuMiscSaveSnippet, menuMiscInvokeSnippet, menuMiscViewSnippet, menuMiscKeepUniqueItems, menuMiscNumberItems, menuMiscOrderItems, menuMiscReverseItems, menuMiscListDifferentItems, menuMiscQueryCommonItems, menuMiscExplorerFolder, menuMiscCommandPrompt, menuMiscBurnToCD, menuMiscWebDownload, menuMiscWebClientUtilities;
public ToolStripMenuItem menuWindow, menuWindowNext, menuWindowPrior, menuWindowArrangeIcons, menuWindowCascade, menuWindowTileHorizontal, menuWindowTileVertical;
public ToolStripMenuItem menuHelp, menuHelpAbout, menuHelpDocumentation, menuHelpHistoryOfChanges, menuHelpKeyDescriber, menuHelpHotKeySummary, menuHelpAlternateMenu, menuHelpContextMenu, menuHelpSendToMenu, menuHelpElevateVersion;
public StatusStrip statusBar;
public ToolStripStatusLabel lblStatus;
public MdiFrame() {
SectionBreak = Util.Literalize(App.ReadOption("SectionBreak", SectionBreak));
this.SuspendLayout();
this.IsMdiContainer = true;
menuMain = CreateMainMenu();
//menuMain.ShowItemToolTips = true;
menuMain.AccessibleRole = AccessibleRole.MenuBar;
menuFile = CreateMenu("&File");
menuFileNew = CreateMenuItem("&New", "Control+N", menuItem_Click, "frame speak");
menuFileNewFromClipboard = CreateMenuItem("New from Clipboard", "Control+Shift+N", menuItem_Click, "frame speak");
menuFileOpen = CreateMenuItem("&Open ...", "Control+O", menuItem_Click, "frame speak");
menuFileOpenOtherFormat = CreateMenuItem("Open Other Format ...", "Control+Shift+O", menuItem_Click, "frame speak");
menuFileOpenAgain = CreateMenuItem("Open Again", "Alt+O", menuItem_Click, "child speak");
menuFileRecent = CreateMenuItem("Recent Files ...", "Alt+R", menuItem_Click, "frame silent");
menuFileSetFavorite = CreateMenuItem("Set Favorite", "Control+&L", menuItem_Click, "child speak");
//menuFileSetFavorite = CreateMenuItem("Set on Favorite &List", "Control+L", menuItem_Click, "child speak");
menuFileClearFavorite = CreateMenuItem("Clear Favorite", "Control+Shift+L", menuItem_Click, "child speak");
menuFileListFavorites = CreateMenuItem("List Favorites ...", "Alt+L", menuItem_Click, "frame silent");
menuFileFind = CreateMenuItem("File Find ...", "Alt+Shift+F", menuItem_Click, "frame speak");
menuFileSave = CreateMenuItem("&Save", "Control+S", menuItem_Click, "child speak");
menuFileSaveAs = CreateMenuItem("Save &As ...", "Control+Shift+S", menuItem_Click, "child silent");
menuFileSaveCopy = CreateMenuItem("Save Copy ...", "Alt+Shift+S", menuItem_Click, "child speak");
menuFileExport = CreateMenuItem("Export Format ...", "Alt+Shift+E", menuItem_Click, "child silent");
menuFileRename = CreateMenuItem("Rename ...", "Alt+Shift+R", menuItem_Click, "child silent");
menuFileProperties = CreateMenuItem("Properties", "Alt+Enter", menuItem_Click, "child speak");
menuFileMailBody = CreateMenuItem("&Mail Body ...", "Control+M", menuItem_Click, "child speak");
menuFileMailAttach = CreateMenuItem("Mail Attachment ...", "Control+Shift+M", menuItem_Click, "child speak");
menuFilePrint = CreateMenuItem("&Print", "Control+P", menuItem_Click, "child silent");
menuFileRun = CreateMenuItem("Run", "F5", menuItem_Click, "child speak");
menuFileCurrentWindows = CreateMenuItem("Current Windows ...", "F4", menuItem_Click, "frame silent");
menuFileClose = CreateMenuItem("&Close Window", "Control+F4", menuItem_Click, "child speak");
menuFileCloseAllButCurrentWindow = CreateMenuItem("Close All but Current Window", "Control+Shift+F4", menuItem_Click, "child speak");
menuFileExit = CreateMenuItem("&E&xit EdSharp", "Alt+F4", menuItem_Click, "frame speak");
menuFile.DropDownItems.AddRange(new ToolStripItem[] {menuFileNew, menuFileNewFromClipboard, menuFileOpen, menuFileOpenOtherFormat, menuFileOpenAgain, menuFileRecent, menuFileSetFavorite, menuFileClearFavorite, menuFileListFavorites, menuFileFind, menuFileSave, menuFileSaveAs, menuFileSaveCopy, menuFileExport, menuFileRename, menuFileProperties, menuFileMailBody, menuFileMailAttach, menuFilePrint, menuFileRun, menuFileCurrentWindows, menuFileClose, menuFileCloseAllButCurrentWindow, menuFileExit});
//Dialog.Show("File.", menuFile.DropDownItems.Count);
menuEdit = CreateMenu("&Edit");
menuEditSelectAll = CreateMenuItem("Select &All", "Control+A", menuItem_Click, "child speak");
menuEditUnselectAll = CreateMenuItem("Unselect All", "Control+Shift+A", menuItem_Click, "child speak");
menuEditCopy = CreateMenuItem("&Copy", "Control+C", menuItem_Click, "child speak");
menuEditCopyAppend = CreateMenuItem("Copy Append", "Alt+C", menuItem_Click, "child speak");
menuEditCopyRichText = CreateMenuItem("Copy Rich Text", "Control+Shift+C", menuItem_Click, "child speak");
menuEditCut = CreateMenuItem("Cut", "Control+&X", menuItem_Click, "child speak");
menuEditCutAppend = CreateMenuItem("Cut Append", "Alt+X", menuItem_Click, "child speak");
menuEditPaste = CreateMenuItem("Paste", "Control+&V", menuItem_Click, "child speak");
menuEditPasteFile = CreateMenuItem("Paste File ...", "Control+Shift+V", menuItem_Click, "child speak");
menuEditUndo = CreateMenuItem("Undo", "Control+&Z", menuItem_Click, "child speak");
menuEditRedo = CreateMenuItem("Redo", "Control+Shift+Z", menuItem_Click, "child speak");
menuEditStartSelection = CreateMenuItem("Start Selection", "F8", menuItem_Click, "child speak");
menuEditCompleteSelection = CreateMenuItem("Complete Selection", "Shift+F8", menuItem_Click, "child speak");
menuEditReselect = CreateMenuItem("Reselect", "Control+Shift+F8", menuItem_Click, "child speak");
menuEditCopyAll = CreateMenuItem("Copy All", "Control+F8", menuItem_Click, "child speak");
menuEditSelectChunk = CreateMenuItem("Select Chunk", "Control+Space", menuItem_Click, "child silent");
menuEditAppendFromClipboard = CreateMenuItem("Append from Clipboard", "Alt+D7", menuItem_Click, "child silent");
menuEditQuote = CreateMenuItem("&Quote", "Control+Q", menuItem_Click, "child speak");
menuEditUnquote = CreateMenuItem("Unquote", "Control+Shift+Q", menuItem_Click, "child speak");
menuEditUpperCase = CreateMenuItem("&Upper Case", "Control+U", menuItem_Click, "child speak");
menuEditLowerCase = CreateMenuItem("Lower Case", "Control+Shift+U", menuItem_Click, "child speak");
menuEditProperCase = CreateMenuItem("Proper Case", "Alt+U", menuItem_Click, "child speak");
menuEditSwapCase = CreateMenuItem("Swap Case", "Alt+Shift+U", menuItem_Click, "child speak");
menuEditYieldEncoding = CreateMenuItem("Yield Encoding", "Alt+Shift+Y", menuItem_Click, "child silent");
menuEditJoinLines = CreateMenuItem("Join Lines", "Control+Shift+J", menuItem_Click, "child speak");
menuEditHardLineBreak = CreateMenuItem("Hard Line Break ...", "Control+Shift+H", menuItem_Click, "child silent");
menuEditEnterNewLine = CreateMenuItem("Enter New Line", "Enter", menuItem_Click, "child silent");
menuEditIndentNewLine = CreateMenuItem("Indent New Line", "Shift+Enter", menuItem_Click, "child silent");
menuEditIndentNewLinePrior = CreateMenuItem("Indent New Line Prior", "Alt+Shift+Enter", menuItem_Click, "child speak");
menuEditIndent = CreateMenuItem("Indent", "Tab", menuItem_Click, "child silent");
menuEditOutdent = CreateMenuItem("Outdent", "Shift+Tab", menuItem_Click, "child silent");
menuEditAlign = CreateMenuItem("Align", "Alt+Shift+A", menuItem_Click, "child speak");
menuEditIndentMode = CreateMenuItem("Indent Mode", "Alt+Shift+I", menuItem_Click, "child speak");
menuEditJustify = CreateMenuItem("Justify ...", "Alt+Shift+J", menuItem_Click, "child silent");
menuEditStyle = CreateMenuItem("Style ...", "Alt+Shift+OemQuestion", menuItem_Click, "child silent");
menuEditBaseline = CreateMenuItem("Baseline ...", "Alt+Shift+D6", menuItem_Click, "child silent");
menuEditSetSelectionFont = CreateMenuItem("Set Selection Font ...", "Alt+Shift+OemMinus", menuItem_Click, "child speak");
menuEdit.DropDownItems.AddRange(new ToolStripItem[] {menuEditSelectAll, menuEditUnselectAll, menuEditCopy, menuEditCopyAppend, menuEditCopyRichText, menuEditCut, menuEditCutAppend, menuEditPaste, menuEditPasteFile, menuEditUndo, menuEditRedo, menuEditStartSelection, menuEditCompleteSelection, menuEditReselect, menuEditCopyAll, menuEditSelectChunk, menuEditAppendFromClipboard, menuEditQuote, menuEditUnquote, menuEditUpperCase, menuEditLowerCase, menuEditProperCase, menuEditSwapCase, menuEditYieldEncoding, menuEditJoinLines, menuEditHardLineBreak, menuEditEnterNewLine, menuEditIndentNewLine, menuEditIndentNewLinePrior, menuEditIndent, menuEditOutdent, menuEditAlign, menuEditIndentMode, menuEditJustify, menuEditStyle, menuEditBaseline, menuEditSetSelectionFont});
//Dialog.Show("Edit.", menuEdit.DropDownItems.Count);
menuDelete = CreateMenu("&Delete");
menuDeleteReplaceRegular = CreateMenuItem("&Replace ...", "Control+R", menuItem_Click, "child silent");
menuDeleteReplaceWithRegExp = CreateMenuItem("Replace with Regular Expression ...", "Control+Shift+R", menuItem_Click, "child silent");
menuDeleteHardLine = CreateMenuItem("Delete Hard Line", "Control+D", menuItem_Click, "child silent");
menuDeleteParagraph = CreateMenuItem("Delete Paragraph", "Control+Shift+D", menuItem_Click, "child silent");
menuDeleteLine = CreateMenuItem("Delete Line", "Alt+Back", menuItem_Click, "child silent");
menuDeleteRight = CreateMenuItem("Delete Right", "Control+Shift+Delete", menuItem_Click, "child silent");
menuDeleteLeft = CreateMenuItem("Delete Left", "Control+Shift+Back", menuItem_Click, "child silent");
menuDeleteDown = CreateMenuItem("Delete Down", "Alt+Shift+Delete", menuItem_Click, "child speak");
menuDeleteUp = CreateMenuItem("Delete Up", "Alt+Shift+Back", menuItem_Click, "child speak");
menuDeleteFile = CreateMenuItem("Delete File", "Alt+Shift+D", menuItem_Click, "child speak");
menuDeleteTrimBlanks = CreateMenuItem("Trim Blanks", "Control+Shift+Enter", menuItem_Click, "child speak");
menuDelete.DropDownItems.AddRange(new ToolStripMenuItem[] {menuDeleteReplaceRegular, menuDeleteReplaceWithRegExp, menuDeleteHardLine, menuDeleteParagraph, menuDeleteLine, menuDeleteRight, menuDeleteLeft, menuDeleteDown, menuDeleteUp, menuDeleteFile, menuDeleteTrimBlanks});
//Dialog.Show("Delete.", menuDelete.DropDownItems.Count);
menuNavigate = CreateMenu("&Navigate");
menuNavigateForwardFind = CreateMenuItem("Forward &Find ...", "Control+F", menuItem_Click, "child silent");
menuNavigateReverseFind = CreateMenuItem("Reverse Find ...", "Control+Shift+F", menuItem_Click, "child silent");
menuNavigateForwardFindWithRegExp = CreateMenuItem("Forward Find with Regular Expression ...", "Control+F3", menuItem_Click, "child silent");
menuNavigateReverseFindWithRegExp = CreateMenuItem("Reverse Find with Regular Expression ...", "Control+Shift+F3", menuItem_Click, "child silent");
menuNavigateForwardFindAtCursor = CreateMenuItem("Forward Find at Cursor", "Alt+F3", menuItem_Click, "child silent");
menuNavigateReverseFindAtCursor = CreateMenuItem("Reverse Find at Cursor", "Alt+Shift+F3", menuItem_Click, "child silent");
menuNavigateForwardFindAgain = CreateMenuItem("Forward Find Again", "F3", menuItem_Click, "child silent");
menuNavigateReverseFindAgain = CreateMenuItem("Reverse Find Again", "Shift+F3", menuItem_Click, "child silent");
menuNavigateJumpToLine = CreateMenuItem("&Jump to Line ...", "Control+J", menuItem_Click, "child silent");
menuNavigateJumpToLineAgain = CreateMenuItem("Jump to Line Again", "Alt+J", menuItem_Click, "child silent");
menuNavigateGoToPercent = CreateMenuItem("&Go to Percent ...", "Control+G", menuItem_Click, "child silent");
menuNavigateGoToPercentAgain = CreateMenuItem("Go to Percent Again", "Alt+G", menuItem_Click, "child silent");
menuNavigateGoToPart = CreateMenuItem("Go to Part", "Alt+Shift+G", menuItem_Click, "child silent");
menuNavigateSetBookmark = CreateMenuItem("Set Bookmar&k", "Control+K", menuItem_Click, "child speak");
menuNavigateClearBookmark = CreateMenuItem("Clear Bookmark", "Control+Shift+K", menuItem_Click, "child speak");
menuNavigateGoToBookmark = CreateMenuItem("Go to Bookmark", "Alt+K", menuItem_Click, "child speak");
menuNavigateHomeCharacter = CreateMenuItem("Home Character", "Alt+Home", menuItem_Click, "child silent");
menuNavigateEndCharacter = CreateMenuItem("End Character", "Alt+End", menuItem_Click, "child silent");
menuNavigateStartTag = CreateMenuItem("Start Tag", "Control+Shift+Oemcomma", menuItem_Click, "child silent");
menuNavigateEndTag = CreateMenuItem("End Tag", "Control+Shift+OemPeriod", menuItem_Click, "child silent");
menuNavigateNextJustify = CreateMenuItem("Next Alignment", "Control+OemCloseBrackets", menuItem_Click, "child silent");
menuNavigatePriorJustify = CreateMenuItem("Prior Alignment", "Control+OemOpenBrackets", menuItem_Click, "child silent");
menuNavigateNextStyle = CreateMenuItem("Next Style", "Control+OemQuestion", menuItem_Click, "child silent");
menuNavigatePriorStyle = CreateMenuItem("Prior Style", "Control+Shift+OemQuestion", menuItem_Click, "child silent");
menuNavigateNextBaseline = CreateMenuItem("Next Baseline", "Control+D6", menuItem_Click, "child silent");
menuNavigatePriorBaseline = CreateMenuItem("Prior Baseline", "Control+Shift+D6", menuItem_Click, "child silent");
menuNavigateNextFont = CreateMenuItem("Next Font", "Control+OemMinus", menuItem_Click, "child silent");
menuNavigatePriorFont = CreateMenuItem("Prior Font", "Control+Shift+OemMinus", menuItem_Click, "child silent");
menuNavigateRightBrace = CreateMenuItem("Right Brace", "Control+Shift+OemCloseBrackets", menuItem_Click, "child silent");
menuNavigateLeftBrace = CreateMenuItem("Left Brace", "Control+Shift+OemOpenBrackets", menuItem_Click, "child silent");
menuNavigateNextBlock = CreateMenuItem("Next Block", "Control+B", menuItem_Click, "child silent");
menuNavigatePriorBlock = CreateMenuItem("Prior Block", "Control+Shift+B", menuItem_Click, "child silent");
menuNavigateNextIndent = CreateMenuItem("Next Indent", "Control+I", menuItem_Click, "child silent");
menuNavigatePriorIndent = CreateMenuItem("Prior Indent", "Control+Shift+I", menuItem_Click, "child silent");
menuNavigateNextChunk = CreateMenuItem("Next Chunk", "Alt+Right", menuItem_Click, "child silent");
menuNavigatePriorChunk = CreateMenuItem("Prior Chunk", "Alt+Left", menuItem_Click, "child silent");
menuNavigateNextSentence = CreateMenuItem("Next Sentence", "Alt+Down", menuItem_Click, "child silent");
menuNavigatePriorSentence = CreateMenuItem("Prior Sentence", "Alt+Up", menuItem_Click, "child silent");
menuNavigateNextParagraph = CreateMenuItem("Next Paragraph", "Control+Down", menuItem_Click, "child silent");
menuNavigatePriorParagraph = CreateMenuItem("Prior Paragraph", "Control+Up", menuItem_Click, "child silent");
menuNavigateNextPart= CreateMenuItem("Next Part", "Alt+PageDown", menuItem_Click, "child silent");
menuNavigatePriorPart= CreateMenuItem("Prior Part", "Alt+PageUp", menuItem_Click, "child silent");
menuNavigateNextSection= CreateMenuItem("Next Section", "Control+PageDown", menuItem_Click, "child silent");
menuNavigatePriorSection= CreateMenuItem("Prior Section", "Control+PageUp", menuItem_Click, "child silent");
menuNavigateGoToSection= CreateMenuItem("Go to Section", "F6", menuItem_Click, "child speak");
menuNavigateGoToContents = CreateMenuItem("Go to Contents", "Shift+F6", menuItem_Click, "child speak");
menuNavigateSearchForTopic = CreateMenuItem("Search for Topic ...", "Control+F6", menuItem_Click, "child silent");
menuNavigateSearchForTopicAgain = CreateMenuItem("Search for Topic Again", "Alt+F6", menuItem_Click, "child silent");
menuNavigateGoToStartOfSelection = CreateMenuItem("Go to Start of Selection", "Alt+Shift+F8", menuItem_Click, "child speak");
menuNavigate.DropDownItems.AddRange(new ToolStripItem[] {menuNavigateForwardFind, menuNavigateReverseFind, menuNavigateForwardFindWithRegExp, menuNavigateReverseFindWithRegExp, menuNavigateForwardFindAtCursor, menuNavigateReverseFindAtCursor, menuNavigateForwardFindAgain, menuNavigateReverseFindAgain, menuNavigateJumpToLine, menuNavigateJumpToLineAgain, menuNavigateGoToPercent, menuNavigateGoToPercentAgain, menuNavigateGoToPart, menuNavigateSetBookmark, menuNavigateClearBookmark, menuNavigateGoToBookmark, menuNavigateHomeCharacter, menuNavigateEndCharacter, menuNavigateStartTag, menuNavigateEndTag, menuNavigateNextJustify, menuNavigatePriorJustify, menuNavigateNextStyle, menuNavigatePriorStyle, menuNavigateNextBaseline, menuNavigatePriorBaseline, menuNavigateNextFont, menuNavigatePriorFont, menuNavigateRightBrace, menuNavigateNextBlock, menuNavigatePriorBlock, menuNavigateLeftBrace, menuNavigateNextIndent, menuNavigatePriorIndent, menuNavigateNextChunk, menuNavigatePriorChunk, menuNavigateNextSentence, menuNavigatePriorSentence, menuNavigateNextParagraph, menuNavigatePriorParagraph, menuNavigateNextPart, menuNavigatePriorPart, menuNavigateNextSection, menuNavigatePriorSection, menuNavigateGoToSection, menuNavigateGoToContents, menuNavigateSearchForTopic, menuNavigateSearchForTopicAgain, menuNavigateGoToStartOfSelection});
//Dialog.Show("Navigate.", menuNavigate.DropDownItems.Count);
menuQuery = CreateMenu("&Query");
menuQueryAddress = CreateMenuItem("Address", "Alt+A", menuItem_Click, "child silent");
menuQueryBraces = CreateMenuItem("Braces", "Alt+Shift+OemCloseBrackets", menuItem_Click, "child silent");
menuQueryBlock = CreateMenuItem("Block", "Alt+B", menuItem_Click, "child silent");
menuQueryIndent = CreateMenuItem("Indentation", "Alt+I", menuItem_Click, "child silent");
menuQueryPath = CreateMenuItem("Path", "Alt+P", menuItem_Click, "child silent");
menuQueryTopic = CreateMenuItem("Topic", "Alt+T", menuItem_Click, "child speak");
menuQueryYield = CreateMenuItem("Yield", "Alt+Y", menuItem_Click, "child speak");
menuQueryStatus = CreateMenuItem("Status", "Alt+Z", menuItem_Click, "child silent");
menuQueryCompiler = CreateMenuItem("Compiler", "Alt+D0", menuItem_Click, "frame silent");
menuQuerySelected = CreateMenuItem("Selected", "Shift+Space", menuItem_Click, "child silent");
menuQueryChunk = CreateMenuItem("Chunk", "Shift+Back", menuItem_Click, "child silent");
menuQueryReadAll = CreateMenuItem("Read All", "Alt+F8", menuItem_Click, "child speak");
menuQueryWindowsOpen = CreateMenuItem("Windows Open", "Shift+F4", menuItem_Click, "child speak");
menuQueryClipboard = CreateMenuItem("Clipboard", "Alt+OemQuotes", menuItem_Click, "frame silent");
menuQueryTime = CreateMenuItem("Time", "Alt+OemSemicolon", menuItem_Click, "frame silent");
menuQueryStyles = CreateMenuItem("Styles", "Alt+OemQuestion", menuItem_Click, "child silent");
menuQueryFont = CreateMenuItem("Font", "Alt+OemMinus", menuItem_Click, "child silent");
menuQuery.DropDownItems.AddRange(new ToolStripItem[] {menuQueryAddress, menuQueryBraces, menuQueryBlock, menuQueryIndent, menuQueryPath, menuQueryTopic, menuQueryYield, menuQueryStatus, menuQueryCompiler, menuQuerySelected, menuQueryChunk, menuQueryReadAll, menuQueryWindowsOpen, menuQueryClipboard, menuQueryTime, menuQueryStyles, menuQueryFont});
//Dialog.Show("Query.", menuQuery.DropDownItems.Count);
menuMisc = CreateMenu("&Misc");
menuMiscSetDefaultFont = CreateMenuItem("Set Default Font and Color ...", "Alt+Shift+Oemplus", menuItem_Click, "child speak");
menuMiscConfigurationOptions = CreateMenuItem("Configuration Options ...", "Alt+Shift+C", menuItem_Click, "frame silent");
menuMiscManualOptions = CreateMenuItem("Manual Options", "Alt+Shift+M", menuItem_Click, "frame silent");
menuMiscResetConfiguration = CreateMenuItem("Reset Configuration", "Alt+Shift+D0", menuItem_Click, "frame silent");
menuMiscGoToFolder = CreateMenuItem("Go to Folder", "Control+D0", menuItem_Click, "frame silent");
menuMiscGoToSpecialFolder = CreateMenuItem("Go to Special Folder", "Control+Shift+D0", menuItem_Click, "frame silent");
menuMiscWordWrap = CreateMenuItem("&Word Wrap", "Control+W", menuItem_Click, "child speak");
menuMiscUnwrap = CreateMenuItem("Unwrap", "Control+Shift+W", menuItem_Click, "child speak");
menuMiscExtraSpeechToggle = CreateMenuItem("Extra Speech Toggle", "Control+Shift+X", menuItem_Click, "frame silent");
menuMiscExtraSpeechLog = CreateMenuItem("Extra Speech Log", "Alt+Shift+X", menuItem_Click, "frame speak");
menuMiscEnvironmentVariables = CreateMenuItem("&Environment Variables ...", "Control+E", menuItem_Click, "frame speak");
menuMiscSpellCheck = CreateMenuItem("Spell Check", "F7", menuItem_Click, "child speak");
menuMiscThesaurus = CreateMenuItem("Thesaurus", "Shift+F7", menuItem_Click, "child speak");
menuMiscLookupTerm = CreateMenuItem("Lookup Term", "Alt+F7", menuItem_Click, "frame silent");
menuMiscTranslateLanguage = CreateMenuItem("Translate Language", "Alt+Shift+F7", menuItem_Click, "frame speak");
menuMiscGuardDocument = CreateMenuItem("Guard Document", "Control+F7", menuItem_Click, "child speak");
menuMiscNoGuard = CreateMenuItem("No Guard", "Control+Shift+F7", menuItem_Click, "child speak");
menuMiscPyBrace = CreateMenuItem("PyBrace", "Alt+Shift+OemOpenBrackets", menuItem_Click, "child speak");
menuMiscPyDent = CreateMenuItem("PyDent", "Alt+OemOpenBrackets", menuItem_Click, "child speak");
menuMiscInferIndent = CreateMenuItem("Infer Indent", "Alt+OemCloseBrackets", menuItem_Click, "child silent");
menuMiscFormatCode = CreateMenuItem("Format Code", "Control+D4", menuItem_Click, "child speak");
menuMiscRepeatLine = CreateMenuItem("Repeat Line", "Control+Y", menuItem_Click, "child speak");
menuMiscSectionBreak = CreateMenuItem("Section Break", "Control+Enter", menuItem_Click, "child speak");
menuMiscPathToClipboard = CreateMenuItem("Path to Clipboard", "Alt+Shift+P", menuItem_Click, "child speak");
menuMiscPathList = CreateMenuItem("Path List", "Control+Shift+P", menuItem_Click, "frame speak");
menuMiscInsertTime = CreateMenuItem("Insert Time", "Alt+Shift+OemSemicolon", menuItem_Click, "child speak");
menuMiscCalculateDate = CreateMenuItem("Calculate Date ...", "Control+Shift+OemSemicolon", menuItem_Click, "child silent");
menuMiscHTMLFormat = CreateMenuItem("HTML Format", "Control+H", menuItem_Click, "child speak");
menuMiscTextConvert = CreateMenuItem("&Text Convert", "Control+T", menuItem_Click, "child speak");
menuMiscTextCombine = CreateMenuItem("Text Combine", "Control+Shift+T", menuItem_Click, "child speak");
menuMiscTextContents = CreateMenuItem("Text Contents", "Alt+Shift+T", menuItem_Click, "child speak");
menuMiscYieldWithRegExp = CreateMenuItem("Yield with Regular Expression ...", "Control+Shift+Y", menuItem_Click, "child silent");
//menuMiscYieldWithRegExp.ShortcutKeys = Util.String2Key("Control+Shift+Y");
menuMiscExtractWithRegExp = CreateMenuItem("Extract with Regular Expression ...", "Control+Shift+E", menuItem_Click, "child silent");
menuMiscRunAtCursor = CreateMenuItem("Run at Cursor ...", "Shift+F5", menuItem_Click, "child silent");
menuMiscSpecialCharacter = CreateMenuItem("Special Character ...", "F2", menuItem_Click, "child silent");
menuMiscEvaluateExpression = CreateMenuItem("Evaluate Expression", "Control+Oemplus", menuItem_Click, "child speak");
menuMiscReplaceTokens = CreateMenuItem("Replace Tokens", "Control+Shift+Oemplus", menuItem_Click, "child silent");
menuMiscTransformFiles = CreateMenuItem("Transform Files", "Alt+Oemplus", menuItem_Click, "child speak");
menuMiscGoToEnvironment = CreateMenuItem("Go to Environment", "Control+Shift+G", menuItem_Click, "frame speak");
menuMiscCompile = CreateMenuItem("Compile", "Control+F5", menuItem_Click, "child speak");
menuMiscPickCompiler = CreateMenuItem("Pick Compiler", "Control+Shift+F5", menuItem_Click, "frame silent");
menuMiscPromptCommand = CreateMenuItem("Prompt Command", "Alt+F5", menuItem_Click, "child silent");
menuMiscReviewOutput = CreateMenuItem("Review Output", "Alt+Shift+F5", menuItem_Click, "child speak");
menuMiscSaveSnippet = CreateMenuItem("Save Snippet", "Alt+S", menuItem_Click, "child speak");
menuMiscInvokeSnippet = CreateMenuItem("Invoke Snippet", "Alt+V", menuItem_Click, "child speak");
menuMiscViewSnippet = CreateMenuItem("View Snippet", "Alt+Shift+V", menuItem_Click, "frame speak");
menuMiscKeepUniqueItems = CreateMenuItem("Keep Unique Items", "Alt+Shift+K", menuItem_Click, "child speak");
menuMiscNumberItems = CreateMenuItem("Number Items ...", "Alt+Shift+N", menuItem_Click, "child silent");
menuMiscOrderItems = CreateMenuItem("Order Items", "Alt+Shift+O", menuItem_Click, "child speak");
menuMiscReverseItems = CreateMenuItem("Reverse Items", "Alt+Shift+Z", menuItem_Click, "child speak");
menuMiscListDifferentItems = CreateMenuItem("List Different Items", "Alt+Shift+L", menuItem_Click, "child speak");
menuMiscQueryCommonItems = CreateMenuItem("Query Common Items", "Alt+Shift+Q", menuItem_Click, "child speak");
menuMiscExplorerFolder = CreateMenuItem("Explorer Folder", "Alt+Oem5", menuItem_Click, "frame speak");
menuMiscCommandPrompt = CreateMenuItem("Command Prompt", "Control+Oem5", menuItem_Click, "frame speak");