diff --git a/Example/Example.cs b/Example/Example.cs
index 45954362ec..08b420e45d 100644
--- a/Example/Example.cs
+++ b/Example/Example.cs
@@ -57,7 +57,7 @@ public ExampleWindow ()
};
// When login button is clicked display a message popup
- btnLogin.Clicked += () => {
+ btnLogin.Clicked += (s,e) => {
if (usernameText.Text == "admin" && passwordText.Text == "password") {
MessageBox.Query ("Logging In", "Login Successful", "Ok");
Application.RequestStop ();
diff --git a/README.md b/README.md
index 6c7225d0f8..4b7eb78d8e 100644
--- a/README.md
+++ b/README.md
@@ -121,7 +121,7 @@ public class ExampleWindow : Window {
};
// When login button is clicked display a message popup
- btnLogin.Clicked += () => {
+ btnLogin.Clicked += (s,e) => {
if (usernameText.Text == "admin" && passwordText.Text == "password") {
MessageBox.Query ("Logging In", "Login Successful", "Ok");
Application.RequestStop ();
diff --git a/Terminal.Gui/Configuration/ConfigurationManager.cs b/Terminal.Gui/Configuration/ConfigurationManager.cs
index fac2fa85bb..6048294dd7 100644
--- a/Terminal.Gui/Configuration/ConfigurationManager.cs
+++ b/Terminal.Gui/Configuration/ConfigurationManager.cs
@@ -301,19 +301,6 @@ internal static Stream ToStream ()
return stream;
}
- ///
- /// Event arguments for the events.
- ///
- public class ConfigurationManagerEventArgs : EventArgs {
-
- ///
- /// Initializes a new instance of
- ///
- public ConfigurationManagerEventArgs ()
- {
- }
- }
-
///
/// Gets or sets whether the should throw an exception if it encounters
/// an error on deserialization. If (the default), the error is logged and printed to the
@@ -353,14 +340,14 @@ private static void ClearJsonErrors ()
public static void OnUpdated ()
{
Debug.WriteLine ($"ConfigurationManager.OnApplied()");
- Updated?.Invoke (new ConfigurationManagerEventArgs ());
+ Updated?.Invoke (null, new ConfigurationManagerEventArgs ());
}
///
/// Event fired when the configuration has been updated from a configuration source.
/// application.
///
- public static event Action? Updated;
+ public static event EventHandler? Updated;
///
/// Resets the state of . Should be called whenever a new app session
@@ -440,14 +427,14 @@ public static void Apply ()
public static void OnApplied ()
{
Debug.WriteLine ($"ConfigurationManager.OnApplied()");
- Applied?.Invoke (new ConfigurationManagerEventArgs ());
+ Applied?.Invoke (null, new ConfigurationManagerEventArgs ());
}
///
/// Event fired when an updated configuration has been applied to the
/// application.
///
- public static event Action? Applied;
+ public static event EventHandler? Applied;
///
/// Name of the running application. By default this property is set to the application's assembly name.
diff --git a/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs b/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs
new file mode 100644
index 0000000000..74acce2ec7
--- /dev/null
+++ b/Terminal.Gui/Configuration/ConfigurationManagerEventArgs.cs
@@ -0,0 +1,36 @@
+using System;
+
+#nullable enable
+
+namespace Terminal.Gui.Configuration {
+ ///
+ /// Event arguments for the events.
+ ///
+ public class ConfigurationManagerEventArgs : EventArgs {
+
+ ///
+ /// Initializes a new instance of
+ ///
+ public ConfigurationManagerEventArgs ()
+ {
+ }
+ }
+
+ ///
+ /// Event arguments for the events.
+ ///
+ public class ThemeManagerEventArgs : EventArgs {
+ ///
+ /// The name of the new active theme..
+ ///
+ public string NewTheme { get; set; } = string.Empty;
+
+ ///
+ /// Initializes a new instance of
+ ///
+ public ThemeManagerEventArgs (string newTheme)
+ {
+ NewTheme = newTheme;
+ }
+ }
+}
diff --git a/Terminal.Gui/Configuration/ThemeScope.cs b/Terminal.Gui/Configuration/ThemeScope.cs
index 22da7e4f20..6b5ee2eb02 100644
--- a/Terminal.Gui/Configuration/ThemeScope.cs
+++ b/Terminal.Gui/Configuration/ThemeScope.cs
@@ -110,7 +110,7 @@ internal override bool Apply ()
/// }
/// }
///
- public class ThemeManager : IDictionary {
+ public partial class ThemeManager : IDictionary {
private static readonly ThemeManager _instance = new ThemeManager ();
static ThemeManager () { } // Make sure it's truly lazy
private ThemeManager () { } // Prevent instantiation outside
@@ -152,38 +152,20 @@ public string Theme {
}
}
- ///
- /// Event arguments for the events.
- ///
- public class ThemeManagerEventArgs : EventArgs {
- ///
- /// The name of the new active theme..
- ///
- public string NewTheme { get; set; } = string.Empty;
-
- ///
- /// Initializes a new instance of
- ///
- public ThemeManagerEventArgs (string newTheme)
- {
- NewTheme = newTheme;
- }
- }
-
///
/// Called when the selected theme has changed. Fires the event.
///
internal void OnThemeChanged (string theme)
{
Debug.WriteLine ($"Themes.OnThemeChanged({theme}) -> {Theme}");
- ThemeChanged?.Invoke (new ThemeManagerEventArgs (theme));
+ ThemeChanged?.Invoke (this, new ThemeManagerEventArgs (theme));
}
///
/// Event fired he selected theme has changed.
/// application.
///
- public event Action? ThemeChanged;
+ public event EventHandler? ThemeChanged;
///
/// Holds the definitions.
diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
index 5de19fa85a..094b79be65 100644
--- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
+++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
@@ -743,8 +743,8 @@ public override void PrepareToRun (MainLoop mainLoop, Action keyHandle
mLoop.ProcessInput = (e) => ProcessInput (e);
- mLoop.WinChanged = (e) => {
- ChangeWin (e);
+ mLoop.WinChanged = (s,e) => {
+ ChangeWin (e.Size);
};
}
@@ -1868,8 +1868,8 @@ internal class WindowsMainLoop : IMainLoopDriver {
///
/// Invoked when the window is changed.
///
- public Action WinChanged;
-
+ public EventHandler WinChanged;
+
public WindowsMainLoop (ConsoleDriver consoleDriver = null)
{
this.consoleDriver = consoleDriver ?? throw new ArgumentNullException ("Console driver instance must be provided.");
@@ -1991,7 +1991,7 @@ void IMainLoopDriver.MainIteration ()
}
if (winChanged) {
winChanged = false;
- WinChanged?.Invoke (windowSize);
+ WinChanged?.Invoke (this, new SizeChangedEventArgs(windowSize));
}
}
}
diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs
index 921a3d0f95..d9e5eb40b4 100644
--- a/Terminal.Gui/Core/Application.cs
+++ b/Terminal.Gui/Core/Application.cs
@@ -59,7 +59,7 @@ namespace Terminal.Gui {
/// to the mainloop, allowing user code to use async/await.
///
///
- public static class Application {
+ public static partial class Application {
static readonly Stack toplevels = new Stack ();
///
@@ -162,15 +162,15 @@ public static Key AlternateForwardKey {
if (alternateForwardKey != value) {
var oldKey = alternateForwardKey;
alternateForwardKey = value;
- OnAlternateForwardKeyChanged (oldKey);
+ OnAlternateForwardKeyChanged (new KeyChangedEventArgs (oldKey, value));
}
}
}
- static void OnAlternateForwardKeyChanged (Key oldKey)
+ static void OnAlternateForwardKeyChanged (KeyChangedEventArgs e)
{
foreach (var top in toplevels.ToArray ()) {
- top.OnAlternateForwardKeyChanged (oldKey);
+ top.OnAlternateForwardKeyChanged (e);
}
}
@@ -186,12 +186,12 @@ public static Key AlternateBackwardKey {
if (alternateBackwardKey != value) {
var oldKey = alternateBackwardKey;
alternateBackwardKey = value;
- OnAlternateBackwardKeyChanged (oldKey);
+ OnAlternateBackwardKeyChanged (new KeyChangedEventArgs (oldKey, value));
}
}
}
- static void OnAlternateBackwardKeyChanged (Key oldKey)
+ static void OnAlternateBackwardKeyChanged (KeyChangedEventArgs oldKey)
{
foreach (var top in toplevels.ToArray ()) {
top.OnAlternateBackwardKeyChanged (oldKey);
@@ -210,7 +210,7 @@ public static Key QuitKey {
if (quitKey != value) {
var oldKey = quitKey;
quitKey = value;
- OnQuitKeyChanged (oldKey);
+ OnQuitKeyChanged (new KeyChangedEventArgs (oldKey, value));
}
}
}
@@ -222,11 +222,11 @@ public static Key QuitKey {
///
public static List SupportedCultures => supportedCultures;
- static void OnQuitKeyChanged (Key oldKey)
+ static void OnQuitKeyChanged (KeyChangedEventArgs e)
{
// Duplicate the list so if it changes during enumeration we're safe
foreach (var top in toplevels.ToArray ()) {
- top.OnQuitKeyChanged (oldKey);
+ top.OnQuitKeyChanged (e);
}
}
@@ -257,7 +257,7 @@ static void OnQuitKeyChanged (Key oldKey)
/// must also subscribe to
/// and manually dispose of the token when the application is done.
///
- public static event Action NotifyNewRunState;
+ public static event EventHandler NotifyNewRunState;
///
/// Notify that a existent is stopping ( was called).
@@ -267,7 +267,7 @@ static void OnQuitKeyChanged (Key oldKey)
/// must also subscribe to
/// and manually dispose of the token when the application is done.
///
- public static event Action NotifyStopRunState;
+ public static event EventHandler NotifyStopRunState;
///
/// This event is raised on each iteration of the .
@@ -730,15 +730,25 @@ static View FindTopFromView (View view)
///
public static View MouseGrabView => mouseGrabView;
+ ///
+ /// Event to be invoked when a view want grab the mouse which can be canceled.
+ ///
+ public static event EventHandler GrabbingMouse;
+
+ ///
+ /// Event to be invoked when a view want ungrab the mouse which can be canceled.
+ ///
+ public static event EventHandler UnGrabbingMouse;
+
///
/// Event to be invoked when a view grab the mouse.
///
- public static event Action GrabbedMouse;
+ public static event EventHandler GrabbedMouse;
///
/// Event to be invoked when a view ungrab the mouse.
///
- public static event Action UnGrabbedMouse;
+ public static event EventHandler UnGrabbedMouse;
///
/// Grabs the mouse, forcing all mouse events to be routed to the specified view until UngrabMouse is called.
@@ -749,9 +759,11 @@ public static void GrabMouse (View view)
{
if (view == null)
return;
- OnGrabbedMouse (view);
- mouseGrabView = view;
- Driver.UncookMouse ();
+ if (!OnGrabbingMouse (view)) {
+ OnGrabbedMouse (view);
+ mouseGrabView = view;
+ Driver.UncookMouse ();
+ }
}
///
@@ -761,23 +773,43 @@ public static void UngrabMouse ()
{
if (mouseGrabView == null)
return;
- OnUnGrabbedMouse (mouseGrabView);
- mouseGrabView = null;
- Driver.CookMouse ();
+ if (!OnUnGrabbingMouse (mouseGrabView)) {
+ OnUnGrabbedMouse (mouseGrabView);
+ mouseGrabView = null;
+ Driver.CookMouse ();
+ }
+ }
+
+ static bool OnGrabbingMouse (View view)
+ {
+ if (view == null)
+ return false;
+ var evArgs = new GrabMouseEventArgs (view);
+ GrabbingMouse?.Invoke (view, evArgs);
+ return evArgs.Cancel;
+ }
+
+ static bool OnUnGrabbingMouse (View view)
+ {
+ if (view == null)
+ return false;
+ var evArgs = new GrabMouseEventArgs (view);
+ UnGrabbingMouse?.Invoke (view, evArgs);
+ return evArgs.Cancel;
}
static void OnGrabbedMouse (View view)
{
if (view == null)
return;
- GrabbedMouse?.Invoke (view);
+ GrabbedMouse?.Invoke (view, new ViewEventArgs (view));
}
static void OnUnGrabbedMouse (View view)
{
if (view == null)
return;
- UnGrabbedMouse?.Invoke (view);
+ UnGrabbedMouse?.Invoke (view, new ViewEventArgs (view));
}
///
@@ -1036,7 +1068,7 @@ public static RunState Begin (Toplevel toplevel)
Driver.Refresh ();
}
- NotifyNewRunState?.Invoke (rs);
+ NotifyNewRunState?.Invoke (toplevel, new RunStateEventArgs (rs));
return rs;
}
@@ -1504,24 +1536,10 @@ public static void RequestStop (Toplevel top = null)
static void OnNotifyStopRunState (Toplevel top)
{
if (ExitRunLoopAfterFirstIteration) {
- NotifyStopRunState?.Invoke (top);
+ NotifyStopRunState?.Invoke (top, new ToplevelEventArgs (top));
}
}
- ///
- /// Event arguments for the event.
- ///
- public class ResizedEventArgs : EventArgs {
- ///
- /// The number of rows in the resized terminal.
- ///
- public int Rows { get; set; }
- ///
- /// The number of columns in the resized terminal.
- ///
- public int Cols { get; set; }
- }
-
///
/// Invoked when the terminal was resized. The new size of the terminal is provided.
///
@@ -1537,7 +1555,7 @@ static void TerminalResized ()
t.SetRelativeLayout (full);
t.LayoutSubviews ();
t.PositionToplevels ();
- t.OnResized (full.Size);
+ t.OnResized (new SizeChangedEventArgs (full.Size));
}
Refresh ();
}
diff --git a/Terminal.Gui/Core/Autocomplete/Autocomplete.cs b/Terminal.Gui/Core/Autocomplete/Autocomplete.cs
index 7283327732..9b225e5b8a 100644
--- a/Terminal.Gui/Core/Autocomplete/Autocomplete.cs
+++ b/Terminal.Gui/Core/Autocomplete/Autocomplete.cs
@@ -74,18 +74,18 @@ public virtual View HostControl {
}
}
- private void Top_Removed (View obj)
+ private void Top_Removed (object sender, SuperViewChangedEventArgs e)
{
Visible = false;
ManipulatePopup ();
}
- private void Top_DrawContentComplete (Rect obj)
+ private void Top_DrawContentComplete (object sender, DrawEventArgs e)
{
ManipulatePopup ();
}
- private void Top_DrawContent (Rect obj)
+ private void Top_DrawContent (object sender, DrawEventArgs e)
{
if (!closed) {
ReopenSuggestions ();
diff --git a/Terminal.Gui/Core/Canvas.cs b/Terminal.Gui/Core/Canvas.cs
deleted file mode 100644
index 5b2f23cc02..0000000000
--- a/Terminal.Gui/Core/Canvas.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Terminal.Gui.Core {
- ///
- /// The is a that can be used to draw on the screen.
- /// It is the base class of and .
- ///
- public class Canvas : Responder {
- ///
- /// Initializes a new instance of the class.
- ///
- public Canvas () : this (Rect.Empty) {}
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The that defines the position and size of the on the screen.
- /// relative coordinates.
- public Canvas (Rect frame)
- {
- }
- }
-}
diff --git a/Terminal.Gui/Core/CollectionNavigator.cs b/Terminal.Gui/Core/CollectionNavigator.cs
index 6637daf209..e0dc7d44e0 100644
--- a/Terminal.Gui/Core/CollectionNavigator.cs
+++ b/Terminal.Gui/Core/CollectionNavigator.cs
@@ -15,7 +15,7 @@ namespace Terminal.Gui {
/// If the user pauses keystrokes for a short time (see ), the search string is cleared.
///
///
- public class CollectionNavigator {
+ public partial class CollectionNavigator {
///
/// Constructs a new CollectionNavigator.
///
@@ -44,29 +44,10 @@ public CollectionNavigator () { }
///
public IEnumerable