Ejemplo n.º 1
0
 /// <inheritdoc/>
 public void Dispose()
 {
     if (null != _spellChecker)
     {
         _spellChecker.Dispose();
         _spellChecker = null;
     }
 }
Ejemplo n.º 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);
                }
            }
        }