Skip to content

Commit d9ddc82

Browse files
Fix for reload of comment formatting options not triggering a UI refresh. Use reflection and echo property change notices for all public properties on internal options object.
1 parent 56e9d09 commit d9ddc82

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

CodeMaid/UI/Dialogs/Options/Formatting/FormattingDataTemplate.xaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@
77
<StackPanel>
88
<StackPanel Orientation="Horizontal">
99
<TextBlock Text="Wrap comments at column" VerticalAlignment="Center" />
10-
<TextBox Text="{Binding CommentWrapColumn, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right" Width="40" />
10+
<TextBox Text="{Binding WrapAtColumn, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right" Width="40" />
1111
</StackPanel>
1212

13-
<CheckBox Content="Skip wrapping on the last word" IsChecked="{Binding CommentSkipWrapOnLastWord}" />
13+
<CheckBox Content="Skip wrapping on the last word" IsChecked="{Binding SkipWrapOnLastWord}" />
1414

1515
<StackPanel Orientation="Horizontal">
1616
<TextBlock Text="Extra indent for values inside XML comments" VerticalAlignment="Center" />
17-
<TextBox Text="{Binding CommentXmlValueIndent, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right" Width="40" />
17+
<TextBox Text="{Binding XmlValueIndent, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right" Width="40" />
1818
</StackPanel>
1919

20-
<CheckBox Content="Add spacing around XML tags" IsChecked="{Binding CommentXmlSpaceTags}" />
21-
<CheckBox Content="Add space inside self closing tags" IsChecked="{Binding CommentXmlSpaceSingleTags}" />
22-
<CheckBox Content="Keep XML tags together" IsChecked="{Binding CommentXmlKeepTagsTogether}" />
23-
<CheckBox Content="Align XML &lt;param&gt; tags" IsChecked="{Binding CommentXmlAlignParamTags}" />
24-
<CheckBox Content="Always split &lt;summary&gt; tags onto multiple lines" IsChecked="{Binding CommentXmlSplitSummaryTagToMultipleLines}" />
25-
<CheckBox Content="Always split all XML tags onto multiple lines" IsChecked="{Binding CommentXmlSplitAllTags}" />
26-
20+
<CheckBox Content="Add spacing around XML tags" IsChecked="{Binding XmlSpaceTagContent}" />
21+
<CheckBox Content="Add space inside self closing tags" IsChecked="{Binding XmlSpaceSingleTags}" />
22+
<CheckBox Content="Keep XML tags together" IsChecked="{Binding XmlKeepTagsTogether}" />
23+
<CheckBox Content="Align XML &lt;param&gt; tags" IsChecked="{Binding XmlAlignParamTags}" />
24+
<CheckBox Content="Always split &lt;summary&gt; tags onto multiple lines" IsChecked="{Binding XmlSplitSummaryTag}" />
25+
<CheckBox Content="Always split all XML tags onto multiple lines" IsChecked="{Binding XmlSplitAllTags}" />
2726
</StackPanel>
2827
</GroupBox>
2928

3029
<GroupBox Header="Cleanup">
31-
<CheckBox Content="Run format comments during cleanup" IsChecked="{Binding CommentRunDuringCleanup}" />
30+
<CheckBox Content="Run format comments during cleanup" IsChecked="{Binding FormatDuringCleanup}" />
3231
</GroupBox>
3332

3433
<GroupBox Header="Preview" VerticalAlignment="Stretch">

CodeMaid/UI/Dialogs/Options/Formatting/FormattingViewModel.cs

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public override void LoadSettings()
7272
{
7373
_options = new CodeCommentOptions(Settings.Default, 4);
7474

75+
RaisePropertyChangedForAllOptionsProperties();
7576
UpdatePreviewText();
7677
}
7778

@@ -90,7 +91,7 @@ public override void SaveSettings()
9091
/// <summary>
9192
/// Gets or sets the flag indicating if comment formatting will run during cleanup.
9293
/// </summary>
93-
public bool CommentRunDuringCleanup
94+
public bool FormatDuringCleanup
9495
{
9596
get { return _options.FormatDuringCleanup; }
9697
set
@@ -106,7 +107,7 @@ public bool CommentRunDuringCleanup
106107
/// <summary>
107108
/// Gets or sets the flag indicating if comment formatting should skip wrapping the last word.
108109
/// </summary>
109-
public bool CommentSkipWrapOnLastWord
110+
public bool SkipWrapOnLastWord
110111
{
111112
get { return _options.SkipWrapOnLastWord; }
112113
set
@@ -122,7 +123,7 @@ public bool CommentSkipWrapOnLastWord
122123
/// <summary>
123124
/// Gets or sets the column where comments will attempt to wrap.
124125
/// </summary>
125-
public int CommentWrapColumn
126+
public int WrapAtColumn
126127
{
127128
get { return _options.WrapAtColumn; }
128129
set
@@ -139,7 +140,7 @@ public int CommentWrapColumn
139140
/// <summary>
140141
/// Gets or sets the flag indicating if the content of param tags should be aligned.
141142
/// </summary>
142-
public bool CommentXmlAlignParamTags
143+
public bool XmlAlignParamTags
143144
{
144145
get { return _options.XmlAlignParamTags; }
145146
set
@@ -155,7 +156,7 @@ public bool CommentXmlAlignParamTags
155156
/// <summary>
156157
/// Gets or sets the flag indicating if an extra space should be added inside XML tags.
157158
/// </summary>
158-
public bool CommentXmlSpaceTags
159+
public bool XmlSpaceTagContent
159160
{
160161
get { return _options.XmlSpaceTagContent; }
161162
set
@@ -171,7 +172,7 @@ public bool CommentXmlSpaceTags
171172
/// <summary>
172173
/// Gets or sets the flag indicating if summary tags should always be split to multiple lines.
173174
/// </summary>
174-
public bool CommentXmlSplitSummaryTagToMultipleLines
175+
public bool XmlSplitSummaryTag
175176
{
176177
get { return _options.XmlSplitSummaryTag; }
177178
set
@@ -187,7 +188,7 @@ public bool CommentXmlSplitSummaryTagToMultipleLines
187188
/// <summary>
188189
/// Gets or sets the amount of extra spacing to add before XML values.
189190
/// </summary>
190-
public int CommentXmlValueIndent
191+
public int XmlValueIndent
191192
{
192193
get { return _options.XmlValueIndent; }
193194
set
@@ -201,7 +202,7 @@ public int CommentXmlValueIndent
201202
}
202203
}
203204

204-
public bool CommentXmlTagsToLowerCase
205+
public bool XmlTagsToLowerCase
205206
{
206207
get { return _options.XmlTagsToLowerCase; }
207208
set
@@ -214,7 +215,7 @@ public bool CommentXmlTagsToLowerCase
214215
}
215216
}
216217

217-
public bool CommentXmlSpaceSingleTags
218+
public bool XmlSpaceSingleTags
218219
{
219220
get { return _options.XmlSpaceSingleTags; }
220221
set
@@ -227,7 +228,7 @@ public bool CommentXmlSpaceSingleTags
227228
}
228229
}
229230

230-
public bool CommentXmlKeepTagsTogether
231+
public bool XmlKeepTagsTogether
231232
{
232233
get { return _options.XmlKeepTagsTogether; }
233234
set
@@ -240,7 +241,7 @@ public bool CommentXmlKeepTagsTogether
240241
}
241242
}
242243

243-
public bool CommentXmlSplitAllTags
244+
public bool XmlSplitAllTags
244245
{
245246
get { return _options.XmlSplitAllTags; }
246247
set
@@ -253,6 +254,24 @@ public bool CommentXmlSplitAllTags
253254
}
254255
}
255256

257+
/// <summary>
258+
/// Calls <see cref="Bindable.RaisePropertyChanged"/> for every public property exposed on
259+
/// the <see cref="CodeCommentOptions"/> class. This ensures that changes to that class
260+
/// (which do not raise events) will be bubbled up to the UI correctly.
261+
/// </summary>
262+
/// <remarks>
263+
/// Note: For this to work properly, the wrapping property on this view model must match the
264+
/// name of the underlying property within the options class.
265+
/// </remarks>
266+
private void RaisePropertyChangedForAllOptionsProperties()
267+
{
268+
var optionsProperties = _options.GetType().GetProperties();
269+
foreach (var optionsProperty in optionsProperties)
270+
{
271+
RaisePropertyChanged(optionsProperty.Name);
272+
}
273+
}
274+
256275
#endregion Options
257276

258277
#region Preview Text and Helpers

0 commit comments

Comments
 (0)