Skip to content

Commit

Permalink
Don't raise stylechanged events when setting style
Browse files Browse the repository at this point in the history
The style changed events are only supposed to be raised when a style
is changed via the user interface. When this happens programmatically,
this can result in incorrect states.
  • Loading branch information
ThoNohT committed Nov 11, 2016
1 parent 6eff7e9 commit 90e9439
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
1 change: 0 additions & 1 deletion NohBoard/Controls/FontChooser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public FontChooser()
get { return this.font; }
set
{
Console.WriteLine($"Font changed to {value.Name}");
this.font = value;
this.DisplayLabel.Font = value;
this.Refresh();
Expand Down
19 changes: 14 additions & 5 deletions NohBoard/Controls/KeySubStylePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ namespace ThoNohT.NohBoard.Controls
/// </summary>
public partial class KeySubStylePanel : UserControl
{
/// <summary>
/// Indicates whether the style is being programatically set, this should not raise events.
/// </summary>
private bool setting;

#region Events

/// <summary>
Expand Down Expand Up @@ -79,6 +84,8 @@ public KeySubStyle SubStyle
}
set
{
this.setting = true;

this.clrBackground.Color = value.Background;
this.txtBackgoundImage.Text = value.BackgroundImageFileName.SanitizeFilename();

Expand All @@ -88,6 +95,8 @@ public KeySubStyle SubStyle
this.clrOutline.Color = value.Outline;
this.chkShowOutline.Checked = value.ShowOutline;
this.udOutlineWidth.Value = value.OutlineWidth;

this.setting = false;
}
}

Expand All @@ -109,39 +118,39 @@ public string Title
/// </summary>
private void clr_ColorChanged(ColorChooser sender, System.Drawing.Color color)
{
this.StyleChanged?.Invoke(this.SubStyle);
if (!this.setting) this.StyleChanged?.Invoke(this.SubStyle);
}

/// <summary>
/// Handles the font changed event of the text font chooser.
/// </summary>
private void fntText_FontChanged(FontChooser sender, System.Drawing.Font font)
{
this.StyleChanged?.Invoke(this.SubStyle);
if (!this.setting) this.StyleChanged?.Invoke(this.SubStyle);
}

/// <summary>
/// Handles the checked changed event of the show outline checkbox.
/// </summary>
private void chkShowOutline_CheckedChanged(object sender, System.EventArgs e)
{
this.StyleChanged?.Invoke(this.SubStyle);
if (!this.setting) this.StyleChanged?.Invoke(this.SubStyle);
}

/// <summary>
/// Handles the value changed event of the outline width updown.
/// </summary>
private void udOutlineWidth_ValueChanged(object sender, System.EventArgs e)
{
this.StyleChanged?.Invoke(this.SubStyle);
if (!this.setting) this.StyleChanged?.Invoke(this.SubStyle);
}

/// <summary>
/// Handles the text changed event of the background image textbox.
/// </summary>
private void txtBackgoundImage_TextChanged(object sender, System.EventArgs e)
{
this.StyleChanged?.Invoke(this.SubStyle);
if (!this.setting) this.StyleChanged?.Invoke(this.SubStyle);
}

#endregion Control event handlers
Expand Down
13 changes: 11 additions & 2 deletions NohBoard/Controls/MouseSpeedStylePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ namespace ThoNohT.NohBoard.Controls
/// </summary>
public partial class MouseSpeedStylePanel : UserControl
{
/// <summary>
/// Indicates whether the style is currently being programmatically set, this should not raise events.
/// </summary>
private bool setting;

#region Events

/// <summary>
Expand Down Expand Up @@ -73,9 +78,13 @@ public MouseSpeedIndicatorStyle IndicatorStyle
}
set
{
this.setting = true;

this.clrInner.Color = value.InnerColor;
this.clrOuter.Color = value.OuterColor;
this.udOutlineWidth.Value = value.OutlineWidth;

this.setting = false;
}
}

Expand All @@ -97,15 +106,15 @@ public string Title
/// </summary>
private void clr_ColorChanged(ColorChooser sender, System.Drawing.Color color)
{
this.IndicatorStyleChanged?.Invoke(this.IndicatorStyle);
if (!this.setting) this.IndicatorStyleChanged?.Invoke(this.IndicatorStyle);
}

/// <summary>
/// Handles the value changed event of the outline width updown.
/// </summary>
private void udOutlineWidth_ValueChanged(object sender, System.EventArgs e)
{
this.IndicatorStyleChanged?.Invoke(this.IndicatorStyle);
if (!this.setting) this.IndicatorStyleChanged?.Invoke(this.IndicatorStyle);
}

#endregion Methods
Expand Down

0 comments on commit 90e9439

Please sign in to comment.