Ver código fonte

Simplified HighlightEventArgs

Tig 1 ano atrás
pai
commit
99948b1486

+ 4 - 4
Terminal.Gui/View/Adornment/Border.cs

@@ -228,7 +228,7 @@ public class Border : Adornment
             return;
         }
 
-        if (e.HighlightStyle.HasFlag (HighlightStyle.Pressed))
+        if (e.NewValue.HasFlag (HighlightStyle.Pressed))
         {
             if (!_savedForeColor.HasValue)
             {
@@ -252,7 +252,7 @@ public class Border : Adornment
         }
 #endif
 
-        if (e.HighlightStyle == HighlightStyle.None && _savedForeColor.HasValue)
+        if (e.NewValue == HighlightStyle.None && _savedForeColor.HasValue)
         {
             ColorScheme cs = new ColorScheme (ColorScheme)
             {
@@ -299,7 +299,7 @@ public class Border : Adornment
                 _startGrabPoint = new (mouseEvent.Position.X + Frame.X, mouseEvent.Position.Y + Frame.Y);
                 _dragPosition = mouseEvent.Position;
                 Application.GrabMouse (this);
-                SetHighlight (HighlightStyle);
+                SetHighlight (new (HighlightStyle, HighlightStyle));
             }
 
             return true;
@@ -343,7 +343,7 @@ public class Border : Adornment
         {
             _dragPosition = null;
             Application.UngrabMouse ();
-            SetHighlight (HighlightStyle.None);
+            SetHighlight (new (HighlightStyle, HighlightStyle.None));
 
             return true;
         }

+ 2 - 2
Terminal.Gui/View/Adornment/Margin.cs

@@ -43,7 +43,7 @@ public class Margin : Adornment
     {
         if (ShadowStyle != Gui.ShadowStyle.None)
         {
-            if (_pressed && e.HighlightStyle == HighlightStyle.None)
+            if (_pressed && e.CurrentValue == HighlightStyle.None)
             {
                 Thickness = new (Thickness.Left - 1, Thickness.Top, Thickness.Right + 1, Thickness.Bottom);
 
@@ -61,7 +61,7 @@ public class Margin : Adornment
                 return;
             }
 
-            if (!_pressed && (e.HighlightStyle.HasFlag (HighlightStyle.Pressed) /*|| e.HighlightStyle.HasFlag (HighlightStyle.PressedOutside)*/))
+            if (!_pressed && (e.CurrentValue.HasFlag (HighlightStyle.Pressed) /*|| e.HighlightStyle.HasFlag (HighlightStyle.PressedOutside)*/))
             {
                 Thickness = new (Thickness.Left + 1, Thickness.Top, Thickness.Right - 1, Thickness.Bottom);
                 _pressed = true;

+ 1 - 1
Terminal.Gui/View/View.cs

@@ -109,7 +109,7 @@ public partial class View : Responder, ISupportInitializeNotification
 {
     /// <summary>
     ///     Cancelable event fired when the <see cref="Command.Accept"/> command is invoked. Set
-    ///     <see cref="HandledEventArgs.Cancel"/>
+    ///     <see cref="HandledEventArgs.Handled"/>
     ///     to cancel the event.
     /// </summary>
     public event EventHandler<HandledEventArgs> Accept;

+ 14 - 26
Terminal.Gui/View/ViewMouse.cs

@@ -34,21 +34,10 @@ public enum HighlightStyle
 /// <summary>
 /// Event arguments for the <see cref="View.Highlight"/> event.
 /// </summary>
-public class HighlightEventArgs : CancelEventArgs
+public class HighlightEventArgs : CancelEventArgs<HighlightStyle>
 {
-    /// <summary>
-    /// Constructs a new instance of <see cref="HighlightEventArgs"/>.
-    /// </summary>
-    /// <param name="style"></param>
-    public HighlightEventArgs (HighlightStyle style)
-    {
-        HighlightStyle = style;
-    }
-
-    /// <summary>
-    /// The highlight style.
-    /// </summary>
-    public HighlightStyle HighlightStyle { get; }
+    /// <inheritdoc />
+    public HighlightEventArgs (HighlightStyle currentValue, HighlightStyle newValue) : base (currentValue, newValue) { }
 }
 
 public partial class View
@@ -170,7 +159,7 @@ public partial class View
             return false;
         }
 
-        if (OnMouseLeave (mouseEvent) == true)      
+        if (OnMouseLeave (mouseEvent) == true)
         {
             return true;
         }
@@ -335,14 +324,15 @@ public partial class View
 
             if (Viewport.Contains (mouseEvent.Position))
             {
-                if (this is not Adornment && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.Pressed) ? HighlightStyle.Pressed : HighlightStyle.None) == true)
+                if (this is not Adornment && SetHighlight (new (HighlightStyle,
+                                                                HighlightStyle.HasFlag (HighlightStyle.Pressed) ? HighlightStyle.Pressed : HighlightStyle.None)) == true)
                 {
                     return true;
                 }
             }
             else
             {
-                if (this is not Adornment && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.PressedOutside) ? HighlightStyle.PressedOutside : HighlightStyle.None) == true)
+                if (this is not Adornment && SetHighlight (new (HighlightStyle, HighlightStyle.HasFlag (HighlightStyle.PressedOutside) ? HighlightStyle.PressedOutside : HighlightStyle.None)) == true)
 
                 {
                     return true;
@@ -379,7 +369,7 @@ public partial class View
         {
             if (Application.MouseGrabView == this)
             {
-                SetHighlight (HighlightStyle.None);
+                SetHighlight (new (HighlightStyle, HighlightStyle.None));
             }
 
             return mouseEvent.Handled = true;
@@ -408,7 +398,7 @@ public partial class View
             // We're grabbed. Clicked event comes after the last Release. This is our signal to ungrab
             Application.UngrabMouse ();
 
-            if (SetHighlight (HighlightStyle.None))
+            if (SetHighlight (new (HighlightStyle, HighlightStyle.None)))
             {
                 return true;
             }
@@ -444,7 +434,7 @@ public partial class View
     /// </remarks>
     /// <returns><see langword="true"/>, if the Highlight event was handled, <see langword="false"/> otherwise.</returns>
 
-    internal bool SetHighlight (HighlightStyle style)
+    internal bool SetHighlight (HighlightEventArgs args)
     {
         // TODO: Make the highlight colors configurable
         if (!CanFocus)
@@ -453,7 +443,7 @@ public partial class View
         }
 
         // Enable override via virtual method and/or event
-        if (OnHighlight (style) == true)
+        if (OnHighlight (args) == true)
         {
             return true;
         }
@@ -475,7 +465,7 @@ public partial class View
             return true;
         }
 #endif 
-        if (style.HasFlag (HighlightStyle.Pressed) || style.HasFlag (HighlightStyle.PressedOutside))
+        if (args.NewValue.HasFlag (HighlightStyle.Pressed) || args.NewValue.HasFlag (HighlightStyle.PressedOutside))
         {
             if (_savedHighlightColorScheme is null && ColorScheme is { })
             {
@@ -505,7 +495,7 @@ public partial class View
         }
 
 
-        if (style == HighlightStyle.None)
+        if (args.NewValue == HighlightStyle.None)
         {
             // Unhighlight
             if (_savedHighlightColorScheme is { })
@@ -528,9 +518,8 @@ public partial class View
     ///     Called when the view is to be highlighted.
     /// </summary>
     /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
-    protected virtual bool? OnHighlight (HighlightStyle highlight)
+    protected virtual bool? OnHighlight (HighlightEventArgs args)
     {
-        HighlightEventArgs args = new (highlight);
         Highlight?.Invoke (this, args);
 
         if (args.Cancel)
@@ -538,7 +527,6 @@ public partial class View
             return true;
         }
 
-        args = new (highlight);
         Margin?.Highlight?.Invoke (this, args);
 
         //args = new (highlight);

+ 3 - 3
Terminal.Gui/Views/ComboBox.cs

@@ -668,13 +668,13 @@ public class ComboBox : View
             return;
         }
 
-        if (string.IsNullOrEmpty (_search.Text) && string.IsNullOrEmpty (e.OldValue))
+        if (string.IsNullOrEmpty (_search.Text) && string.IsNullOrEmpty (e.CurrentValue))
         {
             ResetSearchSet ();
         }
-        else if (_search.Text != e.OldValue)
+        else if (_search.Text != e.CurrentValue)
         {
-            if (_search.Text.Length < e.OldValue.Length)
+            if (_search.Text.Length < e.CurrentValue.Length)
             {
                 _selectedItem = -1;
             }

+ 2 - 2
Terminal.Gui/Views/Shortcut.cs

@@ -297,7 +297,7 @@ public class Shortcut : View
 
     private void Shortcut_Highlight (object sender, HighlightEventArgs e)
     {
-        if (e.HighlightStyle.HasFlag (HighlightStyle.Pressed))
+        if (e.CurrentValue.HasFlag (HighlightStyle.Pressed))
         {
             if (!_savedForeColor.HasValue)
             {
@@ -311,7 +311,7 @@ public class Shortcut : View
             base.ColorScheme = cs;
         }
 
-        if (e.HighlightStyle == HighlightStyle.None && _savedForeColor.HasValue)
+        if (e.CurrentValue == HighlightStyle.None && _savedForeColor.HasValue)
         {
             var cs = new ColorScheme (base.ColorScheme)
             {

+ 3 - 3
UICatalog/Scenarios/ListViewWithSelection.cs

@@ -120,7 +120,7 @@ public class ListViewWithSelection : Scenario
 
     private void _customRenderCB_Toggled (object sender, CancelEventArgs<bool?> stateEventArgs)
     {
-        if (stateEventArgs.OldValue == true)
+        if (stateEventArgs.CurrentValue == true)
         {
             _listView.SetSource (_scenarios);
         }
@@ -134,14 +134,14 @@ public class ListViewWithSelection : Scenario
 
     private void AllowMarkingCB_Toggled (object sender, [NotNull] CancelEventArgs<bool?> stateEventArgs)
     {
-        _listView.AllowsMarking = (bool)!stateEventArgs.OldValue;
+        _listView.AllowsMarking = (bool)!stateEventArgs.CurrentValue;
         _allowMultipleCB.Visible = _listView.AllowsMarking;
         _appWindow.SetNeedsDisplay ();
     }
 
     private void AllowMultipleCB_Toggled (object sender, [NotNull] CancelEventArgs<bool?> stateEventArgs)
     {
-        _listView.AllowsMultipleSelection = (bool)!stateEventArgs.OldValue;
+        _listView.AllowsMultipleSelection = (bool)!stateEventArgs.CurrentValue;
         _appWindow.SetNeedsDisplay ();
     }
 

+ 4 - 4
UICatalog/Scenarios/PosAlignDemo.cs

@@ -274,10 +274,10 @@ public sealed class PosAlignDemo : Scenario
                                               }
 
                                               // Add or remove buttons
-                                              if (e.NewValue < e.OldValue)
+                                              if (e.NewValue < e.CurrentValue)
                                               {
                                                   // Remove buttons
-                                                  for (int i = e.OldValue - 1; i >= e.NewValue; i--)
+                                                  for (int i = e.CurrentValue - 1; i >= e.NewValue; i--)
                                                   {
                                                       Button button = addedViews [i];
                                                       appWindow.Remove (button);
@@ -286,10 +286,10 @@ public sealed class PosAlignDemo : Scenario
                                                   }
                                               }
 
-                                              if (e.NewValue > e.OldValue)
+                                              if (e.NewValue > e.CurrentValue)
                                               {
                                                   // Add buttons
-                                                  for (int i = e.OldValue; i < e.NewValue; i++)
+                                                  for (int i = e.CurrentValue; i < e.NewValue; i++)
                                                   {
                                                       var button = new Button
                                                       {

+ 1 - 1
UICatalog/Scenarios/ProgressBarStyles.cs

@@ -289,7 +289,7 @@ public class ProgressBarStyles : Scenario
         ckbBidirectional.Toggled += (s, e) =>
                                     {
                                         ckbBidirectional.Checked = marqueesBlocksPB.BidirectionalMarquee =
-                                                                       marqueesContinuousPB.BidirectionalMarquee = (bool)!e.OldValue;
+                                                                       marqueesContinuousPB.BidirectionalMarquee = (bool)!e.CurrentValue;
                                     };
 
 

+ 2 - 2
UICatalog/Scenarios/SpinnerStyles.cs

@@ -164,9 +164,9 @@ public class SpinnerViewStyles : Scenario
                                           }
                                       };
 
-        ckbReverse.Toggled += (s, e) => { spinner.SpinReverse = (bool)!e.OldValue; };
+        ckbReverse.Toggled += (s, e) => { spinner.SpinReverse = (bool)!e.CurrentValue; };
 
-        ckbBounce.Toggled += (s, e) => { spinner.SpinBounce = (bool)!e.OldValue; };
+        ckbBounce.Toggled += (s, e) => { spinner.SpinBounce = (bool)!e.CurrentValue; };
 
         app.Unloaded += App_Unloaded;
 

+ 3 - 3
UICatalog/Scenarios/TextAlignmentAndDirection.cs

@@ -484,7 +484,7 @@ public class TextAlignmentAndDirection : Scenario
             Enabled = false
         };
 
-        justifyCheckbox.Toggled += (s, e) => ToggleJustify (e.OldValue is { } && (bool)e.OldValue);
+        justifyCheckbox.Toggled += (s, e) => ToggleJustify (e.CurrentValue is { } && (bool)e.CurrentValue);
 
         justifyOptions.SelectedItemChanged += (s, e) => { ToggleJustify (false, true); };
 
@@ -504,7 +504,7 @@ public class TextAlignmentAndDirection : Scenario
 
         wrapCheckbox.Toggled += (s, e) =>
                                 {
-                                    if (e.OldValue == true)
+                                    if (e.CurrentValue == true)
                                     {
                                         foreach (Label t in multiLineLabels)
                                         {
@@ -536,7 +536,7 @@ public class TextAlignmentAndDirection : Scenario
 
         autoSizeCheckbox.Toggled += (s, e) =>
                                     {
-                                        if (e.OldValue == true)
+                                        if (e.CurrentValue == true)
                                         {
                                             foreach (Label t in multiLineLabels)
                                             {

+ 2 - 2
UICatalog/Scenarios/TextFormatterDemo.cs

@@ -137,8 +137,8 @@ public class TextFormatterDemo : Scenario
                                    {
                                        for (int i = 0; i < alignments.Count; i++)
                                        {
-                                           singleLines [i].Text = e.OldValue == true ? text : unicode;
-                                           multipleLines [i].Text = e.OldValue == true ? text : unicode;
+                                           singleLines [i].Text = e.CurrentValue == true ? text : unicode;
+                                           multipleLines [i].Text = e.CurrentValue == true ? text : unicode;
                                        }
                                    };
 

+ 2 - 2
UnitTests/View/MouseTests.cs

@@ -568,7 +568,7 @@ public class MouseTests (ITestOutputHelper output) : TestsAllViews
 
         void View_Highlight (object sender, HighlightEventArgs e)
         {
-            if (e.HighlightStyle == HighlightStyle.None)
+            if (e.NewValue == HighlightStyle.None)
             {
                 disablingHighlight++;
             }
@@ -637,7 +637,7 @@ public class MouseTests (ITestOutputHelper output) : TestsAllViews
 
         void View_Highlight (object sender, HighlightEventArgs e)
         {
-            if (e.HighlightStyle == HighlightStyle.None)
+            if (e.NewValue == HighlightStyle.None)
             {
                 disablingHighlight++;
             }

+ 2 - 2
UnitTests/View/TitleTests.cs

@@ -16,7 +16,7 @@ public class TitleTests (ITestOutputHelper output)
 
         r.TitleChanged += (s, args) =>
                           {
-                              Assert.Equal (expectedOld, args.OldValue);
+                              Assert.Equal (expectedOld, args.CurrentValue);
                               Assert.Equal (r.Title, args.NewValue);
                           };
 
@@ -40,7 +40,7 @@ public class TitleTests (ITestOutputHelper output)
 
         r.TitleChanging += (s, args) =>
                            {
-                               Assert.Equal (expectedOld, args.OldValue);
+                               Assert.Equal (expectedOld, args.CurrentValue);
                                Assert.Equal (expectedDuring, args.NewValue);
                                args.Cancel = cancel;
                            };

+ 2 - 2
UnitTests/Views/TextFieldTests.cs

@@ -430,7 +430,7 @@ public class TextFieldTests (ITestOutputHelper output)
         var tf = new TextField { Width = 10, Text = "-1" };
 
         tf.TextChanging += (s, e) => newText = e.NewValue;
-        tf.TextChanged += (s, e) => oldText = e.OldValue;
+        tf.TextChanged += (s, e) => oldText = e.CurrentValue;
 
         var top = new Toplevel ();
         top.Add (tf);
@@ -1191,7 +1191,7 @@ public class TextFieldTests (ITestOutputHelper output)
     [TextFieldTestsAutoInitShutdown]
     public void TextChanged_Event ()
     {
-        _textField.TextChanged += (s, e) => { Assert.Equal ("TAB to jump between text fields.", e.OldValue); };
+        _textField.TextChanged += (s, e) => { Assert.Equal ("TAB to jump between text fields.", e.CurrentValue); };
 
         _textField.Text = "changed";
         Assert.Equal ("changed", _textField.Text);