1 Star 0 Fork 1

Erbash/UyghurEditPP

forked from Hesenjan/UyghurEditPP 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
MainForm.cs 76.34 KB
一键复制 编辑 原始数据 按行查看 历史
Uyghur 提交于 2021-05-06 10:16 . Add files via upload
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514
/*
* 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;
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.F || e.Key == System.Windows.Input.Key.H){
e.Handled = true;
FindReplace();
}
}
else if(gModkey == 0 && e.Key== System.Windows.Input.Key.F3){
ToolIzdeDawamClick(null,null);
e.Handled = true;
}
}
void ToolIzdeDawamClick(object sender, EventArgs e)
{
if(string.IsNullOrEmpty(gFindReplace.txtFind.Text)){
FindReplace();
}
else{
gFindReplace.ContinueLastOperation();
}
}
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;
Match soz;
int oldPos = gEditor.CaretOffset;
while((soz = finder.Match(alltext,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>10){
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)
{
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();
}
gConfig["CHONGLUQI"] = new Rectangle(this.Location.X,this.Location.Y,this.Size.Width, this.Size.Height);
}
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,1200, 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 = false;
}
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"];
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.SetLangId(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");
menuBas.Text = gLang.GetText("Bésip Chiqar");
menuHKod.Text = gLang.GetText("Höjjetning Kodi");
menuIzlar.Text = gLang.GetText("Izlar");
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("Slawyanchining Imlasini Közetsun");
menuBelge.Text = gLang.GetText("Tinish Belgiler we Boshluqni Tengshe");
menuImlaAuto.Text = gLang.GetText("Aptomatik Tekshür");
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 printérda bésip chiqiridu");
toolKes.ToolTipText = gLang.GetText("Tallanghanni kesip éliwalidu");
toolKochur.ToolTipText = gLang.GetText("Tallanghanni köchürüwalidu");
toolOchur.ToolTipText = gLang.GetText("Tallanghanni ö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 Tallanghan rayonni Uyghurchigha aylanduridu");
toolULY.ToolTipText = gLang.GetText("Hazirqi höjjet yaki Tallanghan rayonni Latinchigha aylanduridu");
toolUSY.ToolTipText = gLang.GetText("Hazirqi höjjet yaki Tallanghan rayonni Slawyanchigha aylanduridu");
menuYeziqAuto.Text = gLang.GetText("Közitidighan Yéziqni Aptomatik Tallisun");
menuYeziqAuto.ToolTipText = gLang.GetText("Höjjet közniki almashqanda shu köznektiki yéziqqa mas kélidighan Imla Tekshürgüchni aktiplaydu");
menuOCR.ToolTipText = gLang.GetText("Resimni yéziqqa aylanduridu");
this.toolULY2UEY.ToolTipText = gLang.GetText("Hazirqi höjjet yaki Tallanghan rayondiki Latinchini Uyghurchigha aylanduridu");
this.toolUSY2UEY.ToolTipText = gLang.GetText("Hazirqi höjjet yaki Tallanghan rayondiki Slawyanchini Uyghurchigha aylanduridu");
this.toolUEY2ULY.ToolTipText = gLang.GetText("Hazirqi höjjet yaki Tallanghan rayondiki Uyghurchini Latinchigha aylanduridu");
this.toolUSY2ULY.ToolTipText = gLang.GetText("Hazirqi höjjet yaki Tallanghan rayondiki Slawyanchini Latinchigha aylanduridu");
this.toolUEY2USY.ToolTipText = gLang.GetText("Hazirqi höjjet yaki Tallanghan rayondiki Uyghurchini Slawyanchigha aylanduridu");
this.toolULY2USY.ToolTipText = gLang.GetText("Hazirqi höjjet yaki Tallanghan rayondiki Latinchchini Slawyanchigha aylanduridu");
menuMakeHTML.Text = gLang.GetText("Addiy") + " HTML " + gLang.GetText("Yasa");
}
void MenuTilClick(object sender, EventArgs e)
{
ToolStripMenuItem selItem = (ToolStripMenuItem)sender;
CheckLangMenu((string)selItem.Tag);
}
void ToolOpenClick(object sender, EventArgs e)
{
OpenFileDialog opnFileDlg = new OpenFileDialog();
string filter= "Text files|*.txt;*.uut|";
filter += "Image files|" + gImgexts;
filter += "|All files|*.*";
opnFileDlg.Filter = filter;
opnFileDlg.Multiselect = false;
if(opnFileDlg.ShowDialog(this)== DialogResult.OK)
{
OpenaFile(opnFileDlg.FileName);
}
}
public void OpenaFile(string filename){
String extName = Path.GetExtension(filename);
if(gImgexts.IndexOf(extName,StringComparison.OrdinalIgnoreCase)!=-1)
{
UpdateIzlar(filename);
OCRForm ocr = new OCRForm(gEditor, filename);
ocr.Owner = this;
ocr.ShowInTaskbar = false;
ocr.Show();
}
else{
AddNew(filename);
}
}
void MenuYengiClick(object sender, EventArgs e)
{
AddNew(String.Format("Namsiz_{0}.txt",gFileNum));
gFileNum++;
}
void MainFormPaint(object sender, PaintEventArgs e)
{
// stBarUchur.Text = "UyghurEdit++ V"+GetVersion() + "(2020/11/12) Aptor: Gheyret T.Kenji";
// stBarUchur.Text = "UyghurEdit++ V "+GetVersion() + " Aptor: Gheyret T.Kenji";
// stBarQur.Text = gLang.GetText("Jemiy ") + gEditor.LineCount.ToString() + gLang.GetText(" qur");
toolQatla.Checked = gEditor.WordWrap;
toolBas.Enabled = gEditor.Text.Length>0;
toolSaqla.Enabled = gEditor.IsModified;
if(gEditor.IsModified && mainTab.SelectedTab.Text.StartsWith("*")==false){
mainTab.SelectedTab.Text = "*" + mainTab.SelectedTab.Text;
}
else if(gEditor.IsModified == false && mainTab.SelectedTab.Text.StartsWith("*")==true){
mainTab.SelectedTab.Text = mainTab.SelectedTab.Text.Substring(1);
}
if(string.IsNullOrEmpty(mainTab.SelectedTab.Tag.ToString())){
menuHKod.Enabled = false;
}
else{
menuHKod.Enabled = true;
}
if(gEditor.CodePage<0){
if(gEditor.CodePage == -3){
stBarEncode.Text = "Boghda-Fangjeng";
}
else if(gEditor.CodePage == -2){
stBarEncode.Text = "Weifang-WIN";
}
else if(gEditor.CodePage == -1){
stBarEncode.Text = "Weifang-DOS";
}
}
else{
stBarEncode.Text = gEditor.Encoding==null? Encoding.UTF8.EncodingName:gEditor.Encoding.EncodingName;
}
menuBas.Enabled = toolBas.Enabled;
menuSaqla.Enabled = toolSaqla.Enabled;
menuYeniwal.Enabled = toolYeniwal.Enabled;
menuYPushayman.Enabled = toolYPushayman.Enabled;
toolKes.Enabled = gEditor.SelectionLength>0;
toolKochur.Enabled = gEditor.SelectionLength>0;
toolOchur.Enabled = gEditor.SelectionLength>0;
toolChapla.Enabled = Clipboard.GetDataObject()!=null;
toolYeniwal.Enabled = gEditor.CanUndo;
toolYPushayman.Enabled = gEditor.CanRedo;
menuKes.Enabled = toolKes.Enabled ;
menuKochur.Enabled = toolKochur.Enabled;
menuOchur.Enabled = toolOchur.Enabled;
menuChapla.Enabled = toolChapla.Enabled;
menuChaplaUighursoft.Enabled = toolChapla.Enabled;
menuChaplaDuldul.Enabled = toolChapla.Enabled;
menuChaplaBashqilar.Enabled = toolChapla.Enabled;
menuQuryotkel.Enabled = gEditor.LineCount>5;
menuQurNomur.Checked = gEditor.ShowLineNumbers;
}
public static String GetVersion()
{
Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
//return v.Major + "." + v.Minor + "." + v.Build;
return v.Major + "." + v.Minor+ "." + v.Build;
}
void CaretChanged(object sender, EventArgs e){
//System.Diagnostics.Debug.WriteLine(e.ToString());
//System.Diagnostics.Debug.WriteLine(gEditor.SelectionStart + ": " + gEditor.CaretOffset);
string herpcode="0000";
try{
UInt32 code = gEditor.TextArea.Document.GetCharAt(gEditor.CaretOffset);
herpcode = code.ToString("X4");
// Invalidate();
}catch(Exception){
}
stBarLs.Text = gEditor.TextArea.Caret.Line+" : "+gEditor.TextArea.Caret.Column + " : U" + herpcode;
//stBarLs.Text = "1000000"+":"+"1000" + " [" + herpcode+"]";
}
void TabControl1SelectedIndexChanged(object sender, EventArgs e)
{
if(mainTab.TabPages.Count>0){
if(mainTab.SelectedTab.Tag.ToString().Length ==0){
Text = mainTab.SelectedTab.Text + " - UyghurEdit++";
}
else{
Text = mainTab.SelectedTab.Tag.ToString() + " - UyghurEdit++";
}
ElementHost host = (ElementHost)mainTab.SelectedTab.Controls[0];
gEditor = (TextEditor)host.Child;
gEditor.Focus();
CaretChanged(null,null);
TextSelctionChanged(null,null);
if(gFindReplace!=null){
gFindReplace.Editor = gEditor;
}
gEditor.TextArea.TextView.Redraw();
Uyghur.YEZIQ curYeziq = Uyghur.Detect(gEditor.Text);
if(curYeziq == Uyghur.YEZIQ.UEY || curYeziq == Uyghur.YEZIQ.YOQ)
{
// menuChong.Enabled = false;
// menuKichik.Enabled = false;
// menuMawzu.Enabled = false;
gEditor.RightToLeft = true;
if(gYeziqAuto){
ImlaniAktipla("UEY");
}
}
else if(curYeziq == Uyghur.YEZIQ.ULY || curYeziq == Uyghur.YEZIQ.USY){
// menuChong.Enabled = true;
// menuKichik.Enabled = true;
// menuMawzu.Enabled = true;
gEditor.RightToLeft = false;
if(gYeziqAuto)
{
if(curYeziq == Uyghur.YEZIQ.ULY){
ImlaniAktipla("ULY");
}
else{
ImlaniAktipla("USY");
}
}
}
}
Invalidate();
}
void ToolYeniwalClick(object sender, EventArgs e)
{
gEditor.Undo();
gEditor.BringCaretToView();
}
void ToolYPushaymanClick(object sender, EventArgs e)
{
gEditor.Redo();
gEditor.BringCaretToView();
}
void TextOzgerdi(object sender, EventArgs e){
Invalidate();
}
void ToolQatlaClick(object sender, EventArgs e)
{
gEditor.WordWrap = !toolQatla.Checked;
}
void ToolKesClick(object sender, EventArgs e)
{
gEditor.Cut();
}
void ToolKochurClick(object sender, EventArgs e)
{
gEditor.Copy();
}
void ToolChaplaClick(object sender, EventArgs e)
{
gEditor.Paste();
gEditor.BringCaretToView();
}
void ToolOchurClick(object sender, EventArgs e)
{
gEditor.Delete();
}
void ToolOngSolClick(object sender, EventArgs e)
{
gEditor.RightToLeft = !gEditor.RightToLeft;
// gRTL = gEditor.RightToLeft;
// gConfig["RTL"] = gRTL;
}
string GetFromClipboad(){
String clipText = null;
try {
IDataObject dataObject = Clipboard.GetDataObject();
if(dataObject.GetDataPresent(DataFormats.UnicodeText)) {
clipText = ((String)dataObject.GetData(DataFormats.UnicodeText)).Replace(Uyghur.Sozghuch,"");
}
} catch (Exception) {
}
return clipText;
}
void MenuSaqlaClick(object sender, EventArgs e)
{
if(File.Exists(mainTab.SelectedTab.Tag.ToString())){
gEditor.Save(mainTab.SelectedTab.Tag.ToString());
if(mainTab.SelectedTab.Text.StartsWith("*")){
mainTab.SelectedTab.Text= mainTab.SelectedTab.Text.Substring(1);
}
//TabControl1SelectedIndexChanged(null,null);
}
else{
MenuBSaqlaClick(null,null);
}
}
void MenuBSaqlaClick(object sender, EventArgs e)
{
string newflname = SaveAs(gEditor, mainTab.SelectedTab.Tag.ToString());
if(newflname!=null){
mainTab.SelectedTab.Text = Path.GetFileName(newflname);
mainTab.SelectedTab.Tag = newflname;
Text = newflname + " - UyghurEdit++";
}
}
string SaveAs(TextEditor curEdit, string fileName = null){
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = fileName;
sfd.Filter = "Text file|*.txt|Text file|*.uut|All files(*.*)|*.*";
DialogResult dr = sfd.ShowDialog();
if(dr == DialogResult.OK){
curEdit.Save(sfd.FileName);
UpdateIzlar(sfd.FileName);
//TabControl1SelectedIndexChanged(null,null);
return sfd.FileName;
}
else{
return null;
}
}
//Tool bar da Text box ni korsitidu
void MenuQuryotkelClick(object sender, EventArgs e)
{
toolTBox.Visible = true;
toolTBox.Focus();
}
//Korsitilgen Qur numurighan yotkilish
void ToolTextKeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar=='\r'){
e.Handled = true;
try{
int line = int.Parse(toolTBox.Text.Trim());
toolTBox.Visible = false;
gEditor.Focus();
gEditor.TextArea.Caret.Line = line;
gEditor.TextArea.Caret.Column = 0;
gEditor.BringCaretToView();
}
finally{
}
}
}
void ButQurNomurClick(object sender, EventArgs e)
{
gEditor.ShowLineNumbers = !gEditor.ShowLineNumbers;
Invalidate();
}
void MenuULElipbeClick(object sender, EventArgs e)
{
FormULElipbe frm = new FormULElipbe();
frm.ShowInTaskbar = false;
frm.ShowDialog();
gEditor.Focus();
}
void MenuKunupkaClick(object sender, EventArgs e)
{
FormKunupka frm = new FormKunupka(this);
frm.ShowInTaskbar = false;
frm.Show(this);
gEditor.Focus();
}
void MenuChaplaUighursoftClick(object sender, EventArgs e)
{
string cliptext = GetFromClipboad();
if(cliptext!=null){
cliptext = Uyghur.FromUighursoft(cliptext);
System.Diagnostics.Debug.WriteLine(cliptext);
gEditor.Document.Insert(gEditor.CaretOffset,cliptext);
}
}
void MenuChaplaDuldulClick(object sender, EventArgs e)
{
string cliptext = GetFromClipboad();
if(cliptext!=null){
cliptext = Uyghur.FromDuldul(cliptext);
System.Diagnostics.Debug.WriteLine(cliptext);
// gEditor.SelectedText = cliptext;
gEditor.Document.Insert(gEditor.CaretOffset,cliptext);
}
}
void MenuChaplaBashqilarClick(object sender, EventArgs e)
{
string cliptext = GetFromClipboad();
if(cliptext!=null){
cliptext = Uyghur.FromBashqilar(cliptext);
System.Diagnostics.Debug.WriteLine(cliptext);
gEditor.Document.Insert(gEditor.CaretOffset,cliptext);
}
}
void ToolULYClick(object sender, EventArgs e)
{
if(gEditor.Text.Length==0) return;
if(gEditor.SelectedText.Length>0){
string newtext = Uyghur.ToULY(gEditor.SelectedText);
if(newtext!=null){
gEditor.SelectedText = newtext;
}
}
else{
string newtext = Uyghur.ToULY(gEditor.Text);
if(newtext!=null){
MenuYengiClick(null,null);
gEditor.Text = Uyghur.ULYJumleChongYaz(newtext);
gEditor.RightToLeft = false;
TabControl1SelectedIndexChanged(null,null);
}
}
}
void ToolUSYClick(object sender, EventArgs e)
{
if(gEditor.Text.Length==0) return;
if(gEditor.SelectedText.Length>0){
string newtext = Uyghur.ToUSY(gEditor.SelectedText);
if(newtext!=null){
gEditor.SelectedText = newtext;
}
}
else{
string newtext = Uyghur.ToUSY(gEditor.Text);
if(newtext!=null){
MenuYengiClick(null,null);
gEditor.Text = Uyghur.USYJumleChongYaz(newtext);
gEditor.RightToLeft = false;
TabControl1SelectedIndexChanged(null,null);
}
}
}
void ToolUEYClick(object sender, EventArgs e)
{
if(gEditor.Text.Length==0) return;
if(gEditor.SelectedText.Length>0){
string txtuey = gEditor.SelectedText;
string newtext = Uyghur.ToUEY(txtuey);
if(newtext!=null){
gEditor.SelectedText = newtext;
}
}
else{
string txtuey = gEditor.Text;
string newtext = Uyghur.ToUEY(txtuey);
if(newtext!=null){
MenuYengiClick(null,null);
gEditor.Text = newtext;
gEditor.RightToLeft = true;
TabControl1SelectedIndexChanged(null,null);
}
}
}
void ToolULY2UEYClick(object sender, EventArgs e)
{
if(gEditor.Text.Length==0) return;
if(gEditor.SelectedText.Length>0){
string txtuey = gEditor.SelectedText;
string newtext = Uyghur.ULY2UEY(txtuey);
if(newtext!=null){
gEditor.SelectedText = newtext;
}
}
else{
string txtuey = gEditor.Text;
string newtext = Uyghur.ULY2UEY(txtuey);
if(newtext!=null){
MenuYengiClick(null,null);
gEditor.Text = newtext;
gEditor.RightToLeft = true;
TabControl1SelectedIndexChanged(null,null);
}
}
}
void ToolUSY2UEYClick(object sender, EventArgs e)
{
if(gEditor.Text.Length==0) return;
if(gEditor.SelectedText.Length>0){
string txtuey = gEditor.SelectedText;
string newtext = Uyghur.USY2UEY(txtuey);
if(newtext!=null){
gEditor.SelectedText = newtext;
}
}
else{
string txtuey = gEditor.Text;
string newtext = Uyghur.USY2UEY(txtuey);
if(newtext!=null){
MenuYengiClick(null,null);
gEditor.Text = newtext;
gEditor.RightToLeft = true;
TabControl1SelectedIndexChanged(null,null);
}
}
}
void ToolUEY2ULYClick(object sender, EventArgs e)
{
if(gEditor.Text.Length==0) return;
if(gEditor.SelectedText.Length>0){
string newtext = Uyghur.UEY2ULY(gEditor.SelectedText);
if(newtext!=null){
gEditor.SelectedText = newtext;
}
}
else{
string newtext = Uyghur.UEY2ULY(gEditor.Text);
if(newtext!=null){
MenuYengiClick(null,null);
gEditor.Text = Uyghur.ULYJumleChongYaz(newtext);
gEditor.RightToLeft = false;
TabControl1SelectedIndexChanged(null,null);
}
}
}
void ToolUSY2ULYClick(object sender, EventArgs e)
{
if(gEditor.Text.Length==0) return;
if(gEditor.SelectedText.Length>0){
string txtuey = gEditor.SelectedText;
string newtext = Uyghur.USY2ULY(txtuey);
if(newtext!=null){
gEditor.SelectedText = newtext;
}
}
else{
string txtuey = gEditor.Text;
string newtext = Uyghur.USY2ULY(txtuey);
if(newtext!=null){
MenuYengiClick(null,null);
gEditor.Text = newtext;
gEditor.RightToLeft = false;
TabControl1SelectedIndexChanged(null,null);
}
}
}
void ToolUEY2USYClick(object sender, EventArgs e)
{
if(gEditor.Text.Length==0) return;
if(gEditor.SelectedText.Length>0){
string newtext = Uyghur.UEY2USY(gEditor.SelectedText);
if(newtext!=null){
gEditor.SelectedText = newtext;
}
}
else{
string newtext = Uyghur.UEY2USY(gEditor.Text);
if(newtext!=null){
MenuYengiClick(null,null);
gEditor.Text = Uyghur.USYJumleChongYaz(newtext);
gEditor.RightToLeft = false;
TabControl1SelectedIndexChanged(null,null);
}
}
}
void ToolULY2USYClick(object sender, EventArgs e)
{
if(gEditor.Text.Length==0) return;
if(gEditor.SelectedText.Length>0){
string txtuey = gEditor.SelectedText;
string newtext = Uyghur.ULY2USY(txtuey);
if(newtext!=null){
gEditor.SelectedText = newtext;
}
}
else{
string txtuey = gEditor.Text;
string newtext = Uyghur.ULY2USY(txtuey);
if(newtext!=null){
MenuYengiClick(null,null);
gEditor.Text = newtext;
gEditor.RightToLeft = false;
TabControl1SelectedIndexChanged(null,null);
}
}
}
DialogResult CloseTab(int tabIndex){
TabPage pg = mainTab.TabPages[tabIndex];
ElementHost curHost = (ElementHost)pg.Controls[0];
TextEditor curEdit = (TextEditor)curHost.Child;
string filenm = (String)pg.Tag;
DialogResult dr = DialogResult.None;
if(curEdit.IsModified)
{
dr = MessageBox.Show(this, gLang.GetText("Höjjetning mezmunida özgirish boldi. Saqlamsiz?"),"UyghurEdit++ v"+ GetVersion(), MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question);
if(dr == DialogResult.Cancel){
return dr;
}
if(dr == DialogResult.Yes){
if(File.Exists(filenm)){
curEdit.Save(pg.Tag.ToString());
}
else{
SaveAs(curEdit);
}
}
}
gIzOffset[filenm] = curEdit.CaretOffset;
mainTab.TabPages.RemoveAt(tabIndex);
curEdit.Clear();
curHost.Dispose();
return dr;
}
void MainFormFormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dr;
while(mainTab.TabPages.Count!=0){
dr = CloseTab(0);
if(dr == DialogResult.Cancel){
e.Cancel = true;
break;
}
}
gConfig["IZLAR"] = gIzlar.ToArray();
gConfig["ORUNLAR"] = gIzOffset;
try
{
System.Diagnostics.Debug.WriteLine(gConfig["CHONGLUQI"]);
using(FileStream fs = new FileStream(gConfName, FileMode.Create)){
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, gConfig);
}
}
catch(SerializationException er)
{
System.Diagnostics.Debug.WriteLine("Failed to serialize. Reason: " + er.Message);
throw;
}
gLang.Save(Path.Combine(Application.StartupPath, "langdata.txt"));
}
void MenuAxirlashturClick(object sender, EventArgs e)
{
this.Close();
}
void MenuHemmeClick(object sender, EventArgs e)
{
gEditor.SelectAll();
}
void MenuHojjetBashClick(object sender, EventArgs e)
{
gEditor.CaretOffset = 0;
gEditor.ScrollToHome();
}
void MenuHojjetAxirClick(object sender, EventArgs e)
{
gEditor.CaretOffset = gEditor.Text.Length;
gEditor.ScrollToEnd();
}
void MenuImlaClick(object sender, EventArgs e){
menuYeziqAuto.Checked = gYeziqAuto;
Uyghur.YEZIQ curYeziq = Uyghur.Detect(gEditor.Text);
if(curYeziq == Uyghur.YEZIQ.UEY){
menuBelge.Enabled = true;
}
else{
menuBelge.Enabled = true;
}
if((menuImlaUEY.Checked && curYeziq == Uyghur.YEZIQ.UEY)||
(menuImlaULY.Checked && curYeziq == Uyghur.YEZIQ.ULY)||
(menuImlaUSY.Checked && curYeziq == Uyghur.YEZIQ.USY)
)
{
menuImlaAuto.Enabled = true;
}
else{
menuImlaAuto.Enabled = false;
}
}
void MenuImlaClickActive(object sender, EventArgs e){
ToolStripMenuItem curMenu =(ToolStripMenuItem)sender;
Cursor = Cursors.WaitCursor;
string yeziq = "YOQ";
curMenu.Checked = !curMenu.Checked;
if(curMenu.Checked)
{
if(curMenu == menuImlaUEY){
yeziq="UEY";
}
else if(curMenu == menuImlaULY){
yeziq="ULY";
}
else if(curMenu == menuImlaUSY){
yeziq="USY";
}
}
ImlaniAktipla(yeziq);
Cursor = Cursors.Default;
gEditor.TextArea.TextView.Redraw();
}
void ImlaniAktipla(string yeziq)
{
Stream imlastrem;
menuImlaUEY.Checked=false;
menuImlaULY.Checked=false;
menuImlaUSY.Checked=false;
if(yeziq.Equals("YOQ")){
gImlab.WordFinder = null;
}
else{
if(yeziq.Equals("UEY")){
menuImlaUEY.Checked=true;
}
else if(yeziq.Equals("ULY")){
menuImlaULY.Checked = true;
}
else if(yeziq.Equals("USY")){
menuImlaUSY.Checked = true;
}
// if(File.Exists("uyghur_imla.txt")){
//imlastrem = File.OpenRead("uyghur_imla.txt");
imlastrem=System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("UyghurEditPP.uyghur_imla.txt");
if(yeziq.Equals("UEY") && gUyghurcheSoz != gImlab.WordFinder){
gMenuSozTekshurme.Header= Uyghur.ULY2UEY("Bu sözni ötküzüwet");
gMenuSozToghra.Header = Uyghur.ULY2UEY("Bu söz toghra");
gImlab.WordFinder = gUyghurcheSoz;
gImlab.SpellCheker.Load(imlastrem,Uyghur.YEZIQ.UEY);
}
else if(yeziq.Equals("ULY") && gLatincheSoz != gImlab.WordFinder){
gMenuSozTekshurme.Header= "Bu sözni ötküzüwet";
gMenuSozToghra.Header = "Bu söz toghra";
gImlab.WordFinder = gLatincheSoz;
gImlab.SpellCheker.Load(imlastrem,Uyghur.YEZIQ.ULY);
}
else if( yeziq.Equals("USY") && gSlawyancheSoz != gImlab.WordFinder){
gMenuSozTekshurme.Header= Uyghur.ULY2USY("Bu sözni ötküzüwet");
gMenuSozToghra.Header = Uyghur.ULY2USY("Bu söz toghra");
gImlab.WordFinder = gSlawyancheSoz;
gImlab.SpellCheker.Load(imlastrem,Uyghur.YEZIQ.USY);//Imla mbirini slawyanchigha ozgertip ishlitidu
}
imlastrem.Close();
}
gConfig["IMLAYEZIQ"]=yeziq;
}
void MenuMouseEntered(object sender, EventArgs e)
{
ToolStripMenuItem curMenu =(ToolStripMenuItem)sender;
string tooltip = null;
if(curMenu == menuIzlar){
tooltip=gLang.GetText("Yéqinda tehrirlen’gen höjjetlerning isimliri");
}
else if(curMenu == menuBSaqla){
tooltip=gLang.GetText("Tehrirlewatqan höjjetni diskigha bashqa isim bilen saqlaydu");
}
else if(curMenu == menuHKod){
tooltip = gLang.GetText("Tehrirlewatqan höjjettiki mezmunlar normal körünmise, bu yerni sinap béqing");
}
else if(curMenu == menuImlaAuto){
tooltip = gLang.GetText("Xata-toghra ambirini ishlitip imlasi xata sözlerni aptomatik tüzitidu");
}
else if(curMenu == menuBelge){
tooltip = gLang.GetText("Tinish belgilerning aldi-keynidiki kem qalghan yaki artuqche qoshulup qalghan boshluqlarni toghrilaydu.");
}
else if(curMenu == menuImlaUEY || curMenu == menuImlaUEY ||curMenu == menuImlaUEY){
if(curMenu.Checked){
tooltip = gLang.GetText("Yene bir chékilse Imla tekshürmeydu.");
}
else{
tooltip = gLang.GetText("Imla tekshürüsh üchün chéking.");
}
}
else if(curMenu == menuMakeHTML){
tooltip = gLang.GetText("Hazirqi tékisttin addiy") + " HTML " + gLang.GetText("hasil qilidu.");
}
else if(curMenu == menuYeziqAuto){
tooltip = curMenu.ToolTipText;
}
if(tooltip!=null){
stBarUchur.Text = tooltip;
}
}
void MenuBasClick(object sender, EventArgs e)
{
// gEditor.Document.print();
}
void KunupkaClick(object sender, EventArgs e)
{
KUNUPKA kun;
if(gKunupka == KUNUPKA.System){
kun = KUNUPKA.Uyghur;
}
else if(gKunupka == KUNUPKA.Uyghur){
kun = KUNUPKA.UyghurLY;
}
else{
kun = KUNUPKA.System;
}
SetKunupka(kun);
}
void SetKunupka(KUNUPKA kun){
gKunupka = kun;
if(gKunupka == KUNUPKA.System){
stKunupka.Text = "System";
}
else if(gKunupka == KUNUPKA.UyghurLY){
stKunupka.Text = "Uyghurche";
}
else{
stKunupka.Text = "ئۇيغۇرچە";
}
gConfig["KUNUPKA"] = gKunupka;
}
//Hojjet baldiqi Qosh chekilse(Eng axirqi hojjetke yeqin yerder)
//Yengi hojjet yasilidu
void MainFormMouseDoubleClick(object sender, MouseEventArgs e)
{
int last = mainTab.TabPages.Count-1;
Rectangle rc = mainTab.GetTabRect(last);
rc.X = rc.X+rc.Width;
Point np = new Point(e.Location.X, e.Location.Y - (menuBar.Height + rc.Height));
if(rc.Contains(np))
{
MenuYengiClick(null,null);
}
}
void MenuBelgeClick(object sender, EventArgs e)
{
Regex regkopbosh= new Regex("[ ]{2,}",RegexOptions.Compiled);
Regex regaxir= new Regex("[ \t]*([!\\)›»\\]؟،؛?,;])",RegexOptions.Compiled); //Axirlashqan tinish belgiler
Regex regbash= new Regex("([‹«\\(\\[])[ \t]*",RegexOptions.Compiled); //Axirlashqan tinish belgiler
Regex siziq = new Regex("[ ]*[-–][ ]*",RegexOptions.Compiled);
string txt = siziq.Replace(gEditor.Text, "-");
txt = regbash.Replace(txt, new MatchEvaluator(bash));
txt = regaxir.Replace(txt, new MatchEvaluator(axir));
txt = regkopbosh.Replace(txt," ");
MenuYengiClick(null,null);
gEditor.Text = txt;
if(Uyghur.Detect(txt) == Uyghur.YEZIQ.UEY){
gEditor.RightToLeft = true;
}
else{
gEditor.RightToLeft = false;
}
TabControl1SelectedIndexChanged(null,null);
}
string bash(Match mm){
return " "+mm.Value.Trim();
}
string axir(Match mm){
return mm.Value.Trim()+" ";
}
void MenuImlaAutoClick(object sender, EventArgs e)
{
string alltext = gEditor.Text;
if (alltext.Length == 0)
return;
int sani = 0;
int xatasani = 0;
int tuz = 0;
string toghrisi;
int stpos = 0;
Match soz;
System.Windows.Input.Cursor old = System.Windows.Input.Mouse.OverrideCursor;
System.Windows.Input.Mouse.OverrideCursor= System.Windows.Input.Cursors.Wait;
while((soz = gImlab.WordFinder.Match(alltext,stpos)).Success)
{
sani++;
if(gImlab.SpellCheker.IsListed(soz.Value)==false)
{
xatasani++;
toghrisi = gImlab.SpellCheker.Toghrisi(soz.Value);
if(toghrisi!=null){
if(char.IsUpper(soz.Value[0])){
toghrisi=char.ToUpper(toghrisi[0])+toghrisi.Substring(1);
}
gEditor.CaretOffset = soz.Index;
gEditor.Document.Replace(soz.Index,soz.Value.Length,toghrisi);
alltext = gEditor.Text.ToLower();
stpos = soz.Index+toghrisi.Length;
tuz++;
continue;
}
if(gImlab.WordFinder == gLatincheSoz)
{
if(gImlab.SpellCheker.IsListed(soz.Value.Replace('o','ö').Replace('u','ü').Replace('e','é'))){
toghrisi = soz.Value.Replace('o','ö').Replace('u','ü').Replace('e','é');
if(char.IsUpper(soz.Value[0])){
toghrisi=char.ToUpper(toghrisi[0])+toghrisi.Substring(1);
}
gEditor.CaretOffset = soz.Index;
gEditor.Document.Replace(soz.Index,soz.Value.Length,toghrisi);
alltext = gEditor.Text.ToLower();
stpos = soz.Index+toghrisi.Length;
tuz++;
continue;
}
if(gImlab.SpellCheker.IsListed(soz.Value.Replace('o','ö').Replace('u','ü'))){
toghrisi = soz.Value.Replace('o','ö').Replace('u','ü');
if(char.IsUpper(soz.Value[0])){
toghrisi=char.ToUpper(toghrisi[0])+toghrisi.Substring(1);
}
gEditor.CaretOffset = soz.Index;
gEditor.Document.Replace(soz.Index,soz.Value.Length,toghrisi);
alltext = gEditor.Text.ToLower();
stpos = soz.Index+toghrisi.Length;
tuz++;
continue;
}
if(gImlab.SpellCheker.IsListed(soz.Value.Replace('o','ö'))){
toghrisi = soz.Value.Replace('o','ö');
if(char.IsUpper(soz.Value[0])){
toghrisi=char.ToUpper(toghrisi[0])+toghrisi.Substring(1);
}
gEditor.CaretOffset = soz.Index;
gEditor.Document.Replace(soz.Index,soz.Value.Length,toghrisi);
alltext = gEditor.Text.ToLower();
stpos = soz.Index+toghrisi.Length;
tuz++;
continue;
}
if(gImlab.SpellCheker.IsListed(soz.Value.Replace('u','ü'))){
toghrisi = soz.Value.Replace('u','ü');
if(char.IsUpper(soz.Value[0])){
toghrisi=char.ToUpper(toghrisi[0])+toghrisi.Substring(1);
}
gEditor.CaretOffset = soz.Index;
gEditor.Document.Replace(soz.Index,soz.Value.Length,toghrisi);
alltext = gEditor.Text.ToLower();
stpos = soz.Index+toghrisi.Length;
tuz++;
continue;
}
if(gImlab.SpellCheker.IsListed(soz.Value.Replace('e','é'))){
toghrisi = soz.Value.Replace('e','é');
if(char.IsUpper(soz.Value[0])){
toghrisi=char.ToUpper(toghrisi[0])+toghrisi.Substring(1);
}
gEditor.CaretOffset = soz.Index;
gEditor.Document.Replace(soz.Index,soz.Value.Length,toghrisi);
alltext = gEditor.Text.ToLower();
stpos = soz.Index+toghrisi.Length;
tuz++;
continue;
}
}
}
stpos = soz.Index+soz.Value.Length;
}
gEditor.BringCaretToView();
if(sani>0)
{
float toghriliq = (float)(sani-xatasani)/(float)sani;
stBarUchur.Text = gLang.GetText("Tekshürülgen söz: ") + sani + "; " + gLang.GetText("Xata söz: ") + xatasani + "; " + gLang.GetText("Tüzitilgen söz: ") + tuz + "; "+ gLang.GetText("Toghriliqi: ")+toghriliq.ToString("0.0%");
}
System.Windows.Input.Mouse.OverrideCursor= old;
}
private void menuCodePageClick(object sender, System.EventArgs e)
{
ToolStripMenuItem menu = sender as ToolStripMenuItem;
if(menu==null) return;
if(menu.Checked) return;
int codePage = (int)menu.Tag;
if(-3==codePage||
-2==codePage||
-1==codePage
)
{
FileStream inStrm = File.OpenRead(mainTab.SelectedTab.Tag.ToString());
byte[] Buffer=new byte[inStrm.Length];
inStrm.Read(Buffer,0,Buffer.Length);
inStrm.Close();
switch(codePage)
{
case -1:
gEditor.Text=Uyghur.WeifangDosToUnicode(Buffer);
gEditor.IsModified = false;
break;
case -2:
gEditor.Text = Uyghur.WeifangDosToUnicode(Buffer);
gEditor.IsModified = false;
break;
case -3:
gEditor.Text=Uyghur.WeifangDosToUnicode(Buffer);
gEditor.IsModified = false;
break;
}
gEditor.CodePage = codePage;
}
else{
gEditor.Encoding = System.Text.Encoding.GetEncoding(codePage);
gEditor.Load(mainTab.SelectedTab.Tag.ToString());
}
TabControl1SelectedIndexChanged(null,null);
}
void MainFormDragEnter(object sender, System.Windows.DragEventArgs e)
{
String[] file=(String[])e.Data.GetData(DataFormats.FileDrop);
//String baseName = Path.GetFileName(file[0]).ToLower();
e.Effects= System.Windows.DragDropEffects.All;
}
void MainFormDragDrop(object sender, System.Windows.DragEventArgs e)
{
String[] files=(String[])e.Data.GetData(DataFormats.FileDrop);
foreach(string file in files){
OpenaFile(file);
}
}
void MenuHeqqideClick(object sender, EventArgs e)
{
FormHeqqide heqqide = new FormHeqqide();
heqqide.ShowInTaskbar = false;
heqqide.ShowDialog();
gEditor.Focus();
}
void MenuTekrarClick(object sender, EventArgs e)
{
string ngramtext="";
NGram ngram = new NGram(1);
Uyghur.YEZIQ curYeziq = Uyghur.Detect(gEditor.Text);
if(curYeziq == Uyghur.YEZIQ.UEY)
{
ngramtext = ngram.MakeNGram(gEditor.Text,this.gUyghurcheSoz);
MenuYengiClick(null,null);
gEditor.Text = ngramtext;
gEditor.RightToLeft = true;
}
else if(curYeziq == Uyghur.YEZIQ.ULY){
ngramtext = ngram.MakeNGram(gEditor.Text,this.gLatincheSoz);
MenuYengiClick(null,null);
gEditor.Text = ngramtext;
gEditor.RightToLeft = false;
}
else if(curYeziq == Uyghur.YEZIQ.USY){
ngramtext = ngram.MakeNGram(gEditor.Text,this.gSlawyancheSoz);
MenuYengiClick(null,null);
gEditor.Text = ngramtext;
gEditor.RightToLeft = false;
}
}
void MenuTizClick(object sender, EventArgs e)
{
List<string> abzaslar = new List<string>();
foreach(DocumentLine qur in gEditor.Document.Lines){
abzaslar.Add(gEditor.Document.GetText(qur.Offset,qur.Length));
}
USort usort= new USort();
string sortedabzaslar = usort.Sort(abzaslar);
MenuYengiClick(null,null);
gEditor.WordWrap = false;
gEditor.Text = sortedabzaslar;
}
void MenuOCRClick(object sender, EventArgs e)
{
OCRForm ocr = new OCRForm(gEditor);
ocr.Owner = this;
ocr.ShowInTaskbar = false;
ocr.Show(this);
}
void MenuFontClick(object sender, EventArgs e)
{
FontDialog fontDlg = new FontDialog();
Font tmpFont = new Font(gFontName,gFontSize);
fontDlg.Font = tmpFont;
fontDlg.ShowApply = true;
fontDlg.ShowColor = false;
fontDlg.ShowEffects = false;
if(fontDlg.ShowDialog() != DialogResult.Cancel ){
gFontName = fontDlg.Font.Name;
gFontSize = fontDlg.Font.Size;
gFontStyle = fontDlg.Font.Style==FontStyle.Italic?1:0;
gFontWeight = fontDlg.Font.Style==FontStyle.Bold? 1: 0;
gConfig["FONTNAME"] = gFontName;
gConfig["FONTSIZE"] = gFontSize;
gConfig["FONTSTYLE"] = gFontStyle;
gConfig["FONTWEIGHT"] = gFontWeight;
gEditor.FontFamily = new System.Windows.Media.FontFamily(gFontName);
gEditor.FontSize = gFontSize;
gEditor.FontStyle = gFontStyle == 0? System.Windows.FontStyles.Normal:System.Windows.FontStyles.Italic;
gEditor.FontWeight = gFontWeight == 0? System.Windows.FontWeights.Normal:System.Windows.FontWeights.Bold;
gContextMenu.FontFamily = gEditor.FontFamily;
gContextMenu.FontSize = 20;
gContextMenu.FontStyle = gEditor.FontStyle;
}
}
void MenuYeziqAutoClick(object sender, EventArgs e)
{
gYeziqAuto = ! gYeziqAuto;
menuYeziqAuto.Checked = gYeziqAuto;
gConfig["YEZIQAUTO"] = gYeziqAuto;
if(gYeziqAuto){
TabControl1SelectedIndexChanged(null,null);
}
}
void MenuQoralDropDownOpened(object sender, EventArgs e)
{
Uyghur.YEZIQ curYeziq = Uyghur.Detect(gEditor.Text);
if(curYeziq == Uyghur.YEZIQ.UEY){
menuTiz.Enabled = true;
}
else{
menuTiz.Enabled = false;
}
}
void MenuHKodDropDownOpened(object sender, EventArgs e)
{
if(gEditor.Encoding!=null){
foreach(var itm in menuHKod.DropDownItems){
var curitm = itm as ToolStripMenuItem;
if(curitm!=null){
curitm.Checked = false;
if(gEditor.CodePage == (int)curitm.Tag){
curitm.Checked = true;
}
}
}
}
}
void MenuImlaAmbarClick(object sender, EventArgs e)
{
if(File.Exists(gImlab.SpellCheker.IshletkcuhiAmbarIsimi)){
AddNew(gImlab.SpellCheker.IshletkcuhiAmbarIsimi);
}
if(File.Exists(gImlab.SpellCheker.XataToghraAmbarIsimi)){
AddNew(gImlab.SpellCheker.XataToghraAmbarIsimi);
}
}
void MenuMakeHTMLClick(object sender, EventArgs e)
{
Uyghur.YEZIQ curYeziq = Uyghur.Detect(gEditor.Text);
string strhtml = MakeHtml(gEditor.Document.Lines,curYeziq);
MenuYengiClick(null,null);
gEditor.WordWrap = false;
gEditor.RightToLeft = false;
gEditor.Text = strhtml;
}
string MakeHtml(IList<DocumentLine> lines , Uyghur.YEZIQ yeziq)
{
StringBuilder htmlBuf = new StringBuilder();
htmlBuf.AppendLine("<!doctype html>");
if(yeziq==Uyghur.YEZIQ.UEY){
htmlBuf.AppendLine("<html lang=\"ug\" dir=\"rtl\">");
}
else{
htmlBuf.AppendLine("<html lang=\"ug\">");
}
//Tunji Qurni HTML ning Title qilip ishlitimiz
string title="";
int tline = 0;
for(int i= 0; i<lines.Count;i++){
title = gEditor.Document.GetText(lines[i].Offset,lines[i].Length);
if(!string.IsNullOrWhiteSpace(title)){
tline = i;
break;
}
}
htmlBuf.AppendLine("<head>");
htmlBuf.AppendLine(" <title>" + title + "</title>");
htmlBuf.AppendLine(" <meta charset=\"utf-8\">");
htmlBuf.AppendLine(" <meta name=\"description\" content=\"UyghurEdit++ da hasil qilinghan addiy HTML\">");
htmlBuf.AppendLine(" <meta name=\"author\" content=\"UyghurEdit++\">");
htmlBuf.AppendLine(" <style type=\"text/css\">");
htmlBuf.AppendLine(" <!--");
htmlBuf.AppendLine(" p {color:blue; line-height:1.5;text-align:justify;font-family: \"UKIJ Tuz\", \"UKIJ Tuz Tom\";}");
htmlBuf.AppendLine(" h2 {text-transform: capitalize;text-align:center;font-family: \"UKIJ Tuz\", \"UKIJ Tuz Tom\";}");
htmlBuf.AppendLine(" -->");
htmlBuf.AppendLine(" </style>");
htmlBuf.AppendLine("</head>");
htmlBuf.AppendLine("<body>");
htmlBuf.AppendLine("<h2>" + title + "</h2>");
for(int i= tline+1; i<lines.Count;i++){
title = gEditor.Document.GetText(lines[i].Offset,lines[i].Length);
htmlBuf.AppendLine("<p>" + title + "</p>");
}
htmlBuf.AppendLine("</body>");
htmlBuf.AppendLine("</html>");
return htmlBuf.ToString();
}
class NGram:IComparer<string>
{
int N = 1;
public NGram(int cntGram = 1){
N= cntGram;
}
public String MakeNGram(string strOrg, Regex sozFinder){
int gSozSani = 0;
TstTree mBuf=new TstTree();
StringBuilder wBuf=new StringBuilder();
int i,j;
MatchCollection sozler;
sozler = sozFinder.Matches(strOrg, 0);
for(i=0;i<=sozler.Count-N;i++){
wBuf.Length=0;
for(j=i;j<N+i;j++){
wBuf.Append(" "+sozler[j].Value);
}
if(mBuf.Add(wBuf.ToString().Trim())==1){
gSozSani++;
}
}
List<string> ret=new List<string>();
mBuf.GetAll(1,ret);
mBuf = null;
ret.Sort(this);
wBuf.Length = 0;
foreach(string str in ret){
wBuf.AppendLine(str);
}
return wBuf.ToString();
}
public String MakeNGram(TextEditor curEdit, Regex sozFinder){
int gSozSani = 0;
TstTree mBuf=new TstTree();
StringBuilder wBuf=new StringBuilder();
int i,j;
MatchCollection sozler;
foreach(DocumentLine qur in curEdit.Document.Lines){
sozler = sozFinder.Matches(curEdit.Document.GetText(qur.Offset,qur.Length), 0);
if(sozler.Count<N) continue ;
for(i=0;i<=sozler.Count-N;i++){
wBuf.Length=0;
for(j=i;j<N+i;j++){
wBuf.Append(" "+sozler[j].Value);
}
if(mBuf.Add(wBuf.ToString().Trim())==1){
gSozSani++;
}
}
}
List<string> ret=new List<string>();
mBuf.GetAll(1,ret);
mBuf = null;
ret.Sort(this);
wBuf.Length = 0;
foreach(string str in ret){
wBuf.AppendLine(str);
}
return wBuf.ToString();
}
public int Compare(string aa,string bb)
{
int frq1=int.Parse(aa.Split('\t')[1]);
int frq2=int.Parse(bb.Split('\t')[1]);
return frq2-frq1;
}
}
class USort:IComparer<string>
{
public USort(){
}
public string Sort(List<string> abzaslar){
StringBuilder wBuf=new StringBuilder();
abzaslar.Sort(this);
foreach(string str in abzaslar){
wBuf.AppendLine(str);
}
return wBuf.ToString();
}
public int Compare_normal(string a,string b)
{
int ret=0;
a = a.Replace(Uyghur.Sozghuch,"");
b = b.Replace(Uyghur.Sozghuch,"");
int lenA=a.Length;
int lenB=b.Length;
a +='\0';
b +='\0';
int posA=0,posB=0;
int indexA=0,indexB=0;
int index;
bool siziqche=false;
while((posA<=lenA) && (posB<=lenB))
{
if(a[posA]=='-'||a[posA]==' ')
{
posA++;
siziqche=true;
continue;
}
if(b[posB]=='-'||b[posB]==' ')
{
posB++;
siziqche=true;
continue;
}
indexA=2*Uyghur.GetUnicodeIndex(a[posA]);
indexB=2*Uyghur.GetUnicodeIndex(b[posB]);
if(indexA==2*Uyghur.UYGIN_HM)
{
indexA=67;
if((posA+1)<=lenA){
index=Uyghur.GetUnicodeIndex(a[posA+1]);
if(index==Uyghur.UYGIN_A || index==Uyghur.UYGIN_E|| index==Uyghur.UYGIN_EE || index==Uyghur.UYGIN_I|| index==Uyghur.UYGIN_O|| index==Uyghur.UYGIN_OO|| index==Uyghur.UYGIN_U|| index==Uyghur.UYGIN_UU)
{
posA++;
indexA=index*2-1;
}
}
}
if(indexB==2*Uyghur.UYGIN_HM)
{
indexB=67;
if((posB+1)<=lenB){
index=Uyghur.GetUnicodeIndex(b[posB+1]);
if(index==Uyghur.UYGIN_A || index==Uyghur.UYGIN_E|| index==Uyghur.UYGIN_EE || index==Uyghur.UYGIN_I|| index==Uyghur.UYGIN_O|| index==Uyghur.UYGIN_OO|| index==Uyghur.UYGIN_U|| index==Uyghur.UYGIN_UU)
{
posB++;
indexB=index*2-1;
}
}
}
if(indexA>=0 && indexB>=0)
{
ret=indexA-indexB;
}
else{
ret=(int)(a[posA]-b[posB]);
}
if(ret!=0)
{
break;
}
posA++;
posB++;
}
if(ret==0 && siziqche==true)
{
posA=0;
posB=0;
while((posA<=lenA) && (posB<=lenB))
{
indexA=2*Uyghur.GetUnicodeIndex(a[posA]);
indexB=2*Uyghur.GetUnicodeIndex(b[posB]);
if(indexA==2*Uyghur.UYGIN_HM)
{
indexA=65;
if((posA+1)<=lenA){
index=Uyghur.GetUnicodeIndex(a[posA+1]);
if(index==Uyghur.UYGIN_A || index==Uyghur.UYGIN_E|| index==Uyghur.UYGIN_EE || index==Uyghur.UYGIN_I|| index==Uyghur.UYGIN_O|| index==Uyghur.UYGIN_OO|| index==Uyghur.UYGIN_U|| index==Uyghur.UYGIN_UU)
{
posA++;
indexA=index*2-1;
}
}
}
if(indexB==2*Uyghur.UYGIN_HM)
{
indexB=65;
if((posB+1)<=lenB){
index=Uyghur.GetUnicodeIndex(b[posB+1]);
if(index==Uyghur.UYGIN_A || index==Uyghur.UYGIN_E|| index==Uyghur.UYGIN_EE || index==Uyghur.UYGIN_I|| index==Uyghur.UYGIN_O|| index==Uyghur.UYGIN_OO|| index==Uyghur.UYGIN_U|| index==Uyghur.UYGIN_UU)
{
posB++;
indexB=index*2-1;
}
}
}
if(indexA>=0 && indexB>=0)
{
ret=indexA-indexB;
}
else{
ret=(int)(a[posA]-b[posB]);
}
if(ret!=0)
{
break;
}
posA++;
posB++;
}
}
return ret;
}
public int Compare(string a,string b)
{
int ret=0;
a = a.Replace(Uyghur.Sozghuch,"");
b = b.Replace(Uyghur.Sozghuch,"");
int lenA=a.Length;
int lenB=b.Length;
a +='\0';
b +='\0';
int posA=0,posB=0;
int indexA=0,indexB=0;
ret=0;
bool hemze=false;
while((posA<=lenA) && (posB<=lenB))
{
indexA=Uyghur.GetUnicodeIndex(a[posA]);
indexB=Uyghur.GetUnicodeIndex(b[posB]);
if(indexA==Uyghur.UYGIN_HM){posA++;hemze=true;continue;}
if(indexB==Uyghur.UYGIN_HM){posB++;hemze=true;continue;}
if(indexA>=0 && indexB>=0)
{
ret=indexA-indexB;
}
else{
ret=(int)(a[posA]-b[posB]);
}
if(ret!=0)
{
break;
}
posA++;
posB++;
}
if(ret==0)
{
if(hemze)
ret=lenA-lenB;
}
return ret;
}
public int Compare_neme(string a,string b)
{
int ret=0;
int lenA=a.Length;
int lenB=b.Length;
int posA=0,posB=0;
int indexA=0,indexB=0;
int index;
bool siziqche=false;
while((posA<lenA) && (posB<lenB))
{
if(a[posA]=='-'||a[posA]==' ')
{
posA++;
siziqche=true;
continue;
}
if(b[posB]=='-'||b[posB]==' ')
{
posB++;
siziqche=true;
continue;
}
indexA=2*Uyghur.GetUnicodeIndex(a[posA]);
indexB=2*Uyghur.GetUnicodeIndex(b[posB]);
if(indexA==2*Uyghur.UYGIN_HM)
{
if((posA+1)<=lenA){
index=2*Uyghur.GetUnicodeIndex(a[posA+1]);
if(index>0)
{
posA++;
indexA=index-1;
}
}
}
if(indexB==2*Uyghur.UYGIN_HM)
{
if((posB+1)<=lenB){
index=2*Uyghur.GetUnicodeIndex(b[posB+1]);
if(index>0)
{
posB++;
indexB=index-1;
}
}
}
if(indexA>=0 && indexB>=0)
{
ret=indexA-indexB;
}
else{
ret=(int)(a[posA]-b[posB]);
}
if(ret!=0)
{
break;
}
posA++;
posB++;
}
if(ret==0 && siziqche==true)
{
posA=0;
posB=0;
while((posA<=lenA) && (posB<=lenB))
{
indexA=2*Uyghur.GetUnicodeIndex(a[posA]);
indexB=2*Uyghur.GetUnicodeIndex(b[posB]);
if(indexA==2*Uyghur.UYGIN_HM)
{
if((posA+1)<=lenA){
index=2*Uyghur.GetUnicodeIndex(a[posA+1]);
if(index>=0)
{
posA++;
indexA=index-1;
}
}
}
if(indexB==2*Uyghur.UYGIN_HM)
{
if((posB+1)<=lenB){
index=2*Uyghur.GetUnicodeIndex(b[posB+1]);
if(index>=0)
{
posB++;
indexB=index-1;
}
}
}
if(indexA>=0 && indexB>=0)
{
ret=indexA-indexB;
}
else{
ret=(int)(a[posA]-b[posB]);
}
if(ret!=0)
{
break;
}
posA++;
posB++;
}
}
return ret;
}
}
}
enum KUNUPKA{System=0,Uyghur,UyghurLY};
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Erbash/UyghurEditPP.git
git@gitee.com:Erbash/UyghurEditPP.git
Erbash
UyghurEditPP
UyghurEditPP
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385