/// <summary> /// Sets the dictionaries. /// </summary> /// <param name="checker">The checker.</param> internal static void SetDictionaries(DocumentSpellChecker checker) { foreach (var dic in Dictionaries) { try { checker.AddDictionary(dic.Value, dic.Key); } catch (Exception ex) { AppCore.Log.ErrorFormat("Error add dictionary {1} \n {0}", ex, dic.Key.Name); } } }
private IDocumentSpellChecker EnsureSpellCheckerExists(IHtmlEditor key) { DocumentSpellChecker p = (DocumentSpellChecker)checker[key]; if (p == null) { p = new DocumentSpellChecker(key); p.WordChecker += new WordCheckerHandler(p_WordChecker); p.WordCheckerFinished += new WordCheckerFinishedHandler(p_WordCheckerFinished); p.WordCheckerStop += new WordCheckerStopHandler(p_WordCheckerStop); p.WordOnContext += new WordOnContextHandler(p_WordOnContext); checker[key] = p; } return(p); }
/// <summary> /// Constructor for properties with backreference parameter to spellchecker instance. /// </summary> /// <param name="documentSpellChecker">Spellchecker instance this property instance refers to.</param> public SpellCheckerProperties(IDocumentSpellChecker documentSpellChecker) { this.documentSpellChecker = (DocumentSpellChecker)documentSpellChecker; // default for spellchecking HighlightColor hc = HighlightColor.Color(Color.Red); UnderlineStyle us = UnderlineStyle.Wave; IHighLightStyle hs = new HighLightStyle(); hs.LineColor = hc; hs.UnderlineStyle = us; this.documentSpellChecker.HighLightStyle = hs; ignoreWordsWithDigits = true; ignoreUpperCaseWords = true; maxSuggestionsCount = 25; ignoreHtml = true; ignoreList = new List <string>(); replaceList = new Dictionary <string, string>(); checkInternal = true; if (String.IsNullOrEmpty(this.Dictionary)) { this.Dictionary = System.Threading.Thread.CurrentThread.CurrentUICulture.Name; } }
void SpellerOperation(object sender, EventArgs e) { CommandWrapper cw = (CommandWrapper)sender; string checkpath; if (cw.CommandID.Guid.Equals(Commands.CommandGroup)) { DocumentSpellChecker ds = (DocumentSpellChecker)EnsureSpellCheckerExists(cw.TargetEditor); switch ((SpellCommand)cw.ID) { case SpellCommand.RemoveHighLight: EnsureSpellCheckerExists(cw.TargetEditor).RemoveWordCheckingHighlights(); break; case SpellCommand.ClearBuffer: EnsureSpellCheckerExists(cw.TargetEditor).MisSpelledWords.Clear(); break; case SpellCommand.StopBackground: IsInBackground = false; EnsureSpellCheckerExists(cw.TargetEditor).BackgroundService = false; IsInCheck = false; break; case SpellCommand.StartBackground: IsInBackground = true; if (ds.Spelling.Dictionary.DictionaryFolder == null) { ds.Spelling.Dictionary.DictionaryFolder = "Dictionary"; } checkpath = Path.Combine(ds.Spelling.Dictionary.DictionaryFolder, ds.Spelling.Dictionary.DictionaryFile); if (!File.Exists(checkpath)) { ds.Spelling.Dictionary.DictionaryFile = String.Format("{0}.dic", EnsurePropertiesExists(cw.TargetEditor).LanguageType); } ds.Spelling.SuggestionMode = EnsurePropertiesExists(cw.TargetEditor).SuggestionType; ds.Spelling.IgnoreAllCapsWords = EnsurePropertiesExists(cw.TargetEditor).IgnoreUpperCaseWords; ds.Spelling.IgnoreWordsWithDigits = EnsurePropertiesExists(cw.TargetEditor).IgnoreWordsWithDigits; ds.Spelling.MaxSuggestions = EnsurePropertiesExists(cw.TargetEditor).MaxSuggestionsCount; ds.Spelling.IgnoreHtml = EnsurePropertiesExists(cw.TargetEditor).IgnoreHtml; ds.Spelling.IgnoreList.AddRange(EnsurePropertiesExists(cw.TargetEditor).IgnoreList); foreach (KeyValuePair <string, string> de in EnsurePropertiesExists(cw.TargetEditor).ReplaceList) { ds.Spelling.ReplaceList[de.Key] = de.Value; } IsInCheck = true; EnsureSpellCheckerExists(cw.TargetEditor).DoWordCheckingHighlights(EnsurePropertiesExists(cw.TargetEditor).HighLightStyle, true); break; case SpellCommand.StartWordByWord: if (ds.Spelling.Dictionary.DictionaryFolder == null) { ds.Spelling.Dictionary.DictionaryFolder = "Dictionary"; } checkpath = Path.Combine(ds.Spelling.Dictionary.DictionaryFolder, ds.Spelling.Dictionary.DictionaryFile); if (!File.Exists(checkpath)) { ds.Spelling.Dictionary.DictionaryFile = String.Format("{0}.dic", EnsurePropertiesExists(cw.TargetEditor).LanguageType); } ds.Spelling.Dictionary.DictionaryFile = String.Format("{0}.dic", EnsurePropertiesExists(cw.TargetEditor).LanguageType); ds.Spelling.SuggestionMode = EnsurePropertiesExists(cw.TargetEditor).SuggestionType; ds.Spelling.IgnoreAllCapsWords = EnsurePropertiesExists(cw.TargetEditor).IgnoreUpperCaseWords; ds.Spelling.IgnoreWordsWithDigits = EnsurePropertiesExists(cw.TargetEditor).IgnoreWordsWithDigits; ds.Spelling.MaxSuggestions = EnsurePropertiesExists(cw.TargetEditor).MaxSuggestionsCount; ds.Spelling.IgnoreHtml = EnsurePropertiesExists(cw.TargetEditor).IgnoreHtml; ds.Spelling.IgnoreList.AddRange(EnsurePropertiesExists(cw.TargetEditor).IgnoreList); foreach (KeyValuePair <string, string> de in EnsurePropertiesExists(cw.TargetEditor).ReplaceList) { ds.Spelling.ReplaceList[de.Key] = de.Value; } IsInCheck = true; ds.DoWordCheckingHighlights(ds.HighLightStyle, false); break; case SpellCommand.StopWordByWord: IsInCheck = false; break; case SpellCommand.StopBlock: IsInCheck = false; break; case SpellCommand.StartBlock: ds.Spelling.SuggestionMode = EnsurePropertiesExists(cw.TargetEditor).SuggestionType; ds.Spelling.IgnoreAllCapsWords = EnsurePropertiesExists(cw.TargetEditor).IgnoreUpperCaseWords; ds.Spelling.IgnoreWordsWithDigits = EnsurePropertiesExists(cw.TargetEditor).IgnoreWordsWithDigits; ds.Spelling.MaxSuggestions = EnsurePropertiesExists(cw.TargetEditor).MaxSuggestionsCount; IsInCheck = true; ds.DoBlockCheckingHighlights(EnsurePropertiesExists(cw.TargetEditor).HighLightStyle); break; } } }
private static IList<Lazy<IWordDictionary, IWordDictionaryMetadata>> GetExportedDictionaries() { var documentSpellChecker = new DocumentSpellChecker(); RadCompositionInitializer.SatisfyImports(documentSpellChecker); return documentSpellChecker.DictionaryList; }
/// <summary> /// Determines whether the specified document has spelling errors. /// </summary> /// <param name="document"> /// The document. /// </param> /// <param name="culture"> /// The culture. /// </param> /// <returns> /// The asynchronous task. /// </returns> public async Task<bool> HasErrors(RadDocument document, CultureInfo culture) { if (document == null) throw new ArgumentNullException("document"); if (culture == null) throw new ArgumentNullException("culture"); var getUserDictionaryTask = GetUserDictionaryAsync(); var getDictionaryTask = GetDictionaryAsync(culture); var getIgnoredWordsTask = GetIgnoredWordsAsync(); await TaskEx.WhenAll(getUserDictionaryTask, getDictionaryTask, getIgnoredWordsTask); var userDictionary = getUserDictionaryTask.Result; var dictionary = getDictionaryTask.Result; var ignoredWords = getIgnoredWordsTask.Result; var spellChecker = new DocumentSpellChecker(userDictionary); try { if (dictionary != null) { spellChecker.AddDictionary(dictionary, culture); spellChecker.RemoveCustomDictionary(culture); } spellChecker.SpellCheckingCulture = culture; var proofingManager = new DocumentProofingManager(document, spellChecker, ignoredWords); using (var position = new DocumentPosition(document)) { var nextErrorWord = proofingManager.GetNextErrorWord(position); return nextErrorWord != null; } } finally { spellChecker.RemoveCustomDictionary(CultureInfo.InvariantCulture); } }