diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs
index a8cdb0a57..d1af3392f 100644
--- a/Terminal.Gui/Core/View.cs
+++ b/Terminal.Gui/Core/View.cs
@@ -159,17 +159,6 @@ namespace Terminal.Gui {
///
public Rune HotKeySpecifier { get => viewText.HotKeySpecifier; set => viewText.HotKeySpecifier = value; }
- ///
- /// Clicked , raised when the user clicks the primary mouse button within the Bounds of this
- /// or if the user presses the action key while this view is focused. (TODO: IsDefault)
- ///
- ///
- /// Client code can hook up to this event, it is
- /// raised when the button is activated either with
- /// the mouse or the keyboard.
- ///
- 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 ();
var edges = new HashSet<(View, View)> ();
@@ -1703,7 +1687,6 @@ namespace Terminal.Gui {
SetNeedsDisplay ();
}
- Clicked?.Invoke ();
return true;
}
return false;
diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs
index b5fa6fec4..3aeb0554a 100644
--- a/Terminal.Gui/Views/Button.cs
+++ b/Terminal.Gui/Views/Button.cs
@@ -190,5 +190,44 @@ namespace Terminal.Gui {
}
return base.ProcessKey (kb);
}
+
+
+ ///
+ /// Clicked , raised when the user clicks the primary mouse button within the Bounds of this
+ /// or if the user presses the action key while this view is focused. (TODO: IsDefault)
+ ///
+ ///
+ /// Client code can hook up to this event, it is
+ /// raised when the button is activated either with
+ /// the mouse or the keyboard.
+ ///
+ public Action Clicked;
+
+ ///
+ /// Method invoked when a mouse event is generated
+ ///
+ ///
+ /// true, if the event was handled, false otherwise.
+ 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;
+ }
}
}
diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs
index 117d74f79..cd6c9d1ec 100644
--- a/Terminal.Gui/Views/Label.cs
+++ b/Terminal.Gui/Views/Label.cs
@@ -43,5 +43,43 @@ namespace Terminal.Gui {
public Label (int x, int y, ustring text) : base (x, y, text)
{
}
+
+ ///
+ /// Clicked , raised when the user clicks the primary mouse button within the Bounds of this
+ /// or if the user presses the action key while this view is focused. (TODO: IsDefault)
+ ///
+ ///
+ /// Client code can hook up to this event, it is
+ /// raised when the button is activated either with
+ /// the mouse or the keyboard.
+ ///
+ public Action Clicked;
+
+ ///
+ /// Method invoked when a mouse event is generated
+ ///
+ ///
+ /// true, if the event was handled, false otherwise.
+ 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;
+ }
}
}
diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs
index b0841c53f..32bc6f48d 100644
--- a/UICatalog/Scenarios/AllViewsTester.cs
+++ b/UICatalog/Scenarios/AllViewsTester.cs
@@ -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.Make ("List Item #1"), ustring.Make ("List Item #2"), ustring.Make ("List Item #3")});
view?.GetType ().GetProperty ("Source")?.GetSetMethod ()?.Invoke (view, new [] { source });
}