Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 86150a4

Browse files
committed
Fixed some issues with formatting options becoming "dirty" unnecessarily.
1 parent 9ea1ae2 commit 86150a4

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
127127
if ((e.PropertyName == "Parent") || (e.PropertyName == null)) {
128128
// All properties might have changed -> update everything
129129
cachedOptions = CreateCachedOptions();
130-
OnPropertyChanged(e.PropertyName);
130+
// OnPropertyChanged(e.PropertyName);
131131
} else {
132132
// Some other property has changed, check if we have our own value for it
133133
if (!activeOptions.Contains(e.PropertyName)) {
@@ -136,7 +136,7 @@ private void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
136136
if (propertyInfo != null) {
137137
var val = GetEffectiveOption(e.PropertyName);
138138
propertyInfo.SetValue(cachedOptions, val);
139-
OnPropertyChanged(e.PropertyName);
139+
// OnPropertyChanged(e.PropertyName);
140140
}
141141
}
142142
}
@@ -265,14 +265,16 @@ public void Load(Properties parentProperties)
265265
if (parentProperties == null)
266266
throw new ArgumentNullException("parentProperties");
267267

268-
Properties formatProperties = parentProperties.NestedProperties("CSharpFormatting");
269-
if (formatProperties != null) {
270-
foreach (var key in formatProperties.Keys) {
271-
try {
272-
object val = formatProperties.Get(key, (object) null);
273-
SetOption(key, val);
274-
} catch (Exception) {
275-
// Silently ignore loading error, then this property will be "as parent" automatically
268+
if (parentProperties.Contains("CSharpFormatting")) {
269+
Properties formatProperties = parentProperties.NestedProperties("CSharpFormatting");
270+
if (formatProperties != null) {
271+
foreach (var key in formatProperties.Keys) {
272+
try {
273+
object val = formatProperties.Get(key, (object)null);
274+
SetOption(key, val);
275+
} catch (Exception) {
276+
// Silently ignore loading error, then this property will be "as parent" automatically
277+
}
276278
}
277279
}
278280
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ public CSharpSolutionFormattingOptionPanel()
6464
internal partial class CSharpFormattingOptionPanel : OptionPanel
6565
{
6666
readonly CSharpFormattingOptionsPersistence persistenceHelper;
67+
bool isDirty;
6768

6869
public CSharpFormattingOptionPanel(CSharpFormattingOptionsPersistence persistenceHelper, bool allowPresets)
6970
{
7071
if (persistenceHelper == null)
7172
throw new ArgumentNullException("persistenceHelper");
7273

7374
this.persistenceHelper = persistenceHelper;
75+
this.isDirty = false;
7476
InitializeComponent();
7577

7678
formattingEditor.AllowPresets = allowPresets;
@@ -79,12 +81,18 @@ public CSharpFormattingOptionPanel(CSharpFormattingOptionsPersistence persistenc
7981
public override void LoadOptions()
8082
{
8183
base.LoadOptions();
82-
formattingEditor.OptionsContainer = persistenceHelper.StartEditing();
84+
formattingEditor.OptionsContainer = persistenceHelper.StartEditing();
85+
formattingEditor.OptionsContainer.PropertyChanged += (sender, e) => isDirty = true;
8386
}
8487

8588
public override bool SaveOptions()
8689
{
87-
return persistenceHelper.Save() && base.SaveOptions();
90+
if (isDirty) {
91+
return persistenceHelper.Save() && base.SaveOptions();
92+
} else {
93+
// Nothing has been changed here, return without action
94+
return true;
95+
}
8896
}
8997
}
9098
}

0 commit comments

Comments
 (0)