//=====================================================================

        /// <summary>
        /// Returns a value indicating whether two specified instances of <c>SpellCheckerDictionary</c> are equal
        /// </summary>
        /// <param name="d1">The first dictionary to compare</param>
        /// <param name="d2">The second dictionary to compare</param>
        /// <returns>Returns true if the dictionaries are equal, false if they are not</returns>
        public static bool Equals(SpellCheckerDictionary d1, SpellCheckerDictionary d2)
        {
            if (d1 == null && d2 == null)
            {
                return(true);
            }

            if (d1 == null)
            {
                return(false);
            }

            return(d1.Equals(d2));
        }
Example #2
0
        //=====================================================================

        /// <summary>
        /// This returns an enumerable list of available dictionaries
        /// </summary>
        /// <remarks>The returned enumerable list contains the default English (en-US) dictionary along with
        /// any custom dictionaries found in the <see cref="SpellingConfigurationFile.GlobalConfigurationFilePath"/>
        /// folder and any optional additional search folders specified.</remarks>
        public static IDictionary <string, SpellCheckerDictionary> AvailableDictionaries(
            IEnumerable <string> additionalSearchFolders)
        {
            Dictionary <string, SpellCheckerDictionary> availableDictionaries = new Dictionary <string,
                                                                                                SpellCheckerDictionary>(StringComparer.OrdinalIgnoreCase);
            CultureInfo info;
            string      dllPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            // This is supplied with the application and is always available.  It may be replaced by a
            // user-supplied dictionary below.
            availableDictionaries["en-US"] = new SpellCheckerDictionary(new CultureInfo("en-US"),
                                                                        Path.Combine(dllPath, "en_US.aff"), Path.Combine(dllPath, "en_US.dic"),
                                                                        Path.Combine(SpellingConfigurationFile.GlobalConfigurationFilePath, "en-US_User.dic"));

            var searchFolders = new List <string>();

            searchFolders.Add(SpellingConfigurationFile.GlobalConfigurationFilePath);

            if (additionalSearchFolders != null)
            {
                searchFolders.AddRange(additionalSearchFolders);
            }

            foreach (string folder in searchFolders)
            {
                try
                {
                    // Culture names can vary in format (en-US, arn, az-Cyrl, az-Cyrl-AZ, az-Latn, az-Latn-AZ,
                    // etc.) so look for any affix files with a related dictionary file and see if they are valid
                    // cultures.  If so, we'll take them.
                    if (Directory.Exists(folder))
                    {
                        foreach (string affixFile in Directory.EnumerateFiles(folder, "*.aff"))
                        {
                            if (File.Exists(Path.ChangeExtension(affixFile, ".dic")))
                            {
                                try
                                {
                                    info = new CultureInfo(Path.GetFileNameWithoutExtension(affixFile).Replace("_", "-"));
                                }
                                catch (CultureNotFoundException)
                                {
                                    // Ignore filenames that are not cultures
                                    info = null;
                                }

                                if (info != null)
                                {
                                    availableDictionaries[info.Name] = new SpellCheckerDictionary(info, affixFile,
                                                                                                  Path.ChangeExtension(affixFile, ".dic"),
                                                                                                  Path.Combine(Path.GetDirectoryName(affixFile), info.Name + "_User.dic"));
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Ignore exceptions due to inaccessible folders
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }

            return(availableDictionaries);
        }
        //=====================================================================
        /// <summary>
        /// Returns a value indicating whether two specified instances of <c>SpellCheckerDictionary</c> are equal
        /// </summary>
        /// <param name="d1">The first dictionary to compare</param>
        /// <param name="d2">The second dictionary to compare</param>
        /// <returns>Returns true if the dictionaries are equal, false if they are not</returns>
        public static bool Equals(SpellCheckerDictionary d1, SpellCheckerDictionary d2)
        {
            if((object)d1 == null && (object)d2 == null)
                return true;

            if((object)d1 == null)
                return false;

            return d1.Equals(d2);
        }
Example #4
0
        /// <summary>
        /// This is overridden to allow proper comparison of <c>SpellCheckerDictionary</c> objects
        /// </summary>
        /// <param name="obj">The object to which this instance is compared</param>
        /// <returns>Returns true if the object equals this instance, false if it does not</returns>
        public override bool Equals(object obj)
        {
            SpellCheckerDictionary d = obj as SpellCheckerDictionary;

            return(d != null && this.Culture.Name == d.Culture.Name);
        }
        //=====================================================================
        /// <summary>
        /// This returns an enumerable list of available dictionaries
        /// </summary>
        /// <remarks>The returned enumerable list contains the default English (en-US) dictionary along with
        /// any custom dictionaries found in the <see cref="SpellingConfigurationFile.GlobalConfigurationFilePath"/>
        /// folder and any optional additional search folders specified.</remarks>
        public static IDictionary<string, SpellCheckerDictionary> AvailableDictionaries(
            IEnumerable<string> additionalSearchFolders)
        {
            Dictionary<string, SpellCheckerDictionary> availableDictionaries = new Dictionary<string,
                SpellCheckerDictionary>(StringComparer.OrdinalIgnoreCase);
            CultureInfo info;
            string dllPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            // This is supplied with the application and is always available.  It may be replaced by a
            // user-supplied dictionary below.
            availableDictionaries["en-US"] = new SpellCheckerDictionary(new CultureInfo("en-US"),
                Path.Combine(dllPath, "en_US.aff"), Path.Combine(dllPath, "en_US.dic"),
                Path.Combine(SpellingConfigurationFile.GlobalConfigurationFilePath, "en-US_User.dic"));

            var searchFolders = new List<string>();
            searchFolders.Add(SpellingConfigurationFile.GlobalConfigurationFilePath);

            if(additionalSearchFolders != null)
                searchFolders.AddRange(additionalSearchFolders);

            foreach(string folder in searchFolders)
            {
                try
                {
                    // Culture names can vary in format (en-US, arn, az-Cyrl, az-Cyrl-AZ, az-Latn, az-Latn-AZ,
                    // etc.) so look for any affix files with a related dictionary file and see if they are valid
                    // cultures.  If so, we'll take them.
                    if(Directory.Exists(folder))
                        foreach(string affixFile in Directory.EnumerateFiles(folder, "*.aff"))
                            if(File.Exists(Path.ChangeExtension(affixFile, ".dic")))
                            {
                                try
                                {
                                    info = new CultureInfo(Path.GetFileNameWithoutExtension(affixFile).Replace("_", "-"));
                                }
                                catch(CultureNotFoundException)
                                {
                                    // Ignore filenames that are not cultures
                                    info = null;
                                }

                                if(info != null)
                                    availableDictionaries[info.Name] = new SpellCheckerDictionary(info, affixFile,
                                        Path.ChangeExtension(affixFile, ".dic"),
                                        Path.Combine(Path.GetDirectoryName(affixFile), info.Name + "_User.dic"));
                            }
                }
                catch(Exception ex)
                {
                    // Ignore exceptions due to inaccessible folders
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }

            return availableDictionaries;
        }