Fixed RadioGroup

This commit is contained in:
Tig
2024-06-26 13:46:44 -07:00
parent 28f529ae95
commit 2acb867196
3 changed files with 63 additions and 57 deletions

View File

@@ -67,7 +67,8 @@ namespace Terminal.Gui;
/// a View can be accessed with the <see cref="SuperView"/> property.
/// </para>
/// <para>
/// To flag a region of the View's <see cref="Viewport"/> to be redrawn call <see cref="SetNeedsDisplay(Rectangle)"/>
/// To flag a region of the View's <see cref="Viewport"/> to be redrawn call
/// <see cref="SetNeedsDisplay(Rectangle)"/>
/// .
/// To flag the entire view for redraw call <see cref="SetNeedsDisplay()"/>.
/// </para>
@@ -106,6 +107,61 @@ namespace Terminal.Gui;
public partial class View : Responder, ISupportInitializeNotification
{
/// <summary>
/// Cancelable event fired when the <see cref="Command.Accept"/> command is invoked. Set
/// <see cref="CancelEventArgs.Cancel"/>
/// to cancel the event.
/// </summary>
public event EventHandler<CancelEventArgs> Accept;
/// <summary>Gets or sets arbitrary data for the view.</summary>
/// <remarks>This property is not used internally.</remarks>
public object Data { get; set; }
/// <summary>Gets or sets an identifier for the view;</summary>
/// <value>The identifier.</value>
/// <remarks>The id should be unique across all Views that share a SuperView.</remarks>
public string Id { get; set; } = "";
/// <summary>Pretty prints the View</summary>
/// <returns></returns>
public override string ToString () { return $"{GetType ().Name}({Id}){Frame}"; }
/// <inheritdoc/>
protected override void Dispose (bool disposing)
{
LineCanvas.Dispose ();
DisposeKeyboard ();
DisposeAdornments ();
for (int i = InternalSubviews.Count - 1; i >= 0; i--)
{
View subview = InternalSubviews [i];
Remove (subview);
subview.Dispose ();
}
base.Dispose (disposing);
Debug.Assert (InternalSubviews.Count == 0);
}
/// <summary>
/// Called when the <see cref="Command.Accept"/> command is invoked. Fires the <see cref="Accept"/>
/// event.
/// </summary>
/// <returns>
/// If <see langword="true"/> the event was canceled. If <see langword="false"/> the event was fired but not canceled.
/// If <see langword="null"/> no event was fired.
/// </returns>
protected bool? OnAccept ()
{
var args = new CancelEventArgs ();
Accept?.Invoke (this, args);
return Accept is null ? null : args.Cancel;
}
#region Constructors and Initialization
/// <summary>
@@ -125,6 +181,7 @@ public partial class View : Responder, ISupportInitializeNotification
{
SetupAdornments ();
SetupKeyboard ();
//SetupMouse ();
SetupText ();
@@ -230,40 +287,10 @@ public partial class View : Responder, ISupportInitializeNotification
}
Initialized?.Invoke (this, EventArgs.Empty);
}
#endregion Constructors and Initialization
/// <summary>Gets or sets an identifier for the view;</summary>
/// <value>The identifier.</value>
/// <remarks>The id should be unique across all Views that share a SuperView.</remarks>
public string Id { get; set; } = "";
/// <summary>Gets or sets arbitrary data for the view.</summary>
/// <remarks>This property is not used internally.</remarks>
public object Data { get; set; }
/// <summary>
/// Cancelable event fired when the <see cref="Command.Accept"/> command is invoked. Set
/// <see cref="CancelEventArgs.Cancel"/>
/// to cancel the event.
/// </summary>
public event EventHandler<CancelEventArgs> Accept;
/// <summary>
/// Called when the <see cref="Command.Accept"/> command is invoked. Fires the <see cref="Accept"/>
/// event.
/// </summary>
/// <returns>If <see langword="true"/> the event was canceled.</returns>
protected bool? OnAccept ()
{
var args = new CancelEventArgs ();
Accept?.Invoke (this, args);
return Accept is null ? null : args.Cancel;
}
#region Visibility
private bool _enabled = true;
@@ -318,6 +345,7 @@ public partial class View : Responder, ISupportInitializeNotification
public virtual void OnEnabledChanged () { EnabledChanged?.Invoke (this, EventArgs.Empty); }
private bool _visible = true;
/// <summary>Gets or sets a value indicating whether this <see cref="Responder"/> and all its child controls are displayed.</summary>
public virtual bool Visible
{
@@ -349,7 +377,6 @@ public partial class View : Responder, ISupportInitializeNotification
}
}
/// <summary>Method invoked when the <see cref="Visible"/> property from a view is changed.</summary>
public virtual void OnVisibleChanged () { VisibleChanged?.Invoke (this, EventArgs.Empty); }
@@ -494,27 +521,4 @@ public partial class View : Responder, ISupportInitializeNotification
public event EventHandler<StateEventArgs<string>> TitleChanging;
#endregion
/// <summary>Pretty prints the View</summary>
/// <returns></returns>
public override string ToString () { return $"{GetType ().Name}({Id}){Frame}"; }
/// <inheritdoc/>
protected override void Dispose (bool disposing)
{
LineCanvas.Dispose ();
DisposeKeyboard ();
DisposeAdornments ();
for (int i = InternalSubviews.Count - 1; i >= 0; i--)
{
View subview = InternalSubviews [i];
Remove (subview);
subview.Dispose ();
}
base.Dispose (disposing);
Debug.Assert (InternalSubviews.Count == 0);
}
}

View File

@@ -415,6 +415,8 @@ public partial class View
return true;
}
// TODO: NewKeyDownEvent returns bool. It should be bool? so state of InvokeCommand can be reflected up stack
bool? handled = OnInvokingKeyBindings (keyEvent, KeyBindingScope.HotKey | KeyBindingScope.Focused);
if (handled is { } && (bool)handled)

View File

@@ -84,7 +84,7 @@ public class RadioGroup : View
{
SelectedItem = _cursor;
return !OnAccept ();
return OnAccept () != false;
}
);
@@ -97,7 +97,7 @@ public class RadioGroup : View
{
SelectedItem = (int)ctx.KeyBinding?.Context!;
return !OnAccept();
return OnAccept () != false;
}
return true;