/// <summary> /// Ensure that the spelling dictionary (if any) for the specified ws will give the specified /// answer regarding the specified word. /// </summary> public static void SetSpellingStatus(string word, int ws, SIL.FieldWorks.Common.COMInterfaces.ILgWritingSystemFactory wsf, bool fCorrect) { using (Enchant.Dictionary dict = GetDictionary(ws, wsf)) { if (dict == null) { return; // no spelling dict to update. } SetSpellingStatus(word, fCorrect, dict); } }
/// <summary> /// Ensure that the spelling dictionary (if any) for the specified ws will give the specified /// answer regarding the specified word. /// </summary> public static void SetSpellingStatus(string word, int ws, ILgWritingSystemFactory wsf, bool fCorrect) { //I'm not sure why we want to avoid keeping references to Enchant Dictionaries around //but since we are doing this here and in WfiWordFormServices any object which holds onto //a dictionary reference must deal with the possibility that it will be disposed out from under them. // -naylor 9-2011 using (Enchant.Dictionary dict = GetDictionary(ws, wsf)) { if (dict == null) { return; // no spelling dict to update. } SetSpellingStatus(word, fCorrect, dict); } }
public Broker() { try { _handle = Bindings.enchant_broker_init(); _isLibEnchantAvailable = true; } catch (DllNotFoundException) { _isLibEnchantAvailable = false; } if (_isLibEnchantAvailable == true) { VerifyNoErrors(); if (_handle.IsInvalid) { throw new ApplicationException("Unable to initialize broker"); } } _dictionaryCache = new Dictionary<string, WeakReference>(); _pwlDictionaryCache = new Dictionary<string, WeakReference>(); }
public TextBoxSpellChecker() { _extendees = new Dictionary<Control, string>(); bool brokerSuccessfullyCreated = false; try { _broker = new Broker(); brokerSuccessfullyCreated = true; } catch { //it's okay if we can't create one. // probably because Enchant isn't installed on this machine } if (brokerSuccessfullyCreated) { _hotSpotProvider = new HotSpotProvider(); _hotSpotProvider.RetrieveHotSpots += CheckSpelling; _dictionaries = new Dictionary<string, Dictionary>(); } }
/// <summary> /// Make sure that a dictionary exists for the specified writing system. /// </summary> public static Dictionary EnsureDictionary(int ws, string icuLocale, ILgWritingSystemFactory wsf) { Enchant.Dictionary result = EnchantHelper.GetDictionary(ws, wsf); if (result != null) { return(result); } string dirPath = GetSpellingDirectoryPath(); if (!System.IO.Directory.Exists(dirPath)) { System.IO.Directory.CreateDirectory(dirPath); } string dicPath = GetDicPath(dirPath, icuLocale); System.IO.TextWriter writer = System.IO.File.CreateText(System.IO.Path.ChangeExtension(dicPath, ".aff")); writer.WriteLine("SET UTF-8"); writer.Close(); if (!System.IO.File.Exists(dicPath)) { // If it already exists, probably we disabled it by deleting the .aff file--an approach we // no longer use; re-creating it should reinstate it. writer = System.IO.File.CreateText(dicPath); writer.WriteLine("0"); writer.Close(); } // Apparently, although the broker will find the new dictionary when asked for it explicitly, // it doesn't appear in the list of possible dictionaries (Enchant.Broker.Default.Dictionaries) // which is used to populate the spelling dictionary combo box in the writing system dialog // unless we dispose the old broker (which causes a new one to be created). // Note: I (JohnT) have a vague recollection that disposing the broker can cause problems for // any existing dictionaries we hang on to. So don't dispose it more than necessary. Enchant.Broker.Default.Dispose(); // Now it should exist! return(EnchantHelper.GetDictionary(ws, wsf)); }
private static bool RemoveDictionaryFromCache(IDictionary<string, WeakReference> cache, Dictionary dictionary) { foreach (KeyValuePair<string, WeakReference> pair in cache) { if (pair.Value.IsAlive && pair.Value.Target == dictionary) { cache.Remove(pair.Key); return true; } } return false; }
private Dictionary CreateAndRegisterDictionary(SafeDictionaryHandle handle, IDictionary<string, WeakReference> cache, string language_tag) { Dictionary dictionary; dictionary = new Dictionary(handle); dictionary.Disposed += OnDictionaryDisposed; // always store the dictionaries we have created // so that we can dispose of them cleanly and give a // better error message (ObjectDisposed) instead of a crash // if someone tries to use a dictionary after the broker // that created it has been disposed. cache[language_tag] = new WeakReference(dictionary); return dictionary; }
/// <summary> /// Ensure that the specified spelling dictionary will give the specified answer regarding the specified word. /// </summary> public static void SetSpellingStatus(string word, bool fCorrect, Dictionary dict) { if (fCorrect) { if (!dict.Check(word)) dict.Add(word); } else { if (dict.Check(word)) dict.Remove(word); } }
/// <summary> /// Add the word to the spelling dictionary. /// Overrides to also add to the wordform inventory. /// </summary> /// <param name="dict"></param> /// <param name="word"></param> /// <param name="ws"></param> public override void AddToSpellDict(Dictionary dict, string word, int ws) { base.AddToSpellDict(dict, word, ws); if (m_cache == null) return; // bizarre, but means we just can't do it. // If it's in a current vernacular writing system, we want to update the WFI as well. bool fVern = false; foreach (LgWritingSystem lws in m_cache.LangProject.CurVernWssRS) if (lws.Hvo == ws) { fVern = true; break; } if (!fVern) return; // Now add to WFI. int hvoWf = SIL.FieldWorks.FDO.Ling.WfiWordform.FindOrCreateWordform(m_cache, word, ws, true); IWfiWordform wf = SIL.FieldWorks.FDO.Ling.WfiWordform.CreateFromDBObject(m_cache, hvoWf); wf.SpellingStatus = (int)SpellingStatusStates.correct; }