Пример #1
0
        /// <summary>
        /// Sets the active spellchecker for the specified culture.  If
        /// culture is null, the default culture is used
        /// </summary>
        /// <param name="ci">culture info</param>
        /// <returns>true on success</returns>
        public bool SetActiveSpellChecker(CultureInfo ci = null)
        {
            bool retVal             = true;
            Guid guid               = Guid.Empty;
            Guid cultureNeutralGuid = Guid.Empty;

            if (ci == null)
            {
                ci = CultureInfo.DefaultThreadCurrentUICulture;
            }

            guid = _spellCheckers.GetPreferredOrDefaultByCulture(ci);
            cultureNeutralGuid = _spellCheckers.GetPreferredOrDefaultByCulture(null);

            if (!Equals(guid, Guid.Empty))  // found something for the specific culture
            {
                var type = _spellCheckers.Lookup(guid);

                if (_activeSpellChecker != null)
                {
                    _activeSpellChecker.Dispose();
                    _activeSpellChecker = null;
                }

                retVal = createAndSetActiveSpellChecker(type, ci);

                if (!retVal)
                {
                    _activeSpellChecker = SpellCheckers.NullSpellChecker;
                    retVal = true; // TODO::
                }
            }
            else
            {
                if (!Equals(cultureNeutralGuid, Guid.Empty))
                {
                    var type = _spellCheckers.Lookup(cultureNeutralGuid);
                    retVal = createAndSetActiveSpellChecker(type, ci);
                }
                else
                {
                    retVal = false;
                }

                if (!retVal)
                {
                    _activeSpellChecker = SpellCheckers.NullSpellChecker;
                    retVal = true; // TODO::
                }
            }

            return(retVal);
        }
Пример #2
0
        /// <summary>
        /// Sets the spell checker represented by id
        /// as a Guid or name.
        /// </summary>
        /// <param name="idOrName">GUID or name of the spell checker</param>
        /// <returns>true on success</returns>
        public bool SetActiveSpellChecker(String idOrName)
        {
            bool retVal;
            var  guid = Guid.Empty;

            if (!Guid.TryParse(idOrName, out guid))
            {
                guid = _spellCheckers.GetByName(idOrName);
            }

            var type = Guid.Equals(idOrName, Guid.Empty) ?
                       typeof(NullSpellChecker) :
                       _spellCheckers.Lookup(guid);

            if (type != null)
            {
                if (_activeSpellChecker != null)
                {
                    _activeSpellChecker.Dispose();
                    _activeSpellChecker = null;
                }

                retVal = createAndSetActiveSpellChecker(type);
            }
            else
            {
                createAndSetActiveSpellChecker(typeof(NullSpellChecker));
                retVal = false;
            }

            return(retVal);
        }