removed View.Clicked

This commit is contained in:
Charlie Kindel
2020-06-23 07:33:12 -07:00
parent b8d43963cf
commit f41acdf6ba
4 changed files with 82 additions and 21 deletions

View File

@@ -159,17 +159,6 @@ namespace Terminal.Gui {
/// </summary>
public Rune HotKeySpecifier { get => viewText.HotKeySpecifier; set => viewText.HotKeySpecifier = value; }
/// <summary>
/// Clicked <see cref="Action"/>, raised when the user clicks the primary mouse button within the Bounds of this <see cref="View"/>
/// or if the user presses the action key while this view is focused. (TODO: IsDefault)
/// </summary>
/// <remarks>
/// Client code can hook up to this event, it is
/// raised when the button is activated either with
/// the mouse or the keyboard.
/// </remarks>
public Action Clicked;
internal Direction FocusDirection {
get => SuperView?.FocusDirection ?? focusDirection;
set {
@@ -1179,12 +1168,6 @@ namespace Terminal.Gui {
if (Focused?.ProcessKey (keyEvent) == true)
return true;
var c = keyEvent.KeyValue;
if (c == '\n' || c == ' ' || keyEvent.Key == HotKey) {
Clicked?.Invoke ();
return true;
}
return false;
}
@@ -1545,11 +1528,12 @@ namespace Terminal.Gui {
return;
}
viewText.Size = Bounds.Size;
Rect oldBounds = Bounds;
OnLayoutStarted (new LayoutEventArgs () { OldBounds = oldBounds });
viewText.Size = Bounds.Size;
// Sort out the dependencies of the X, Y, Width, Height properties
var nodes = new HashSet<View> ();
var edges = new HashSet<(View, View)> ();
@@ -1703,7 +1687,6 @@ namespace Terminal.Gui {
SetNeedsDisplay ();
}
Clicked?.Invoke ();
return true;
}
return false;

View File

@@ -190,5 +190,44 @@ namespace Terminal.Gui {
}
return base.ProcessKey (kb);
}
/// <summary>
/// Clicked <see cref="Action"/>, raised when the user clicks the primary mouse button within the Bounds of this <see cref="View"/>
/// or if the user presses the action key while this view is focused. (TODO: IsDefault)
/// </summary>
/// <remarks>
/// Client code can hook up to this event, it is
/// raised when the button is activated either with
/// the mouse or the keyboard.
/// </remarks>
public Action Clicked;
/// <summary>
/// Method invoked when a mouse event is generated
/// </summary>
/// <param name="mouseEvent"></param>
/// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
public override bool OnMouseEvent (MouseEvent mouseEvent)
{
MouseEventArgs args = new MouseEventArgs (mouseEvent);
MouseClick?.Invoke (args);
if (args.Handled)
return true;
if (MouseEvent (mouseEvent))
return true;
if (mouseEvent.Flags == MouseFlags.Button1Clicked) {
if (!HasFocus && SuperView != null) {
SuperView.SetFocus (this);
SetNeedsDisplay ();
}
Clicked?.Invoke ();
return true;
}
return false;
}
}
}

View File

@@ -43,5 +43,43 @@ namespace Terminal.Gui {
public Label (int x, int y, ustring text) : base (x, y, text)
{
}
/// <summary>
/// Clicked <see cref="Action"/>, raised when the user clicks the primary mouse button within the Bounds of this <see cref="View"/>
/// or if the user presses the action key while this view is focused. (TODO: IsDefault)
/// </summary>
/// <remarks>
/// Client code can hook up to this event, it is
/// raised when the button is activated either with
/// the mouse or the keyboard.
/// </remarks>
public Action Clicked;
/// <summary>
/// Method invoked when a mouse event is generated
/// </summary>
/// <param name="mouseEvent"></param>
/// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
public override bool OnMouseEvent (MouseEvent mouseEvent)
{
MouseEventArgs args = new MouseEventArgs (mouseEvent);
MouseClick?.Invoke (args);
if (args.Handled)
return true;
if (MouseEvent (mouseEvent))
return true;
if (mouseEvent.Flags == MouseFlags.Button1Clicked) {
if (!HasFocus && SuperView != null) {
SuperView.SetFocus (this);
SetNeedsDisplay ();
}
Clicked?.Invoke ();
return true;
}
return false;
}
}
}

View File

@@ -1,5 +1,6 @@
using NStack;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -367,7 +368,7 @@ namespace UICatalog {
}
// If the view supports a Source property, set it so we have something to look at
if (view != null && view.GetType ().GetProperty ("Source") != null) {
if (view != null && view.GetType ().GetProperty ("Source") != null && view.GetType().GetProperty("Source").PropertyType == typeof(Terminal.Gui.IListDataSource)) {
var source = new ListWrapper (new List<ustring> () { ustring.Make ("List Item #1"), ustring.Make ("List Item #2"), ustring.Make ("List Item #3")});
view?.GetType ().GetProperty ("Source")?.GetSetMethod ()?.Invoke (view, new [] { source });
}