public bool AddToDictionary(string wordToAdd)
        {
            string[] dicSuggestions        = m_engine.GetSimpleFormOfWord(wordToAdd);
            string   selectedDicSuggestion = null;

            if (dicSuggestions.Length <= 0)
            {
                this.VerificationWindowInteractive.InvokeMethod(() =>
                                                                PersianMessageBox.Show(VerificationWindowInteractive.GetWin32Window(),
                                                                                       "افزودن این واژه به واژه‌نامه ممکن نیست!"));
            }
            else if (dicSuggestions.Length == 1 && dicSuggestions[0] == wordToAdd)
            {
                selectedDicSuggestion = dicSuggestions[0];
            }
            else
            {
                this.VerificationWindowInteractive.InvokeMethod(() =>
                {
                    selectedDicSuggestion = ListBoxForm.ShowListBoxForm(
                        VerificationWindowInteractive.GetWin32Window(),
                        dicSuggestions, wordToAdd,
                        "کدام کلمه به واژه‌نامه افزوده شود؟ لطفاً ساده‌ترین شکل معنادار کلمه را انتخاب کنید.",
                        "افزودن به واژه‌نامه");
                });
            }

            if (selectedDicSuggestion != null)
            {
                if (m_engine.AddToDictionary(selectedDicSuggestion, wordToAdd, Globals.ThisAddIn.SpellCheckerWrapper.UserDictionary))
                {
                    //PersianMessageBox.Show(VerificationWindowInteractive.GetWin32Window(), "کلمه با موفقیت به واژه‌نامه افزوده شد");
                    LogHelper.Info(Constants.LogKeywords.EntryAddedToDictionary, selectedDicSuggestion);
                    return(true);
                }

                this.VerificationWindowInteractive.InvokeMethod(() =>
                                                                PersianMessageBox.Show(
                                                                    VerificationWindowInteractive.GetWin32Window(), "این شکل از کلمه در واژه‌نامه وجود دارد!"));
            }

            return(false);
        }
        public override ProceedTypes GetProceedTypeForVerificationResult(VerificationResult verResult)
        {
            UserSelectedActions userAction = verResult.UserAction;
            string selectedSug             = verResult.SelectedSuggestion;

            var proceedType = ProceedTypes.IdleProceed;

            if (userAction == UserSelectedActions.Change)
            {
                if (m_curVerData.RangeToHighlight.Text != selectedSug)
                {
                    m_sessionLogger.AddUsage(selectedSug);
                    if (!m_curVerData.RangeToHighlight.TryChangeText(selectedSug))
                    {
                        this.VerificationWindowInteractive.InvokeMethod(() =>
                                                                        PersianMessageBox.Show(VerificationWindowInteractive.GetWin32Window(), "تغییر مورد نظر قابل اعمال نیست!"));

                        return(ProceedTypes.InvalidUserAction);
                    }
                    else
                    {
                        base.RefreshForChangeCalled(m_curVerData.RangeToHighlight, selectedSug);
                        return(ProceedTypes.IdleProceed);
                    }
                }
            }
            else if (userAction == UserSelectedActions.ChangeAll)
            {
                m_sessionLogger.AddUsage(selectedSug);

                var par        = m_curVerData.RangeToHighlight.FirstParagraph;
                var priorRange = par.GetRange(par.Start, m_curVerData.RangeToHighlight.Start);
                if (priorRange != null && !priorRange.IsRangeValid)
                {
                    priorRange = null;
                }

                if (m_lastSCS == SpaceCorrectionState.SpaceInsertationLeft ||
                    m_lastSCS == SpaceCorrectionState.SpaceInsertationLeftSerrially)
                {
                    if (priorRange != null)
                    {
                        try
                        {
                            priorRange.ReplaceAllTwoWordsCombination(m_curWord1, m_curWord2, selectedSug);
                        }
                        catch
                        {
                            priorRange = null;

#if DEBUG
                            throw;
#endif
                        }
                    }

                    DocumentUtils.ReplaceAllTwoWordsCombinationInDocument(this.Document,
                                                                          m_curWord1, m_curWord2, selectedSug);
                }
                else if (m_lastSCS == SpaceCorrectionState.SpaceInsertationRight ||
                         m_lastSCS == SpaceCorrectionState.SpaceInsertationRightSerrially)
                {
                    if (priorRange != null)
                    {
                        try
                        {
                            priorRange.ReplaceAllTwoWordsCombination(m_curWord0, m_curWord1, selectedSug);
                        }
                        catch
                        {
                            priorRange = null;

#if DEBUG
                            throw;
#endif
                        }
                    }

                    DocumentUtils.ReplaceAllTwoWordsCombinationInDocument(this.Document,
                                                                          m_curWord0, m_curWord1, selectedSug);
                }
                else if (m_lastSCS == SpaceCorrectionState.SpaceDeletation ||
                         m_lastSCS == SpaceCorrectionState.SpaceDeletationSerrially)
                {
                    if (priorRange != null)
                    {
                        try
                        {
                            priorRange.ReplaceAllWordsStandardized(m_curWord1, selectedSug);
                        }
                        catch
                        {
                            priorRange = null;

#if DEBUG
                            throw;
#endif
                        }
                    }

                    DocumentUtils.ReplaceAllWordsStandardizedInDocument(Document, m_curWord1, selectedSug);
                }
                else
                {
                    if (priorRange != null)
                    {
                        try
                        {
                            priorRange.ReplaceAllWordsStandardized(m_curWord1, selectedSug);
                        }
                        catch
                        {
                            priorRange = null;

#if DEBUG
                            throw;
#endif
                        }
                    }

                    DocumentUtils.ReplaceAllWordsStandardizedInDocument(this.Document, m_curWord1, selectedSug);
                }

                int priorRangeLength = 0;
                if (priorRange == null || !priorRange.IsRangeValid)
                {
                    priorRangeLength = 0;
                }
                else
                {
                    try
                    {
                        priorRangeLength = priorRange.Text.Length;
                    }
                    catch (Exception)
                    {
                        priorRangeLength = 0;
                        throw;
                    }
                }

                base.RefreshForChangeAllCalled(priorRangeLength, m_curVerData.RangeToHighlight, selectedSug);
                return(ProceedTypes.IdleProceed);
            }
            else if (userAction == UserSelectedActions.IgnoreAll)
            {
                Globals.ThisAddIn.SpellCheckerWrapper.IgnoreList.AddToIgnoreList(m_curWordCombToCheck);
                return(ProceedTypes.IdleProceed);
            }
            else if (userAction == UserSelectedActions.AddToDictionary)
            {
                string strToAdd = m_curWord1;

                if (verResult.ViewerControlArg != null)
                {
                    strToAdd = (string)verResult.ViewerControlArg;
                }

                if (!AddToDictionary(strToAdd))
                {
                    return(ProceedTypes.InvalidUserAction);
                }

                base.RefreshForAddToDictionaryCalled();
                return(ProceedTypes.ActiveProceed);
            }

            return(proceedType);
        }
Exemplo n.º 3
0
        public override ProceedTypes GetProceedTypeForVerificationResult(VerificationResult verRes)
        {
            UserSelectedActions userAction = verRes.UserAction;
            string selectedSug             = verRes.SelectedSuggestion;

            //Debug.WriteLine(userAction.ToString());

            if (userAction == UserSelectedActions.Change)
            {
                m_changeRules.AddNumberChangeRule(m_curVerifData.ErrorText, selectedSug);

                if (m_curVerifData.RangeToHighlight.Text != selectedSug)
                {
                    if (!m_curVerifData.RangeToHighlight.TryChangeText(selectedSug))
                    {
                        this.VerificationWindowInteractive.InvokeMethod(() =>
                                                                        PersianMessageBox.Show(VerificationWindowInteractive.GetWin32Window(), "تغییر مورد نظر قابل اعمال نیست!")
                                                                        );

                        return(ProceedTypes.InvalidUserAction);
                    }
                    else
                    {
                        base.RefreshForChangeCalled(m_curVerifData.ErrorText, selectedSug);
                        return(ProceedTypes.IdleProceed);
                    }
                }
            }
            else if (userAction == UserSelectedActions.ChangeAll)
            {
                KeyValuePair <NumberChangeRule.InputFormats, NumberChangeRule.InputDigitLanguages>   ruleKey;
                KeyValuePair <NumberChangeRule.OutputFormats, NumberChangeRule.OutputDigitLanguages> ruleValue;
                m_changeRules.AddNumberChangeRule(m_curVerifData.ErrorText, selectedSug, out ruleKey, out ruleValue);

                if (m_curVerifData.RangeToHighlight.Text != selectedSug)
                {
                    if (!m_curVerifData.RangeToHighlight.TryChangeText(selectedSug))
                    {
                        this.VerificationWindowInteractive.InvokeMethod(() =>
                                                                        PersianMessageBox.Show(VerificationWindowInteractive.GetWin32Window(), "تغییر مورد نظر قابل اعمال نیست!"));
                    }
                }

                PerformReplaceAll(ruleKey, ruleValue);
                base.RefreshForChangeCalled(m_curVerifData.ErrorText, selectedSug);;
            }

            return(ProceedTypes.IdleProceed);
        }
Exemplo n.º 4
0
        public override ProceedTypes GetProceedTypeForVerificationResult(VerificationResult verResult)
        {
            UserSelectedActions userAction = verResult.UserAction;
            string selectedSug             = verResult.SelectedSuggestion;
            string wordToChange            = m_curVerData.RangeToHighlight.Text;

            if (userAction == UserSelectedActions.Change)
            {
                if (wordToChange != selectedSug)
                {
                    if (!m_curVerData.RangeToHighlight.TryChangeText(selectedSug))
                    {
                        this.VerificationWindowInteractive.InvokeMethod(() =>
                                                                        PersianMessageBox.Show(VerificationWindowInteractive.GetWin32Window(), "تغییر مورد نظر قابل اعمال نیست!")
                                                                        );

                        return(ProceedTypes.InvalidUserAction);
                    }
                    else
                    {
                        this.m_sessionLogger.AddUsage(selectedSug);
                        base.RefreshForChangeCalled(m_curVerData.RangeToHighlight, selectedSug);
                        return(ProceedTypes.IdleProceed);
                    }
                }
            }
            else if (userAction == UserSelectedActions.ChangeAll)
            {
                this.m_sessionLogger.AddUsage(selectedSug);

                var par        = m_curVerData.RangeToHighlight.FirstParagraph;
                var priorRange = par.GetRange(par.Start, m_curVerData.RangeToHighlight.Start);
                if (priorRange != null && !priorRange.IsRangeValid)
                {
                    priorRange = null;
                }

                try
                {
                    if (priorRange != null)
                    {
                        priorRange.ReplaceAllWordsCaseInsensitive(wordToChange, selectedSug);
                    }
                }
                catch
                {
                    priorRange = null;
#if DEBUG
                    throw;
#endif
                }

                DocumentUtils.ReplaceAllWordsCaseInsensitiveInDocument(this.Document, wordToChange, selectedSug);

                int priorRangeLength = 0;
                if (priorRange == null || !priorRange.IsRangeValid)
                {
                    priorRangeLength = 0;
                }
                else
                {
                    try
                    {
                        priorRangeLength = priorRange.Text.Length;
                    }
                    catch (Exception)
                    {
                        priorRangeLength = 0;
#if DEBUG
                        throw;
#endif
                    }
                }

                base.RefreshForChangeAllCalled(priorRangeLength, m_curVerData.RangeToHighlight, selectedSug);
                return(ProceedTypes.IdleProceed);
            }

            return(ProceedTypes.IdleProceed);
        }
Exemplo n.º 5
0
        public override ProceedTypes GetProceedTypeForVerificationResult(VerificationResult verRes)
        {
            UserSelectedActions userAction = verRes.UserAction;
            string selectedSug             = verRes.SelectedSuggestion;

            //Debug.WriteLine(userAction.ToString());

            if (userAction == UserSelectedActions.Change)
            {
                if (m_curVerifData.RangeToHighlight.Text != selectedSug)
                {
                    if (!m_curVerifData.RangeToHighlight.TryChangeText(selectedSug))
                    {
                        this.VerificationWindowInteractive.InvokeMethod(() =>
                                                                        PersianMessageBox.Show(VerificationWindowInteractive.GetWin32Window(), "تغییر مورد نظر قابل اعمال نیست!")
                                                                        );

                        return(ProceedTypes.InvalidUserAction);
                    }
                    else
                    {
                        base.RefreshForChangeCalled(m_curVerifData.ErrorText, selectedSug);
                        return(ProceedTypes.IdleProceed);
                    }
                }
            }

            return(ProceedTypes.IdleProceed);
        }
Exemplo n.º 6
0
        public override ProceedTypes GetProceedTypeForVerificationResult(VerificationResult verResult)
        {
            UserSelectedActions userAction = verResult.UserAction;
            var data = m_curVerifData;

            string selectedSug = verResult.SelectedSuggestion;

            if (userAction == UserSelectedActions.Change || userAction == UserSelectedActions.ChangeAll)
            {
                int selectedIndex = SearchArray(m_lastSugs, selectedSug);

                if (data.RangeToHighlight.Text != selectedSug)
                {
                    if (data.RangeToHighlight.TryChangeText(selectedSug))
                    {
                        m_punctuationCheckerEngine.CorrectMistake(selectedIndex);
                    }
                    else
                    {
                        m_punctuationCheckerEngine.SkipMistake();
                        if (userAction == UserSelectedActions.Change)
                        {
                            this.VerificationWindowInteractive.InvokeMethod(
                                () => PersianMessageBox.Show(VerificationWindowInteractive.GetWin32Window(), "تغییر مورد نظر قابل اعمال نیست!"));

                            return(ProceedTypes.InvalidUserAction);
                        }
                    }
                } // end of common sections between change and change-all

                // it is an if by purpose
                if (userAction == UserSelectedActions.ChangeAll)
                {
                    m_punctuationCheckerEngine.SetGoldenRule();
                    // Now the new change-all stuff
                    m_punctuationCheckerEngine.BookMarkSkipIndex();

                    PerformReplaceAll(selectedIndex);

                    string parTextNew = data.RangeToHighlight.FirstParagraph.Text;
                    if (this.NeedRefinedStrings)
                    {
                        parTextNew = StringUtil.RefineAndFilterPersianWord(parTextNew);
                    }

                    m_punctuationCheckerEngine.InitInputString(parTextNew);
                    m_punctuationCheckerEngine.RecallSkipIndex();
                    m_punctuationCheckerEngine.UnsetGoldenRule();
                }

                if (userAction == UserSelectedActions.Change)
                {
                    base.RefreshForChangeCalled(data.ErrorText, selectedSug);
                }
                else
                {
                    base.RefreshForChangeAllCalled(data.ErrorText, selectedSug);
                }


                return(ProceedTypes.IdleProceed);
            }
            else if (userAction == UserSelectedActions.Ignore)
            {
                m_punctuationCheckerEngine.SkipMistake();
                return(ProceedTypes.IdleProceed);
            }
            else if (userAction == UserSelectedActions.IgnoreAll)
            {
                m_punctuationCheckerEngine.DisableLastRule();
                return(ProceedTypes.IdleProceed);
            }

            return(ProceedTypes.IdleProceed);
        }