Fixes #3183 - OnMouseEvent calling OnMouseClick too often (#3184)

* Removed resharper settings from editorconfig

* Fixed bug; updated bad unit tests

* Fixed API doc issue

* Updated nuget
This commit is contained in:
Tig
2024-01-16 06:39:45 -07:00
committed by GitHub
parent 93659510c3
commit a7ea48eb62
8 changed files with 116 additions and 106 deletions

View File

@@ -11,8 +11,8 @@
<InformationalVersion>2.0</InformationalVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ReactiveUI.Fody" Version="19.5.31" />
<PackageReference Include="ReactiveUI" Version="19.5.31" />
<PackageReference Include="ReactiveUI.Fody" Version="19.5.39" />
<PackageReference Include="ReactiveUI" Version="19.5.39" />
<PackageReference Include="ReactiveMarbles.ObservableEvents.SourceGenerator" Version="1.3.1" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>

View File

@@ -40,7 +40,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
<PackageReference Include="System.IO.Abstractions" Version="20.0.4" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.1" />
<PackageReference Include="System.Management" Version="8.0.0" />
<PackageReference Include="Wcwidth" Version="2.0.0" />
<!-- Enable Nuget Source Link for github -->

View File

@@ -1,114 +1,120 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace Terminal.Gui {
public partial class View {
/// <summary>
/// Event fired when the view receives the mouse event for the first time.
/// </summary>
public event EventHandler<MouseEventEventArgs> MouseEnter;
namespace Terminal.Gui;
/// <summary>
/// Event fired when the view receives a mouse event for the last time.
/// </summary>
public event EventHandler<MouseEventEventArgs> MouseLeave;
public partial class View {
/// <summary>
/// Event fired when a mouse event is generated.
/// </summary>
public event EventHandler<MouseEventEventArgs> MouseClick;
/// <summary>
/// Gets or sets a value indicating whether this <see cref="View"/> wants mouse position reports.
/// </summary>
/// <value><see langword="true"/> if want mouse position reports; otherwise, <see langword="false"/>.</value>
public virtual bool WantMousePositionReports { get; set; }
/// <inheritdoc/>
public override bool OnMouseEnter (MouseEvent mouseEvent)
{
if (!Enabled) {
return true;
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="View"/> want continuous button pressed event.
/// </summary>
public virtual bool WantContinuousButtonPressed { get; set; }
if (!CanBeVisible (this)) {
return false;
}
/// <summary>
/// Event fired when the view receives the mouse event for the first time.
/// </summary>
public event EventHandler<MouseEventEventArgs> MouseEnter;
var args = new MouseEventEventArgs (mouseEvent);
MouseEnter?.Invoke (this, args);
/// <summary>
/// Event fired when the view receives a mouse event for the last time.
/// </summary>
public event EventHandler<MouseEventEventArgs> MouseLeave;
return args.Handled || base.OnMouseEnter (mouseEvent);
/// <summary>
/// Event fired when a mouse event is generated.
/// </summary>
public event EventHandler<MouseEventEventArgs> MouseClick;
/// <inheritdoc/>
public override bool OnMouseEnter (MouseEvent mouseEvent)
{
if (!Enabled) {
return true;
}
/// <inheritdoc/>
public override bool OnMouseLeave (MouseEvent mouseEvent)
{
if (!Enabled) {
return true;
}
if (!CanBeVisible (this)) {
return false;
}
var args = new MouseEventEventArgs (mouseEvent);
MouseLeave?.Invoke (this, args);
return args.Handled || base.OnMouseLeave (mouseEvent);
}
/// <summary>
/// Method invoked when a mouse event is generated
/// </summary>
/// <param name="mouseEvent"></param>
/// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
public virtual bool OnMouseEvent (MouseEvent mouseEvent)
{
if (!Enabled) {
return true;
}
if (!CanBeVisible (this)) {
return false;
}
var args = new MouseEventEventArgs (mouseEvent);
if (OnMouseClick (args))
return true;
if (MouseEvent (mouseEvent))
return true;
if (mouseEvent.Flags == MouseFlags.Button1Clicked) {
if (CanFocus && !HasFocus && SuperView != null) {
SuperView.SetFocus (this);
SetNeedsDisplay ();
}
return true;
}
if (!CanBeVisible (this)) {
return false;
}
/// <summary>
/// Invokes the MouseClick event.
/// </summary>
protected bool OnMouseClick (MouseEventEventArgs args)
{
if (!Enabled) {
return true;
}
var args = new MouseEventEventArgs (mouseEvent);
MouseEnter?.Invoke (this, args);
MouseClick?.Invoke (this, args);
return args.Handled;
return args.Handled || base.OnMouseEnter (mouseEvent);
}
/// <inheritdoc/>
public override bool OnMouseLeave (MouseEvent mouseEvent)
{
if (!Enabled) {
return true;
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="View"/> wants mouse position reports.
/// </summary>
/// <value><see langword="true"/> if want mouse position reports; otherwise, <see langword="false"/>.</value>
public virtual bool WantMousePositionReports { get; set; }
if (!CanBeVisible (this)) {
return false;
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="View"/> want continuous button pressed event.
/// </summary>
public virtual bool WantContinuousButtonPressed { get; set; }
var args = new MouseEventEventArgs (mouseEvent);
MouseLeave?.Invoke (this, args);
return args.Handled || base.OnMouseLeave (mouseEvent);
}
}
/// <summary>
/// Method invoked when a mouse event is generated
/// </summary>
/// <param name="mouseEvent"></param>
/// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
public virtual bool OnMouseEvent (MouseEvent mouseEvent)
{
if (!Enabled) {
return true;
}
if (!CanBeVisible (this)) {
return false;
}
var args = new MouseEventEventArgs (mouseEvent);
if (MouseEvent (mouseEvent)) {
return true;
}
if (mouseEvent.Flags == MouseFlags.Button1Clicked) {
if (CanFocus && !HasFocus && SuperView != null) {
SuperView.SetFocus (this);
SetNeedsDisplay ();
}
return OnMouseClick (args);
}
if (mouseEvent.Flags == MouseFlags.Button2Clicked) {
return OnMouseClick (args);
}
if (mouseEvent.Flags == MouseFlags.Button3Clicked) {
return OnMouseClick (args);
}
if (mouseEvent.Flags == MouseFlags.Button4Clicked) {
return OnMouseClick (args);
}
return false;
}
/// <summary>
/// Invokes the MouseClick event.
/// </summary>
protected bool OnMouseClick (MouseEventEventArgs args)
{
if (!Enabled) {
return true;
}
MouseClick?.Invoke (this, args);
return args.Handled;
}
}

View File

@@ -7,7 +7,7 @@ namespace Terminal.Gui;
/// <summary>
/// The <see cref="Dialog"/> <see cref="View"/> is a <see cref="Window"/> that by default is centered and contains one
/// or more <see cref="Button"/>s. It defaults to the <see cref="Colors.ColorSchemes ["Dialog"]"/> color scheme and has a 1 cell padding around the edges.
/// or more <see cref="Button"/>s. It defaults to the <c>Colors.ColorSchemes ["Dialog"]</c> color scheme and has a 1 cell padding around the edges.
/// </summary>
/// <remarks>
/// To run the <see cref="Dialog"/> modally, create the <see cref="Dialog"/>, and pass it to <see cref="Application.Run(Func{Exception, bool})"/>.

View File

@@ -28,8 +28,8 @@
<None Update="./Scenarios/Spinning_globe_dark_small.gif" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />

View File

@@ -102,7 +102,7 @@ public class MouseTests {
var mouseEvent = new MouseEvent () {
X = clickX,
Y = clickY,
Flags = MouseFlags.Button1Pressed
Flags = MouseFlags.Button1Clicked
};
var mouseEventArgs = new MouseEventEventArgs (mouseEvent);
@@ -194,7 +194,7 @@ public class MouseTests {
var mouseEvent = new MouseEvent () {
X = clickX,
Y = clickY,
Flags = MouseFlags.Button1Pressed
Flags = MouseFlags.Button1Clicked
};
var mouseEventArgs = new MouseEventEventArgs (mouseEvent);

View File

@@ -25,7 +25,7 @@
<PackageReference Include="ReportGenerator" Version="5.2.0" />
<PackageReference Include="System.Collections" Version="4.3.0" />
<PackageReference Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="20.0.4" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@@ -1307,8 +1307,12 @@ public class TextFieldTests {
View = tf
};
// In #3183 OnMouseClicked is no longer called before MouseEvent().
// This call causes the context menu to pop, and MouseEvent() returns true.
// Thus, the clickCounter is NOT incremented.
// Which is correct, because the user did NOT click with the left mouse button.
Application.OnMouseEvent (new MouseEventEventArgs (mouseEvent));
Assert.Equal (2, clickCounter);
Assert.Equal (1, clickCounter);
}
private void SuppressKey (object s, Key arg)