-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrmMain.cs
4104 lines (3693 loc) · 149 KB
/
FrmMain.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.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Speech.Synthesis;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Drawing;
// Roughly 17,483 lines of code total as of 2-26-2022.
// Important Points in this module:
// FrmMain_PreviewKeyDown
// string rtf = RTBMain.Rtf; // For changes to keyboard shortcuts dieplays
namespace Tachufind
{
public partial class FrmMain : Form
{
//public sealed class SpellCheck { };
public FrmMain()
{
InitializeComponent();
}
SpeechSynthesizer synth = new SpeechSynthesizer();
bool loadfirst = true;
bool synthStopped = false;
string[] lines;
int lineNumber = 0; // for speech synthesizer
List<LineInfo> lineInfo = new List<LineInfo>();
Dictionary<int, LineInfo> lineInfoDict = new Dictionary<int, LineInfo>();
public static Queue<SearchInstance> queSearches = new Queue<SearchInstance>();
readonly InputLanguage cultureInfo = InputLanguage.CurrentInputLanguage;
public static PageSetupDialog PageSetupDialog1 = new PageSetupDialog();
public System.Drawing.Printing.PageSettings DefaultPageSettings { get; set; }
readonly Stack<int> returnStack = new Stack<int>();
readonly GeneralFns genFns = new GeneralFns();
readonly FileIO FIO = new FileIO();
readonly FrmAboutApp frmAboutApp = new FrmAboutApp();
readonly FrmSaved frmSaved = new FrmSaved();
readonly FrmGetQuizes frmGetQuizes = new FrmGetQuizes();
readonly FrmOptions frmOptions = new FrmOptions();
public static FrmQuiz frmQuiz = new FrmQuiz();
readonly FrmSection frmSection = new FrmSection();
readonly FrmShortcuts frmShortcuts = new FrmShortcuts();
readonly FrmUser frmUser = new FrmUser();
public static FrmOCR frmOCR = new FrmOCR();
int EOF;
int clickNum = 1;
public Color findColor; // color of the string
public string findString; // string to find
public int boundryMarkerCount = 0;
public int cursorPreSearchPosition = 0;
static int timeLeft = 0;
KeyboardShortcuts keyboardShortcuts = new KeyboardShortcuts();
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
Globals.User_Settings.Save(); // MyUserSettings - For saving form location, RTBBackcolor, etc
e.Cancel = false;
bool cancelClose = IfNotsavedDocPromptAndSave(sender, e);
if (cancelClose)
{
e.Cancel = true;
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString(), "Error Detected", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
// LOCATION ifNotsavedDocPromptAndSave
bool IfNotsavedDocPromptAndSave(object sender, EventArgs e)
{
if (Globals.SpeechSynthClosing) { Globals.SpeechSynthClosing = false; return false; }
int answer = 0;
if (Globals.PBoolRTBModified == true)
{
ToggleFormVisibility();
answer = (int)MessageBox.Show("Save changes to this document?", "Unsaved Document", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (answer == (int)System.Windows.Forms.DialogResult.Yes)
{
// Save the presently open file
SaveFileBasedOnExtensionType(Globals.User_Settings.FilePath);
return false;
}
if (answer == (int)System.Windows.Forms.DialogResult.Cancel)
{
return true;
}
}
return false;
}
private void SetDefaultColors() {
Globals.User_Settings = new MyUserSettings();
Globals.User_Settings.Color00 = Color.White;
Globals.User_Settings.Color01 = Color.FromArgb(255, 0, 0, 255); // Blue
Globals.User_Settings.Color02 = Color.FromArgb(255, 0, 255, 0); // Green
Globals.User_Settings.Color03 = Color.FromArgb(255, 255, 0, 0); // Red
Globals.User_Settings.Color04 = Color.FromArgb(255, 0, 255, 255); // Yellow
Globals.User_Settings.Color05 = Color.FromArgb(255, 148, 0, 211); // Dark Violet 5
Globals.User_Settings.Color06 = Color.FromArgb(255, 139, 69, 19); // Saddle Brown
Globals.User_Settings.Color07 = Color.FromArgb(255, 112, 128, 144); // Slate Gray
Globals.User_Settings.Color08 = Color.FromArgb(255, 30, 144, 255); // Dodger Blue
Globals.User_Settings.Color09 = Color.FromArgb(255, 220, 20, 60); // Crimson
Globals.User_Settings.Color10 = Color.FromArgb(255, 128, 128, 0); // Olive
Globals.User_Settings.Color11 = Color.Black;
}
private void FrmMain_Load(object sender, EventArgs e)
{
SpeechSynthesizer synth = new SpeechSynthesizer();
Globals.Synth = synth;
synth.SetOutputToDefaultAudioDevice();
Globals.User_Settings = new MyUserSettings();
Globals.User_Settings.Color00 = Color.White;
if (Globals.User_Settings.Color01 == null){ Globals.User_Settings.Color01 = Color.FromArgb(255, 0, 0, 255);} // Blue
if (Globals.User_Settings.Color02 == null){ Globals.User_Settings.Color02 = Color.FromArgb(255, 0, 255, 0);} // Green
if (Globals.User_Settings.Color03 == null){ Globals.User_Settings.Color03 = Color.FromArgb(255, 255, 0, 0); } // Red
if (Globals.User_Settings.Color04 == null){ Globals.User_Settings.Color04 = Color.FromArgb(255, 0, 255, 255); } // Yellow
if (Globals.User_Settings.Color05 == null){ Globals.User_Settings.Color05 = Color.FromArgb(255, 148, 0, 211);} // Dark Violet 5
if (Globals.User_Settings.Color06 == null){ Globals.User_Settings.Color06 = Color.FromArgb(255, 139, 69, 19); } // Saddle Brown
if (Globals.User_Settings.Color07 == null){ Globals.User_Settings.Color07 = Color.FromArgb(255, 112, 128, 144);} // Slate Gray
if (Globals.User_Settings.Color08 == null){ Globals.User_Settings.Color08 = Color.FromArgb(255, 30, 144, 255); } // Dodger Blue
if (Globals.User_Settings.Color09 == null){ Globals.User_Settings.Color09 = Color.FromArgb(255, 220, 20, 60);} // Crimson
if (Globals.User_Settings.Color10 == null) { Globals.User_Settings.Color10 = Color.FromArgb(255, 128, 128, 0); } // Olive
Globals.User_Settings.Color11 = Color.Black;
//this.DataBindings.Add(new Binding("BackColor", Globals.user_settings, "RTBMainBackColor"));
this.RTBMain.LanguageOption = RichTextBoxLanguageOptions.UIFonts;
Globals.FindStart = 0;
this.KeyPreview = true;
//this.PreviewKeyDown += FrmMain_PreviewKeyDown;
// For AutoOpen File at startup (Properties.chkOpenFromLastLocation)
string ext; // = "";
string fileContents; // = "";
// NEED TO ADD BETA TIME FRAME
// LOCATION согласен
try
{
Cursor.Current = Cursors.Default;
SetDefaultSearch(); // search initialization for FrmColor
// User agreement
//frmUser.ShowDialog();
// Check to see if User has agreed to User Agreement (this is temporarily disabled)
if (!(Globals.User_Settings.StrSetUserAgreed == "согласен"))
{
FrmUser frmUser = new FrmUser();
frmUser.Visible = false;
frmUser.ShowDialog(); // Show User Agreement
}
if (!Globals.User_Settings.StrSetUserAgreed.Contains("согласен"))
{
System.Windows.Forms.Application.Exit();
}
// Set Form location before changing Global.init to false. (FrmMain_LocationChanged)
// Uses if(Globals.init == true) { return; } to prevent premature registration of form location at start up.
this.Left = Globals.User_Settings.FrmMainLocation.X;
this.Top = Globals.User_Settings.FrmMainLocation.Y;
this.Width = Globals.User_Settings.FrmMainSize.Width;
this.Height = Globals.User_Settings.FrmMainSize.Height;
Globals.FrmMainInit = false; // End INIT phase, allow updates of forms when they are repositioned
// Top Buttons
this.FrmMainColorBtn01.BackColor = Globals.User_Settings.Color01;
this.FrmMainColorBtn02.BackColor = Globals.User_Settings.Color02;
this.FrmMainColorBtn03.BackColor = Globals.User_Settings.Color03;
this.FrmMainColorBtn04.BackColor = Globals.User_Settings.Color04;
this.FrmMainColorBtn05.BackColor = Globals.User_Settings.Color05;
// Bottom .buttons
this.FrmMainColorBtn06.BackColor = Globals.User_Settings.Color06;
this.FrmMainColorBtn07.BackColor = Globals.User_Settings.Color07;
this.FrmMainColorBtn08.BackColor = Globals.User_Settings.Color08;
this.FrmMainColorBtn09.BackColor = Globals.User_Settings.Color09;
this.FrmMainColorBtn10.BackColor = Globals.User_Settings.Color10;
clickNum = 0;
frmAboutApp.Visible = false;
//frmColor.Visible = false;
frmGetQuizes.Visible = false;
frmOptions.Visible = false;
frmQuiz.Visible = false;
frmSection.Visible = false;
frmShortcuts.Visible = false;
frmSaved.Visible = false;
frmUser.Visible = false;
frmOCR.Visible = false;
this.RTBMain.EnableAutoDragDrop = true;
//this.RTBMain.SelectionIndent = 2;
//this.RTBMain.SelectionRightIndent = 2;
if (Globals.User_Settings.FilePath.Length > 0)
{
this.Text = "Tachufind Editing: " + Globals.User_Settings.FilePath;
}
else
{ // If file not exist, set default X positions, Y positions, width and height.
this.Text = "Tachufind Editing: New file";
}
Globals.BoolCursorState = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
this.RTBMain.AutoWordSelection = true;
Globals.PBoolRTBModified = false;
this.RTBMain.WordWrap = true;
Globals.Current_RTB_withFocus = this.RTBMain;
this.RTBMain.SelectionStart = Globals.User_Settings.CursorPosition;
btnQuiz.Visible = true;
// For AutoOpen File at startup (Properties.chkOpenFromLastLocation)
if (Globals.User_Settings.FrmOptionsOpenFromLastLocation & File.Exists(Globals.User_Settings.FilePath))
{
fileContents = FIO.ReadFile(Globals.User_Settings.FilePath01);
ext = FIO.GetFileExtension(Globals.User_Settings.FilePath); // Get Extension in UpperCase format
SetNewlyOpenedFileSettings();
AddItemsToDropDownList();
if (ext == ".RTF")
{ // this solves the \highlight bug
for (int i = 0; i <= 20; i++)
{
fileContents.Replace("\\highlight" + Convert.ToString(i), ""); // Get rid of \\highlight0, \\highlight1, etc.
}
this.RTBMain.Rtf = fileContents;
Globals.P_RTFMain_RTF = fileContents;
Globals.P_RTFMain_TXT = this.RTBMain.Text;
Globals.PBoolRTBModified = false;
}
if (Globals.User_Settings.FilePath.Length > 0)
{
this.Text = "Tachufind Editing: " + Globals.User_Settings.FilePath;
}
else
{
this.Text = "Tachufind Editing: New file";
}
}
else
{
this.Left = Convert.ToInt32(ClientSize.Width / 2.3);
this.Top = Convert.ToInt32(ClientSize.Height / 8);
if (this.Height > Screen.PrimaryScreen.WorkingArea.Height)
{
this.Height = Convert.ToInt32(ClientSize.Height / 1.2); //860
}
if (this.Width > Screen.PrimaryScreen.WorkingArea.Width)
{
this.Width = Convert.ToInt32(ClientSize.Height / 1.2); // 600
}
}
// make sure form loads to minumum standards
if (this.Width < 200) {
this.Width = 200;
}
if (this.Height < 200)
{
this.Height = 200;
}
RTBSearch.ForeColor = Color.Black;
Globals.PBoolRTBModified = false;
Cursor.Current = Cursors.Default;
this.RTBMain.SelectionLength = 0;
int cursorposition = this.RTBMain.Text.Length - this.RTBMain.Text.Length + 1;
this.RTBMain.SelectionStart = cursorposition;
Globals.FindStart = 0; // inserted 9-8-2020
this.RTBMain.SelectionStart = Globals.FindStart;
Globals.PBoolRTBModified = false; // must be set to false here due to autofile load
foreach (InstalledVoice voice in Globals.Synth.GetInstalledVoices())
{
if (loadfirst)
{
Globals.Voice = voice.VoiceInfo.Name;
cmboVoice.Text = voice.VoiceInfo.Name;
string description = voice.VoiceInfo.Description.Replace("Microsoft", "").Trim();
description = description.Replace("Desktop ", "");
txtVInfo.Text += description;
txtVInfo.Text += " " + voice.VoiceInfo.Culture + "\r\n";
loadfirst = false;
}
cmboVoice.Items.Add(voice.VoiceInfo.Name);
}
// Recover setting as it existed when app was closed.
if (Globals.User_Settings.TTS_Voice.Length > 1) {
cmboVoice.SelectedItem = cmboVoice.Items.Cast<string>().FirstOrDefault(x => x == Globals.User_Settings.TTS_Voice);
}
this.SpeedChanger.Value = Globals.User_Settings.TTS_Speed;
this.Refresh();
this.Focus();
this.BringToFront();
this.Show();
RTBMain.Focus();
AddItemsToDropDownList(); // inserted 8-4-2022
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString(), "Error Detected", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} // END OF private void FrmMain_Load(object sender, EventArgs e)
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
private void RTBMain_TextChanged(object sender, EventArgs e)
{
Globals.PBoolRTBModified = true;
}
private void BtnColor_Click(object sender, EventArgs e)
{
foreach (Form form in System.Windows.Forms.Application.OpenForms)
{
if (form.Name == "FrmColor")
{
form.Visible = true;
form.Left = Globals.User_Settings.FrmColorLocation.X;
form.Top = Globals.User_Settings.FrmColorLocation.Y;
form.BringToFront();
form.Refresh();
}
}
if (Globals.FrmColorExists == false)
{
FrmColor frmColor = new FrmColor(this);
frmColor.Visible = true;
frmColor.Refresh();
frmColor.BringToFront();
frmColor.Left = Globals.User_Settings.FrmColorLocation.X;
frmColor.Top = Globals.User_Settings.FrmColorLocation.Y;
frmColor.BackColor = Color.FromArgb(200, 190, 200);
Globals.FrmColorExists = true;
}
}
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// FUNCTIONS used by FrmMain_Load(object sender, EventArgs e)
// search initialization for FrmColor
void SetDefaultSearch()
{
// Set searchitems defaults
SearchSettings.SearchName = "";
SearchSettings.rbEditColor = true;
SearchSettings.chkAutoFindNext = true;
//SearchSettings.rbReplaceAll = true;
//SearchSettings.rbSuffix = false;
//SearchSettings.rbPrefix = false;
SearchSettings.chkMatchCase = false;
SearchSettings.chkWordOnly = false;
SearchSettings.chkReverse = false;
SearchSettings.frmColorFind01_Txt = "";
SearchSettings.frmColorReplace01_Txt = "";
SearchSettings.frmColorFind02_Txt = "";
SearchSettings.frmColorReplace02_Txt = "";
SearchSettings.frmColorFind03_Txt = "";
SearchSettings.frmColorReplace03_Txt = "";
SearchSettings.frmColorFind04_Txt = "";
SearchSettings.frmColorReplace04_Txt = "";
SearchSettings.frmColorFind05_Txt = "";
SearchSettings.frmColorReplace05_Txt = "";
SearchSettings.frmColorFind06_Txt = "";
SearchSettings.frmColorReplace06_Txt = "";
SearchSettings.frmColorFind07_Txt = "";
SearchSettings.frmColorReplace07_Txt = "";
SearchSettings.frmColorFind08_Txt = "";
SearchSettings.frmColorReplace08_Txt = "";
SearchSettings.frmColorFind09_Txt = "";
SearchSettings.frmColorReplace09_Txt = "";
SearchSettings.frmColorFind10_Txt = "";
SearchSettings.frmColorReplace10_Txt = "";
// LOCATION Button Colors
// Top Buttons
this.FrmMainColorBtn01.BackColor = Globals.User_Settings.Color01; // colorStore.GetColor("C3");
this.FrmMainColorBtn02.BackColor = Globals.User_Settings.Color02;
this.FrmMainColorBtn03.BackColor =Globals.User_Settings.Color03;
this.FrmMainColorBtn04.BackColor =Globals.User_Settings.Color04;
this.FrmMainColorBtn05.BackColor = Globals.User_Settings.Color05;
//
this.FrmMainColorBtn06.BackColor = Globals.User_Settings.Color06;
this.FrmMainColorBtn07.BackColor = Globals.User_Settings.Color07;
this.FrmMainColorBtn08.BackColor = Globals.User_Settings.Color08;
this.FrmMainColorBtn09.BackColor = Globals.User_Settings.Color09;
this.FrmMainColorBtn10.BackColor = Globals.User_Settings.Color10;
}
// END of void setDefaultSearch()
// All AppProperties need to be set before
public void SetNewlyOpenedFileSettings()
{
try
{
this.Left = Globals.User_Settings.FrmMainLocation.X;
this.Top = Globals.User_Settings.FrmMainLocation.Y;
//this.Left = Convert.ToInt32(Globals.FrmMainXLocation);
//this.Top = Convert.ToInt32(Globals.FrmMainYLocation);
this.Width = Convert.ToInt32(Globals.User_Settings.FrmMainSize.Width);
this.Height = Convert.ToInt32(Globals.User_Settings.FrmMainSize.Height);
Globals.FindStart = 0;
this.RTBMain.SelectionStart = Globals.FindStart;
//ColorDialog dlg = new ColorDialog();
//dlg.AnyColor = true;
//dlg.Color = Globals.user_settings.RTBMainBackColor;
//Globals.user_settings.RTBMainBackColor = Globals.backColorStd;
RTBMain.SelectAll();
RTBMain.BackColor = Globals.User_Settings.RTBMainBackColor;
RTBMain.SelectionBackColor = Globals.User_Settings.RTBMainBackColor;
RTBMain.SelectionLength = 0;
//RTBMain.SelectionStart = 0;
Globals.PBoolRTBModified = false;
// CHANGE - ScrollToCaret() To scroll to top of textbox
RTBMain.ScrollToCaret();
//dlg.Dispose();
// this SearchItems.colorBtn0 info needs to be converted after being read from the info file
}
// END of public void setNewlyOpenedFileSettings()
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString(), "Error Detected", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} // End of public void setNewlyOpenedFileSettings()
// TODO preserve file history so it can be loaded on new install
// LOCATION Adds items back to the dropdown list
public void AddItemsToDropDownList() // This fn added to VS 9-12-2020
{
if (Globals.User_Settings.FilePath01.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath01);
}
if (Globals.User_Settings.FilePath02.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath02);
}
if (Globals.User_Settings.FilePath03.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath03);
}
if (Globals.User_Settings.FilePath04.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath04);
}
if (Globals.User_Settings.FilePath05.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath05);
}
if (Globals.User_Settings.FilePath06.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath06);
}
if (Globals.User_Settings.FilePath07.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath07);
}
if (Globals.User_Settings.FilePath08.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath08);
}
if (Globals.User_Settings.FilePath09.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath09);
}
if (Globals.User_Settings.FilePath10.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath10);
}
if (Globals.User_Settings.FilePath11.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath11);
}
if (Globals.User_Settings.FilePath12.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath12);
}
if (Globals.User_Settings.FilePath13.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath13);
}
if (Globals.User_Settings.FilePath14.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath14);
}
if (Globals.User_Settings.FilePath15.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath15);
}
if (Globals.User_Settings.FilePath16.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath16);
}
if (Globals.User_Settings.FilePath17.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath17);
}
if (Globals.User_Settings.FilePath18.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath18);
}
if (Globals.User_Settings.FilePath19.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath19);
}
if (Globals.User_Settings.FilePath20.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath20);
}
if (Globals.User_Settings.FilePath21.Length > 0)
{
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath21);
}
} // END of public void addItemsToDropDownList()
// END FUNCTIONS used by FrmMain_Load(object sender, EventArgs e)
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
public bool CheckEntryForSearch()
{
bool check = true;
int EndOfFile = this.RTBMain.TextLength;
string find = "";
find = GeneralFns.DoTrim(this.RTBSearch.Text);
if (EndOfFile < 2)
{
MessageBox.Show("Error: There is no file to search!");
check = false;
}
return check;
}
// if a form is currently visible, make it invisible, then on next function run, toggle it back to visible
private void ToggleFormVisibility() {
for (int i = System.Windows.Forms.Application.OpenForms.Count - 1; i >= 0; i--)
{
if (System.Windows.Forms.Application.OpenForms[i].Name != "FrmMain")
System.Windows.Forms.Application.OpenForms[i].Visible = false;
}
}
private void SaveFileBasedOnExtensionType(string filePath)
{
string strExt = null;
FileIO File_IO = new FileIO();
try
{
strExt = System.IO.Path.GetExtension(filePath);
strExt = strExt.ToUpper();
switch (strExt)
{
case ".RTF":
RTBMain.SaveFile(filePath);
break;
default:
// to save as plain text
Cursor.Current = Cursors.WaitCursor;
File_IO.WriteFile(filePath, RTBMain.Text);
this.RTBMain.SelectionStart = 0;
this.RTBMain.SelectionLength = 0;
Cursor.Current = Cursors.Default;
break;
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString(), "Error Detected", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
// LOCATION Fix highlighting bug
string FixHighLightingBug(string rtfText)
{
string extension = FIO.GetFileExtension(Globals.User_Settings.FilePath);
extension = extension.ToUpper();
if (extension == ".RTF")
{
// this solves the \highlight bug
int i = 0;
for (i = 0; i <= 20; i++)
{
rtfText.Replace("\\highlight" + Convert.ToString(i), "");
}
}
return rtfText;
}
void DisplayFilePath()
{
if (Globals.User_Settings.FilePath.Length > 0)
{
this.Text = "Tachufind Editing: " + Globals.User_Settings.FilePath;
}
else
{
this.Text = "Tachufind Editing: New file";
}
}
void HandleDropDownListItems()
{
if (Globals.User_Settings.FilePath01 == Globals.User_Settings.FilePath)
{
return;
}
if (Globals.User_Settings.FilePath01 == "")
{
Globals.User_Settings.FilePath01 = Globals.User_Settings.FilePath;
this.fileToolStripMenuItem.DropDownItems.Add(Globals.User_Settings.FilePath);
return;
}
// Properties.filePath01 != Properties.filePath
RemoveItemFromDropDownList(Globals.User_Settings.FilePath);
IncrementFilePathPositions();
ClearDuplicates();
AddItemsToDropDownList();
}
// Removes an item from the dropdown list
public void RemoveItemFromDropDownList(string filePath)
{
try
{
if (filePath.Length < 1) { return; }
int dropDownItemsCount = 7;
while (this.fileToolStripMenuItem.DropDownItems.Count > dropDownItemsCount)
{ // LOCATION - Setting for number of menu items
this.fileToolStripMenuItem.DropDownItems.RemoveAt(dropDownItemsCount);
}
// Clear any listings that match filePath
if (Globals.User_Settings.FilePath01 == filePath) { Globals.User_Settings.FilePath01 = ""; }
if (Globals.User_Settings.FilePath02 == filePath) { Globals.User_Settings.FilePath02 = ""; }
if (Globals.User_Settings.FilePath03 == filePath) { Globals.User_Settings.FilePath03 = ""; }
if (Globals.User_Settings.FilePath04 == filePath) { Globals.User_Settings.FilePath04 = ""; }
if (Globals.User_Settings.FilePath05 == filePath) { Globals.User_Settings.FilePath05 = ""; }
if (Globals.User_Settings.FilePath06 == filePath) { Globals.User_Settings.FilePath06 = ""; }
if (Globals.User_Settings.FilePath07 == filePath) { Globals.User_Settings.FilePath07 = ""; }
if (Globals.User_Settings.FilePath08 == filePath) { Globals.User_Settings.FilePath08 = ""; }
if (Globals.User_Settings.FilePath09 == filePath) { Globals.User_Settings.FilePath09 = ""; }
if (Globals.User_Settings.FilePath10 == filePath) { Globals.User_Settings.FilePath10 = ""; }
if (Globals.User_Settings.FilePath11 == filePath) { Globals.User_Settings.FilePath11 = ""; }
if (Globals.User_Settings.FilePath12 == filePath) { Globals.User_Settings.FilePath12 = ""; }
if (Globals.User_Settings.FilePath13 == filePath) { Globals.User_Settings.FilePath13 = ""; }
if (Globals.User_Settings.FilePath14 == filePath) { Globals.User_Settings.FilePath14 = ""; }
if (Globals.User_Settings.FilePath15 == filePath) { Globals.User_Settings.FilePath15 = ""; }
if (Globals.User_Settings.FilePath16 == filePath) { Globals.User_Settings.FilePath16 = ""; }
if (Globals.User_Settings.FilePath17 == filePath) { Globals.User_Settings.FilePath17 = ""; }
if (Globals.User_Settings.FilePath18 == filePath) { Globals.User_Settings.FilePath18 = ""; }
if (Globals.User_Settings.FilePath19 == filePath) { Globals.User_Settings.FilePath19 = ""; }
if (Globals.User_Settings.FilePath20 == filePath) { Globals.User_Settings.FilePath20 = ""; }
if (Globals.User_Settings.FilePath21 == filePath) { Globals.User_Settings.FilePath21 = ""; }
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString(), "Error Detected", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
void IncrementFilePathPositions()
{
// Move everything down starting from highest to lowest
// overwritinging filePath13
Globals.User_Settings.FilePath21 = Globals.User_Settings.FilePath20;
Globals.User_Settings.FilePath20 = Globals.User_Settings.FilePath19;
Globals.User_Settings.FilePath19 = Globals.User_Settings.FilePath18;
Globals.User_Settings.FilePath18 = Globals.User_Settings.FilePath17;
Globals.User_Settings.FilePath17 = Globals.User_Settings.FilePath16;
Globals.User_Settings.FilePath16 = Globals.User_Settings.FilePath15;
Globals.User_Settings.FilePath15 = Globals.User_Settings.FilePath14;
Globals.User_Settings.FilePath14 = Globals.User_Settings.FilePath13;
Globals.User_Settings.FilePath13 = Globals.User_Settings.FilePath12;
Globals.User_Settings.FilePath12 = Globals.User_Settings.FilePath11;
Globals.User_Settings.FilePath11 = Globals.User_Settings.FilePath10;
Globals.User_Settings.FilePath10 = Globals.User_Settings.FilePath09;
Globals.User_Settings.FilePath09 = Globals.User_Settings.FilePath08;
Globals.User_Settings.FilePath08 = Globals.User_Settings.FilePath07;
Globals.User_Settings.FilePath07 = Globals.User_Settings.FilePath06;
Globals.User_Settings.FilePath06 = Globals.User_Settings.FilePath05;
Globals.User_Settings.FilePath05 = Globals.User_Settings.FilePath04;
Globals.User_Settings.FilePath04 = Globals.User_Settings.FilePath03;
Globals.User_Settings.FilePath03 = Globals.User_Settings.FilePath02;
Globals.User_Settings.FilePath02 = Globals.User_Settings.FilePath01;
Globals.User_Settings.FilePath01 = Globals.User_Settings.FilePath;
}
void ClearDuplicates()
{
string f1 = Globals.User_Settings.FilePath01; string f2 = Globals.User_Settings.FilePath02;
string f3 = Globals.User_Settings.FilePath03; string f4 = Globals.User_Settings.FilePath04;
string f5 = Globals.User_Settings.FilePath05; string f6 = Globals.User_Settings.FilePath06;
string f7 = Globals.User_Settings.FilePath07; string f8 = Globals.User_Settings.FilePath08;
string f9 = Globals.User_Settings.FilePath09; string f10 = Globals.User_Settings.FilePath10;
string f11 = Globals.User_Settings.FilePath11; string f12 = Globals.User_Settings.FilePath12;
string f13 = Globals.User_Settings.FilePath13; string f14 = Globals.User_Settings.FilePath14;
string f15 = Globals.User_Settings.FilePath15; string f16 = Globals.User_Settings.FilePath16;
string f17 = Globals.User_Settings.FilePath17; string f18 = Globals.User_Settings.FilePath18;
string f19 = Globals.User_Settings.FilePath19; string f20 = Globals.User_Settings.FilePath20;
string f21 = Globals.User_Settings.FilePath21;
string[] reference = { f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21 };
//string[] filepaths = reference.Distinct().ToArray(); // Clear duplicates
string[] filepaths = reference.Where(x => !string.IsNullOrEmpty(x)).Distinct().ToArray();
var result = filepaths.OrderBy(x => x == "").ThenBy(x => ""); // Move all "" to right
Queue queuepath = new Queue();
foreach (string item in result)
{
if (item != "" && (File.Exists(item))) // Added (File.Exists(item)) 3-5-2023
{
queuepath.Enqueue(item); // Add authentic paths to queue
}
}
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath01 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath01 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath02 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath02 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath03 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath03 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath04 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath04 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath05 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath05 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath06 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath06 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath07 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath07 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath08 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath08 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath09 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath09 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath10 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath10 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath11 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath11 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath12 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath12 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath13 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath13 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath14 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath14 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath15 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath15 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath16 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath16 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath17 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath17 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath18 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath18 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath19 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath19 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath20 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath20 = ""; }
if (queuepath.Count > 0)
{
Globals.User_Settings.FilePath21 = (string)queuepath.Dequeue();
}
else { Globals.User_Settings.FilePath21 = ""; }
}
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// End Of FILE Menu
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// General Functions Region
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
public RichTextBoxFinds GetFindMode()
{
SearchInstance searchItem = new SearchInstance();
RichTextBoxFinds caseMode = 0;
RichTextBoxFinds wordMode = 0;
RichTextBoxFinds directionMode = 0;
searchItem.RichTextBoxFinds_GFindMode = 0;
// clear
if (SearchSettings.chkMatchCase == true)
{
caseMode = RichTextBoxFinds.MatchCase;
// 4 0100
}
if (SearchSettings.chkWordOnly == true)
{
wordMode = RichTextBoxFinds.WholeWord;
// 2 0010
}
if (SearchSettings.chkReverse == true)
{
directionMode = RichTextBoxFinds.Reverse;
// 16 1000
}
searchItem.RichTextBoxFinds_GFindMode = caseMode | wordMode | directionMode;
return searchItem.RichTextBoxFinds_GFindMode;
}
public void FrmColorBtnFindClick()
{
try
{
EOF = this.RTBMain.Text.Length;
string[] FrmColor_ArryFind_Txts = {SearchSettings.frmColorFind01_Txt, SearchSettings.frmColorFind02_Txt,
SearchSettings.frmColorFind03_Txt, SearchSettings.frmColorFind04_Txt, SearchSettings.frmColorFind05_Txt,
SearchSettings.frmColorFind06_Txt, SearchSettings.frmColorFind07_Txt, SearchSettings.frmColorFind08_Txt,
SearchSettings.frmColorFind09_Txt, SearchSettings.frmColorFind10_Txt};
Color[] colorArray = { Globals.User_Settings.Color01, Globals.User_Settings.Color02, Globals.User_Settings.Color03,
Globals.User_Settings.Color04, Globals.User_Settings.Color05, Globals.User_Settings.Color06, Globals.User_Settings.Color07,
Globals.User_Settings.Color08, Globals.User_Settings.Color09, Globals.User_Settings.Color10};
if (Globals.BtnFindSearchChanged)
{ // if RTBMain clicked
Globals.BtnFindStart = this.RTBMain.SelectionStart;
Globals.BtnFindSearchChanged = false;
}
if (Globals.BtnFindStart < 0)
{ // btnFindStart = -1 EO-One-search
Globals.BtnFindSearchRoundCount += 1; //Globals.btnFindSearchRoundCount + 1;
Globals.BtnFindStart = 0;
if (Globals.BtnFindSearchRoundCount == 8 | FrmColor_ArryFind_Txts[Globals.BtnFindSearchRoundCount] == "")
{
MessageBox.Show("End Of Search", "End Of Search", MessageBoxButtons.OK);
//MessageBox.Show(new Form() { TopMost = true }, "End Of Search", "End Of Search", MessageBoxButtons.OK);
Globals.BtnFindSearchRoundCount = 0;
return;
}
}
string find = FrmColor_ArryFind_Txts[Globals.BtnFindSearchRoundCount]; // get items one by one
Globals.BtnFindStart = this.RTBMain.Find(find, Globals.BtnFindStart, GetFindMode());
if (Globals.BtnFindStart > -1)
{
this.RTBMain.Select(Globals.BtnFindStart, find.Length);
Globals.BtnFindStart = Globals.BtnFindStart + find.Length;
string CNumber = "C" + (Globals.BtnFindSearchRoundCount + 1).ToString();
Globals.BtnFindCurrentColor = colorArray[Globals.BtnFindSearchRoundCount + 1];
}
else
{
this.RTBMain.Select(RTBMain.SelectionStart, 0);
this.BtnReturn.PerformClick();
}
this.Focus();
this.RTBMain.Focus();
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString(), "Error Detected", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public void FrmColorBtnReplaceClick()
{
FrmColor frmColor = new FrmColor(this);
try
{
string[] FrmColor_ArryFind_Txts = {SearchSettings.frmColorFind01_Txt, SearchSettings.frmColorFind02_Txt,
SearchSettings.frmColorFind03_Txt, SearchSettings.frmColorFind04_Txt, SearchSettings.frmColorFind05_Txt,
SearchSettings.frmColorFind06_Txt, SearchSettings.frmColorFind07_Txt, SearchSettings.frmColorFind08_Txt,
SearchSettings.frmColorFind09_Txt, SearchSettings.frmColorFind10_Txt};
string[] FrmColor_ArryReplace_Txts = {SearchSettings.frmColorReplace01_Txt, SearchSettings.frmColorReplace02_Txt,
SearchSettings.frmColorReplace03_Txt, SearchSettings.frmColorReplace04_Txt, SearchSettings.frmColorReplace05_Txt,
SearchSettings.frmColorReplace06_Txt, SearchSettings.frmColorReplace07_Txt, SearchSettings.frmColorReplace08_Txt,
SearchSettings.frmColorReplace09_Txt, SearchSettings.frmColorReplace10_Txt};
if (SearchSettings.rbEditColor)
{
this.RTBMain.SelectionColor = Globals.BtnFindCurrentColor; //Color
this.RTBMain.Select(); // (selStart, 0); // deselect
}
if (SearchSettings.rbEditColor == false) // rbMultipleReplace is selected
{
string test = FrmColor_ArryReplace_Txts[Globals.BtnFindSearchRoundCount];
this.RTBMain.SelectedText = FrmColor_ArryReplace_Txts[Globals.BtnFindSearchRoundCount];
//doFindAutoReplace(Globals.btnFindStart);
}
if (SearchSettings.chkAutoFindNext == true)
{
frmColor.btnFind.PerformClick();
}
}
catch (Exception ex)