private bool OnSpellCheckSettingsChanged(SpellCheckerConfig spellerConfig)
        {
            if (SpellCheckSettingsChanged != null)
            {
                var e = new SpellCheckSettingsChangedEventArgs();
                e.Settings           = spellerConfig;
                e.CustomDictionaries = GetSelectedCustomDictionaries();

                e.PrespellCorrectBe        = cbPrespellCorrectBe.Checked;
                e.PrespellCorrectPrefixes  = cbPrespellCorrectPrefixes.Checked;
                e.PrespellCorrectSuffixes  = cbPrespellCorrectSuffixes.Checked;
                e.ReloadSpellCheckerEngine = m_reloadSpellCheckerEngine;

                SpellCheckSettingsChanged(e);
                if (e.CancelLoadingUserDictionary)
                {
                    errorProvider.SetError(txtFileName, "فایل واژه‌نامه بدرستی انتخاب نشده است.");
                    return(false);
                }

                if (e.ErroneousUserDictionaries.Count > 0)
                {
                    var sb = new StringBuilder();
                    foreach (string file in e.ErroneousUserDictionaries)
                    {
                        sb.AppendLine(file);
                    }

                    errorProvider.SetError(linkLabelSpellCheckerCreateDictionary, "فایل‌های زیر به درستی بارگذاری نشده‌اند:" + Environment.NewLine + sb);
                    return(false);
                }
            }

            return(true);
        }
        private SpellCheckerConfig GetSpellCheckSettings()
        {
            var spellCheckSettings = new SpellCheckerConfig(txtFileName.Text,
                                                            m_appSettings.SpellChecker_EditDistance, m_appSettings.SpellChecker_MaxSuggestions)
            {
                StemPath = SettingsHelper.GetFullPath(Constants.StemFileName,
                                                      VirastyarFilePathTypes.AllUsersFiles)
            };

            return(spellCheckSettings);
        }
Exemplo n.º 3
0
        public bool Initialize(SpellCheckSettingsChangedEventArgs e)
        {
            m_spellCheckerSettings = new SpellCheckerConfig(e.Settings.DicPath, e.Settings.EditDistance, e.Settings.SuggestionCount)
            {
                StemPath = e.Settings.StemPath
            };
            SetDictionaries(e.CustomDictionaries);

            m_prespellCorrectBe       = e.PrespellCorrectBe;
            m_prespellCorrectPrefixes = e.PrespellCorrectPrefixes;
            m_prespellCorrectSuffixes = e.PrespellCorrectSuffixes;

            return(InitializeCore(e));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SpellCheckerWrapper"/> class.
        /// </summary>
        /// <param name="userDicPath">The user dic path.</param>
        /// <param name="editDistance">The edit distance.</param>
        /// <param name="maxSug">The maximum number of suggestions.</param>
        /// <param name="dics">array of main and custom dictionary paths. It is expected that the main dictionary has the index 0.</param>
        /// <param name="prespellCorrectPrefixes">if set to <c>true</c> enable correct-prefixes prespelling rule.</param>
        /// <param name="prespellCorrectSuffixes">if set to <c>true</c> enable correct-suffixes prespelling rule.</param>
        /// <param name="prespellCorrectBe">if set to <c>true</c> enable correct-suffixes prespelling rule.</param>
        /// <param name="stemPath">The path to the stem file.</param>
        public SpellCheckerWrapper(string userDicPath, int editDistance, int maxSug, string[] dics,
                                   bool prespellCorrectPrefixes, bool prespellCorrectSuffixes, bool prespellCorrectBe, string stemPath)
        {
            UserDictionary         = userDicPath;
            m_spellCheckerSettings = new SpellCheckerConfig(userDicPath, editDistance, maxSug)
            {
                StemPath = stemPath
            };
            IsInitialized = false;
            Enabled       = true;
            SetDictionaries(dics);

            m_prespellCorrectBe       = prespellCorrectBe;
            m_prespellCorrectPrefixes = prespellCorrectPrefixes;
            m_prespellCorrectSuffixes = prespellCorrectSuffixes;
        }
        private void SaveConfigurations()
        {
            #region Spell-Check Settings

            SpellCheckerConfig spellCheckerInternalConfig = GetSpellCheckSettings();

            if (OnSpellCheckSettingsChanged(spellCheckerInternalConfig))
            {
                m_appSettings.SpellChecker_UserDictionaryPath = spellCheckerInternalConfig.DicPath;
                m_appSettings.SpellChecker_EditDistance       = spellCheckerInternalConfig.EditDistance;
                m_appSettings.SpellChecker_MaxSuggestions     = spellCheckerInternalConfig.SuggestionCount;

                m_appSettings.PreprocessSpell_CorrectBe      = cbPrespellCorrectBe.Checked;
                m_appSettings.PreprocessSpell_CorrectPrefix  = cbPrespellCorrectPrefixes.Checked;
                m_appSettings.PreprocessSpell_CorrectPostfix = cbPrespellCorrectSuffixes.Checked;

                Debug.Assert(listViewUserDictionaries.Items.Count > 0);

                if (listViewUserDictionaries.Items.Count > 0)
                {
                    m_appSettings.SpellChecker_MainDictionaryPath     = GetFileNameFromItem(listViewUserDictionaries.Items[0]);
                    m_appSettings.SpellChecker_MainDictionarySelected = listViewUserDictionaries.Items[0].Checked;

                    var sbPaths        = new StringBuilder();
                    var sbDescs        = new StringBuilder();
                    int selectionFlags = 0;
                    for (int i = 1; i < listViewUserDictionaries.Items.Count; ++i)
                    {
                        sbPaths.AppendFormat("{0};", GetFileNameFromItem(listViewUserDictionaries.Items[i]));
                        sbDescs.AppendFormat("{0};", GetDescriptionFromItem(listViewUserDictionaries.Items[i]));

                        if (listViewUserDictionaries.Items[i].Checked)
                        {
                            selectionFlags = selectionFlags | (1 << (i - 1));
                        }
                    }

                    m_appSettings.SpellChecker_CustomDictionaries              = sbPaths.ToString();
                    m_appSettings.SpellChecker_CustomDictionariesDescription   = sbDescs.ToString();
                    m_appSettings.SpellChecker_CustomDictionariesSelectionFlag = selectionFlags;
                }
            }

            #endregion

            #region Storing All-Chars-Refiner settings

            m_allCharactersRefinerSettings           = GetAllCharsRefinerSettings();
            m_appSettings.RefineCategoriesFlag       = (int)m_allCharactersRefinerSettings.NotIgnoredCategories;
            m_appSettings.RefineIgnoreListConcated   = m_allCharactersRefinerSettings.GetIgnoreListAsString();
            m_appSettings.RefineHalfSpacePositioning = m_allCharactersRefinerSettings.RefineHalfSpacePositioning;
            m_appSettings.RefineNormalizeHeYe        = m_allCharactersRefinerSettings.NormalizeHeYe;
            m_appSettings.RefineLongHeYeToShort      = m_allCharactersRefinerSettings.ConvertLongHeYeToShort;
            m_appSettings.RefineShortHeYeToLong      = m_allCharactersRefinerSettings.ConvertShortHeYeToLong;

            #endregion

            #region Storing Word-Completion Settings

            UpdateWordCompletionSettings();
            m_appSettings.WordCompletionCompleteWithoutHotKey = cbWCCompleteWithoutHotkey.Checked;
            m_appSettings.WordCompletionInsertSpace           = cbWCInsertSpace.Checked;
            if (rbWCShowAllWords.Checked)
            {
                m_appSettings.WordCompletionSugCount = -1;
            }
            else
            {
                m_appSettings.WordCompletionSugCount = (int)numUpDownWCWordCount.Value;
            }

            m_appSettings.WordCompletionMinWordLength = (int)numUpDownWCMinWordLength.Value;
            m_appSettings.WordCompletionFontSize      = (int)numUpDownWCFontSize.Value;

            #endregion

            #region Automatic Update and Report

            m_appSettings.LogReport_AutomaticReport = rdoSendReportAccept.Checked;

            #endregion

            m_appSettings.Save();

            OnRefineAllCharactersSettingsChanged(m_allCharactersRefinerSettings);
        }
Exemplo n.º 6
0
 public bool Initialize(string userDicPath, int editDistance, int maxSug, string[] customDics)
 {
     m_spellCheckerSettings = new SpellCheckerConfig(userDicPath, editDistance, maxSug);
     SetDictionaries(customDics);
     return(Initialize());
 }