예제 #1
0
        private void ResetIgnoreLists(IContextBoundSettingsStore boundSettings)
        {
            CachedSpellChecker oldIgnoreDictionaries;
            var           selectedIgnoreDictionaries = new HashSet <string>(boundSettings.EnumEntryIndices <SpellCheckSettings, string, byte>(x => x.IgnoreDictionaries));
            var           activeIgnoreDictionaries   = YouCantSpell.SpellChecker.GetAllAvailableDictionaryNames().Where(selectedIgnoreDictionaries.Contains).ToList();
            ISpellChecker newIgnoreDictionaries      = null;

            if (activeIgnoreDictionaries.Count > 0)
            {
                newIgnoreDictionaries = activeIgnoreDictionaries.Count == 1
                                        ? (ISpellChecker) new SpellChecker(activeIgnoreDictionaries[0])
                                        : new SpellCheckerCollection(activeIgnoreDictionaries.Select(x => new SpellChecker(x)).Cast <ISpellChecker>());
            }

            var ignoreWords            = new HashSet <string>(boundSettings.EnumEntryIndices <SpellCheckSettings, string, byte>(x => x.IgnoreEntries));
            var ignoreWordsInsensitive = new HashSet <string>(ignoreWords, StringComparer.CurrentCultureIgnoreCase);

            lock (_ignoredSync) {
                oldIgnoreDictionaries = _ignoreDictionaries;
                _ignored            = ignoreWords;
                _ignoredInsensitive = ignoreWordsInsensitive;
                _ignoreDictionaries = null == newIgnoreDictionaries ? null : new CachedSpellChecker(newIgnoreDictionaries, true);
            }

            if (null != oldIgnoreDictionaries)
            {
                oldIgnoreDictionaries.Dispose();
            }
        }
예제 #2
0
        private void ResetSpellChecker(IContextBoundSettingsStore boundSettings)
        {
            var selectedSepllCheckers = new HashSet <string>(boundSettings.EnumEntryIndices <SpellCheckSettings, string, byte>(x => x.SpellCheckDictionaries));
            // we sort the spell checkers so that just in case we don't have any set we can take the EN dictionaries first.
            var availableSepllCheckers = YouCantSpell.SpellChecker.GetAllAvailableDictionaryNames().OrderByDescending(x => {
                if (String.Equals(x, "EN_US", StringComparison.OrdinalIgnoreCase))
                {
                    return(100);
                }
                if (x.StartsWith("EN", StringComparison.OrdinalIgnoreCase))
                {
                    return(50);
                }
                return(0);
            }).ToList();

            var activeSepllCheckers = availableSepllCheckers.Where(selectedSepllCheckers.Contains).ToList();

            if (activeSepllCheckers.Count == 0 && availableSepllCheckers.Count > 0)
            {
                // if there are no active spell checkers we should take one off the top of the available list, preferring en_us and en_gb.
                activeSepllCheckers.Add(availableSepllCheckers[0]);
            }

            ISpellChecker newSpellCheckCore = new SpellCheckerCollection(activeSepllCheckers.Select(x => new SpellChecker(x)).Cast <ISpellChecker>());

            newSpellCheckCore.Add(boundSettings.EnumEntryIndices <SpellCheckSettings, string, byte>(x => x.UserEntries));
            newSpellCheckCore = new CachedSpellChecker(newSpellCheckCore, true);

            lock (_spellCheckerSync){
                if (null == _spellChecker)
                {
                    _spellChecker = new SpellCheckerPointer(newSpellCheckCore, true);
                }
                else
                {
                    _spellChecker.Replace(newSpellCheckCore);
                }
            }
        }