mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
View Keyboard/Mouse -> nullable enable
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
namespace Terminal.Gui;
|
#nullable enable
|
||||||
|
namespace Terminal.Gui;
|
||||||
|
|
||||||
public partial class View
|
public partial class View
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#nullable enable
|
||||||
namespace Terminal.Gui;
|
namespace Terminal.Gui;
|
||||||
|
|
||||||
public partial class View
|
public partial class View
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
|
#nullable enable
|
||||||
|
|
||||||
|
|
||||||
namespace Terminal.Gui;
|
namespace Terminal.Gui;
|
||||||
|
|
||||||
/// <summary>Enables diagnostic functions for <see cref="View"/>.</summary>
|
/// <summary>Enables diagnostic functions for <see cref="View"/>.</summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel;
|
#nullable enable
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Terminal.Gui;
|
namespace Terminal.Gui;
|
||||||
@@ -50,7 +51,7 @@ public partial class View // Keyboard APIs
|
|||||||
public event EventHandler<KeyChangedEventArgs> HotKeyChanged;
|
public event EventHandler<KeyChangedEventArgs> HotKeyChanged;
|
||||||
|
|
||||||
private Key _hotKey = new ();
|
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); }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the hot key defined for this view. Pressing the hot key on the keyboard while this view has focus will
|
/// 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
|
|||||||
/// <param name="context">Arbitrary context that can be associated with this key binding.</param>
|
/// <param name="context">Arbitrary context that can be associated with this key binding.</param>
|
||||||
/// <returns><see langword="true"/> if the HotKey bindings were added.</returns>
|
/// <returns><see langword="true"/> if the HotKey bindings were added.</returns>
|
||||||
/// <exception cref="ArgumentException"></exception>
|
/// <exception cref="ArgumentException"></exception>
|
||||||
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)
|
if (_hotKey == hotKey)
|
||||||
{
|
{
|
||||||
@@ -657,7 +658,7 @@ public partial class View // Keyboard APIs
|
|||||||
/// <param name="key">The key to test.</param>
|
/// <param name="key">The key to test.</param>
|
||||||
/// <param name="boundView">Returns the view the key is bound to.</param>
|
/// <param name="boundView">Returns the view the key is bound to.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
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
|
// recurse through the subviews to find the views that has the key bound
|
||||||
boundView = null;
|
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 <see cref="Key.Handled"/> to true to
|
/// Invoked when a key is pressed that may be mapped to a key binding. Set <see cref="Key.Handled"/> to true to
|
||||||
/// stop the key from being processed by other views.
|
/// stop the key from being processed by other views.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<Key> InvokingKeyBindings;
|
public event EventHandler<Key>? InvokingKeyBindings;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invokes any binding that is registered on this <see cref="View"/> and matches the <paramref name="key"/>
|
/// Invokes any binding that is registered on this <see cref="View"/> and matches the <paramref name="key"/>
|
||||||
@@ -719,7 +720,7 @@ public partial class View // Keyboard APIs
|
|||||||
// TODO: This is a "prototype" debug check. It may be too annoying vs. useful.
|
// TODO: This is a "prototype" debug check. It may be too annoying vs. useful.
|
||||||
// Scour the bindings up our View hierarchy
|
// Scour the bindings up our View hierarchy
|
||||||
// to ensure that the key is not already bound to a different set of commands.
|
// 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}.");
|
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
|
|||||||
/// <see langword="true"/> if the command was invoked the command was handled.
|
/// <see langword="true"/> if the command was invoked the command was handled.
|
||||||
/// <see langword="false"/> if the command was invoked and the command was not handled.
|
/// <see langword="false"/> if the command was invoked and the command was not handled.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
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;
|
bool? toReturn = null;
|
||||||
|
|
||||||
@@ -798,9 +799,9 @@ public partial class View // Keyboard APIs
|
|||||||
/// <see langword="null"/> if no command was found. <see langword="true"/> if the command was invoked, and it
|
/// <see langword="null"/> if no command was found. <see langword="true"/> if the command was invoked, and it
|
||||||
/// handled the command. <see langword="false"/> if the command was invoked, and it did not handle the command.
|
/// handled the command. <see langword="false"/> if the command was invoked, and it did not handle the command.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
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<CommandContext, bool?> implementation))
|
if (CommandImplementations.TryGetValue (command, out Func<CommandContext, bool?>? implementation))
|
||||||
{
|
{
|
||||||
var context = new CommandContext (command, key, keyBinding); // Create the context here
|
var context = new CommandContext (command, key, keyBinding); // Create the context here
|
||||||
return implementation (context);
|
return implementation (context);
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
using System.ComponentModel;
|
#nullable enable
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace Terminal.Gui;
|
namespace Terminal.Gui;
|
||||||
|
|
||||||
public partial class View // Mouse APIs
|
public partial class View // Mouse APIs
|
||||||
{
|
{
|
||||||
[CanBeNull]
|
private ColorScheme? _savedHighlightColorScheme;
|
||||||
private ColorScheme _savedHighlightColorScheme;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fired when the view is highlighted. Set <see cref="CancelEventArgs.Cancel"/> to <see langword="true"/>
|
/// Fired when the view is highlighted. Set <see cref="CancelEventArgs.Cancel"/> to <see langword="true"/>
|
||||||
/// to implement a custom highlight scheme or prevent the view from being highlighted.
|
/// to implement a custom highlight scheme or prevent the view from being highlighted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<CancelEventArgs<HighlightStyle>> Highlight;
|
public event EventHandler<CancelEventArgs<HighlightStyle>>? Highlight;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets whether the <see cref="View"/> will be highlighted visually while the mouse button is
|
/// Gets or sets whether the <see cref="View"/> will be highlighted visually while the mouse button is
|
||||||
@@ -29,10 +29,10 @@ public partial class View // Mouse APIs
|
|||||||
/// The coordinates are relative to <see cref="View.Viewport"/>.
|
/// The coordinates are relative to <see cref="View.Viewport"/>.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public event EventHandler<MouseEventEventArgs> MouseClick;
|
public event EventHandler<MouseEventEventArgs>? MouseClick;
|
||||||
|
|
||||||
/// <summary>Event fired when the mouse moves into the View's <see cref="Viewport"/>.</summary>
|
/// <summary>Event fired when the mouse moves into the View's <see cref="Viewport"/>.</summary>
|
||||||
public event EventHandler<MouseEventEventArgs> MouseEnter;
|
public event EventHandler<MouseEventEventArgs>? MouseEnter;
|
||||||
|
|
||||||
/// <summary>Event fired when a mouse event occurs.</summary>
|
/// <summary>Event fired when a mouse event occurs.</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
@@ -40,10 +40,10 @@ public partial class View // Mouse APIs
|
|||||||
/// The coordinates are relative to <see cref="View.Viewport"/>.
|
/// The coordinates are relative to <see cref="View.Viewport"/>.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public event EventHandler<MouseEventEventArgs> MouseEvent;
|
public event EventHandler<MouseEventEventArgs>? MouseEvent;
|
||||||
|
|
||||||
/// <summary>Event fired when the mouse leaves the View's <see cref="Viewport"/>.</summary>
|
/// <summary>Event fired when the mouse leaves the View's <see cref="Viewport"/>.</summary>
|
||||||
public event EventHandler<MouseEventEventArgs> MouseLeave;
|
public event EventHandler<MouseEventEventArgs>? MouseLeave;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Processes a <see cref="MouseEvent"/>. This method is called by <see cref="Application.OnMouseEvent"/> when a mouse
|
/// Processes a <see cref="MouseEvent"/>. This method is called by <see cref="Application.OnMouseEvent"/> when a mouse
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Terminal.Gui.ViewTests;
|
namespace Terminal.Gui.ViewTests;
|
||||||
|
|
||||||
public class EnabledTests (ITestOutputHelper _output) : TestsAllViews
|
public class EnabledTests () : TestsAllViews
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Enabled_False_Leaves ()
|
public void Enabled_False_Leaves ()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Terminal.Gui.ViewTests;
|
namespace Terminal.Gui.ViewTests;
|
||||||
|
|
||||||
public class RestoreFocusTests (ITestOutputHelper _output) : TestsAllViews
|
public class RestoreFocusTests () : TestsAllViews
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RestoreFocus_Restores ()
|
public void RestoreFocus_Restores ()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Terminal.Gui.ViewTests;
|
namespace Terminal.Gui.ViewTests;
|
||||||
|
|
||||||
public class VisibleTests (ITestOutputHelper _output) : TestsAllViews
|
public class VisibleTests () : TestsAllViews
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Visible_False_Leaves ()
|
public void Visible_False_Leaves ()
|
||||||
|
|||||||
Reference in New Issue
Block a user