public void OptionChanged(TextViewGroupOption option) { if (optionsStorage is null) { return; } if (writeOptionHash.Contains(option)) { return; } try { writeOptionHash.Add(option); optionsStorage.Write(groupName, option); foreach (var textView in textViews.ToArray()) { var coll = GetCollection(textView.TextDataModel.ContentType); if (!StringComparer.OrdinalIgnoreCase.Equals(option.Definition.ContentType, coll.ContentType.TypeName)) { continue; } try { textView.Options.SetOptionValue(option.OptionId, option.Value); } catch (ArgumentException) { // Invalid option value } } TextViewOptionChanged?.Invoke(this, new TextViewOptionChangedEventArgs(option.Definition.ContentType, option.Definition.Name)); } finally { writeOptionHash.Remove(option); } }
public void OptionChanged(TextViewGroupOption option) { if (optionsStorage == null) { return; } if (writeOptionHash.Contains(option)) { return; } try { writeOptionHash.Add(option); optionsStorage.Write(groupName, option); foreach (var textView in textViews.ToArray()) { try { textView.Options.SetOptionValue(option.OptionId, option.Value); } catch (ArgumentException) { // Invalid option value } } TextViewOptionChanged?.Invoke(this, new TextViewOptionChangedEventArgs(option.Definition.ContentType, option.Definition.Name)); } finally { writeOptionHash.Remove(option); } }
ISettingsSection GetOrCreateOptionSection(string groupName, TextViewGroupOption option) { var key = new OptionKey(new ContentTypeKey(groupName, option.Definition.ContentType), option.OptionId); if (toOptionSection.TryGetValue(key, out var sect)) { return(sect); } var ctSect = GetOrCreateContentTypeSection(groupName, option.Definition.ContentType); sect = ctSect.CreateSection(OptionName); toOptionSection.Add(key, sect); sect.Attribute(OptionNameAttr, option.OptionId); return(sect); }
bool TryGetValueString(TextViewGroupOption option, out string valueString) { if (!option.Definition.CanBeSaved) { valueString = null; return(false); } var type = option.Definition.Type; try { var c = TypeDescriptor.GetConverter(type); valueString = c.ConvertToInvariantString(option.Value); return(true); } catch (FormatException) { } catch (NotSupportedException) { } valueString = null; return(false); }
public void Write(string groupName, TextViewGroupOption option) { if (groupName == null) { throw new ArgumentNullException(nameof(groupName)); } if (option == null) { throw new ArgumentNullException(nameof(option)); } if (!option.Definition.CanBeSaved) { return; } var sect = GetOrCreateOptionSection(groupName, option); if (!TryGetValueString(option, out string valueString)) { return; } sect.Attribute(OptionValueAttr, valueString); }
bool TryGetValue(TextViewGroupOption option, string textValue, out object value) { var type = option.Definition.Type; var c = TypeDescriptor.GetConverter(type); try { value = c.ConvertFromInvariantString(textValue); if (type.IsValueType && value == null) { return(false); } if (value != null && !type.IsAssignableFrom(value.GetType())) { return(false); } return(true); } catch (FormatException) { } catch (NotSupportedException) { } value = null; return(false); }
public void Add(TextViewGroupOption option) => Options.Add(option);