Browse Source

- Fix: Retrieving effective formatting options from parent containers didn't work properly.

- Fix: CSharpFormattingOptionsPersistence didn't load global options from settings.
pull/403/head
Andreas Weizel 12 years ago
parent
commit
96a0466856
  1. 36
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsContainer.cs
  2. 3
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsPersistence.cs

36
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsContainer.cs

@ -44,6 +44,7 @@ namespace CSharpBinding.FormattingStrategy @@ -44,6 +44,7 @@ namespace CSharpBinding.FormattingStrategy
this.parent = parent;
this.activeOptions = new HashSet<string>();
Reset();
cachedOptions = CreateOptions();
}
public CSharpFormattingOptionsContainer Parent
@ -120,33 +121,6 @@ namespace CSharpBinding.FormattingStrategy @@ -120,33 +121,6 @@ namespace CSharpBinding.FormattingStrategy
return null;
}
/// <summary>
/// Retrieves the value of a formatting option where desired type and option name are defined by a
/// property getter on <see cref="ICSharpCode.NRefactory.CSharp.CSharpFormattingOptions"/>.
/// Searches in current and (if nothing set here) parent containers.
/// </summary>
/// <param name="propertyGetter">
/// Property getter lambda expression
/// (example: o =&gt; o.IndentStructBody)
/// </param>
/// <returns>True, if option with given type could be found in hierarchy. False otherwise.</returns>
public T GetEffectiveOption<T>(Expression<Func<CSharpFormattingOptions, T>> propertyGetter)
where T : struct
{
// Get name of property (to look for in dictionary)
string optionName = null;
MemberExpression memberExpression = propertyGetter.Body as MemberExpression;
if (memberExpression != null) {
optionName = memberExpression.Member.Name;
var val = GetEffectiveOption(optionName);
if (val is T) {
return (T) val;
}
}
return default(T);
}
/// <summary>
/// Retrieves the value of a formatting option by looking at current and (if nothing set here) parent
/// containers.
@ -160,9 +134,11 @@ namespace CSharpBinding.FormattingStrategy @@ -160,9 +134,11 @@ namespace CSharpBinding.FormattingStrategy
do
{
object val = null;
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option);
if (propertyInfo != null) {
val = propertyInfo.GetValue(container.cachedOptions);
if (container.activeOptions.Contains(option)) {
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option);
if (propertyInfo != null) {
val = propertyInfo.GetValue(container.cachedOptions);
}
}
if (val != null) {
return val;

3
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsPersistence.cs

@ -39,6 +39,7 @@ namespace CSharpBinding.FormattingStrategy @@ -39,6 +39,7 @@ namespace CSharpBinding.FormattingStrategy
// Load global settings
GlobalOptions = new CSharpFormattingOptionsPersistence(
SD.PropertyService.MainPropertiesContainer, new CSharpFormattingOptionsContainer());
GlobalOptions.Load();
// Handlers for solution loading/unloading
SD.ProjectService.SolutionOpened += SolutionOpened;
@ -66,7 +67,7 @@ namespace CSharpBinding.FormattingStrategy @@ -66,7 +67,7 @@ namespace CSharpBinding.FormattingStrategy
// Lazily create options container
projectOptions[key] = new CSharpFormattingOptionsPersistence(
csproject.ExtensionProperties,
new CSharpFormattingOptionsContainer(SolutionOptions.OptionsContainer));
new CSharpFormattingOptionsContainer((SolutionOptions ?? GlobalOptions).OptionsContainer)); // HACK!
}
return projectOptions[key];

Loading…
Cancel
Save