Esempio n. 1
0
    private void MenuItem_Click(object sender, EventArgs e)
    {
        WordMeuItem bnt = (WordMeuItem)sender;

        SelectionStart  = bnt.Index;
        SelectionLength = bnt.Length;
        SelectedText    = bnt.Text;
    }
Esempio n. 2
0
    private void ShowSynounyms(object sender, EventArgs e)
    {
        WordMeuItem MI = (WordMeuItem)sender;

        MI.Word = MI.Word.ToLower();
        string TL = DownloadTranslation(MI.Word).ToLower();
        bool   CanGiveSynounyms = !string.IsNullOrEmpty(TL);

        if (CanGiveSynounyms)
        {
            string cnt = Engine.LoadTranslation(Engine.TLID.LoadingSuggetionsPlzWait);
            //Asyc Download Suggestions
            BallonToolTip Ballon = new BallonToolTip();

            bool   IsFromInputLang = TL != MI.Word;
            string Word            = MI.Word;
            if (IsFromInputLang && InputLang != "EN")
            {
                Word = DownloadTranslation(Word, InputLang, "EN");
            }
            if (!IsFromInputLang && TargetLang != "EN")
            {
                Word = DownloadTranslation(Word, TargetLang, "EN");
            }

            if (Word.Contains(" "))
            {
                foreach (string w in Word.Split(' '))
                {
                    string TTL = string.Empty;
                    if (IsFromInputLang && InputLang != "EN")
                    {
                        TTL = DownloadTranslation(w, "EN", InputLang);
                    }
                    if (!IsFromInputLang && TargetLang != "EN")
                    {
                        TTL = DownloadTranslation(w, "EN", TargetLang);
                    }
                    if (MI.Word.ToLower().StartsWith(Word.ToLower()))
                    {
                        Word = TTL;
                    }
                }
            }


            string[] Suggestions           = new string[0];
            System.Threading.Thread Thread = new System.Threading.Thread(() => {
                try {
                    Suggestions = WordAPI.DownloadSynonyms(Word);
                } catch { }
                if (Suggestions == null)
                {
                    Suggestions = new string[0];
                }
                if (!IsFromInputLang)
                {
                    for (int i = 0; i < Suggestions.Length; i++)
                    {
                        Suggestions[i] = DownloadTranslation(Suggestions[i], "EN", TargetLang);
                    }
                }
            });

            Timer ti = new Timer();
            ti.Interval = 500;
            ti.Tick    += (sdr, ev) => {
                if (Thread.ThreadState == System.Threading.ThreadState.Stopped)
                {
                    ti.Enabled = false;
                    string WordList = string.Empty;
                    if (Suggestions == null)
                    {
                        Ballon         = new BallonToolTip();
                        Ballon.Title   = Engine.LoadTranslation(Engine.TLID.NoSynonymsFound);
                        Ballon.Message = Engine.LoadTranslation(Engine.TLID.TryManuallySearch);
                        Engine.UpdateToolTip(Ballon, true);
                        return;
                    }
                    foreach (string Suggestion in Suggestions)
                    {
                        if (!string.IsNullOrWhiteSpace(Suggestion))
                        {
                            WordList += Suggestion + ", ";
                        }
                    }
                    if (string.IsNullOrWhiteSpace(WordList))
                    {
                        WordList = @"  ";
                    }
                    WordList       = WordList.Substring(0, WordList.Length - 2);
                    Ballon         = new BallonToolTip();
                    Ballon.Title   = string.IsNullOrWhiteSpace(WordList) ? Engine.LoadTranslation(Engine.TLID.NoSynonymsFound) : string.Format(Engine.LoadTranslation(Engine.TLID.SynonymsFor), MI.Word);
                    Ballon.Message = string.IsNullOrWhiteSpace(WordList) ? Engine.LoadTranslation(Engine.TLID.TryManuallySearch) : WordList;
                    Engine.UpdateToolTip(Ballon, true);
                }
            };

            Engine.ShowToolTip(MI.Location, cnt, string.Format(Engine.LoadTranslation(Engine.TLID.SynonymsFor), MI.Word), Ballon, true, this);
            Thread.Start();
            ti.Enabled = true;
        }
        else
        {
            if (MessageBox.Show(Engine.LoadTranslation(Engine.TLID.FailedToDetectWordLang), "VNXTLP", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information) == DialogResult.Retry)
            {
                ShowSynounyms(sender, e);
            }
            return;
        }
    }
Esempio n. 3
0
    protected override void OnMouseUp(MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right && SpellCheckEnable)
        {
            try {
                int index = GetCharIndexFromPosition((e).Location);
                while (index < Text.Length && WordSeparators.Contains(Text[index]))
                {
                    index++;//Fix Rigth
                }
                while (index - 1 >= 0 && !WordSeparators.Contains(Text[index - 1]))
                {
                    index--;//Fix Left
                }
                if (index < Text.Length)
                {
                    string Word = string.Empty;
                    int    len  = 0;
                    while (index + len < Text.Length && !WordSeparators.Contains(Text[index + len]))
                    {
                        Word += Text[index + len];
                        len++;
                    }
                    bool isWrong = false;
                    //Get Manual Suggestion, Tl Suggestion
                    bool          CantSugest  = false;
                    List <string> Suggestions = null;
                    if (WordTL.ContainsKey(Word.ToLower()))
                    {
                        Suggestions = new List <string>();
                        string[] TLS = WordTL[Word.ToLower()];
                        if (TLS.Length > 0 && TLS[0] == IGNORE)
                        {
                            return;
                        }
                        foreach (string TL in TLS)
                        {
                            Suggestions.Add(TL);
                        }
                    }
                    else
                    {
                        bool Contains = false;
                        foreach (string Phrase in PhraseCache.Keys)
                        {
                            if (Text.ToLower().Contains(Phrase))
                            {
                                int PhraseIndex = Text.ToLower().IndexOf(Phrase);
                                if (PhraseIndex <= index && index <= PhraseIndex + Phrase.Length)
                                {
                                    Contains    = true;
                                    index       = PhraseIndex;
                                    len         = Phrase.Length;
                                    Word        = Phrase;
                                    Suggestions = new List <string>();
                                    foreach (string sugg in PhraseCache[Word])
                                    {
                                        Suggestions.Add(sugg);
                                    }
                                    break;
                                }
                            }
                        }
                        if (!Contains)
                        {
                            string TL = DownloadTranslation(Word);
                            if (TL != null && TL != Word)
                            {
                                WordTL.Add(Word, new string[] { TL });
                                Suggestions = new List <string>();
                                Suggestions.Add(TL);
                            }
                            else
                            {
                                CantSugest = (TL != null && TL == Word && TargetLang == "EN");
                            }
                        }
                    }

                    //Get Dic suggestions
                    if (Suggestions == null)
                    {
                        if (SuggestionLoaded)
                        {
                            foreach (Suggestion Suggestion in TextSuggestions)
                            {
                                if (Suggestion.Word == Word)
                                {
                                    Suggestions = Suggestion.Suggestions;
                                }
                            }
                            if (Suggestions == null && !CantSugest)
                            {
                                return;
                            }
                            isWrong = true;
                        }
                        else
                        {
                            if (SpellChecker.Spell(Word) && !CantSugest)
                            {
                                CantSugest = true;
                            }
                            else
                            {
                                Suggestions = SpellChecker.Suggest(Word);
                                isWrong     = true;
                            }
                        }
                    }

                    CMS = new ContextMenuStrip();
                    if (!CantSugest)
                    {
                        for (int i = 0; i < Suggestions.Count; i++)
                        {
                            WordMeuItem MI = new WordMeuItem();
                            MI.Word   = Word;
                            MI.Text   = Suggestions[i];
                            MI.Index  = index;
                            MI.Length = len;
                            MI.Click += MenuItem_Click;
                            CMS.Items.Add(MI);
                        }

                        if (CMS.Items.Count == 0)
                        {
                            CMS.Items.Add(new ToolStripMenuItem(Engine.LoadTranslation(Engine.TLID.NoSuggestions))
                            {
                                Enabled = false
                            });
                        }

                        if (isWrong)
                        {
                            CMS.Items.Add(new ToolStripSeparator());
                            ToolStripMenuItem NWItem = new ToolStripMenuItem();
                            NWItem.Text   = Engine.LoadTranslation(Engine.TLID.AddOnDictionary);
                            NWItem.Name   = Word;
                            NWItem.Click += AddToDic;
                            CMS.Items.Add(NWItem);
                        }
                    }
                    WordMeuItem SSM = new WordMeuItem();
                    SSM.Text     = Engine.LoadTranslation(Engine.TLID.ShowSynonyms);
                    SSM.Word     = Word;
                    SSM.Location = e.Location;
                    SSM.Click   += ShowSynounyms;
                    if (GetOnlineSynonyms)
                    {
                        if (!isWrong)
                        {
                            CMS.Items.Add(new ToolStripSeparator());
                        }
                        CMS.Items.Add(SSM);
                    }
                    else
                    {
                        if (CantSugest)
                        {
                            return;
                        }
                    }

                    CMS.Show(this, e.Location);
                }
            } catch {
            }
        }
        base.OnMouseUp(e);
    }