Browse Source

Fixed some issues with formatting options becoming "dirty" unnecessarily.

pull/487/head
Andreas Weizel 11 years ago
parent
commit
86150a45d6
  1. 22
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsContainer.cs
  2. 10
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/CSharpFormattingOptionPanel.xaml.cs

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

@ -127,7 +127,7 @@ 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();
OnPropertyChanged(e.PropertyName); // OnPropertyChanged(e.PropertyName);
} 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)) {
@ -136,7 +136,7 @@ namespace CSharpBinding.FormattingStrategy
if (propertyInfo != null) { if (propertyInfo != null) {
var val = GetEffectiveOption(e.PropertyName); var val = GetEffectiveOption(e.PropertyName);
propertyInfo.SetValue(cachedOptions, val); propertyInfo.SetValue(cachedOptions, val);
OnPropertyChanged(e.PropertyName); // OnPropertyChanged(e.PropertyName);
} }
} }
} }
@ -265,14 +265,16 @@ namespace CSharpBinding.FormattingStrategy
if (parentProperties == null) if (parentProperties == null)
throw new ArgumentNullException("parentProperties"); throw new ArgumentNullException("parentProperties");
Properties formatProperties = parentProperties.NestedProperties("CSharpFormatting"); if (parentProperties.Contains("CSharpFormatting")) {
if (formatProperties != null) { Properties formatProperties = parentProperties.NestedProperties("CSharpFormatting");
foreach (var key in formatProperties.Keys) { if (formatProperties != null) {
try { foreach (var key in formatProperties.Keys) {
object val = formatProperties.Get(key, (object) null); try {
SetOption(key, val); object val = formatProperties.Get(key, (object)null);
} catch (Exception) { SetOption(key, val);
// Silently ignore loading error, then this property will be "as parent" automatically } catch (Exception) {
// Silently ignore loading error, then this property will be "as parent" automatically
}
} }
} }
} }

10
src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/CSharpFormattingOptionPanel.xaml.cs

@ -64,6 +64,7 @@ namespace CSharpBinding.OptionPanels
internal partial class CSharpFormattingOptionPanel : OptionPanel internal partial class CSharpFormattingOptionPanel : OptionPanel
{ {
readonly CSharpFormattingOptionsPersistence persistenceHelper; readonly CSharpFormattingOptionsPersistence persistenceHelper;
bool isDirty;
public CSharpFormattingOptionPanel(CSharpFormattingOptionsPersistence persistenceHelper, bool allowPresets) public CSharpFormattingOptionPanel(CSharpFormattingOptionsPersistence persistenceHelper, bool allowPresets)
{ {
@ -71,6 +72,7 @@ namespace CSharpBinding.OptionPanels
throw new ArgumentNullException("persistenceHelper"); throw new ArgumentNullException("persistenceHelper");
this.persistenceHelper = persistenceHelper; this.persistenceHelper = persistenceHelper;
this.isDirty = false;
InitializeComponent(); InitializeComponent();
formattingEditor.AllowPresets = allowPresets; formattingEditor.AllowPresets = allowPresets;
@ -80,11 +82,17 @@ namespace CSharpBinding.OptionPanels
{ {
base.LoadOptions(); base.LoadOptions();
formattingEditor.OptionsContainer = persistenceHelper.StartEditing(); formattingEditor.OptionsContainer = persistenceHelper.StartEditing();
formattingEditor.OptionsContainer.PropertyChanged += (sender, e) => isDirty = true;
} }
public override bool SaveOptions() public override bool SaveOptions()
{ {
return persistenceHelper.Save() && base.SaveOptions(); if (isDirty) {
return persistenceHelper.Save() && base.SaveOptions();
} else {
// Nothing has been changed here, return without action
return true;
}
} }
} }
} }
Loading…
Cancel
Save