|
@@ -1,4 +1,5 @@
|
|
using System.ComponentModel;
|
|
using System.ComponentModel;
|
|
|
|
+using System.Threading.Channels;
|
|
|
|
|
|
namespace Terminal.Gui;
|
|
namespace Terminal.Gui;
|
|
|
|
|
|
@@ -84,8 +85,8 @@ public class Shortcut : View
|
|
|
|
|
|
// If the user clicks anywhere on the Shortcut, other than the CommandView, invoke the Command
|
|
// If the user clicks anywhere on the Shortcut, other than the CommandView, invoke the Command
|
|
MouseClick += Shortcut_MouseClick;
|
|
MouseClick += Shortcut_MouseClick;
|
|
- HelpView.MouseClick += Shortcut_MouseClick;
|
|
|
|
- KeyView.MouseClick += Shortcut_MouseClick;
|
|
|
|
|
|
+ HelpView.MouseClick += Subview_MouseClick;
|
|
|
|
+ KeyView.MouseClick += Subview_MouseClick;
|
|
LayoutStarted += OnLayoutStarted;
|
|
LayoutStarted += OnLayoutStarted;
|
|
Initialized += OnInitialized;
|
|
Initialized += OnInitialized;
|
|
|
|
|
|
@@ -340,6 +341,12 @@ public class Shortcut : View
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void Subview_MouseClick (object sender, MouseEventEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ // TODO: Remove. This does nothing.
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
#region Command
|
|
#region Command
|
|
|
|
|
|
private View _commandView = new ();
|
|
private View _commandView = new ();
|
|
@@ -409,9 +416,6 @@ public class Shortcut : View
|
|
// If you want it to get focus, you need to set it.
|
|
// If you want it to get focus, you need to set it.
|
|
_commandView.CanFocus = false;
|
|
_commandView.CanFocus = false;
|
|
|
|
|
|
- _commandView.MouseClick += Shortcut_MouseClick;
|
|
|
|
- _commandView.Accept += CommandViewAccept;
|
|
|
|
-
|
|
|
|
_commandView.HotKeyChanged += (s, e) =>
|
|
_commandView.HotKeyChanged += (s, e) =>
|
|
{
|
|
{
|
|
if (e.NewKey != Key.Empty)
|
|
if (e.NewKey != Key.Empty)
|
|
@@ -432,360 +436,357 @@ public class Shortcut : View
|
|
UpdateKeyBinding ();
|
|
UpdateKeyBinding ();
|
|
|
|
|
|
return;
|
|
return;
|
|
-
|
|
|
|
- void CommandViewAccept (object sender, CancelEventArgs e)
|
|
|
|
- {
|
|
|
|
- // When the CommandView fires its Accept event, we want to act as though the
|
|
|
|
- // Shortcut was clicked.
|
|
|
|
- //if (base.OnAccept () == true)
|
|
|
|
- //{
|
|
|
|
- // e.Cancel = true;
|
|
|
|
- //}
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void SetCommandViewDefaultLayout ()
|
|
private void SetCommandViewDefaultLayout ()
|
|
- {
|
|
|
|
- CommandView.Margin.Thickness = GetMarginThickness ();
|
|
|
|
- CommandView.X = Pos.Align (Alignment.End, AlignmentModes);
|
|
|
|
- CommandView.Y = 0; //Pos.Center ();
|
|
|
|
- }
|
|
|
|
|
|
+{
|
|
|
|
+ CommandView.Margin.Thickness = GetMarginThickness ();
|
|
|
|
+ CommandView.X = Pos.Align (Alignment.End, AlignmentModes);
|
|
|
|
+ CommandView.Y = 0; //Pos.Center ();
|
|
|
|
+}
|
|
|
|
|
|
- private void Shortcut_TitleChanged (object sender, StateEventArgs<string> e)
|
|
|
|
- {
|
|
|
|
- // If the Title changes, update the CommandView text.
|
|
|
|
- // This is a helper to make it easier to set the CommandView text.
|
|
|
|
- // CommandView is public and replaceable, but this is a convenience.
|
|
|
|
- _commandView.Text = Title;
|
|
|
|
- }
|
|
|
|
|
|
+private void Shortcut_TitleChanged (object sender, StateEventArgs<string> e)
|
|
|
|
+{
|
|
|
|
+ // If the Title changes, update the CommandView text.
|
|
|
|
+ // This is a helper to make it easier to set the CommandView text.
|
|
|
|
+ // CommandView is public and replaceable, but this is a convenience.
|
|
|
|
+ _commandView.Text = Title;
|
|
|
|
+}
|
|
|
|
|
|
- #endregion Command
|
|
|
|
|
|
+#endregion Command
|
|
|
|
|
|
- #region Help
|
|
|
|
|
|
+#region Help
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// The subview that displays the help text for the command. Internal for unit testing.
|
|
|
|
- /// </summary>
|
|
|
|
- internal View HelpView { get; } = new ();
|
|
|
|
|
|
+/// <summary>
|
|
|
|
+/// The subview that displays the help text for the command. Internal for unit testing.
|
|
|
|
+/// </summary>
|
|
|
|
+internal View HelpView { get; } = new ();
|
|
|
|
|
|
- private void SetHelpViewDefaultLayout ()
|
|
|
|
- {
|
|
|
|
- HelpView.Margin.Thickness = GetMarginThickness ();
|
|
|
|
- HelpView.X = Pos.Align (Alignment.End, AlignmentModes);
|
|
|
|
- HelpView.Y = 0; //Pos.Center ();
|
|
|
|
- HelpView.Width = Dim.Auto (DimAutoStyle.Text);
|
|
|
|
- HelpView.Height = CommandView?.Visible == true ? Dim.Height (CommandView) : 1;
|
|
|
|
-
|
|
|
|
- HelpView.Visible = true;
|
|
|
|
- HelpView.VerticalTextAlignment = Alignment.Center;
|
|
|
|
- }
|
|
|
|
|
|
+private void SetHelpViewDefaultLayout ()
|
|
|
|
+{
|
|
|
|
+ HelpView.Margin.Thickness = GetMarginThickness ();
|
|
|
|
+ HelpView.X = Pos.Align (Alignment.End, AlignmentModes);
|
|
|
|
+ HelpView.Y = 0; //Pos.Center ();
|
|
|
|
+ HelpView.Width = Dim.Auto (DimAutoStyle.Text);
|
|
|
|
+ HelpView.Height = CommandView?.Visible == true ? Dim.Height (CommandView) : 1;
|
|
|
|
+
|
|
|
|
+ HelpView.Visible = true;
|
|
|
|
+ HelpView.VerticalTextAlignment = Alignment.Center;
|
|
|
|
+}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Gets or sets the help text displayed in the middle of the Shortcut. Identical in function to <see cref="HelpText"/>
|
|
|
|
- /// .
|
|
|
|
- /// </summary>
|
|
|
|
- public override string Text
|
|
|
|
|
|
+/// <summary>
|
|
|
|
+/// Gets or sets the help text displayed in the middle of the Shortcut. Identical in function to <see cref="HelpText"/>
|
|
|
|
+/// .
|
|
|
|
+/// </summary>
|
|
|
|
+public override string Text
|
|
|
|
+{
|
|
|
|
+ get => HelpView?.Text;
|
|
|
|
+ set
|
|
{
|
|
{
|
|
- get => HelpView?.Text;
|
|
|
|
- set
|
|
|
|
|
|
+ if (HelpView != null)
|
|
{
|
|
{
|
|
- if (HelpView != null)
|
|
|
|
- {
|
|
|
|
- HelpView.Text = value;
|
|
|
|
- ShowHide ();
|
|
|
|
- }
|
|
|
|
|
|
+ HelpView.Text = value;
|
|
|
|
+ ShowHide ();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Gets or sets the help text displayed in the middle of the Shortcut.
|
|
|
|
- /// </summary>
|
|
|
|
- public string HelpText
|
|
|
|
|
|
+/// <summary>
|
|
|
|
+/// Gets or sets the help text displayed in the middle of the Shortcut.
|
|
|
|
+/// </summary>
|
|
|
|
+public string HelpText
|
|
|
|
+{
|
|
|
|
+ get => HelpView?.Text;
|
|
|
|
+ set
|
|
{
|
|
{
|
|
- get => HelpView?.Text;
|
|
|
|
- set
|
|
|
|
|
|
+ if (HelpView != null)
|
|
{
|
|
{
|
|
- if (HelpView != null)
|
|
|
|
- {
|
|
|
|
- HelpView.Text = value;
|
|
|
|
- ShowHide ();
|
|
|
|
- }
|
|
|
|
|
|
+ HelpView.Text = value;
|
|
|
|
+ ShowHide ();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- #endregion Help
|
|
|
|
|
|
+#endregion Help
|
|
|
|
|
|
- #region Key
|
|
|
|
|
|
+#region Key
|
|
|
|
|
|
- private Key _key = Key.Empty;
|
|
|
|
|
|
+private Key _key = Key.Empty;
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Gets or sets the <see cref="Key"/> that will be bound to the <see cref="Command.Accept"/> command.
|
|
|
|
- /// </summary>
|
|
|
|
- public Key Key
|
|
|
|
|
|
+/// <summary>
|
|
|
|
+/// Gets or sets the <see cref="Key"/> that will be bound to the <see cref="Command.Accept"/> command.
|
|
|
|
+/// </summary>
|
|
|
|
+public Key Key
|
|
|
|
+{
|
|
|
|
+ get => _key;
|
|
|
|
+ set
|
|
{
|
|
{
|
|
- get => _key;
|
|
|
|
- set
|
|
|
|
|
|
+ if (value == null)
|
|
{
|
|
{
|
|
- if (value == null)
|
|
|
|
- {
|
|
|
|
- throw new ArgumentNullException ();
|
|
|
|
- }
|
|
|
|
|
|
+ throw new ArgumentNullException ();
|
|
|
|
+ }
|
|
|
|
|
|
- _key = value;
|
|
|
|
|
|
+ _key = value;
|
|
|
|
|
|
- UpdateKeyBinding ();
|
|
|
|
|
|
+ UpdateKeyBinding ();
|
|
|
|
|
|
- KeyView.Text = Key == Key.Empty ? string.Empty : $"{Key}";
|
|
|
|
- ShowHide ();
|
|
|
|
- }
|
|
|
|
|
|
+ KeyView.Text = Key == Key.Empty ? string.Empty : $"{Key}";
|
|
|
|
+ ShowHide ();
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- private KeyBindingScope _keyBindingScope = KeyBindingScope.HotKey;
|
|
|
|
|
|
+private KeyBindingScope _keyBindingScope = KeyBindingScope.HotKey;
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Gets or sets the scope for the key binding for how <see cref="Key"/> is bound to <see cref="Command"/>.
|
|
|
|
- /// </summary>
|
|
|
|
- public KeyBindingScope KeyBindingScope
|
|
|
|
|
|
+/// <summary>
|
|
|
|
+/// Gets or sets the scope for the key binding for how <see cref="Key"/> is bound to <see cref="Command"/>.
|
|
|
|
+/// </summary>
|
|
|
|
+public KeyBindingScope KeyBindingScope
|
|
|
|
+{
|
|
|
|
+ get => _keyBindingScope;
|
|
|
|
+ set
|
|
{
|
|
{
|
|
- get => _keyBindingScope;
|
|
|
|
- set
|
|
|
|
- {
|
|
|
|
- _keyBindingScope = value;
|
|
|
|
|
|
+ _keyBindingScope = value;
|
|
|
|
|
|
- UpdateKeyBinding ();
|
|
|
|
- }
|
|
|
|
|
|
+ UpdateKeyBinding ();
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Gets the subview that displays the key. Internal for unit testing.
|
|
|
|
- /// </summary>
|
|
|
|
|
|
+/// <summary>
|
|
|
|
+/// Gets the subview that displays the key. Internal for unit testing.
|
|
|
|
+/// </summary>
|
|
|
|
|
|
- internal View KeyView { get; } = new ();
|
|
|
|
|
|
+internal View KeyView { get; } = new ();
|
|
|
|
|
|
- private int _minimumKeyTextSize;
|
|
|
|
|
|
+private int _minimumKeyTextSize;
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Gets or sets the minimum size of the key text. Useful for aligning the key text with other <see cref="Shortcut"/>s.
|
|
|
|
- /// </summary>
|
|
|
|
- public int MinimumKeyTextSize
|
|
|
|
|
|
+/// <summary>
|
|
|
|
+/// Gets or sets the minimum size of the key text. Useful for aligning the key text with other <see cref="Shortcut"/>s.
|
|
|
|
+/// </summary>
|
|
|
|
+public int MinimumKeyTextSize
|
|
|
|
+{
|
|
|
|
+ get => _minimumKeyTextSize;
|
|
|
|
+ set
|
|
{
|
|
{
|
|
- get => _minimumKeyTextSize;
|
|
|
|
- set
|
|
|
|
|
|
+ if (value == _minimumKeyTextSize)
|
|
{
|
|
{
|
|
- if (value == _minimumKeyTextSize)
|
|
|
|
- {
|
|
|
|
- //return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- _minimumKeyTextSize = value;
|
|
|
|
- SetKeyViewDefaultLayout ();
|
|
|
|
- CommandView.SetNeedsLayout ();
|
|
|
|
- HelpView.SetNeedsLayout ();
|
|
|
|
- KeyView.SetNeedsLayout ();
|
|
|
|
- SetSubViewNeedsDisplay ();
|
|
|
|
|
|
+ //return;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ _minimumKeyTextSize = value;
|
|
|
|
+ SetKeyViewDefaultLayout ();
|
|
|
|
+ CommandView.SetNeedsLayout ();
|
|
|
|
+ HelpView.SetNeedsLayout ();
|
|
|
|
+ KeyView.SetNeedsLayout ();
|
|
|
|
+ SetSubViewNeedsDisplay ();
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- private int GetMinimumKeyViewSize () { return MinimumKeyTextSize; }
|
|
|
|
|
|
+private int GetMinimumKeyViewSize () { return MinimumKeyTextSize; }
|
|
|
|
|
|
- private void SetKeyViewDefaultLayout ()
|
|
|
|
- {
|
|
|
|
- KeyView.Margin.Thickness = GetMarginThickness ();
|
|
|
|
- KeyView.X = Pos.Align (Alignment.End, AlignmentModes);
|
|
|
|
- KeyView.Y = 0; //Pos.Center ();
|
|
|
|
- KeyView.Width = Dim.Auto (DimAutoStyle.Text, Dim.Func (GetMinimumKeyViewSize));
|
|
|
|
- KeyView.Height = CommandView?.Visible == true ? Dim.Height (CommandView) : 1;
|
|
|
|
-
|
|
|
|
- KeyView.Visible = true;
|
|
|
|
-
|
|
|
|
- // Right align the text in the keyview
|
|
|
|
- KeyView.TextAlignment = Alignment.End;
|
|
|
|
- KeyView.VerticalTextAlignment = Alignment.Center;
|
|
|
|
- KeyView.KeyBindings.Clear ();
|
|
|
|
- }
|
|
|
|
|
|
+private void SetKeyViewDefaultLayout ()
|
|
|
|
+{
|
|
|
|
+ KeyView.Margin.Thickness = GetMarginThickness ();
|
|
|
|
+ KeyView.X = Pos.Align (Alignment.End, AlignmentModes);
|
|
|
|
+ KeyView.Y = 0; //Pos.Center ();
|
|
|
|
+ KeyView.Width = Dim.Auto (DimAutoStyle.Text, Dim.Func (GetMinimumKeyViewSize));
|
|
|
|
+ KeyView.Height = CommandView?.Visible == true ? Dim.Height (CommandView) : 1;
|
|
|
|
+
|
|
|
|
+ KeyView.Visible = true;
|
|
|
|
+
|
|
|
|
+ // Right align the text in the keyview
|
|
|
|
+ KeyView.TextAlignment = Alignment.End;
|
|
|
|
+ KeyView.VerticalTextAlignment = Alignment.Center;
|
|
|
|
+ KeyView.KeyBindings.Clear ();
|
|
|
|
+}
|
|
|
|
|
|
- private void UpdateKeyBinding ()
|
|
|
|
|
|
+private void UpdateKeyBinding ()
|
|
|
|
+{
|
|
|
|
+ if (Key != null)
|
|
{
|
|
{
|
|
- if (Key != null)
|
|
|
|
- {
|
|
|
|
- // Disable the command view key bindings
|
|
|
|
- CommandView.KeyBindings.Remove (Key);
|
|
|
|
- CommandView.KeyBindings.Remove (CommandView.HotKey);
|
|
|
|
- KeyBindings.Remove (Key);
|
|
|
|
- KeyBindings.Add (Key, KeyBindingScope | KeyBindingScope.HotKey, Command.Accept);
|
|
|
|
- //KeyBindings.Add (Key, KeyBindingScope.HotKey, Command.Accept);
|
|
|
|
- }
|
|
|
|
|
|
+ // Disable the command view key bindings
|
|
|
|
+ CommandView.KeyBindings.Remove (Key);
|
|
|
|
+ CommandView.KeyBindings.Remove (CommandView.HotKey);
|
|
|
|
+ KeyBindings.Remove (Key);
|
|
|
|
+ KeyBindings.Add (Key, KeyBindingScope | KeyBindingScope.HotKey, Command.Accept);
|
|
|
|
+ //KeyBindings.Add (Key, KeyBindingScope.HotKey, Command.Accept);
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- #endregion Key
|
|
|
|
|
|
+#endregion Key
|
|
|
|
|
|
- #region Accept Handling
|
|
|
|
|
|
+#region Accept Handling
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Called when the <see cref="Command.Accept"/> command is received. This
|
|
|
|
- /// occurs
|
|
|
|
- /// - if the user clicks anywhere on the shortcut with the mouse
|
|
|
|
- /// - if the user presses Key
|
|
|
|
- /// - if the user presses the HotKey specified by CommandView
|
|
|
|
- /// - if HasFocus and the user presses Space or Enter (or any other key bound to Command.Accept).
|
|
|
|
- /// </summary>
|
|
|
|
- protected bool? OnAccept (CommandContext ctx)
|
|
|
|
|
|
+/// <summary>
|
|
|
|
+/// Called when the <see cref="Command.Accept"/> command is received. This
|
|
|
|
+/// occurs
|
|
|
|
+/// - if the user clicks anywhere on the shortcut with the mouse
|
|
|
|
+/// - if the user presses Key
|
|
|
|
+/// - if the user presses the HotKey specified by CommandView
|
|
|
|
+/// - if HasFocus and the user presses Space or Enter (or any other key bound to Command.Accept).
|
|
|
|
+/// </summary>
|
|
|
|
+protected bool? OnAccept (CommandContext ctx)
|
|
|
|
+{
|
|
|
|
+ var cancel = false;
|
|
|
|
+
|
|
|
|
+ switch (ctx.KeyBinding?.Scope)
|
|
{
|
|
{
|
|
- var cancel = false;
|
|
|
|
|
|
+ case KeyBindingScope.Application:
|
|
|
|
+ cancel = base.OnAccept () == true;
|
|
|
|
|
|
- switch (ctx.KeyBinding?.Scope)
|
|
|
|
- {
|
|
|
|
- case KeyBindingScope.Application:
|
|
|
|
- cancel = base.OnAccept () == true;
|
|
|
|
|
|
+ break;
|
|
|
|
|
|
- break;
|
|
|
|
|
|
+ case KeyBindingScope.Focused:
|
|
|
|
+ base.OnAccept ();
|
|
|
|
|
|
- case KeyBindingScope.Focused:
|
|
|
|
- // TODO: Figure this out
|
|
|
|
- cancel = base.OnAccept () == true;
|
|
|
|
|
|
+ // cancel if we're focused
|
|
|
|
+ cancel = true;
|
|
|
|
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
|
|
|
|
- case KeyBindingScope.HotKey:
|
|
|
|
- cancel = base.OnAccept () == true;
|
|
|
|
|
|
+ case KeyBindingScope.HotKey:
|
|
|
|
+ cancel = base.OnAccept () == true;
|
|
|
|
|
|
- if (CanFocus)
|
|
|
|
- {
|
|
|
|
- SetFocus ();
|
|
|
|
- }
|
|
|
|
|
|
+ if (CanFocus)
|
|
|
|
+ {
|
|
|
|
+ SetFocus ();
|
|
|
|
+ cancel = true;
|
|
|
|
+ }
|
|
|
|
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
|
|
|
|
- default:
|
|
|
|
- cancel = base.OnAccept () == true;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ default:
|
|
|
|
+ // Mouse
|
|
|
|
+ cancel = base.OnAccept () == true;
|
|
|
|
|
|
- CommandView.InvokeCommand (Command.Accept);
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
|
|
- if (!cancel)
|
|
|
|
- {
|
|
|
|
- Action?.Invoke ();
|
|
|
|
- }
|
|
|
|
|
|
+ CommandView.InvokeCommand (Command.Accept, ctx.Key, ctx.KeyBinding);
|
|
|
|
|
|
- return cancel;
|
|
|
|
|
|
+ if (Action is { })
|
|
|
|
+ {
|
|
|
|
+ Action.Invoke ();
|
|
|
|
+ // Assume if there's a subscriber to Action, it's handled.
|
|
|
|
+ cancel = true;
|
|
}
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Gets or sets the action to be invoked when the shortcut key is pressed or the shortcut is clicked on with the
|
|
|
|
- /// mouse.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <remarks>
|
|
|
|
- /// Note, the <see cref="View.Accept"/> event is fired first, and if cancelled, the event will not be invoked.
|
|
|
|
- /// </remarks>
|
|
|
|
- [CanBeNull]
|
|
|
|
- public Action Action { get; set; }
|
|
|
|
|
|
+ return cancel;
|
|
|
|
+}
|
|
|
|
|
|
- #endregion Accept Handling
|
|
|
|
|
|
+/// <summary>
|
|
|
|
+/// Gets or sets the action to be invoked when the shortcut key is pressed or the shortcut is clicked on with the
|
|
|
|
+/// mouse.
|
|
|
|
+/// </summary>
|
|
|
|
+/// <remarks>
|
|
|
|
+/// Note, the <see cref="View.Accept"/> event is fired first, and if cancelled, the event will not be invoked.
|
|
|
|
+/// </remarks>
|
|
|
|
+[CanBeNull]
|
|
|
|
+public Action Action { get; set; }
|
|
|
|
|
|
- private bool? OnSelect (CommandContext ctx)
|
|
|
|
- {
|
|
|
|
- if (CommandView.GetSupportedCommands ().Contains (Command.Select))
|
|
|
|
- {
|
|
|
|
- return CommandView.InvokeCommand (Command.Select, ctx.Key, ctx.KeyBinding);
|
|
|
|
- }
|
|
|
|
- return false;
|
|
|
|
|
|
+#endregion Accept Handling
|
|
|
|
|
|
|
|
+private bool? OnSelect (CommandContext ctx)
|
|
|
|
+{
|
|
|
|
+ if (CommandView.GetSupportedCommands ().Contains (Command.Select))
|
|
|
|
+ {
|
|
|
|
+ return CommandView.InvokeCommand (Command.Select, ctx.Key, ctx.KeyBinding);
|
|
}
|
|
}
|
|
|
|
+ return false;
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
- #region Focus
|
|
|
|
|
|
+#region Focus
|
|
|
|
|
|
- /// <inheritdoc/>
|
|
|
|
- public override ColorScheme ColorScheme
|
|
|
|
|
|
+/// <inheritdoc/>
|
|
|
|
+public override ColorScheme ColorScheme
|
|
|
|
+{
|
|
|
|
+ get => base.ColorScheme;
|
|
|
|
+ set
|
|
{
|
|
{
|
|
- get => base.ColorScheme;
|
|
|
|
- set
|
|
|
|
- {
|
|
|
|
- base.ColorScheme = value;
|
|
|
|
- SetColors ();
|
|
|
|
- }
|
|
|
|
|
|
+ base.ColorScheme = value;
|
|
|
|
+ SetColors ();
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// </summary>
|
|
|
|
- internal void SetColors ()
|
|
|
|
- {
|
|
|
|
- // Border should match superview.
|
|
|
|
- Border.ColorScheme = SuperView?.ColorScheme;
|
|
|
|
|
|
+/// <summary>
|
|
|
|
+/// </summary>
|
|
|
|
+internal void SetColors ()
|
|
|
|
+{
|
|
|
|
+ // Border should match superview.
|
|
|
|
+ Border.ColorScheme = SuperView?.ColorScheme;
|
|
|
|
|
|
- if (HasFocus)
|
|
|
|
- {
|
|
|
|
- // When we have focus, we invert the colors
|
|
|
|
- base.ColorScheme = new (base.ColorScheme)
|
|
|
|
- {
|
|
|
|
- Normal = base.ColorScheme.Focus,
|
|
|
|
- HotNormal = base.ColorScheme.HotFocus,
|
|
|
|
- HotFocus = base.ColorScheme.HotNormal,
|
|
|
|
- Focus = base.ColorScheme.Normal
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
|
|
+ if (HasFocus)
|
|
|
|
+ {
|
|
|
|
+ // When we have focus, we invert the colors
|
|
|
|
+ base.ColorScheme = new (base.ColorScheme)
|
|
{
|
|
{
|
|
- base.ColorScheme = SuperView?.ColorScheme ?? base.ColorScheme;
|
|
|
|
- }
|
|
|
|
|
|
+ Normal = base.ColorScheme.Focus,
|
|
|
|
+ HotNormal = base.ColorScheme.HotFocus,
|
|
|
|
+ HotFocus = base.ColorScheme.HotNormal,
|
|
|
|
+ Focus = base.ColorScheme.Normal
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ base.ColorScheme = SuperView?.ColorScheme ?? base.ColorScheme;
|
|
|
|
+ }
|
|
|
|
|
|
- // Set KeyView's colors to show "hot"
|
|
|
|
- if (IsInitialized && base.ColorScheme is { })
|
|
|
|
|
|
+ // Set KeyView's colors to show "hot"
|
|
|
|
+ if (IsInitialized && base.ColorScheme is { })
|
|
|
|
+ {
|
|
|
|
+ var cs = new ColorScheme (base.ColorScheme)
|
|
{
|
|
{
|
|
- var cs = new ColorScheme (base.ColorScheme)
|
|
|
|
- {
|
|
|
|
- Normal = base.ColorScheme.HotNormal,
|
|
|
|
- HotNormal = base.ColorScheme.Normal
|
|
|
|
- };
|
|
|
|
- KeyView.ColorScheme = cs;
|
|
|
|
- }
|
|
|
|
|
|
+ Normal = base.ColorScheme.HotNormal,
|
|
|
|
+ HotNormal = base.ColorScheme.Normal
|
|
|
|
+ };
|
|
|
|
+ KeyView.ColorScheme = cs;
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- View _lastFocusedView;
|
|
|
|
- /// <inheritdoc/>
|
|
|
|
- public override bool OnEnter (View view)
|
|
|
|
- {
|
|
|
|
- SetColors ();
|
|
|
|
- _lastFocusedView = view;
|
|
|
|
|
|
+View _lastFocusedView;
|
|
|
|
+/// <inheritdoc/>
|
|
|
|
+public override bool OnEnter (View view)
|
|
|
|
+{
|
|
|
|
+ SetColors ();
|
|
|
|
+ _lastFocusedView = view;
|
|
|
|
|
|
- return base.OnEnter (view);
|
|
|
|
- }
|
|
|
|
|
|
+ return base.OnEnter (view);
|
|
|
|
+}
|
|
|
|
|
|
- /// <inheritdoc/>
|
|
|
|
- public override bool OnLeave (View view)
|
|
|
|
- {
|
|
|
|
- SetColors ();
|
|
|
|
- _lastFocusedView = this;
|
|
|
|
|
|
+/// <inheritdoc/>
|
|
|
|
+public override bool OnLeave (View view)
|
|
|
|
+{
|
|
|
|
+ SetColors ();
|
|
|
|
+ _lastFocusedView = this;
|
|
|
|
|
|
- return base.OnLeave (view);
|
|
|
|
- }
|
|
|
|
|
|
+ return base.OnLeave (view);
|
|
|
|
+}
|
|
|
|
|
|
- #endregion Focus
|
|
|
|
|
|
+#endregion Focus
|
|
|
|
|
|
- /// <inheritdoc/>
|
|
|
|
- protected override void Dispose (bool disposing)
|
|
|
|
|
|
+/// <inheritdoc/>
|
|
|
|
+protected override void Dispose (bool disposing)
|
|
|
|
+{
|
|
|
|
+ if (disposing)
|
|
{
|
|
{
|
|
- if (disposing)
|
|
|
|
|
|
+ if (CommandView?.IsAdded == false)
|
|
{
|
|
{
|
|
- if (CommandView?.IsAdded == false)
|
|
|
|
- {
|
|
|
|
- CommandView.Dispose ();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (HelpView?.IsAdded == false)
|
|
|
|
- {
|
|
|
|
- HelpView.Dispose ();
|
|
|
|
- }
|
|
|
|
|
|
+ CommandView.Dispose ();
|
|
|
|
+ }
|
|
|
|
|
|
- if (KeyView?.IsAdded == false)
|
|
|
|
- {
|
|
|
|
- KeyView.Dispose ();
|
|
|
|
- }
|
|
|
|
|
|
+ if (HelpView?.IsAdded == false)
|
|
|
|
+ {
|
|
|
|
+ HelpView.Dispose ();
|
|
}
|
|
}
|
|
|
|
|
|
- base.Dispose (disposing);
|
|
|
|
|
|
+ if (KeyView?.IsAdded == false)
|
|
|
|
+ {
|
|
|
|
+ KeyView.Dispose ();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ base.Dispose (disposing);
|
|
|
|
+}
|
|
}
|
|
}
|