From bc52a0b8fec3aa36eb897a1e230322e791916a87 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 22 Feb 2013 18:16:49 +0100 Subject: [PATCH] Add Freeze() method to HighlightingColor. --- .../Highlighting/HighlightingColor.cs | 77 +++++++++++++++++-- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs index ec8fc39670..66cbb2869c 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs @@ -17,30 +17,82 @@ namespace ICSharpCode.AvalonEdit.Highlighting [Serializable] public class HighlightingColor : ISerializable { + string name; + FontWeight? fontWeight; + FontStyle? fontStyle; + HighlightingBrush foreground; + HighlightingBrush background; + bool frozen; + /// /// Gets/Sets the name of the color. /// - public string Name { get; set; } + public string Name { + get { + return name; + } + set { + if (frozen) + throw new InvalidOperationException(); + name = value; + } + } /// /// Gets/sets the font weight. Null if the highlighting color does not change the font weight. /// - public FontWeight? FontWeight { get; set; } + public FontWeight? FontWeight { + get { + return fontWeight; + } + set { + if (frozen) + throw new InvalidOperationException(); + fontWeight = value; + } + } /// /// Gets/sets the font style. Null if the highlighting color does not change the font style. /// - public FontStyle? FontStyle { get; set; } + public FontStyle? FontStyle { + get { + return fontStyle; + } + set { + if (frozen) + throw new InvalidOperationException(); + fontStyle = value; + } + } /// /// Gets/sets the foreground color applied by the highlighting. /// - public HighlightingBrush Foreground { get; set; } + public HighlightingBrush Foreground { + get { + return foreground; + } + set { + if (frozen) + throw new InvalidOperationException(); + foreground = value; + } + } /// /// Gets/sets the background color applied by the highlighting. /// - public HighlightingBrush Background { get; set; } + public HighlightingBrush Background { + get { + return background; + } + set { + if (frozen) + throw new InvalidOperationException(); + background = value; + } + } /// /// Creates a new HighlightingColor instance. @@ -119,5 +171,20 @@ namespace ICSharpCode.AvalonEdit.Highlighting { return "[" + GetType().Name + " " + (string.IsNullOrEmpty(this.Name) ? ToCss() : this.Name) + "]"; } + + /// + /// Prevent further changes to this highlighting color. + /// + public void Freeze() + { + frozen = true; + } + + /// + /// Gets whether this HighlightingColor instance is frozen. + /// + public bool IsFrozen { + get { return frozen; } + } } }