From ca73f23ac1c7c36a523b87db772596ceaf5459a2 Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 26 Aug 2024 14:33:15 -0700 Subject: [PATCH] View Keyboard/Mouse -> nullable enable --- Terminal.Gui/View/View.Content.cs | 3 ++- Terminal.Gui/View/View.Cursor.cs | 1 + Terminal.Gui/View/View.Diagnostics.cs | 4 +--- Terminal.Gui/View/View.Keyboard.cs | 19 ++++++++++--------- Terminal.Gui/View/View.Mouse.cs | 16 ++++++++-------- UnitTests/View/Navigation/EnabledTests.cs | 2 +- .../View/Navigation/RestoreFocusTests.cs | 2 +- UnitTests/View/Navigation/VisibleTests.cs | 2 +- 8 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Terminal.Gui/View/View.Content.cs b/Terminal.Gui/View/View.Content.cs index 08443a851..131dd90ba 100644 --- a/Terminal.Gui/View/View.Content.cs +++ b/Terminal.Gui/View/View.Content.cs @@ -1,4 +1,5 @@ -namespace Terminal.Gui; +#nullable enable +namespace Terminal.Gui; public partial class View { diff --git a/Terminal.Gui/View/View.Cursor.cs b/Terminal.Gui/View/View.Cursor.cs index bdba7d85f..700398526 100644 --- a/Terminal.Gui/View/View.Cursor.cs +++ b/Terminal.Gui/View/View.Cursor.cs @@ -1,3 +1,4 @@ +#nullable enable namespace Terminal.Gui; public partial class View diff --git a/Terminal.Gui/View/View.Diagnostics.cs b/Terminal.Gui/View/View.Diagnostics.cs index c7ac7b851..6e5797e26 100644 --- a/Terminal.Gui/View/View.Diagnostics.cs +++ b/Terminal.Gui/View/View.Diagnostics.cs @@ -1,6 +1,4 @@ - - - +#nullable enable namespace Terminal.Gui; /// Enables diagnostic functions for . diff --git a/Terminal.Gui/View/View.Keyboard.cs b/Terminal.Gui/View/View.Keyboard.cs index 7a7fd35c5..f5b35803d 100644 --- a/Terminal.Gui/View/View.Keyboard.cs +++ b/Terminal.Gui/View/View.Keyboard.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +#nullable enable +using System.ComponentModel; using System.Diagnostics; namespace Terminal.Gui; @@ -50,7 +51,7 @@ public partial class View // Keyboard APIs public event EventHandler HotKeyChanged; private Key _hotKey = new (); - private void TitleTextFormatter_HotKeyChanged (object sender, KeyChangedEventArgs e) { HotKeyChanged?.Invoke (this, e); } + private void TitleTextFormatter_HotKeyChanged (object? sender, KeyChangedEventArgs e) { HotKeyChanged?.Invoke (this, e); } /// /// Gets or sets the hot key defined for this view. Pressing the hot key on the keyboard while this view has focus will @@ -131,7 +132,7 @@ public partial class View // Keyboard APIs /// Arbitrary context that can be associated with this key binding. /// if the HotKey bindings were added. /// - public virtual bool AddKeyBindingsForHotKey (Key prevHotKey, Key hotKey, [CanBeNull] object context = null) + public virtual bool AddKeyBindingsForHotKey (Key prevHotKey, Key hotKey, object? context = null) { if (_hotKey == hotKey) { @@ -657,7 +658,7 @@ public partial class View // Keyboard APIs /// The key to test. /// Returns the view the key is bound to. /// - public bool IsHotKeyKeyBound (Key key, out View boundView) + public bool IsHotKeyKeyBound (Key key, out View? boundView) { // recurse through the subviews to find the views that has the key bound boundView = null; @@ -683,7 +684,7 @@ public partial class View // Keyboard APIs /// Invoked when a key is pressed that may be mapped to a key binding. Set to true to /// stop the key from being processed by other views. /// - public event EventHandler InvokingKeyBindings; + public event EventHandler? InvokingKeyBindings; /// /// Invokes any binding that is registered on this and matches the @@ -719,7 +720,7 @@ public partial class View // Keyboard APIs // TODO: This is a "prototype" debug check. It may be too annoying vs. useful. // Scour the bindings up our View hierarchy // to ensure that the key is not already bound to a different set of commands. - if (SuperView?.IsHotKeyKeyBound (key, out View previouslyBoundView) ?? false) + if (SuperView?.IsHotKeyKeyBound (key, out View? previouslyBoundView) ?? false) { Debug.WriteLine ($"WARNING: InvokeKeyBindings ({key}) - A subview or peer has bound this Key and will not see it: {previouslyBoundView}."); } @@ -763,7 +764,7 @@ public partial class View // Keyboard APIs /// if the command was invoked the command was handled. /// if the command was invoked and the command was not handled. /// - public bool? InvokeCommands (Command [] commands, [CanBeNull] Key key = null, [CanBeNull] KeyBinding? keyBinding = null) + public bool? InvokeCommands (Command [] commands, Key? key = null, KeyBinding? keyBinding = null) { bool? toReturn = null; @@ -798,9 +799,9 @@ public partial class View // Keyboard APIs /// if no command was found. if the command was invoked, and it /// handled the command. if the command was invoked, and it did not handle the command. /// - public bool? InvokeCommand (Command command, [CanBeNull] Key key = null, [CanBeNull] KeyBinding? keyBinding = null) + public bool? InvokeCommand (Command command, Key? key = null, KeyBinding? keyBinding = null) { - if (CommandImplementations.TryGetValue (command, out Func implementation)) + if (CommandImplementations.TryGetValue (command, out Func? implementation)) { var context = new CommandContext (command, key, keyBinding); // Create the context here return implementation (context); diff --git a/Terminal.Gui/View/View.Mouse.cs b/Terminal.Gui/View/View.Mouse.cs index 302a3346d..b66c07fe3 100644 --- a/Terminal.Gui/View/View.Mouse.cs +++ b/Terminal.Gui/View/View.Mouse.cs @@ -1,17 +1,17 @@ -using System.ComponentModel; +#nullable enable +using System.ComponentModel; namespace Terminal.Gui; public partial class View // Mouse APIs { - [CanBeNull] - private ColorScheme _savedHighlightColorScheme; + private ColorScheme? _savedHighlightColorScheme; /// /// Fired when the view is highlighted. Set to /// to implement a custom highlight scheme or prevent the view from being highlighted. /// - public event EventHandler> Highlight; + public event EventHandler>? Highlight; /// /// Gets or sets whether the will be highlighted visually while the mouse button is @@ -29,10 +29,10 @@ public partial class View // Mouse APIs /// The coordinates are relative to . /// /// - public event EventHandler MouseClick; + public event EventHandler? MouseClick; /// Event fired when the mouse moves into the View's . - public event EventHandler MouseEnter; + public event EventHandler? MouseEnter; /// Event fired when a mouse event occurs. /// @@ -40,10 +40,10 @@ public partial class View // Mouse APIs /// The coordinates are relative to . /// /// - public event EventHandler MouseEvent; + public event EventHandler? MouseEvent; /// Event fired when the mouse leaves the View's . - public event EventHandler MouseLeave; + public event EventHandler? MouseLeave; /// /// Processes a . This method is called by when a mouse diff --git a/UnitTests/View/Navigation/EnabledTests.cs b/UnitTests/View/Navigation/EnabledTests.cs index f909fe924..24bb0c206 100644 --- a/UnitTests/View/Navigation/EnabledTests.cs +++ b/UnitTests/View/Navigation/EnabledTests.cs @@ -2,7 +2,7 @@ namespace Terminal.Gui.ViewTests; -public class EnabledTests (ITestOutputHelper _output) : TestsAllViews +public class EnabledTests () : TestsAllViews { [Fact] public void Enabled_False_Leaves () diff --git a/UnitTests/View/Navigation/RestoreFocusTests.cs b/UnitTests/View/Navigation/RestoreFocusTests.cs index 4fe26722e..12cd0f58b 100644 --- a/UnitTests/View/Navigation/RestoreFocusTests.cs +++ b/UnitTests/View/Navigation/RestoreFocusTests.cs @@ -2,7 +2,7 @@ namespace Terminal.Gui.ViewTests; -public class RestoreFocusTests (ITestOutputHelper _output) : TestsAllViews +public class RestoreFocusTests () : TestsAllViews { [Fact] public void RestoreFocus_Restores () diff --git a/UnitTests/View/Navigation/VisibleTests.cs b/UnitTests/View/Navigation/VisibleTests.cs index fa9d30f72..e4a1e102b 100644 --- a/UnitTests/View/Navigation/VisibleTests.cs +++ b/UnitTests/View/Navigation/VisibleTests.cs @@ -2,7 +2,7 @@ namespace Terminal.Gui.ViewTests; -public class VisibleTests (ITestOutputHelper _output) : TestsAllViews +public class VisibleTests () : TestsAllViews { [Fact] public void Visible_False_Leaves ()