|
|
@ -34,8 +34,13 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
internal class CSharpFormattingOptionsContainer : INotifyPropertyChanged |
|
|
|
internal class CSharpFormattingOptionsContainer : INotifyPropertyChanged |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
private const string IndentationSizePropertyName = "IndentationSize"; |
|
|
|
|
|
|
|
private const string ConvertTabsToSpacesPropertyName = "ConvertTabsToSpaces"; |
|
|
|
|
|
|
|
|
|
|
|
CSharpFormattingOptionsContainer parent; |
|
|
|
CSharpFormattingOptionsContainer parent; |
|
|
|
CSharpFormattingOptions cachedOptions; |
|
|
|
CSharpFormattingOptions cachedOptions; |
|
|
|
|
|
|
|
int? indentationSize; |
|
|
|
|
|
|
|
bool? convertTabsToSpaces; |
|
|
|
|
|
|
|
|
|
|
|
readonly HashSet<string> activeOptions; |
|
|
|
readonly HashSet<string> activeOptions; |
|
|
|
|
|
|
|
|
|
|
@ -106,6 +111,8 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
foreach (var activeOption in options.activeOptions) |
|
|
|
foreach (var activeOption in options.activeOptions) |
|
|
|
activeOptions.Add(activeOption); |
|
|
|
activeOptions.Add(activeOption); |
|
|
|
cachedOptions = options.cachedOptions.Clone(); |
|
|
|
cachedOptions = options.cachedOptions.Clone(); |
|
|
|
|
|
|
|
indentationSize = options.indentationSize; |
|
|
|
|
|
|
|
convertTabsToSpaces = options.convertTabsToSpaces; |
|
|
|
OnPropertyChanged(null); |
|
|
|
OnPropertyChanged(null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -127,6 +134,14 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
if ((e.PropertyName == "Parent") || (e.PropertyName == null)) { |
|
|
|
if ((e.PropertyName == "Parent") || (e.PropertyName == null)) { |
|
|
|
// All properties might have changed -> update everything
|
|
|
|
// All properties might have changed -> update everything
|
|
|
|
cachedOptions = CreateCachedOptions(); |
|
|
|
cachedOptions = CreateCachedOptions(); |
|
|
|
|
|
|
|
} else if (e.PropertyName == IndentationSizePropertyName) { |
|
|
|
|
|
|
|
if (!indentationSize.HasValue) { |
|
|
|
|
|
|
|
indentationSize = GetEffectiveIndentationSize(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (e.PropertyName == ConvertTabsToSpacesPropertyName) { |
|
|
|
|
|
|
|
if (!convertTabsToSpaces.HasValue) { |
|
|
|
|
|
|
|
convertTabsToSpaces = GetEffectiveConvertTabsToSpaces(); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Some other property has changed, check if we have our own value for it
|
|
|
|
// Some other property has changed, check if we have our own value for it
|
|
|
|
if (!activeOptions.Contains(e.PropertyName)) { |
|
|
|
if (!activeOptions.Contains(e.PropertyName)) { |
|
|
@ -148,10 +163,18 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
public object GetOption(string option) |
|
|
|
public object GetOption(string option) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Run up the hierarchy until we find a defined value for property
|
|
|
|
// Run up the hierarchy until we find a defined value for property
|
|
|
|
if (activeOptions.Contains(option)) { |
|
|
|
if (option == IndentationSizePropertyName) { |
|
|
|
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); |
|
|
|
if (indentationSize.HasValue) |
|
|
|
if (propertyInfo != null) { |
|
|
|
return indentationSize.Value; |
|
|
|
return propertyInfo.GetValue(cachedOptions); |
|
|
|
} 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); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -186,6 +209,68 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
return null; |
|
|
|
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>
|
|
|
|
/// <summary>
|
|
|
|
/// Sets an option.
|
|
|
|
/// Sets an option.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -195,18 +280,32 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
// Save value in option values and cached options
|
|
|
|
// Save value in option values and cached options
|
|
|
|
activeOptions.Add(option); |
|
|
|
if (option == IndentationSizePropertyName) { |
|
|
|
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); |
|
|
|
if (value is int) |
|
|
|
if ((propertyInfo != null) && (propertyInfo.PropertyType == value.GetType())) { |
|
|
|
indentationSize = (int) value; |
|
|
|
propertyInfo.SetValue(cachedOptions, 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 { |
|
|
|
} else { |
|
|
|
// Reset this option
|
|
|
|
// Reset this option
|
|
|
|
activeOptions.Remove(option); |
|
|
|
if (option == IndentationSizePropertyName) { |
|
|
|
// Update formatting options object from parents
|
|
|
|
indentationSize = null; |
|
|
|
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); |
|
|
|
} else if (option == ConvertTabsToSpacesPropertyName) { |
|
|
|
if (propertyInfo != null) { |
|
|
|
convertTabsToSpaces = null; |
|
|
|
propertyInfo.SetValue(cachedOptions, GetEffectiveOption(option)); |
|
|
|
} 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); |
|
|
|
OnPropertyChanged(option); |
|
|
@ -219,6 +318,11 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
/// <returns>Option's type.</returns>
|
|
|
|
/// <returns>Option's type.</returns>
|
|
|
|
public Type GetOptionType(string option) |
|
|
|
public Type GetOptionType(string option) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (option == IndentationSizePropertyName) |
|
|
|
|
|
|
|
return typeof(int); |
|
|
|
|
|
|
|
if (option == ConvertTabsToSpacesPropertyName) |
|
|
|
|
|
|
|
return typeof(bool); |
|
|
|
|
|
|
|
|
|
|
|
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); |
|
|
|
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); |
|
|
|
if (propertyInfo != null) { |
|
|
|
if (propertyInfo != null) { |
|
|
|
return propertyInfo.PropertyType; |
|
|
|
return propertyInfo.PropertyType; |
|
|
@ -258,6 +362,19 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
return outputOptions; |
|
|
|
return outputOptions; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void CustomizeEditorOptions(TextEditorOptions editorOptions) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int? indentationSize = GetEffectiveIndentationSize(); |
|
|
|
|
|
|
|
if (indentationSize.HasValue) { |
|
|
|
|
|
|
|
editorOptions.IndentSize = indentationSize.Value; |
|
|
|
|
|
|
|
editorOptions.TabSize = indentationSize.Value; |
|
|
|
|
|
|
|
editorOptions.ContinuationIndent = indentationSize.Value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bool? convertTabsToSpaces = GetEffectiveConvertTabsToSpaces(); |
|
|
|
|
|
|
|
if (convertTabsToSpaces.HasValue) |
|
|
|
|
|
|
|
editorOptions.TabsToSpaces = convertTabsToSpaces.Value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Load(Properties parentProperties) |
|
|
|
public void Load(Properties parentProperties) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (parentProperties == null) |
|
|
|
if (parentProperties == null) |
|
|
@ -275,6 +392,9 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
indentationSize = formatProperties.Get(IndentationSizePropertyName, new int?()); |
|
|
|
|
|
|
|
convertTabsToSpaces = formatProperties.Get(ConvertTabsToSpacesPropertyName, new bool?()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -291,6 +411,10 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
formatProperties.Set(activeOption, val); |
|
|
|
formatProperties.Set(activeOption, val); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (indentationSize.HasValue) |
|
|
|
|
|
|
|
formatProperties.Set(IndentationSizePropertyName, indentationSize.Value); |
|
|
|
|
|
|
|
if (convertTabsToSpaces.HasValue) |
|
|
|
|
|
|
|
formatProperties.Set(ConvertTabsToSpacesPropertyName, convertTabsToSpaces.Value); |
|
|
|
|
|
|
|
|
|
|
|
parentProperties.SetNestedProperties("CSharpFormatting", formatProperties); |
|
|
|
parentProperties.SetNestedProperties("CSharpFormatting", formatProperties); |
|
|
|
} |
|
|
|
} |
|
|
|