Example #1
0
 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>();
			}
		}
Example #3
0
	    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;
	    }
Example #4
0
	    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;
	    }
Example #5
0
		/// <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;
		}