-
Notifications
You must be signed in to change notification settings - Fork 18
/
MainForm.cs
2692 lines (2405 loc) · 83.3 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Created by SharpDevelop.
* User: Gheyret Kenji
* Date: 2020/11/11
* Time: 9:27
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using UyghurEditPP.Document;
using UyghurEditPP.FindReplace;
using System.Windows.Forms.Integration;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.Linq;
namespace UyghurEditPP
{
/// <summary>
/// Description of MainForm.
/// </summary>
///
public partial class MainForm : Form
{
public TextEditor gEditor;
int gFileNum = 1;
public static Language gLang = new Language();
ImlaBoya gImlab;
List<String> gIzlar=new List<String>();
Dictionary<string, int> gIzOffset = new Dictionary<string, int>();
KUNUPKA gKunupka = KUNUPKA.System;
//Regex gReg = new Regex(@"[’\w-[_\d]]+([-]+[’\w-[_\d]]+)*"); //@"([’\w-[_\d]]+)"
//ئابتجخدرزسشغفقكلمنوىيپچژڭگھۆۇۈۋېەلا
//Buning siziqchidin nechchisi bolup ketismu boliwetidiken
//Regex gUyghurcheSoz= new Regex("[ئابتجخدرزسشغفقكلمنوىيپچژڭگھۆۇۈۋېەلا]+([-]+[ئابتجخدرزسشغفقكلمنوىيپچژڭگھۆۇۈۋېەلا]+)*",RegexOptions.Compiled);
// //Qoshma soz otturisida peqet we peqetla birla siziqche bolushi kerek
//Buningda siziqchining aldi keynige boshluq kirip qalsimu qoshma soz dep hokum qilidu
//Emma imla ambirida qoshma sozdiki siziqchening aldi keynide boshluq yoq
//Regex gUyghurcheSoz= new Regex("[ئابتجخدرزسشغفقكلمنوىيپچژڭگھۆۇۈۋېەلا]+([ ]?[-{1}][ ]?[ئابتجخدرزسشغفقكلمنوىيپچژڭگھۆۇۈۋېەلا]+)*",RegexOptions.Compiled);
Regex gUyghurcheSoz; //= new Regex("[ـئابتجخدرزسشغفقكلمنوىيپچژڭگھۆۇۈۋېەلا]+([-{1}][ـئابتجخدرزسشغفقكلمنوىيپچژڭگھۆۇۈۋېەلا]+)*",RegexOptions.Compiled);
Regex gLatincheSoz; //= new Regex("[ABCDEFGHIJKLMNOPQRSTUWXYZÉÖÜabcdefghijklmnopqrstuwxyzéöü’']+([-{1}][abcdefghijklmnopqrstuwxyzéöü’']+)*",RegexOptions.Compiled);
Regex gSlawyancheSoz; //= new Regex("[АБВГДЕЖЗИЙКЛМНОПРСТУФХЧШҒҖҚҢҮҺӘӨабвгдежзийклмнопрстуфхчшғҗқңүһәөъ’']+([-{1}][абвгдежзийклмнопрстуфхчшғҗқңүһәөъ’']+)*",RegexOptions.Compiled);
System.Windows.Controls.ContextMenu gContextMenu = new System.Windows.Controls.ContextMenu();
System.Windows.Controls.MenuItem gMenuSozToghra;
System.Windows.Controls.MenuItem gMenuSozTekshurme;
System.Windows.Controls.Separator gMenuSplit, gMenuSplitToghrisi;
int[] gCodePages = {-3,-2,-1,65000,65001,1200,1201,932, 51932, 936, 950, 1250,1251,1252,1253,1254,1255,1256,1257};
public static string gImgexts = "";
Hashtable gConfig= new Hashtable();
string gConfName = @"uyghuredit.cfg";
string gFontName = "UKIJ Tuz";
float gFontSize = 20.0f;
int gFontStyle = 0;
int gFontWeight = 0;
bool gYeziqAuto = true;
FindReplaceDialog gFindReplace = null;
OCRForm gOCR = null;
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//IntPtr appIns = Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]);
//
// TODO: Add constructor code after the InitializeComponent() call.
//
//this.Padding = new Padding(10,10,10,10);
//string pattern = string.Format("[{0}]+([-{{1}}][{1}]+)*",Uyghur.UEYHerpler,Uyghur.UEYHerpler);
string pattern = string.Format("[{0}]+([-]?[{1}]+)*",Uyghur.UEYHerpler,Uyghur.UEYHerpler);
gUyghurcheSoz= new Regex(pattern,RegexOptions.Compiled);
pattern = string.Format("[{0}]+([-]?[{1}]+)*",Uyghur.ULYHerpler,Uyghur.ULYHerpler);
gLatincheSoz= new Regex(pattern,RegexOptions.Compiled);
pattern = string.Format("[{0}]+([-]?[{1}]+)*",Uyghur.USYHerpler,Uyghur.USYHerpler);
gSlawyancheSoz = new Regex(pattern,RegexOptions.Compiled);
gImlab = new ImlaBoya();
gImlab.SpellCheker = new KenjiSpell();
mainTab.RemoveTab += DeleteTab;
//string fontpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "UKIJTuz.ttf".ToUpper());
//System.Diagnostics.Debug.WriteLine(fontpath);
//bool isexsit = File.Exists(fontpath);
//System.Diagnostics.Debug.WriteLine(isexsit);
System.Diagnostics.Debug.WriteLine(IsFontInstalled("UKIJ Tuz"));
var codecs = ImageCodecInfo.GetImageEncoders();
foreach (var codec in codecs)
{
gImgexts += codec.FilenameExtension + ";";
}
gFindReplace = new FindReplaceDialog(gEditor);
gFindReplace.Closing+=FindReplaceClosing;
ElementHost.EnableModelessKeyboardInterop(gFindReplace);
gMenuSozToghra = new System.Windows.Controls.MenuItem();
gMenuSozToghra.Name="TOGHRA";
gMenuSozToghra.FontWeight = System.Windows.FontWeights.Bold;
gMenuSozToghra.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
gMenuSozToghra.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
gMenuSozToghra.Click += menuSozImla;
gMenuSozTekshurme = new System.Windows.Controls.MenuItem();
gMenuSozTekshurme.Name="OTKUZUWET";
gMenuSozTekshurme.FontWeight = System.Windows.FontWeights.Bold;
gMenuSozTekshurme.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
gMenuSozTekshurme.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
gMenuSozTekshurme.Click += menuSozImla;
gConfName = Path.Combine(Application.StartupPath, gConfName);
}
private bool IsFontInstalled(string fontName) {
using (var testFont = new Font(fontName, 8)) {
return 0 == string.Compare(
fontName,
testFont.Name,
StringComparison.InvariantCultureIgnoreCase);
}
}
void PreviewKey(object sender, System.Windows.Input.KeyEventArgs e)
{
int gModkey =(int)Control.ModifierKeys;
gModkey = (gModkey>>16) &0x000f;
if(gModkey == 2) //Ctrl Key
{
if(e.Key== System.Windows.Input.Key.K){ //Ctrl + K
e.Handled = true;
KunupkaClick(null,null);
}
else if(e.Key == System.Windows.Input.Key.End){
e.Handled = true;
MenuHojjetAxirClick(null,null);
}
else if(e.Key == System.Windows.Input.Key.Z){
e.Handled = true;
ToolYeniwalClick(null,null);
}
else if(e.Key == System.Windows.Input.Key.Y){
e.Handled = true;
ToolYPushaymanClick(null,null);
}
else if(e.Key == System.Windows.Input.Key.V){
e.Handled = true;
ToolChaplaClick(null,null);
}
else if(e.Key == System.Windows.Input.Key.C){
e.Handled = true;
ToolKochurClick(null,null);
}
else if(e.Key == System.Windows.Input.Key.X){
e.Handled = true;
ToolKesClick(null,null);
}
else if(e.Key == System.Windows.Input.Key.F || e.Key == System.Windows.Input.Key.H){
e.Handled = true;
FindReplace();
}
}
else if(gModkey == 0 && e.Key== System.Windows.Input.Key.F1 && gEditor.TextArea.Selection.IsMultiline){
char[] spl = {'\r','\n'};
char[] trch= {' ','-'};
string tmp;
string[] selQurlar = gEditor.SelectedText.Split(spl);
StringBuilder newtxt = new StringBuilder();
foreach(string qur in selQurlar){
tmp = qur.TrimEnd();
if (tmp.Length > 0)
{
if (tmp.EndsWith("-"))
{
newtxt.Append(tmp.TrimEnd(trch).TrimEnd());
}
else
{
newtxt.Append(tmp + " ");
}
}
}
gEditor.TextArea.Selection.ReplaceSelectionWithText(newtxt.ToString());
// double vertOffset = (gEditor.TextArea.TextView.DefaultLineHeight) * 33.0;
// gEditor.ScrollToVerticalOffset(vertOffset);
// gEditor.TextArea.Caret.Line = 35;
// gEditor.TextArea.Caret.Column = 0;
}
else if(gModkey == 0 && e.Key== System.Windows.Input.Key.F2){
// double vertOffset = (gEditor.TextArea.TextView.DefaultLineHeight) * 66.0;
// gEditor.ScrollToVerticalOffset(vertOffset);
// gEditor.TextArea.Caret.Line = 68;
// gEditor.TextArea.Caret.Column = 0;
}
else if(gModkey == 0 && e.Key== System.Windows.Input.Key.F4){
// string txt = gEditor.Text;
// string arabic_region = Uyghur.FilterArabic(txt);
// MenuYengiClick(null,null);
// gEditor.Text = arabic_region;
}
}
void ToolIzdeDawamClick(object sender, EventArgs e)
{
FindReplace();
}
void FindReplace(){
gImlab.FindReplace=true;
gEditor.TextArea.TextView.Redraw();
gFindReplace.ShowMe();
// if (!gEditor.TextArea.Selection.IsMultiline)
// {
// gFindReplace.txtFind.FlowDirection = gEditor.FlowDirection;
// gFindReplace.txtFind.Text = gEditor.TextArea.Selection.GetText();
// gFindReplace.txtReplace.FlowDirection = gEditor.FlowDirection;
// gFindReplace.txtFind.SelectAll();
// gFindReplace.txtFind.Focus();
// }
}
void FindReplaceClosing(object sender, System.ComponentModel.CancelEventArgs e){
e.Cancel = true;
gFindReplace.HideMe();
gImlab.FindReplace=false;
gEditor.TextArea.TextView.Redraw();
}
//Toghra yaki Otkuzuwet ni bir terep qilidu
void menuSozImla(object sender, System.Windows.RoutedEventArgs e)
{
System.Windows.Controls.MenuItem menuNamzat= (System.Windows.Controls.MenuItem)sender;
string soz = (string)menuNamzat.Tag;
gImlab.SpellCheker.Add(soz,1);
gEditor.TextArea.TextView.Redraw();
if(menuNamzat == gMenuSozToghra)
{
gImlab.SpellCheker.SaveToIshletkuchi(soz);
}
}
//Melum bir tab ni ochurmekchi bolghanda bu yer chaqirilidu
void DeleteTab(int tabIndex){
DialogResult dr = CloseTab(tabIndex);
if(dr != DialogResult.Cancel){
if(mainTab.TabPages.Count==0){
gFileNum = 1;
AddNew(String.Format("Namsiz_{0}.txt",gFileNum));
gFileNum++;
}
}
gEditor.Focus();
}
void AddNew(String fileName){
TabPage curPg = null;
TextEditor curEdit = null;
ElementHost curHost = null;
int offset = 0;
if(mainTab.TabPages.Count>0){
curPg = mainTab.TabPages[mainTab.TabPages.Count-1];
curEdit = (TextEditor)((ElementHost)curPg.Controls[0]).Child;
//Eng axirqi tab quruq bolsa, yeng hojjetni shu yerge qachilaydu
if(curPg.Tag.Equals("") && curEdit.IsModified==false && File.Exists(fileName)){
curEdit.Load(fileName);
curPg.Tag = fileName;
curPg.Text = Path.GetFileName(fileName);
mainTab.SelectedTab = curPg;
TabControl1SelectedIndexChanged(null,null);
Text = fileName + " - UyghurEdit++";
UpdateIzlar(fileName);
if(!gIzOffset.TryGetValue(fileName,out offset)){
offset = 0;
}
curEdit.Focus();
if(offset>curEdit.Text.Length){
offset = curEdit.Text.Length;
}
curEdit.CaretOffset = offset;
curEdit.BringCaretToView();
return;
}
}
bool bar=false;
foreach(TabPage pg in mainTab.TabPages){
if(pg.Tag.Equals(fileName)){
bar = true;
curPg = pg;
break;
}
}
if(bar==false){
curEdit = new TextEditor();
curHost = new ElementHost();
curPg = new TabPage(Path.GetFileName(fileName));
mainTab.TabPages.Add(curPg);
curPg.Tag ="";
if(File.Exists(fileName))
{
curEdit.Load(fileName);
curPg.Tag = fileName;
}
curEdit.Padding = new System.Windows.Thickness(2,0,0,0);
curEdit.ShowLineNumbers = true;
//curEdit.Options.ShowEndOfLine = true;
curEdit.FontFamily = new System.Windows.Media.FontFamily(gFontName);
curEdit.FontSize = gFontSize;
curEdit.FontStyle = gFontStyle == 0? System.Windows.FontStyles.Normal:System.Windows.FontStyles.Italic;
curEdit.FontWeight = gFontWeight == 0? System.Windows.FontWeights.Normal:System.Windows.FontWeights.Bold;
gContextMenu.FontFamily = curEdit.FontFamily;
gContextMenu.FontSize = 20; //curEdit.FontSize;
gContextMenu.FontStyle = curEdit.FontStyle;
curEdit.WordWrap = true;
curEdit.TextArea.Caret.PositionChanged += CaretChanged;
curEdit.TextChanged += TextOzgerdi;
curEdit.PreviewMouseWheel += PreviewMouseWheel; //Ctrolni besip turup chaqanekning ghaltikini mangdursa, chongiyip kichikleydu
curEdit.MouseRightButtonUp += PreMouseUp; //chashqinekning ong teripi chekilse
curEdit.PreviewKeyDown += PreviewKey; //Kunupka almashturush degendek ishlarni qilidu
//curEdit.PreviewMouseHoverStopped += MouseHoverStop;
curEdit.TextArea.TextEntering += KeyboardTextInput; //Kunpkidin kirguzush meshghulati qilghanda bu yerge kelidu
curEdit.AllowDrop = true;
curEdit.DragEnter += MainFormDragEnter;
curEdit.Drop += MainFormDragDrop;
curEdit.TextArea.TextView.LineTransformers.Add(gImlab);
curEdit.TextArea.SelectionChanged +=TextSelctionChanged;
curHost.Dock = DockStyle.Fill;
curHost.Child = curEdit;
curPg.Controls.Add(curHost);
}
else{
curHost = (ElementHost)curPg.Controls[0];
curEdit =(TextEditor)curHost.Child;
}
UpdateIzlar(fileName);
mainTab.SelectedTab = curPg;
Text = fileName + " - UyghurEdit++";
TabControl1SelectedIndexChanged(null,null);
if(!gIzOffset.TryGetValue(fileName,out offset)){
offset = 0;
}
curEdit.Focus();
if(offset>curEdit.Text.Length){
offset = curEdit.Text.Length;
}
curEdit.CaretOffset = offset;
curEdit.BringCaretToView();
//System.Diagnostics.Debug.WriteLine(curEdit.PointToScreen(new System.Windows.Point(0, 0)));
}
void TextSelctionChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(gEditor.SelectedText))
{
gImlab.Selection = "";
gEditor.TextArea.TextView.Redraw();
//gEditor.TextArea.TextView.InvalidateLayer(UyghurEditPP.Rendering.KnownLayer.Selection);
}
else{
gImlab.Selection = gEditor.SelectedText;
gImlab.SelectionOffset = gEditor.SelectionStart;
gEditor.TextArea.TextView.Redraw();
//gEditor.TextArea.TextView.InvalidateLayer(UyghurEditPP.Rendering.KnownLayer.Selection);
}
}
//Tallanghan yaki nur belgisi turghan orundiki mezmunni CHong Yezilishqa ozgertidu
void ChongYaz(object sender,EventArgs e)
{
if(gEditor.SelectionLength>0){
gEditor.SelectedText = gEditor.SelectedText.ToUpper();
}
else if((gEditor.CaretOffset-1)>=0){
char nurHerp =gEditor.Document.GetCharAt(gEditor.CaretOffset-1);
if(char.IsLower(nurHerp)){
string txt=char.ToUpper(nurHerp)+"";
gEditor.Document.Replace(gEditor.CaretOffset-1,1,txt);
}
}
}
//Tallanghan yaki nur belgisi turghan orundiki mezmunni kichik Yezilishqa ozgertidu
void KichikYaz(object sender,EventArgs e)
{
if(gEditor.SelectionLength>0){
gEditor.SelectedText = gEditor.SelectedText.ToLower();
}
else if((gEditor.CaretOffset-1)>=0){
char nurHerp =gEditor.Document.GetCharAt(gEditor.CaretOffset-1);
if(char.IsUpper(nurHerp)){
string txt=char.ToLower(nurHerp)+"";
gEditor.Document.Replace(gEditor.CaretOffset-1,1,txt);
}
}
}
//Tallanghan rayondiki Her biz sozning bash heripini chong yezilishqa ozgertidu
void MawzuYaz(object sender,EventArgs e)
{
if(gEditor.SelectionLength>0){
gEditor.SelectedText = Regex.Replace(gEditor.SelectedText, @"(?<!\S)\p{Ll}", m => m.Value.ToUpper());
}
}
void KeyboardTextInput(object sender,System.Windows.Input.TextCompositionEventArgs e)
{
string newtxt="";
if(InputLanguage.CurrentInputLanguage.Culture.ThreeLetterISOLanguageName.Equals("uig")){
}
else if(gKunupka == KUNUPKA.Uyghur){
newtxt = Uyghur.KeyToUEY(e.Text);
e.Handled = true;
if(Uyghur.IsUSozuq(newtxt[0]))
{
if((gEditor.CaretOffset==0) ||
(gEditor.CaretOffset>0 && (Uyghur.IsUSozuq(gEditor.Document.GetCharAt(gEditor.CaretOffset-1))||!Uyghur.IsUyghurcheHerp(gEditor.Document.GetCharAt(gEditor.CaretOffset-1))))
)
{
newtxt = Uyghur.UYG_UN_HM_6+newtxt;
}
}
newtxt = Uyghur.Tirnaqlar(newtxt, gEditor.RightToLeft);
if(gEditor.SelectionLength>0){
gEditor.TextArea.Selection.ReplaceSelectionWithText(newtxt);
}
else{
gEditor.Document.Insert(gEditor.CaretOffset,newtxt);
}
gEditor.TextArea.Caret.BringCaretToView();
}
else if(gKunupka == KUNUPKA.UyghurLY){
e.Handled = true;
newtxt = Uyghur.KeyToULY(e.Text);
newtxt = Uyghur.Tirnaqlar(newtxt, gEditor.RightToLeft);
if(gEditor.SelectionLength>0){
gEditor.TextArea.Selection.ReplaceSelectionWithText(newtxt);
}
else{
gEditor.Document.Insert(gEditor.CaretOffset,newtxt);
}
gEditor.TextArea.Caret.BringCaretToView();
}
else if(gEditor.RightToLeft){
e.Handled = true;
newtxt = Uyghur.Tirnaqlar(e.Text, gEditor.RightToLeft);
if(gEditor.SelectionLength>0){
gEditor.TextArea.Selection.ReplaceSelectionWithText(newtxt);
}
else{
gEditor.Document.Insert(gEditor.CaretOffset,newtxt);
}
gEditor.TextArea.Caret.BringCaretToView();
}
}
//Mouse besilghanda, besilgan orundiki sozni elip, uning imlasi toghrimu?
//Xata bolsa namzat we bashqa munasiwetlik uchurni korsitidu
void PreMouseUp(object sender, System.Windows.Input.MouseEventArgs e){
stBarUchur.Text = "";
var pp = e.GetPosition(gEditor);
TextDocument curDoc = gEditor.Document;
var mousePosition = gEditor.GetPositionFromPoint(pp);
if(curDoc.Text.Length==0 || gImlab.WordFinder == null || mousePosition==null){
return;
}
var line = mousePosition.Value.Line;
var column = mousePosition.Value.Column;
var offset = curDoc.GetOffset(line, column);
if (offset >= curDoc.TextLength || string.IsNullOrWhiteSpace(curDoc.GetText(offset, 1))){
return;
}
int offsetStart = -1;
char herp;
while(offset>=0){
herp = curDoc.GetCharAt(offset);
if((herp!='-' && herp!='\'' && herp!='’' && !char.IsLetter(herp))|| offset == 0){
offsetStart = offset;
break;
}
offset--;
}
if (offsetStart == -1)
return;
//offsetStart++;
Match usoz = gImlab.WordFinder.Match(curDoc.Text,offsetStart);
System.Windows.Controls.MenuItem menuNamzat;
string strNamzat;
string toghrisi=null;
if(usoz.Success && gImlab.SpellCheker.IsListed(usoz.Value)==false){
//gEditor.Select(usoz.Index,usoz.Length);
gEditor.CaretOffset = usoz.Index;
Point txtPos = new Point(usoz.Index,usoz.Length);
gContextMenu.Items.Clear();
gContextMenu.BeginInit();
gContextMenu.FlowDirection = gEditor.FlowDirection;
toghrisi = gImlab.SpellCheker.Toghrisi(usoz.Value);
if(toghrisi!=null){
strNamzat = toghrisi;
if(char.IsUpper(usoz.Value[0])){
strNamzat=char.ToUpper(strNamzat[0])+strNamzat.Substring(1);
}
menuNamzat = new System.Windows.Controls.MenuItem{Header=strNamzat,Tag=txtPos};
menuNamzat.HorizontalContentAlignment = gMenuSozToghra.HorizontalAlignment;
menuNamzat.VerticalContentAlignment = gMenuSozToghra.VerticalAlignment;
menuNamzat.FontWeight = System.Windows.FontWeights.Bold;
menuNamzat.Click += namzat_Click;
gContextMenu.Items.Add(menuNamzat);
gContextMenu.Items.Add(gMenuSplitToghrisi);
}
var namzatlar = gImlab.SpellCheker.Lookup(usoz.Value);
System.Diagnostics.Debug.WriteLine("Symspell Namzat Sani = " + namzatlar.Count);
foreach(var namzat in namzatlar){
if(namzat.Equals(toghrisi))continue;
strNamzat= namzat;
//System.Diagnostics.Debug.WriteLine(strNamzat);
if(char.IsUpper(usoz.Value[0])){
strNamzat=char.ToUpper(strNamzat[0])+strNamzat.Substring(1);
}
menuNamzat = new System.Windows.Controls.MenuItem{Header=strNamzat,Tag=txtPos};
menuNamzat.HorizontalContentAlignment = gMenuSozToghra.HorizontalAlignment;
menuNamzat.VerticalContentAlignment = gMenuSozToghra.VerticalAlignment;
menuNamzat.Click += namzat_Click;
gContextMenu.Items.Add(menuNamzat);
if(gContextMenu.Items.Count>=14){
break;
}
}
if(namzatlar.Count>0){
gContextMenu.Items.Add(gMenuSplit);
}
gMenuSozToghra.Tag = usoz.Value;
gMenuSozTekshurme.Tag = usoz.Value;
gContextMenu.Items.Add(gMenuSozToghra);
gContextMenu.Items.Add(gMenuSozTekshurme);
gContextMenu.EndInit();
var npp = gEditor.TextArea.TextView.GetVisualPosition(gEditor.TextArea.Caret.Position, Rendering.VisualYPosition.TextBottom);
npp = npp - gEditor.TextArea.TextView.ScrollOffset;
gContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Relative;
npp = gEditor.PointToScreen(npp);
gContextMenu.HorizontalOffset = npp.X;
gContextMenu.VerticalOffset = npp.Y;
//gContextMenu.SetValue(System.Windows.Controls.ContextMenuService.PlacementProperty, System.Windows.Controls.Primitives.PlacementMode.Top);
gContextMenu.IsOpen = true;
e.Handled = true;
}
}
void namzat_Click(object sender, System.Windows.RoutedEventArgs e)
{
System.Windows.Controls.MenuItem menuNamzat= (System.Windows.Controls.MenuItem)sender;
string nsoz = menuNamzat.Header.ToString();
Point txtPos = (Point)menuNamzat.Tag;
string xatasoz = gEditor.Document.GetText(txtPos.X,txtPos.Y);
gEditor.Document.Replace(txtPos.X,txtPos.Y,nsoz);
gEditor.CaretOffset = txtPos.X + nsoz.Length;
gImlab.SpellCheker.SaveToXataToghra(xatasoz,nsoz);
//Barliq Xatani izdep tepip almashturidu
//string qelip = "\b"+xatasoz+"\b";
int sani = 0;
string qelip = "(?<!\\w)"+xatasoz+"(?!\\w)";
Regex finder = new Regex(qelip,RegexOptions.Compiled|RegexOptions.IgnoreCase);
string alltext = gEditor.Text.ToLower();
int stpos = gEditor.CaretOffset;
int oldPos = stpos;
// alltext = finder.Replace(alltext,nsoz,stpos);
// gEditor.Text = alltext;
// gEditor.CaretOffset = stpos;
// gEditor.BringCaretToView();
// while((soz = finder.Match(gEditor.Text.ToLower(),stpos)).Success)
Match soz;
while((soz = finder.Match(gEditor.Text,stpos)).Success)
{
gEditor.CaretOffset = soz.Index;
gEditor.Document.Replace(soz.Index,xatasoz.Length,nsoz);
// alltext = gEditor.Text.ToLower();
stpos = soz.Index+nsoz.Length;
sani++;
}
if(sani>0){
stBarUchur.Text = gLang.GetText("Oxshash xataliqlar tüzitildi") + "["+sani+"]";
gEditor.CaretOffset = oldPos;
// gEditor.BringCaretToView();
}
}
void UpdateIzlar(string fileName = null)
{
ToolStripMenuItem iz;
if(gIzlar.Contains(fileName)){
gIzlar.Remove(fileName);
}
if(File.Exists(fileName)){
gIzlar.Insert(0,fileName);
}
if(gIzlar.Count>15){
gIzlar.RemoveAt(gIzlar.Count-1);
}
menuIzlar.DropDownItems.Clear();
foreach(string fname in gIzlar){
iz = new ToolStripMenuItem(fname);
iz.Click += OpenIz;
menuIzlar.DropDownItems.Add(iz);
}
}
void OpenIz(object sender,EventArgs e){
ToolStripMenuItem iz=(ToolStripMenuItem)sender;
if(File.Exists(iz.Text))
{
OpenaFile(iz.Text);
}
}
//CRTL besilghan ehwalda Mouse Wheel ni herketlendurse,
//Fontning chongluqini ozgertkili bolidu
private void PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
{
bool ctrl = (Control.ModifierKeys == Keys.Control);
if (ctrl)
{
double currentSize = gEditor.FontSize;
if (e.Delta>0)
{
double newSize = Math.Min(64,currentSize + 1.0);
gEditor.FontSize = newSize;
}
else
{
double newSize = Math.Max(12,currentSize - 1.0);
gEditor.FontSize = newSize;
}
gFontSize = (int)gEditor.FontSize;
gConfig["FONTSIZE"] = gFontSize;
e.Handled = true;
}
}
void MainFormSizeChanged(object sender, EventArgs e)
{
}
void MainFormResize(object sender, EventArgs e)
{
mainTab.Location = new Point(0,toolBar.Bottom);
mainTab.Width = ClientSize.Width;
mainTab.Height = ClientSize.Height-(toolBar.Height + stBar.Height+menuBar.Height);
stBar.Location = new Point(0,mainTab.Bottom);
if(this.WindowState == FormWindowState.Minimized){
this.gFindReplace.HideMe();
}
}
void LoadConfigurations()
{
String lang;
string imyeziq;
if(File.Exists(gConfName)){
try{
using(FileStream fs = new FileStream(gConfName, FileMode.Open, FileAccess.Read))
{
BinaryFormatter bf = new BinaryFormatter();
gConfig = (Hashtable)bf.Deserialize(fs);
}
}
catch(Exception ee){
System.Diagnostics.Debug.WriteLine(ee.Message);
gConfig = new Hashtable();
}
}
if(gConfig.ContainsKey("LANG"))
{
lang = (string)gConfig["LANG"];
lang = lang.ToLower();
}
else{
lang=CultureInfo.CurrentCulture.ThreeLetterISOLanguageName.ToLower();
}
CheckLangMenu(lang);
if(gConfig.ContainsKey("ORUNLAR")){
gIzOffset =(Dictionary<string,int>)gConfig["ORUNLAR"];
}
if(gConfig.ContainsKey("IZLAR")){
string[] tmpiz= (string[])gConfig["IZLAR"];
foreach(string iz in tmpiz){
if(File.Exists(iz)){
gIzlar.Add(iz);
}
else if(gIzOffset.ContainsKey(iz)){
gIzOffset.Remove(iz);
}
}
UpdateIzlar();
}
if(gConfig.Contains("YEZIQAUTO")){
gYeziqAuto=(bool)gConfig["YEZIQAUTO"];
}
else{
gYeziqAuto=true;
}
if(gConfig.Contains("IMLAYEZIQ")){
imyeziq=(string)gConfig["IMLAYEZIQ"];
}
else{
imyeziq="UEY";
}
KUNUPKA kun;
if(gConfig.Contains("KUNUPKA")){
kun=(KUNUPKA)gConfig["KUNUPKA"];
}
else{
kun=KUNUPKA.System;
}
if(gConfig.Contains("FONTNAME") && gConfig.Contains("FONTSIZE") && gConfig.Contains("FONTSTYLE") && gConfig.Contains("FONTWEIGHT")){
gFontName = (String)gConfig["FONTNAME"];
gFontSize = (float)gConfig["FONTSIZE"];
gFontStyle = (int)gConfig["FONTSTYLE"];
gFontWeight = (int)gConfig["FONTWEIGHT"];
}
else{
gFontName = "UKIJ Tuz";
gFontSize = 20;
gFontStyle = 0;
gFontWeight = 0;
gConfig["FONTNAME"] = gFontName;
gConfig["FONTSIZE"] = gFontSize;
gConfig["FONTSTYLE"] = gFontStyle;
gConfig["FONTWEIGHT"] = gFontWeight;
}
SetKunupka(kun);
if(!gConfig.Contains("CHONGLUQI")){
Rectangle rc = new Rectangle(100,100,1024, 768);
gConfig["CHONGLUQI"] = rc;
}
}
void MainFormShown(object sender, EventArgs e)
{
}
void MainFormLoad(object sender, EventArgs e)
{
int codepage;
this.Font = new Font("UKIJ Tuz",12);
this.menuBar.Font = this.Font;
this.stBar.Font = this.Font;
this.mainTab.Font = this.Font;
this.stBar.Height = this.Font.Height+6;
ToolStripMenuItem cpMenu;
for(int i=0;i<gCodePages.Length;i++){
codepage=gCodePages[i];
if(codepage == -3){
cpMenu = new ToolStripMenuItem("Boghda-Fangjeng");
cpMenu.Click += menuCodePageClick;
cpMenu.Tag = codepage;
menuHKod.DropDownItems.Add(cpMenu);
cpMenu.Enabled = true;
}
else if(codepage == -2){
cpMenu = new ToolStripMenuItem("Weifang-WIN");
cpMenu.Click += menuCodePageClick;
cpMenu.Tag = codepage;
menuHKod.DropDownItems.Add(cpMenu);
cpMenu.Enabled = true;
}
else if(codepage == -1){
cpMenu = new ToolStripMenuItem("Weifang-DOS");
cpMenu.Click += menuCodePageClick;
cpMenu.Tag = codepage;
menuHKod.DropDownItems.Add(cpMenu);
menuHKod.DropDownItems.Add(new ToolStripSeparator());
cpMenu.Enabled = false;
}
else{
Encoding enc = Encoding.GetEncoding(codepage);
cpMenu = new ToolStripMenuItem(enc.EncodingName);
cpMenu.Click += menuCodePageClick;
cpMenu.Tag = codepage;
menuHKod.DropDownItems.Add(cpMenu);
if(codepage == 1201){
menuHKod.DropDownItems.Add(new ToolStripSeparator());
}
}
}
gMenuSplit = new System.Windows.Controls.Separator();
gMenuSplitToghrisi = new System.Windows.Controls.Separator();
LoadConfigurations();
Rectangle rc = (Rectangle)gConfig["CHONGLUQI"];
if (rc.X<0 || rc.Y<0){
rc.X = 100;
rc.Y = 100;
rc.Width=1024;
rc.Height=768;
}
this.Location = new Point(rc.X,rc.Y);
this.Size = new Size(rc.Width,rc.Height);
MenuYengiClick(null,null);
}
void CheckLangMenu(string lang){
foreach(ToolStripMenuItem itm in menuTil.DropDownItems){
itm.Checked = false;
if(itm.Tag.Equals(lang)){
itm.Checked = true;
}
}
gConfig["LANG"] = lang;
gLang.LanguaID = lang;
if("uey".Equals(lang)){
this.menuBar.RightToLeft = RightToLeft.Yes;
//this.menuBar.Font = new Font("UKIJ Tuz",14.0f);
// this.stBar.RightToLeft = RightToLeft.Yes;
// this.stBar.Font = this.menuBar.Font;
// stBarUchur.Font = this.menuBar.Font;
// this.stBar.Height = stBar.Font.Height+10;
}
else{
this.menuBar.RightToLeft = RightToLeft.No;
// this.stBar.RightToLeft = RightToLeft.No;
this.menuBar.Font = this.Font;
// this.stBar.Font = this.menuBar.Font;
// stBarUchur.Font = this.menuBar.Font;
}
UpdateMessage();
gFindReplace.UpdateMessages();
}
void UpdateMessage()
{
toolBar.Font = menuBar.Font;
menuHojjet.Text = gLang.GetText("Höjjet");
menuYengi.Text = gLang.GetText("Yéngi höjjet");
menuAch.Text = gLang.GetText("Ach");
menuSaqla.Text = gLang.GetText("Saqla");
menuBSaqla.Text = gLang.GetText("Bashqa Isimda Saqla");
menuBSaqla.ToolTipText = gLang.GetText("Tehrirlewatqan höjjetni diskigha bashqa isim bilen saqlaydu");
menuBas.Text = gLang.GetText("Bésip Chiqar");
menuHKod.Text = gLang.GetText("Höjjetning Kodi");
menuHKod.ToolTipText = gLang.GetText("Tehrirlewatqan höjjettiki mezmunlar normal körünmise, bu yerni sinap béqing");
menuIzlar.Text = gLang.GetText("Izlar");
menuIzlar.ToolTipText = gLang.GetText("Yéqinda tehrirlen’gen höjjetlerning isimliri");
menuAxirlashtur.Text = gLang.GetText("Axirlashtur");
menuTehrir.Text = gLang.GetText("Tehrirlesh");
menuFont.Text = gLang.GetText("Xet Nusxisi");
menuQurNomur.Text = gLang.GetText("Qur Nomurini Körsetsun");
menuYeniwal.Text = gLang.GetText("Yéniwal");
menuYPushayman.Text = gLang.GetText("Pushayman Qil");
menuOchur.Text = gLang.GetText("Öchür");
menuKes.Text = gLang.GetText("Kes");
menuKochur.Text = gLang.GetText("Köchür");
menuChapla.Text = gLang.GetText("Chapla");
menuHemme.Text = gLang.GetText("Hemmini Talla");
menuChaplaUighursoft.Text = "«Uighursoft»" + gLang.GetText("ningkini Chapla");
menuChaplaDuldul.Text = "«Duldul»" + gLang.GetText("ningkini Chapla");
menuChaplaBashqilar.Text = gLang.GetText("Bashqilarningkini Chapla");
menuHojjetBash.Text = gLang.GetText("Höjjetning Béshigha Yötkel");
menuHojjetAxir.Text = gLang.GetText("Höjjetning Axirigha Yötkel");
menuQuryotkel.Text = gLang.GetText("Körsitilgen Qurgha Yötkel");
menuChong.Text = gLang.GetText("Chong Yézilishqa Özgert");
menuKichik.Text = gLang.GetText("Kichik Yézilishqa Özgert");
menuMawzu.Text = gLang.GetText("Bash Herpni Chong Yézilishqa Özgert");
menuImla.Text = gLang.GetText("Imla");
menuImlaUEY.Text = gLang.GetText("Uyghurchining Imlasini Közetsun");
menuImlaULY.Text = gLang.GetText("Latinchining Imlasini Közetsun");
menuImlaUSY.Text = gLang.GetText("Silawiyanchining Imlasini Közetsun");
menuBelge.Text = gLang.GetText("Tinish Belgiler we Boshluqni Tengshe");
menuBelge.ToolTipText = gLang.GetText("Tinish belgilerning aldi-keynidiki kem qalghan yaki artuqche qoshulup qalghan boshluqlarni toghrilaydu.");
menuImlaAuto.Text = gLang.GetText("Aptomatik Tekshür");
menuImlaAuto.Text = gLang.GetText("Xata-toghra ambirini ishlitip imlasi xata sözlerni aptomatik tüzitidu");
menuImlaAmbar.Text = gLang.GetText("Ishletküchi Ambirini Körset");
menuQoral.Text = gLang.GetText("Qorallar");
menuTiz.Text = gLang.GetText("Élipbe Tertipi Boyiche Tiz");
menuTekrar.Text = gLang.GetText("Sözlerning Tekrarliqi");
menuTil.Text = gLang.GetText("Til-Yéziq");
menuUyghurA.Text = "ئۇيغۇرچە";
menuUyghurL.Text = "Uyghurche";
menuUyghurS.Text = "Уйғурчә";
menuYardem.Text = gLang.GetText("Yardem");
menuKunupka.Text = gLang.GetText("Kona Yéziq Kunupka Orunlashturulushi");
menuULElipbe.Text = gLang.GetText("Uyghur Latin Yéziqi Élipbesi");
menuHeqqide.Text = "UyghurEdit++" + gLang.GetText("Heqqide");
toolYengi.ToolTipText = gLang.GetText("Yéngi höjjet yasaydu");
toolAch.ToolTipText = gLang.GetText("Diskidiki höjjetni oqup tehrirleydu");
toolSaqla.ToolTipText = gLang.GetText("Tehrirlewatqan höjjetni diskigha saqlaydu");
toolBas.ToolTipText = gLang.GetText("Tehrirlewatqan höjjetni pirintérda bésip chiqiridu");
toolKes.ToolTipText = gLang.GetText("Tallan’ghanni kesip éliwalidu");
toolKochur.ToolTipText = gLang.GetText("Tallan’ghanni köchürüwalidu");
toolOchur.ToolTipText = gLang.GetText("Tallan’ghanni öchürüwétidu");
toolYeniwal.ToolTipText = gLang.GetText("Qilghan meshghulattin yéniwalidu");
toolYPushayman.ToolTipText = gLang.GetText("Yéniwalghangha pushayman qilidu");
toolDawam.ToolTipText = gLang.GetText("Nur belgisi turghan yerdin bashlap izdeydu yaki izdeshni dawam qilidu");
toolQatla.ToolTipText = gLang.GetText("Ékran kenglikidin éship ketmigen tehrirlesh haliti");
toolOngSol.ToolTipText = gLang.GetText("Ongdin yaki soldin bashlap yézishqa özgertidu");
toolUEY.ToolTipText = gLang.GetText("Hazirqi höjjet yaki Tallan’ghan rayonni Uyghurchigha aylanduridu");
toolULY.ToolTipText = gLang.GetText("Hazirqi höjjet yaki Tallan’ghan rayonni Latinchigha aylanduridu");