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. 40
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsContainer.cs
  2. 3
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsPersistence.cs

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

@ -44,6 +44,7 @@ namespace CSharpBinding.FormattingStrategy
this.parent = parent; this.parent = parent;
this.activeOptions = new HashSet<string>(); this.activeOptions = new HashSet<string>();
Reset(); Reset();
cachedOptions = CreateOptions();
} }
public CSharpFormattingOptionsContainer Parent public CSharpFormattingOptionsContainer Parent
@ -81,7 +82,7 @@ namespace CSharpBinding.FormattingStrategy
PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
} }
} }
#endregion #endregion
private void HandlePropertyChanged(object sender, PropertyChangedEventArgs e) private void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
@ -120,33 +121,6 @@ namespace CSharpBinding.FormattingStrategy
return null; 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> /// <summary>
/// Retrieves the value of a formatting option by looking at current and (if nothing set here) parent /// Retrieves the value of a formatting option by looking at current and (if nothing set here) parent
/// containers. /// containers.
@ -160,9 +134,11 @@ namespace CSharpBinding.FormattingStrategy
do do
{ {
object val = null; object val = null;
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option); if (container.activeOptions.Contains(option)) {
if (propertyInfo != null) { PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option);
val = propertyInfo.GetValue(container.cachedOptions); if (propertyInfo != null) {
val = propertyInfo.GetValue(container.cachedOptions);
}
} }
if (val != null) { if (val != null) {
return val; return val;
@ -241,7 +217,7 @@ namespace CSharpBinding.FormattingStrategy
propertyInfo.SetValue(outputOptions, val); propertyInfo.SetValue(outputOptions, val);
} }
} }
return outputOptions; return outputOptions;
} }

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

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

Loading…
Cancel
Save