|
|
|
@ -34,8 +34,13 @@ namespace CSharpBinding.FormattingStrategy
@@ -34,8 +34,13 @@ namespace CSharpBinding.FormattingStrategy
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal class CSharpFormattingOptionsContainer : INotifyPropertyChanged |
|
|
|
|
{ |
|
|
|
|
private const string IndentationSizePropertyName = "IndentationSize"; |
|
|
|
|
private const string ConvertTabsToSpacesPropertyName = "ConvertTabsToSpaces"; |
|
|
|
|
|
|
|
|
|
CSharpFormattingOptionsContainer parent; |
|
|
|
|
CSharpFormattingOptions cachedOptions; |
|
|
|
|
int? indentationSize; |
|
|
|
|
bool? convertTabsToSpaces; |
|
|
|
|
|
|
|
|
|
readonly HashSet<string> activeOptions; |
|
|
|
|
|
|
|
|
@ -106,6 +111,8 @@ namespace CSharpBinding.FormattingStrategy
@@ -106,6 +111,8 @@ namespace CSharpBinding.FormattingStrategy
|
|
|
|
|
foreach (var activeOption in options.activeOptions) |
|
|
|
|
activeOptions.Add(activeOption); |
|
|
|
|
cachedOptions = options.cachedOptions.Clone(); |
|
|
|
|
indentationSize = options.indentationSize; |
|
|
|
|
convertTabsToSpaces = options.convertTabsToSpaces; |
|
|
|
|
OnPropertyChanged(null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -128,6 +135,14 @@ namespace CSharpBinding.FormattingStrategy
@@ -128,6 +135,14 @@ namespace CSharpBinding.FormattingStrategy
|
|
|
|
|
// All properties might have changed -> update everything
|
|
|
|
|
cachedOptions = CreateCachedOptions(); |
|
|
|
|
OnPropertyChanged(e.PropertyName); |
|
|
|
|
} else if (e.PropertyName == IndentationSizePropertyName) { |
|
|
|
|
if (!indentationSize.HasValue) { |
|
|
|
|
indentationSize = GetEffectiveIndentationSize(); |
|
|
|
|
} |
|
|
|
|
} else if (e.PropertyName == ConvertTabsToSpacesPropertyName) { |
|
|
|
|
if (!convertTabsToSpaces.HasValue) { |
|
|
|
|
convertTabsToSpaces = GetEffectiveConvertTabsToSpaces(); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// Some other property has changed, check if we have our own value for it
|
|
|
|
|
if (!activeOptions.Contains(e.PropertyName)) { |
|
|
|
@ -150,10 +165,18 @@ namespace CSharpBinding.FormattingStrategy
@@ -150,10 +165,18 @@ namespace CSharpBinding.FormattingStrategy
|
|
|
|
|
public object GetOption(string option) |
|
|
|
|
{ |
|
|
|
|
// Run up the hierarchy until we find a defined value for property
|
|
|
|
|
if (activeOptions.Contains(option)) { |
|
|
|
|
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); |
|
|
|
|
if (propertyInfo != null) { |
|
|
|
|
return propertyInfo.GetValue(cachedOptions); |
|
|
|
|
if (option == IndentationSizePropertyName) { |
|
|
|
|
if (indentationSize.HasValue) |
|
|
|
|
return indentationSize.Value; |
|
|
|
|
} else if (option == ConvertTabsToSpacesPropertyName) { |
|
|
|
|
if (convertTabsToSpaces.HasValue) |
|
|
|
|
return convertTabsToSpaces.Value; |
|
|
|
|
} else { |
|
|
|
|
if (activeOptions.Contains(option)) { |
|
|
|
|
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); |
|
|
|
|
if (propertyInfo != null) { |
|
|
|
|
return propertyInfo.GetValue(cachedOptions); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -188,6 +211,68 @@ namespace CSharpBinding.FormattingStrategy
@@ -188,6 +211,68 @@ namespace CSharpBinding.FormattingStrategy
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int? IndentationSize |
|
|
|
|
{ |
|
|
|
|
get { |
|
|
|
|
return indentationSize; |
|
|
|
|
} |
|
|
|
|
set { |
|
|
|
|
indentationSize = value; |
|
|
|
|
OnPropertyChanged(IndentationSizePropertyName); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves the value of "IndentationSize" option by looking at current and (if nothing set here) parent
|
|
|
|
|
/// containers.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int? GetEffectiveIndentationSize() |
|
|
|
|
{ |
|
|
|
|
// Run up the hierarchy until we find a defined value for property
|
|
|
|
|
CSharpFormattingOptionsContainer container = this; |
|
|
|
|
do |
|
|
|
|
{ |
|
|
|
|
int? val = container.indentationSize; |
|
|
|
|
if (val.HasValue) { |
|
|
|
|
return val.Value; |
|
|
|
|
} |
|
|
|
|
container = container.parent; |
|
|
|
|
} while (container != null); |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool? ConvertTabsToSpaces |
|
|
|
|
{ |
|
|
|
|
get { |
|
|
|
|
return convertTabsToSpaces; |
|
|
|
|
} |
|
|
|
|
set { |
|
|
|
|
convertTabsToSpaces = value; |
|
|
|
|
OnPropertyChanged(ConvertTabsToSpacesPropertyName); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves the value of v option by looking at current and (if nothing set here) parent
|
|
|
|
|
/// containers.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool? GetEffectiveConvertTabsToSpaces() |
|
|
|
|
{ |
|
|
|
|
// Run up the hierarchy until we find a defined value for property
|
|
|
|
|
CSharpFormattingOptionsContainer container = this; |
|
|
|
|
do |
|
|
|
|
{ |
|
|
|
|
bool? val = container.convertTabsToSpaces; |
|
|
|
|
if (val.HasValue) { |
|
|
|
|
return val.Value; |
|
|
|
|
} |
|
|
|
|
container = container.parent; |
|
|
|
|
} while (container != null); |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets an option.
|
|
|
|
|
/// </summary>
|
|
|
|
@ -197,18 +282,32 @@ namespace CSharpBinding.FormattingStrategy
@@ -197,18 +282,32 @@ namespace CSharpBinding.FormattingStrategy
|
|
|
|
|
{ |
|
|
|
|
if (value != null) { |
|
|
|
|
// Save value in option values and cached options
|
|
|
|
|
activeOptions.Add(option); |
|
|
|
|
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); |
|
|
|
|
if ((propertyInfo != null) && (propertyInfo.PropertyType == value.GetType())) { |
|
|
|
|
propertyInfo.SetValue(cachedOptions, value); |
|
|
|
|
if (option == IndentationSizePropertyName) { |
|
|
|
|
if (value is int) |
|
|
|
|
indentationSize = (int) value; |
|
|
|
|
} else if (option == ConvertTabsToSpacesPropertyName) { |
|
|
|
|
if (value is bool) |
|
|
|
|
convertTabsToSpaces = (bool) value; |
|
|
|
|
} else { |
|
|
|
|
activeOptions.Add(option); |
|
|
|
|
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); |
|
|
|
|
if ((propertyInfo != null) && (propertyInfo.PropertyType == value.GetType())) { |
|
|
|
|
propertyInfo.SetValue(cachedOptions, value); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// Reset this option
|
|
|
|
|
activeOptions.Remove(option); |
|
|
|
|
// Update formatting options object from parents
|
|
|
|
|
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); |
|
|
|
|
if (propertyInfo != null) { |
|
|
|
|
propertyInfo.SetValue(cachedOptions, GetEffectiveOption(option)); |
|
|
|
|
if (option == IndentationSizePropertyName) { |
|
|
|
|
indentationSize = null; |
|
|
|
|
} else if (option == ConvertTabsToSpacesPropertyName) { |
|
|
|
|
convertTabsToSpaces = null; |
|
|
|
|
} else { |
|
|
|
|
activeOptions.Remove(option); |
|
|
|
|
// Update formatting options object from parents
|
|
|
|
|
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); |
|
|
|
|
if (propertyInfo != null) { |
|
|
|
|
propertyInfo.SetValue(cachedOptions, GetEffectiveOption(option)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
OnPropertyChanged(option); |
|
|
|
@ -221,6 +320,11 @@ namespace CSharpBinding.FormattingStrategy
@@ -221,6 +320,11 @@ namespace CSharpBinding.FormattingStrategy
|
|
|
|
|
/// <returns>Option's type.</returns>
|
|
|
|
|
public Type GetOptionType(string option) |
|
|
|
|
{ |
|
|
|
|
if (option == IndentationSizePropertyName) |
|
|
|
|
return typeof(int); |
|
|
|
|
if (option == ConvertTabsToSpacesPropertyName) |
|
|
|
|
return typeof(bool); |
|
|
|
|
|
|
|
|
|
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); |
|
|
|
|
if (propertyInfo != null) { |
|
|
|
|
return propertyInfo.PropertyType; |
|
|
|
@ -275,6 +379,9 @@ namespace CSharpBinding.FormattingStrategy
@@ -275,6 +379,9 @@ namespace CSharpBinding.FormattingStrategy
|
|
|
|
|
// Silently ignore loading error, then this property will be "as parent" automatically
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
indentationSize = formatProperties.Get(IndentationSizePropertyName, new int?()); |
|
|
|
|
convertTabsToSpaces = formatProperties.Get(ConvertTabsToSpacesPropertyName, new bool?()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -291,8 +398,13 @@ namespace CSharpBinding.FormattingStrategy
@@ -291,8 +398,13 @@ namespace CSharpBinding.FormattingStrategy
|
|
|
|
|
formatProperties.Set(activeOption, val); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (indentationSize.HasValue) |
|
|
|
|
formatProperties.Set(IndentationSizePropertyName, indentationSize.Value); |
|
|
|
|
if (convertTabsToSpaces.HasValue) |
|
|
|
|
formatProperties.Set(ConvertTabsToSpacesPropertyName, convertTabsToSpaces.Value); |
|
|
|
|
|
|
|
|
|
parentProperties.SetNestedProperties("CSharpFormatting", formatProperties); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|