/// <inheritdoc /> public void LoadConfiguration(SpellingConfigurationFile configuration) { IEnumerable <string> folders; lbAdditionalFolders.Items.Clear(); var dataSource = new List <PropertyState>(); if (configuration.ConfigurationType != ConfigurationType.Global) { dataSource.AddRange(new[] { PropertyState.Inherited, PropertyState.Yes, PropertyState.No }); } else { dataSource.AddRange(new[] { PropertyState.Yes, PropertyState.No }); } cboDetermineResxLang.ItemsSource = dataSource; cboDetermineResxLang.SelectedValue = configuration.ToPropertyState( PropertyNames.DetermineResourceFileLanguageFromName); configFilePath = Path.GetDirectoryName(configuration.Filename); isGlobal = configuration.ConfigurationType == ConfigurationType.Global; if (isGlobal) { chkInheritAdditionalFolders.IsChecked = false; chkInheritAdditionalFolders.Visibility = Visibility.Collapsed; } else { chkInheritAdditionalFolders.IsChecked = configuration.ToBoolean( PropertyNames.InheritAdditionalDictionaryFolders); } if (configuration.HasProperty(PropertyNames.AdditionalDictionaryFolders)) { folders = configuration.ToValues(PropertyNames.AdditionalDictionaryFolders, PropertyNames.AdditionalDictionaryFoldersItem); } else { folders = Enumerable.Empty <string>(); } foreach (string f in folders) { lbAdditionalFolders.Items.Add(f); } var sd = new SortDescription { Direction = ListSortDirection.Ascending }; lbAdditionalFolders.Items.SortDescriptions.Add(sd); if (configuration.HasProperty(PropertyNames.DefaultLanguage) || isGlobal) { defaultLang = configuration.ToCultureInfo(PropertyNames.DefaultLanguage); } this.LoadAvailableLanguages(); }
//===================================================================== /// <summary> /// Load the configuration from the given file /// </summary> /// <param name="filename">The configuration file to load</param> /// <remarks>Any properties not in the configuration file retain their current values. If the file does /// not exist, the configuration will remain unchanged.</remarks> public void Load(string filename) { HashSet<string> tempHashSet; try { // Nothing to do if the file doesn't exist if(!File.Exists(filename)) return; var configuration = new SpellingConfigurationFile(filename, this); this.DefaultLanguage = configuration.ToCultureInfo(PropertyNames.DefaultLanguage); this.SpellCheckAsYouType = configuration.ToBoolean(PropertyNames.SpellCheckAsYouType); this.IgnoreWordsWithDigits = configuration.ToBoolean(PropertyNames.IgnoreWordsWithDigits); this.IgnoreWordsInAllUppercase = configuration.ToBoolean(PropertyNames.IgnoreWordsInAllUppercase); this.IgnoreFormatSpecifiers = configuration.ToBoolean(PropertyNames.IgnoreFormatSpecifiers); this.IgnoreFilenamesAndEMailAddresses = configuration.ToBoolean( PropertyNames.IgnoreFilenamesAndEMailAddresses); this.IgnoreXmlElementsInText = configuration.ToBoolean(PropertyNames.IgnoreXmlElementsInText); this.TreatUnderscoreAsSeparator = configuration.ToBoolean(PropertyNames.TreatUnderscoreAsSeparator); this.IgnoreCharacterClass = configuration.ToEnum<IgnoredCharacterClass>( PropertyNames.IgnoreCharacterClass); this.DetermineResourceFileLanguageFromName = configuration.ToBoolean( PropertyNames.DetermineResourceFileLanguageFromName); csharpOptions.IgnoreXmlDocComments = configuration.ToBoolean( PropertyNames.CSharpOptionsIgnoreXmlDocComments); csharpOptions.IgnoreDelimitedComments = configuration.ToBoolean( PropertyNames.CSharpOptionsIgnoreDelimitedComments); csharpOptions.IgnoreStandardSingleLineComments = configuration.ToBoolean( PropertyNames.CSharpOptionsIgnoreStandardSingleLineComments); csharpOptions.IgnoreQuadrupleSlashComments = configuration.ToBoolean( PropertyNames.CSharpOptionsIgnoreQuadrupleSlashComments); csharpOptions.IgnoreNormalStrings = configuration.ToBoolean( PropertyNames.CSharpOptionsIgnoreNormalStrings); csharpOptions.IgnoreVerbatimStrings = configuration.ToBoolean( PropertyNames.CSharpOptionsIgnoreVerbatimStrings); csharpOptions.IgnoreInterpolatedStrings = configuration.ToBoolean( PropertyNames.CSharpOptionsIgnoreInterpolatedStrings); cadOptions.ImportCodeAnalysisDictionaries = configuration.ToBoolean( PropertyNames.CadOptionsImportCodeAnalysisDictionaries); cadOptions.RecognizedWordHandling = configuration.ToEnum<RecognizedWordHandling>( PropertyNames.CadOptionsRecognizedWordHandling); cadOptions.TreatUnrecognizedWordsAsMisspelled = configuration.ToBoolean( PropertyNames.CadOptionsTreatUnrecognizedWordsAsMisspelled); cadOptions.TreatDeprecatedTermsAsMisspelled = configuration.ToBoolean( PropertyNames.CadOptionsTreatDeprecatedTermsAsMisspelled); cadOptions.TreatCompoundTermsAsMisspelled = configuration.ToBoolean( PropertyNames.CadOptionsTreatCompoundTermsAsMisspelled); cadOptions.TreatCasingExceptionsAsIgnoredWords = configuration.ToBoolean( PropertyNames.CadOptionsTreatCasingExceptionsAsIgnoredWords); this.InheritExcludedExtensions = configuration.ToBoolean(PropertyNames.InheritExcludedExtensions); if(configuration.HasProperty(PropertyNames.ExcludedExtensions)) { tempHashSet = new HashSet<string>(configuration.ToValues(PropertyNames.ExcludedExtensions, PropertyNames.ExcludedExtensionsItem), StringComparer.OrdinalIgnoreCase); if(this.InheritExcludedExtensions) { if(tempHashSet.Count != 0) foreach(string ext in tempHashSet) excludedExtensions.Add(ext); } else excludedExtensions = tempHashSet; } this.InheritAdditionalDictionaryFolders = configuration.ToBoolean( PropertyNames.InheritAdditionalDictionaryFolders); if(configuration.HasProperty(PropertyNames.AdditionalDictionaryFolders)) { tempHashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase); foreach(string folder in configuration.ToValues(PropertyNames.AdditionalDictionaryFolders, PropertyNames.AdditionalDictionaryFoldersItem)) { // Fully qualify relative paths with the configuration file path if(Path.IsPathRooted(folder)) tempHashSet.Add(folder); else tempHashSet.Add(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(filename), folder))); } if(this.InheritAdditionalDictionaryFolders) { if(tempHashSet.Count != 0) foreach(string folder in tempHashSet) additionalDictionaryFolders.Add(folder); } else additionalDictionaryFolders = tempHashSet.ToList(); } this.InheritIgnoredWords = configuration.ToBoolean(PropertyNames.InheritIgnoredWords); if(configuration.HasProperty(PropertyNames.IgnoredWords)) { tempHashSet = new HashSet<string>(configuration.ToValues(PropertyNames.IgnoredWords, PropertyNames.IgnoredWordsItem), StringComparer.OrdinalIgnoreCase); if(this.InheritIgnoredWords) { if(tempHashSet.Count != 0) foreach(string word in tempHashSet) ignoredWords.Add(word); } else ignoredWords = tempHashSet; } this.InheritXmlSettings = configuration.ToBoolean(PropertyNames.InheritXmlSettings); if(configuration.HasProperty(PropertyNames.IgnoredXmlElements)) { tempHashSet = new HashSet<string>(configuration.ToValues(PropertyNames.IgnoredXmlElements, PropertyNames.IgnoredXmlElementsItem)); if(this.InheritXmlSettings) { if(tempHashSet.Count != 0) foreach(string element in tempHashSet) ignoredXmlElements.Add(element); } else ignoredXmlElements = tempHashSet; } if(configuration.HasProperty(PropertyNames.SpellCheckedXmlAttributes)) { tempHashSet = new HashSet<string>(configuration.ToValues(PropertyNames.SpellCheckedXmlAttributes, PropertyNames.SpellCheckedXmlAttributesItem)); if(this.InheritXmlSettings) { if(tempHashSet.Count != 0) foreach(string attr in tempHashSet) spellCheckedXmlAttributes.Add(attr); } else spellCheckedXmlAttributes = tempHashSet; } } catch(Exception ex) { // Ignore errors and just use the defaults System.Diagnostics.Debug.WriteLine(ex); } }
/// <inheritdoc /> public void LoadConfiguration(SpellingConfigurationFile configuration) { IEnumerable<string> folders; lbAdditionalFolders.Items.Clear(); var dataSource = new List<PropertyState>(); if(configuration.ConfigurationType != ConfigurationType.Global) dataSource.AddRange(new[] { PropertyState.Inherited, PropertyState.Yes, PropertyState.No }); else dataSource.AddRange(new[] { PropertyState.Yes, PropertyState.No }); cboDetermineResxLang.ItemsSource = dataSource; cboDetermineResxLang.SelectedValue = configuration.ToPropertyState( PropertyNames.DetermineResourceFileLanguageFromName); configFilePath = Path.GetDirectoryName(configuration.Filename); isGlobal = configuration.ConfigurationType == ConfigurationType.Global; if(isGlobal) { chkInheritAdditionalFolders.IsChecked = false; chkInheritAdditionalFolders.Visibility = Visibility.Collapsed; } else chkInheritAdditionalFolders.IsChecked = configuration.ToBoolean( PropertyNames.InheritAdditionalDictionaryFolders); if(configuration.HasProperty(PropertyNames.AdditionalDictionaryFolders)) { folders = configuration.ToValues(PropertyNames.AdditionalDictionaryFolders, PropertyNames.AdditionalDictionaryFoldersItem); } else folders = Enumerable.Empty<string>(); foreach(string f in folders) lbAdditionalFolders.Items.Add(f); var sd = new SortDescription { Direction = ListSortDirection.Ascending }; lbAdditionalFolders.Items.SortDescriptions.Add(sd); if(configuration.HasProperty(PropertyNames.DefaultLanguage) || isGlobal) defaultLang = configuration.ToCultureInfo(PropertyNames.DefaultLanguage); this.LoadAvailableLanguages(); }