|
@@ -1,10 +1,8 @@
|
|
-using System.ComponentModel;
|
|
|
|
-using System.Threading.Channels;
|
|
|
|
-
|
|
|
|
-namespace Terminal.Gui;
|
|
|
|
|
|
+namespace Terminal.Gui;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
-/// Displays a command, help text, and a key binding. When the key specified by <see cref="Key"/> is pressed, the command will be invoked. Useful for
|
|
|
|
|
|
+/// Displays a command, help text, and a key binding. When the key specified by <see cref="Key"/> is pressed, the
|
|
|
|
+/// command will be invoked. Useful for
|
|
/// displaying a command in <see cref="Bar"/> such as a
|
|
/// displaying a command in <see cref="Bar"/> such as a
|
|
/// menu, toolbar, or status bar.
|
|
/// menu, toolbar, or status bar.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -12,12 +10,13 @@ namespace Terminal.Gui;
|
|
/// <para>
|
|
/// <para>
|
|
/// The following user actions will invoke the <see cref="Command.Accept"/>, causing the
|
|
/// The following user actions will invoke the <see cref="Command.Accept"/>, causing the
|
|
/// <see cref="View.Accept"/> event to be fired:
|
|
/// <see cref="View.Accept"/> event to be fired:
|
|
-/// - Clicking on the <see cref="Shortcut"/>.
|
|
|
|
-/// - Pressing the key specified by <see cref="Key"/>.
|
|
|
|
-/// - Pressing the HotKey specified by <see cref="CommandView"/>.
|
|
|
|
|
|
+/// - Clicking on the <see cref="Shortcut"/>.
|
|
|
|
+/// - Pressing the key specified by <see cref="Key"/>.
|
|
|
|
+/// - Pressing the HotKey specified by <see cref="CommandView"/>.
|
|
/// </para>
|
|
/// </para>
|
|
/// <para>
|
|
/// <para>
|
|
-/// If <see cref="KeyBindingScope"/> is <see cref="KeyBindingScope.Application"/>, <see cref="Key"/> will invoked <see cref="Command.Accept"/>
|
|
|
|
|
|
+/// If <see cref="KeyBindingScope"/> is <see cref="KeyBindingScope.Application"/>, <see cref="Key"/> will invoked
|
|
|
|
+/// <see cref="Command.Accept"/>
|
|
/// command regardless of what View has focus, enabling an application-wide keyboard shortcut.
|
|
/// command regardless of what View has focus, enabling an application-wide keyboard shortcut.
|
|
/// </para>
|
|
/// </para>
|
|
/// <para>
|
|
/// <para>
|
|
@@ -37,8 +36,10 @@ namespace Terminal.Gui;
|
|
/// If the <see cref="Key"/> is <see cref="Key.Empty"/>, the <see cref="Key"/> text is not displayed.
|
|
/// If the <see cref="Key"/> is <see cref="Key.Empty"/>, the <see cref="Key"/> text is not displayed.
|
|
/// </para>
|
|
/// </para>
|
|
/// </remarks>
|
|
/// </remarks>
|
|
-public class Shortcut : View
|
|
|
|
|
|
+public class Shortcut : View, IOrientation, IDesignable
|
|
{
|
|
{
|
|
|
|
+ private readonly OrientationHelper _orientationHelper;
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Creates a new instance of <see cref="Shortcut"/>.
|
|
/// Creates a new instance of <see cref="Shortcut"/>.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -60,6 +61,10 @@ public class Shortcut : View
|
|
Width = GetWidthDimAuto ();
|
|
Width = GetWidthDimAuto ();
|
|
Height = Dim.Auto (DimAutoStyle.Content, 1);
|
|
Height = Dim.Auto (DimAutoStyle.Content, 1);
|
|
|
|
|
|
|
|
+ _orientationHelper = new (this);
|
|
|
|
+ _orientationHelper.OrientationChanging += (sender, e) => OrientationChanging?.Invoke (this, e);
|
|
|
|
+ _orientationHelper.OrientationChanged += (sender, e) => OrientationChanged?.Invoke (this, e);
|
|
|
|
+
|
|
AddCommand (Command.HotKey, ctx => OnAccept (ctx));
|
|
AddCommand (Command.HotKey, ctx => OnAccept (ctx));
|
|
AddCommand (Command.Accept, ctx => OnAccept (ctx));
|
|
AddCommand (Command.Accept, ctx => OnAccept (ctx));
|
|
AddCommand (Command.Select, ctx => OnSelect (ctx));
|
|
AddCommand (Command.Select, ctx => OnSelect (ctx));
|
|
@@ -132,31 +137,48 @@ public class Shortcut : View
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Creates a new instance of <see cref="Shortcut"/>.
|
|
/// Creates a new instance of <see cref="Shortcut"/>.
|
|
/// </summary>
|
|
/// </summary>
|
|
public Shortcut () : this (Key.Empty, string.Empty, null) { }
|
|
public Shortcut () : this (Key.Empty, string.Empty, null) { }
|
|
|
|
|
|
- private Orientation _orientation = Orientation.Horizontal;
|
|
|
|
|
|
+ #region IOrientation members
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Gets or sets the <see cref="Orientation"/> for this <see cref="Shortcut"/>. The default is
|
|
|
|
- /// <see cref="Orientation.Horizontal"/>, which is ideal for status bar, menu bar, and tool bar items If set to
|
|
|
|
- /// <see cref="Orientation.Vertical"/>,
|
|
|
|
- /// the Shortcut will be configured for vertical layout, which is ideal for menu items.
|
|
|
|
|
|
+ /// Gets or sets the <see cref="Orientation"/> for this <see cref="Bar"/>. The default is
|
|
|
|
+ /// <see cref="Orientation.Horizontal"/>.
|
|
/// </summary>
|
|
/// </summary>
|
|
|
|
+ /// <remarks>
|
|
|
|
+ /// <para>
|
|
|
|
+ /// Horizontal orientation arranges the command, help, and key parts of each <see cref="Shortcut"/>s from right to
|
|
|
|
+ /// left
|
|
|
|
+ /// Vertical orientation arranges the command, help, and key parts of each <see cref="Shortcut"/>s from left to
|
|
|
|
+ /// right.
|
|
|
|
+ /// </para>
|
|
|
|
+ /// </remarks>
|
|
|
|
+
|
|
public Orientation Orientation
|
|
public Orientation Orientation
|
|
{
|
|
{
|
|
- get => _orientation;
|
|
|
|
- set
|
|
|
|
- {
|
|
|
|
- _orientation = value;
|
|
|
|
|
|
+ get => _orientationHelper.Orientation;
|
|
|
|
+ set => _orientationHelper.Orientation = value;
|
|
|
|
+ }
|
|
|
|
|
|
- // TODO: Determine what, if anything, is opinionated about the orientation.
|
|
|
|
- }
|
|
|
|
|
|
+ /// <inheritdoc/>
|
|
|
|
+ public event EventHandler<CancelEventArgs<Orientation>> OrientationChanging;
|
|
|
|
+
|
|
|
|
+ /// <inheritdoc/>
|
|
|
|
+ public event EventHandler<EventArgs<Orientation>> OrientationChanged;
|
|
|
|
+
|
|
|
|
+ /// <summary>Called when <see cref="Orientation"/> has changed.</summary>
|
|
|
|
+ /// <param name="newOrientation"></param>
|
|
|
|
+ public void OnOrientationChanged (Orientation newOrientation)
|
|
|
|
+ {
|
|
|
|
+ // TODO: Determine what, if anything, is opinionated about the orientation.
|
|
|
|
+ SetNeedsLayout ();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #endregion
|
|
|
|
+
|
|
private AlignmentModes _alignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast;
|
|
private AlignmentModes _alignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -344,7 +366,6 @@ public class Shortcut : View
|
|
private void Subview_MouseClick (object sender, MouseEventEventArgs e)
|
|
private void Subview_MouseClick (object sender, MouseEventEventArgs e)
|
|
{
|
|
{
|
|
// TODO: Remove. This does nothing.
|
|
// TODO: Remove. This does nothing.
|
|
- return;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
#region Command
|
|
#region Command
|
|
@@ -434,8 +455,6 @@ public class Shortcut : View
|
|
SetKeyViewDefaultLayout ();
|
|
SetKeyViewDefaultLayout ();
|
|
ShowHide ();
|
|
ShowHide ();
|
|
UpdateKeyBinding ();
|
|
UpdateKeyBinding ();
|
|
-
|
|
|
|
- return;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -475,38 +494,38 @@ public class Shortcut : View
|
|
HelpView.VerticalTextAlignment = Alignment.Center;
|
|
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
|
|
|
|
-{
|
|
|
|
- get => HelpView?.Text;
|
|
|
|
- set
|
|
|
|
|
|
+ /// <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
|
|
{
|
|
{
|
|
- if (HelpView is {})
|
|
|
|
|
|
+ get => HelpView?.Text;
|
|
|
|
+ set
|
|
{
|
|
{
|
|
- HelpView.Text = value;
|
|
|
|
- ShowHide ();
|
|
|
|
|
|
+ if (HelpView is { })
|
|
|
|
+ {
|
|
|
|
+ HelpView.Text = value;
|
|
|
|
+ ShowHide ();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
|
|
-/// <summary>
|
|
|
|
-/// Gets or sets the help text displayed in the middle of the Shortcut.
|
|
|
|
-/// </summary>
|
|
|
|
-public string HelpText
|
|
|
|
-{
|
|
|
|
- get => HelpView?.Text;
|
|
|
|
- set
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Gets or sets the help text displayed in the middle of the Shortcut.
|
|
|
|
+ /// </summary>
|
|
|
|
+ public string HelpText
|
|
{
|
|
{
|
|
- if (HelpView is {})
|
|
|
|
|
|
+ get => HelpView?.Text;
|
|
|
|
+ set
|
|
{
|
|
{
|
|
- HelpView.Text = value;
|
|
|
|
- ShowHide ();
|
|
|
|
|
|
+ if (HelpView is { })
|
|
|
|
+ {
|
|
|
|
+ HelpView.Text = value;
|
|
|
|
+ ShowHide ();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
|
|
#endregion Help
|
|
#endregion Help
|
|
|
|
|
|
@@ -561,7 +580,7 @@ public string HelpText
|
|
private int _minimumKeyTextSize;
|
|
private int _minimumKeyTextSize;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Gets or sets the minimum size of the key text. Useful for aligning the key text with other <see cref="Shortcut"/>s.
|
|
|
|
|
|
+ /// Gets or sets the minimum size of the key text. Useful for aligning the key text with other <see cref="Shortcut"/>s.
|
|
/// </summary>
|
|
/// </summary>
|
|
public int MinimumKeyTextSize
|
|
public int MinimumKeyTextSize
|
|
{
|
|
{
|
|
@@ -675,6 +694,7 @@ public string HelpText
|
|
if (Action is { })
|
|
if (Action is { })
|
|
{
|
|
{
|
|
Action.Invoke ();
|
|
Action.Invoke ();
|
|
|
|
+
|
|
// Assume if there's a subscriber to Action, it's handled.
|
|
// Assume if there's a subscriber to Action, it's handled.
|
|
cancel = true;
|
|
cancel = true;
|
|
}
|
|
}
|
|
@@ -700,11 +720,10 @@ public string HelpText
|
|
{
|
|
{
|
|
return CommandView.InvokeCommand (Command.Select, ctx.Key, ctx.KeyBinding);
|
|
return CommandView.InvokeCommand (Command.Select, ctx.Key, ctx.KeyBinding);
|
|
}
|
|
}
|
|
- return false;
|
|
|
|
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
#region Focus
|
|
#region Focus
|
|
|
|
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
@@ -753,7 +772,8 @@ public string HelpText
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- View _lastFocusedView;
|
|
|
|
|
|
+ private View _lastFocusedView;
|
|
|
|
+
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
public override bool OnEnter (View view)
|
|
public override bool OnEnter (View view)
|
|
{
|
|
{
|
|
@@ -774,6 +794,16 @@ public string HelpText
|
|
|
|
|
|
#endregion Focus
|
|
#endregion Focus
|
|
|
|
|
|
|
|
+ /// <inheritdoc/>
|
|
|
|
+ public bool EnableForDesign ()
|
|
|
|
+ {
|
|
|
|
+ Title = "_Shortcut";
|
|
|
|
+ HelpText = "Shortcut help";
|
|
|
|
+ Key = Key.F1;
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
protected override void Dispose (bool disposing)
|
|
protected override void Dispose (bool disposing)
|
|
{
|
|
{
|