Beispiel #1
0
        /// <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));
        }
Beispiel #2
0
        public void BasicSpellingStatus()
        {
#if __MonoCS__
            if (!File.Exists("/usr/lib/enchant-cs/libenchant_myspell.so"))
            {
                Assert.Ignore("The fieldworks-enchant package must be installed on this computer for EnchantHelperTests.BasicSpellingStatus to work!");
            }
#endif
            var dirPath = EnchantHelper.GetSpellingDirectoryPath();
            Directory.CreateDirectory(dirPath);
            var dictId   = "foo";
            var filePath = EnchantHelper.GetDicPath(dirPath, dictId);
            File.Delete(filePath);
            File.Delete(Path.ChangeExtension(filePath, ".aff"));
            string path = EnchantHelper.GetDicPath(EnchantHelper.GetSpellingOverridesDirectory(), dictId);
            File.Delete(path);
            File.Delete(Path.ChangeExtension(path, ".exc"));
            EnchantHelper.EnsureDictionary(dictId);
            Assert.IsTrue(Enchant.Broker.IsLibEnchantAvailable, "Enchant is not available!");
            Assert.IsTrue(Enchant.Broker.Default.DictionaryExists(dictId), "Dictionary doesn't exist!");
            using (var dict = EnchantHelper.GetDict(dictId))
            {
                Assert.That(dict, Is.Not.Null);
                Assert.That(dict.Check("nonsense"), Is.False);
                Assert.That(dict.Check("big"), Is.False);
                EnchantHelper.SetSpellingStatus("big", true, dict);
                Assert.That(dict.Check("big"), Is.True);
                // The standard Enchant fails this test; it is designed to accept title case or all-caps versions of any
                // word that is known correct.
                // For FieldWorks we build a special version that does not.
                // If this test fails, you probably have a new version of Enchant that has not been patched.
                // The required fix (as of version 1.6 of Enchant) is in pwl.c, in the function enchant_pwl_check.
                // Remove the entire block that starts with
                // if(enchant_is_title_case(word, len) || (isAllCaps = enchant_is_all_caps(word, len)))
                Assert.That(dict.Check("Big"), Is.False);
                EnchantHelper.SetSpellingStatus("Big", false, dict);
                Assert.That(dict.Check("Big"), Is.False);
                Assert.That(dict.Check("big"), Is.True);

                // If we set the upper case version only, that is considered correct, but the LC version is not.
                Assert.That(dict.Check("Bother"), Is.False);
                EnchantHelper.SetSpellingStatus("Bother", true, dict);
                Assert.That(dict.Check("Bother"), Is.True);
                Assert.That(dict.Check("bother"), Is.False);

                // Subsequently explicitly setting the LC version to false is not a problem.
                EnchantHelper.SetSpellingStatus("bother", false, dict);
                Assert.That(dict.Check("Bother"), Is.True);
                Assert.That(dict.Check("bother"), Is.False);

                // Now if we set the UC version false, both are.
                EnchantHelper.SetSpellingStatus("Bother", false, dict);
                Assert.That(dict.Check("Bother"), Is.False);
                Assert.That(dict.Check("bother"), Is.False);

                // Now both are explicitly false. Set the LC one to true.
                EnchantHelper.SetSpellingStatus("bother", true, dict);
                Assert.That(dict.Check("Bother"), Is.False);
                Assert.That(dict.Check("bother"), Is.True);

                // Now make the LC one false again.
                EnchantHelper.SetSpellingStatus("bother", false, dict);
                Assert.That(dict.Check("Bother"), Is.False);
                Assert.That(dict.Check("bother"), Is.False);

                // Now make the UC one true again.
                EnchantHelper.SetSpellingStatus("Bother", true, dict);
                Assert.That(dict.Check("Bother"), Is.True);
                Assert.That(dict.Check("bother"), Is.False);
            }
        }