Ver código fonte

fixed OnMouseClick logic

Tig 1 ano atrás
pai
commit
ca7b8bb0ee

+ 8 - 3
Terminal.Gui/View/ViewMouse.cs

@@ -120,7 +120,7 @@ public partial class View
             || mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)
             || mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked))
         {
-            return OnMouseClick (args);
+            OnMouseClick (args);
         }
 
         if (mouseEvent.Flags.HasFlag (MouseFlags.Button1DoubleClicked)
@@ -128,10 +128,13 @@ public partial class View
             || mouseEvent.Flags.HasFlag (MouseFlags.Button3DoubleClicked)
             || mouseEvent.Flags.HasFlag (MouseFlags.Button4DoubleClicked))
         {
-            return OnMouseClick (args);
+            OnMouseClick (args);
         }
 
-        MouseEvent?.Invoke (this, args);
+        if (args.Handled != true)
+        {
+            MouseEvent?.Invoke (this, args);
+        }
 
         return args.Handled == true;
     }
@@ -147,6 +150,7 @@ public partial class View
     {
         if (!Enabled)
         {
+            args.Handled = true;
             return true;
         }
 
@@ -158,6 +162,7 @@ public partial class View
 
         if (!HasFocus && CanFocus)
         {
+            args.Handled = true;
             SetFocus ();
         }
 

+ 10 - 0
Terminal.Gui/Views/Button.cs

@@ -67,6 +67,16 @@ public class Button : View
 
     private void Button_MouseEvent (object sender, MouseEventEventArgs e)
     {
+        if (e.MouseEvent.Flags.HasFlag(MouseFlags.Button1Clicked))
+        {
+            if (Application.MouseGrabView != this)
+            {
+                e.Handled = InvokeCommand (Command.HotKey) == true;
+
+                return;
+            }
+        }
+
         if (e.MouseEvent.Flags == MouseFlags.Button1Pressed)
         {
             if (Application.MouseGrabView == this)

+ 1 - 0
UnitTests/TestHelpers.cs

@@ -74,6 +74,7 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute
 
         if (AutoInit)
         {
+            // TODO: This Dispose call is here until all unit tests that don't correctly dispose Toplevel's they create are fixed.
             Application.Top?.Dispose ();
             Application.Shutdown ();
 #if DEBUG_IDISPOSABLE