diff --git a/Terminal.Gui/Views/HexView.cs b/Terminal.Gui/Views/HexView.cs index 2a37dbb66..293fd883e 100644 --- a/Terminal.Gui/Views/HexView.cs +++ b/Terminal.Gui/Views/HexView.cs @@ -180,7 +180,7 @@ public class HexView : View, IDesignable set { _bpl = value; - OnPositionChanged (); + RaisePositionChanged (); } } @@ -197,7 +197,7 @@ public class HexView : View, IDesignable set { _pos = value; - OnPositionChanged (); + RaisePositionChanged (); } } @@ -274,6 +274,11 @@ public class HexView : View, IDesignable /// protected internal override bool OnMouseEvent (MouseEvent me) { + if (_source is null) + { + return false; + } + if (!me.Flags.HasFlag (MouseFlags.Button1Clicked) && !me.Flags.HasFlag (MouseFlags.Button1DoubleClicked) && !me.Flags.HasFlag (MouseFlags.WheeledDown) @@ -361,8 +366,13 @@ public class HexView : View, IDesignable /// public override void OnDrawContent (Rectangle viewport) { + if (Source is null) + { + return; + } + Attribute currentAttribute; - Attribute current = ColorScheme.Focus; + Attribute current = GetFocusColor (); Driver.SetAttribute (current); Move (0, 0); @@ -371,8 +381,8 @@ public class HexView : View, IDesignable Source.Position = _displayStart; int n = _source.Read (data, 0, data.Length); - Attribute activeColor = ColorScheme.HotNormal; - Attribute trackingColor = ColorScheme.HotFocus; + Attribute activeColor = GetHotNormalColor (); + Attribute trackingColor = GetHotFocusColor (); for (var line = 0; line < viewport.Height; line++) { @@ -384,10 +394,10 @@ public class HexView : View, IDesignable } Move (0, line); - Driver.SetAttribute (ColorScheme.HotNormal); + currentAttribute = GetHotNormalColor (); + Driver.SetAttribute (currentAttribute); Driver.AddStr ($"{_displayStart + line * nblocks * BSIZE:x8} "); - currentAttribute = ColorScheme.HotNormal; SetAttribute (GetNormalColor ()); for (var block = 0; block < nblocks; block++) @@ -463,15 +473,13 @@ public class HexView : View, IDesignable } } - /// Method used to invoke the event passing the . - /// The key value pair. + /// Raises the event. protected void RaiseEdited (HexViewEditEventArgs e) { - OnEditied(e); + OnEditied (e); Edited?.Invoke (this, e); } - /// Event to be invoked when an edit is made on the . public event EventHandler? Edited; @@ -481,16 +489,23 @@ public class HexView : View, IDesignable /// protected virtual void OnEditied (HexViewEditEventArgs e) { } + /// Raises the event. + protected void RaisePositionChanged () + { + HexViewEventArgs args = new (Position, CursorPosition, BytesPerLine); + OnPositionChanged (args); + PositionChanged?.Invoke (this, args); + } + /// - /// Method used to invoke the event passing the - /// arguments. + /// Called when has changed. /// - public virtual void OnPositionChanged () { PositionChanged?.Invoke (this, new (Position, CursorPosition, BytesPerLine)); } + protected virtual void OnPositionChanged (HexViewEventArgs e) { } /// public override bool OnProcessKeyDown (Key keyEvent) { - if (!AllowEdits) + if (!AllowEdits || _source is null) { return false; }