123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845 |
- #nullable enable
- using System.ComponentModel;
- namespace Terminal.Gui;
- /// <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
- /// displaying a command in <see cref="Bar"/> such as a
- /// menu, toolbar, or status bar.
- /// </summary>
- /// <remarks>
- /// <para>
- /// The following user actions will invoke the <see cref="Command.Accept"/>, causing the
- /// <see cref="View.Accepting"/> 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"/>.
- /// </para>
- /// <para>
- /// If <see cref="BindKeyToApplication"/> is <see langword="true"/>, <see cref="Key"/> will invoke
- /// <see cref="Command.Accept"/>
- /// regardless of what View has focus, enabling an application-wide keyboard shortcut.
- /// </para>
- /// <para>
- /// By default, a Shortcut displays the command text on the left side, the help text in the middle, and the key
- /// binding on the
- /// right side. Set <see cref="AlignmentModes"/> to <see cref="AlignmentModes.EndToStart"/> to reverse the order.
- /// </para>
- /// <para>
- /// The command text can be set by setting the <see cref="CommandView"/>'s Text property or by setting
- /// <see cref="View.Title"/>.
- /// </para>
- /// <para>
- /// The help text can be set by setting the <see cref="HelpText"/> property or by setting <see cref="View.Text"/>.
- /// </para>
- /// <para>
- /// The key text is set by setting the <see cref="Key"/> property.
- /// If the <see cref="Key"/> is <see cref="Key.Empty"/>, the <see cref="Key"/> text is not displayed.
- /// </para>
- /// </remarks>
- public class Shortcut : View, IOrientation, IDesignable
- {
- /// <summary>
- /// Creates a new instance of <see cref="Shortcut"/>.
- /// </summary>
- public Shortcut () : this (Key.Empty, null, null, null) { }
- /// <summary>
- /// Creates a new instance of <see cref="Shortcut"/>, binding it to <paramref name="targetView"/> and
- /// <paramref name="command"/>. The Key <paramref name="targetView"/>
- /// has bound to <paramref name="command"/> will be used as <see cref="Key"/>.
- /// </summary>
- /// <remarks>
- /// <para>
- /// This is a helper API that simplifies creation of multiple Shortcuts when adding them to <see cref="Bar"/>-based
- /// objects, like <see cref="MenuBarv2"/>.
- /// </para>
- /// </remarks>
- /// <param name="targetView">
- /// The View that <paramref name="command"/> will be invoked on when user does something that causes the Shortcut's Accept
- /// event to be raised.
- /// </param>
- /// <param name="command">
- /// The Command to invoke on <paramref name="targetView"/>. The Key <paramref name="targetView"/>
- /// has bound to <paramref name="command"/> will be used as <see cref="Key"/>
- /// </param>
- /// <param name="commandText">The text to display for the command.</param>
- /// <param name="helpText">The help text to display.</param>
- public Shortcut (View targetView, Command command, string commandText, string? helpText = null)
- : this (
- targetView?.HotKeyBindings.GetFirstFromCommands (command)!,
- commandText,
- null,
- helpText)
- {
- _targetView = targetView;
- Command = command;
- }
- /// <summary>
- /// Creates a new instance of <see cref="Shortcut"/>.
- /// </summary>
- /// <remarks>
- /// <para>
- /// This is a helper API that mimics the V1 API for creating StatusItems.
- /// </para>
- /// </remarks>
- /// <param name="key"></param>
- /// <param name="commandText">The text to display for the command.</param>
- /// <param name="action"></param>
- /// <param name="helpText">The help text to display.</param>
- public Shortcut (Key key, string? commandText, Action? action, string? helpText = null)
- {
- Id = $"shortcut:{commandText}";
- HighlightStyle = HighlightStyle.None;
- CanFocus = true;
- if (Border is { })
- {
- Border.Settings &= ~BorderSettings.Title;
- }
- Width = GetWidthDimAuto ();
- 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);
- AddCommands ();
- TitleChanged += Shortcut_TitleChanged; // This needs to be set before CommandView is set
- CommandView = new ()
- {
- Id = "CommandView",
- Width = Dim.Auto (),
- Height = Dim.Fill ()
- };
- Title = commandText ?? string.Empty;
- HelpView.Id = "_helpView";
- HelpView.CanFocus = false;
- HelpView.Text = helpText ?? string.Empty;
- KeyView.Id = "_keyView";
- KeyView.CanFocus = false;
- key ??= Key.Empty;
- Key = key;
- Action = action;
- SubViewLayout += OnLayoutStarted;
- ShowHide ();
- }
- // Helper to set Width consistently
- internal Dim GetWidthDimAuto ()
- {
- return Dim.Auto (
- DimAutoStyle.Content,
- minimumContentDim: Dim.Func (() => _minimumNaturalWidth ?? 0),
- maximumContentDim: Dim.Func (() => _minimumNaturalWidth ?? 0))!;
- }
- private AlignmentModes _alignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast;
- // This is used to calculate the minimum width of the Shortcut when Width is NOT Dim.Auto
- // It is calculated by setting Width to DimAuto temporarily and forcing layout.
- // Once Frame.Width gets below this value, LayoutStarted makes HelpView an KeyView smaller.
- private int? _minimumNaturalWidth;
- /// <inheritdoc/>
- protected override bool OnHighlight (CancelEventArgs<HighlightStyle> args)
- {
- if (args.NewValue.HasFlag (HighlightStyle.Hover))
- {
- HasFocus = true;
- }
- return true;
- }
- /// <summary>
- /// Gets or sets the <see cref="AlignmentModes"/> for this <see cref="Shortcut"/>.
- /// </summary>
- /// <remarks>
- /// <para>
- /// The default is <see cref="AlignmentModes.StartToEnd"/>. This means that the CommandView will be on the left,
- /// HelpView in the middle, and KeyView on the right.
- /// </para>
- /// </remarks>
- public AlignmentModes AlignmentModes
- {
- get => _alignmentModes;
- set
- {
- _alignmentModes = value;
- SetCommandViewDefaultLayout ();
- SetHelpViewDefaultLayout ();
- SetKeyViewDefaultLayout ();
- }
- }
- // When one of the subviews is "empty" we don't want to show it. So we
- // Use Add/Remove. We need to be careful to add them in the right order
- // so Pos.Align works correctly.
- internal void ShowHide ()
- {
- RemoveAll ();
- if (CommandView.Visible)
- {
- Add (CommandView);
- SetCommandViewDefaultLayout ();
- }
- if (HelpView.Visible && !string.IsNullOrEmpty (HelpView.Text))
- {
- Add (HelpView);
- SetHelpViewDefaultLayout ();
- }
- if (KeyView.Visible && Key != Key.Empty)
- {
- Add (KeyView);
- SetKeyViewDefaultLayout ();
- }
- SetColors ();
- }
- // Force Width to DimAuto to calculate natural width and then set it back
- private void ForceCalculateNaturalWidth ()
- {
- // Get the natural size of each subview
- CommandView.SetRelativeLayout (Application.Screen.Size);
- HelpView.SetRelativeLayout (Application.Screen.Size);
- KeyView.SetRelativeLayout (Application.Screen.Size);
- _minimumNaturalWidth = PosAlign.CalculateMinDimension (0, SubViews, Dimension.Width);
- // Reset our relative layout
- SetRelativeLayout (SuperView?.GetContentSize () ?? Application.Screen.Size);
- }
- // TODO: Enable setting of the margin thickness
- private Thickness GetMarginThickness ()
- {
- return new (1, 0, 1, 0);
- }
- // When layout starts, we need to adjust the layout of the HelpView and KeyView
- private void OnLayoutStarted (object? sender, LayoutEventArgs e)
- {
- ShowHide ();
- ForceCalculateNaturalWidth ();
- if (Width is DimAuto widthAuto || HelpView!.Margin is null)
- {
- return;
- }
- // Frame.Width is smaller than the natural width. Reduce width of HelpView.
- _maxHelpWidth = int.Max (0, GetContentSize ().Width - CommandView.Frame.Width - KeyView.Frame.Width);
- if (_maxHelpWidth < 3)
- {
- Thickness t = GetMarginThickness ();
- switch (_maxHelpWidth)
- {
- case 0:
- case 1:
- // Scrunch it by removing both margins
- HelpView.Margin.Thickness = new (t.Right - 1, t.Top, t.Left - 1, t.Bottom);
- break;
- case 2:
- // Scrunch just the right margin
- HelpView.Margin.Thickness = new (t.Right, t.Top, t.Left - 1, t.Bottom);
- break;
- }
- }
- else
- {
- // Reset to default
- HelpView.Margin.Thickness = GetMarginThickness ();
- }
- }
- #region Accept/Select/HotKey Command Handling
- private readonly View? _targetView; // If set, _command will be invoked
- /// <summary>
- /// Gets the target <see cref="View"/> that the <see cref="Command"/> will be invoked on.
- /// </summary>
- public View? TargetView => _targetView;
- /// <summary>
- /// Gets the <see cref="Command"/> that will be invoked on <see cref="TargetView"/> when the Shortcut is activated.
- /// </summary>
- public Command Command { get; }
- private void AddCommands ()
- {
- // Accept (Enter key) -
- AddCommand (Command.Accept, DispatchCommand);
- // Hotkey -
- AddCommand (Command.HotKey, DispatchCommand);
- // Select (Space key or click) -
- AddCommand (Command.Select, DispatchCommand);
- }
- private bool? DispatchCommand (ICommandContext? commandContext)
- {
- CommandContext<KeyBinding>? keyCommandContext = commandContext is CommandContext<KeyBinding> ? (CommandContext<KeyBinding>)commandContext : default;
- if (keyCommandContext?.Binding.Data != this)
- {
- // Invoke Select on the command view to cause it to change state if it wants to
- // If this causes CommandView to raise Accept, we eat it
- keyCommandContext = keyCommandContext!.Value with { Binding = keyCommandContext.Value.Binding with { Data = this } };
- CommandView.InvokeCommand (Command.Select, keyCommandContext);
- }
- if (RaiseSelecting (keyCommandContext) is true)
- {
- return true;
- }
- // The default HotKey handler sets Focus
- SetFocus ();
- var cancel = false;
- cancel = RaiseAccepting (commandContext) is true;
- if (cancel)
- {
- return true;
- }
- if (commandContext?.Command != Command.Accept)
- {
- // return false;
- }
- if (Action is { })
- {
- Action.Invoke ();
- // Assume if there's a subscriber to Action, it's handled.
- cancel = true;
- }
- if (_targetView is { })
- {
- _targetView.InvokeCommand (Command, commandContext);
- }
- return cancel;
- }
- /// <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.Accepting"/> event is fired first, and if cancelled, the event will not be invoked.
- /// </remarks>
- public Action? Action { get; set; }
- #endregion Accept/Select/HotKey Command Handling
- #region IOrientation members
- private readonly OrientationHelper _orientationHelper;
- /// <summary>
- /// Gets or sets the <see cref="Orientation"/> for this <see cref="Bar"/>. The default is
- /// <see cref="Orientation.Horizontal"/>.
- /// </summary>
- /// <remarks>
- /// </remarks>
- public Orientation Orientation
- {
- get => _orientationHelper.Orientation;
- set => _orientationHelper.Orientation = value;
- }
- /// <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
- #region Command
- private View _commandView = new ();
- /// <summary>
- /// Gets or sets the View that displays the command text and hotkey.
- /// </summary>
- /// <exception cref="ArgumentNullException"></exception>
- /// <remarks>
- /// <para>
- /// By default, the <see cref="View.Title"/> of the <see cref="CommandView"/> is displayed as the Shortcut's
- /// command text.
- /// </para>
- /// <para>
- /// By default, the CommandView is a <see cref="View"/> with <see cref="View.CanFocus"/> set to
- /// <see langword="false"/>.
- /// </para>
- /// <para>
- /// Setting the <see cref="CommandView"/> will add it to the <see cref="Shortcut"/> and remove any existing
- /// <see cref="CommandView"/>.
- /// </para>
- /// </remarks>
- /// <example>
- /// <para>
- /// This example illustrates how to add a <see cref="Shortcut"/> to a <see cref="StatusBar"/> that toggles the
- /// <see cref="Application.Force16Colors"/> property.
- /// </para>
- /// <code>
- /// var force16ColorsShortcut = new Shortcut
- /// {
- /// Key = Key.F6,
- /// KeyBindingScope = KeyBindingScope.HotKey,
- /// CommandView = new CheckBox { Text = "Force 16 Colors" }
- /// };
- /// var cb = force16ColorsShortcut.CommandView as CheckBox;
- /// cb.Checked = Application.Force16Colors;
- ///
- /// cb.Toggled += (s, e) =>
- /// {
- /// var cb = s as CheckBox;
- /// Application.Force16Colors = cb!.Checked == true;
- /// Application.Refresh();
- /// };
- /// StatusBar.Add(force16ColorsShortcut);
- /// </code>
- /// </example>
- public View CommandView
- {
- get => _commandView;
- set
- {
- ArgumentNullException.ThrowIfNull (value);
- if (value == null)
- {
- throw new ArgumentNullException ();
- }
- // Clean up old
- _commandView.Selecting -= CommandViewOnSelecting;
- _commandView.Accepting -= CommandViewOnAccepted;
- Remove (_commandView);
- _commandView?.Dispose ();
- // Set new
- _commandView = value;
- _commandView.Id = "_commandView";
- // The default behavior is for CommandView to not get focus. I
- // If you want it to get focus, you need to set it.
- _commandView.CanFocus = false;
- _commandView.HotKeyChanged += (s, e) =>
- {
- if (e.NewKey != Key.Empty)
- {
- // Add it
- AddKeyBindingsForHotKey (e.OldKey, e.NewKey);
- }
- };
- _commandView.HotKeySpecifier = new ('_');
- Title = _commandView.Text;
- _commandView.Selecting += CommandViewOnSelecting;
- _commandView.Accepting += CommandViewOnAccepted;
- //ShowHide ();
- UpdateKeyBindings (Key.Empty);
- return;
- void CommandViewOnAccepted (object? sender, CommandEventArgs e)
- {
- // Always eat CommandView.Accept
- e.Cancel = true;
- }
- void CommandViewOnSelecting (object? sender, CommandEventArgs e)
- {
- if ((e.Context is CommandContext<KeyBinding> keyCommandContext && keyCommandContext.Binding.Data != this) ||
- e.Context is CommandContext<MouseBinding>)
- {
- // Forward command to ourselves
- InvokeCommand<KeyBinding> (Command.Select, new ([Command.Select], null, this));
- }
- // BUGBUG: This prevents NumericUpDown on statusbar in HexEditor from working
- e.Cancel = true;
- }
- }
- }
- private void SetCommandViewDefaultLayout ()
- {
- if (CommandView.Margin is { })
- {
- CommandView.Margin.Thickness = GetMarginThickness ();
- }
- CommandView.X = Pos.Align (Alignment.End, AlignmentModes);
- CommandView.VerticalTextAlignment = Alignment.Center;
- CommandView.TextAlignment = Alignment.Start;
- CommandView.TextFormatter.WordWrap = false;
- CommandView.HighlightStyle = HighlightStyle.None;
- }
- private void Shortcut_TitleChanged (object? sender, EventArgs<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
- #region Help
- // The maximum width of the HelpView. Calculated in OnLayoutStarted and used in HelpView.Width (Dim.Auto/Func).
- private int _maxHelpWidth = 0;
- /// <summary>
- /// The subview that displays the help text for the command. Internal for unit testing.
- /// </summary>
- public View HelpView { get; } = new ();
- private void SetHelpViewDefaultLayout ()
- {
- if (HelpView.Margin is { })
- {
- HelpView.Margin.Thickness = GetMarginThickness ();
- }
- HelpView.X = Pos.Align (Alignment.End, AlignmentModes);
- _maxHelpWidth = HelpView.Text.GetColumns ();
- HelpView.Width = Dim.Auto (DimAutoStyle.Text, maximumContentDim: Dim.Func ((() => _maxHelpWidth)));
- HelpView.Height = Dim.Fill ();
- HelpView.Visible = true;
- HelpView.VerticalTextAlignment = Alignment.Center;
- HelpView.TextAlignment = Alignment.Start;
- HelpView.TextFormatter.WordWrap = false;
- HelpView.HighlightStyle = HighlightStyle.None;
- }
- /// <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
- {
- 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
- {
- HelpView.Text = value;
- ShowHide ();
- }
- }
- #endregion Help
- #region Key
- 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
- {
- get => _key;
- set
- {
- ArgumentNullException.ThrowIfNull (value);
- Key oldKey = _key;
- _key = value;
- UpdateKeyBindings (oldKey);
- KeyView.Text = Key == Key.Empty ? string.Empty : $"{Key}";
- ShowHide ();
- }
- }
- private bool _bindKeyToApplication = false;
- /// <summary>
- /// Gets or sets whether <see cref="Key"/> is bound to <see cref="Command"/> via <see cref="View.HotKeyBindings"/> or <see cref="Application.KeyBindings"/>.
- /// </summary>
- public bool BindKeyToApplication
- {
- get => _bindKeyToApplication;
- set
- {
- if (value == _bindKeyToApplication)
- {
- return;
- }
- if (_bindKeyToApplication)
- {
- Application.KeyBindings.Remove (Key);
- }
- else
- {
- HotKeyBindings.Remove (Key);
- }
- _bindKeyToApplication = value;
- UpdateKeyBindings (Key.Empty);
- }
- }
- /// <summary>
- /// Gets the subview that displays the key. Internal for unit testing.
- /// </summary>
- public View KeyView { get; } = new ();
- 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
- {
- get => _minimumKeyTextSize;
- set
- {
- if (value == _minimumKeyTextSize)
- {
- //return;
- }
- _minimumKeyTextSize = value;
- SetKeyViewDefaultLayout ();
- //// TODO: Prob not needed
- //CommandView.SetNeedsLayout ();
- //HelpView.SetNeedsLayout ();
- //KeyView.SetNeedsLayout ();
- //SetSubViewNeedsDraw ();
- }
- }
- private void SetKeyViewDefaultLayout ()
- {
- if (KeyView.Margin is { })
- {
- KeyView.Margin.Thickness = GetMarginThickness ();
- }
- KeyView.X = Pos.Align (Alignment.End, AlignmentModes);
- KeyView.Width = Dim.Auto (DimAutoStyle.Text, minimumContentDim: Dim.Func (() => MinimumKeyTextSize));
- KeyView.Height = Dim.Fill ();
- KeyView.Visible = true;
- // Right align the text in the keyview
- KeyView.TextAlignment = Alignment.End;
- KeyView.VerticalTextAlignment = Alignment.Center;
- KeyView.KeyBindings.Clear ();
- HelpView.HighlightStyle = HighlightStyle.None;
- }
- private void UpdateKeyBindings (Key oldKey)
- {
- if (Key.IsValid)
- {
- if (BindKeyToApplication)
- {
- if (oldKey != Key.Empty)
- {
- Application.KeyBindings.Remove (oldKey);
- }
- Application.KeyBindings.Remove (Key);
- Application.KeyBindings.Add (Key, this, Command.HotKey);
- }
- else
- {
- if (oldKey != Key.Empty)
- {
- HotKeyBindings.Remove (oldKey);
- }
- HotKeyBindings.Remove (Key);
- HotKeyBindings.Add (Key, Command.HotKey);
- }
- }
- }
- #endregion Key
- #region Focus
- /// <inheritdoc/>
- public override ColorScheme? ColorScheme
- {
- get => base.ColorScheme;
- set
- {
- base.ColorScheme = _nonFocusColorScheme = value;
- SetColors ();
- }
- }
- private ColorScheme? _nonFocusColorScheme;
- /// <summary>
- /// </summary>
- internal void SetColors (bool highlight = false)
- {
- if (HasFocus || highlight)
- {
- if (_nonFocusColorScheme is null)
- {
- _nonFocusColorScheme = base.ColorScheme;
- }
- base.ColorScheme ??= new (Attribute.Default);
- // 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 (_nonFocusColorScheme is { })
- {
- base.ColorScheme = _nonFocusColorScheme;
- //_nonFocusColorScheme = null;
- }
- else
- {
- base.ColorScheme = SuperView?.ColorScheme ?? base.ColorScheme;
- }
- }
- // Set KeyView's colors to show "hot"
- if (IsInitialized && base.ColorScheme is { })
- {
- var cs = new ColorScheme (base.ColorScheme)
- {
- Normal = base.ColorScheme.HotNormal,
- HotNormal = base.ColorScheme.Normal
- };
- KeyView.ColorScheme = cs;
- }
- if (CommandView.Margin is { })
- {
- CommandView.Margin.ColorScheme = base.ColorScheme;
- }
- if (HelpView.Margin is { })
- {
- HelpView.Margin.ColorScheme = base.ColorScheme;
- }
- if (KeyView.Margin is { })
- {
- KeyView.Margin.ColorScheme = base.ColorScheme;
- }
- }
- /// <inheritdoc/>
- protected override void OnHasFocusChanged (bool newHasFocus, View? previousFocusedView, View? view) { SetColors (); }
- #endregion Focus
- /// <inheritdoc/>
- public bool EnableForDesign ()
- {
- Title = "_Shortcut";
- HelpText = "Shortcut help";
- Key = Key.F1;
- return true;
- }
- /// <inheritdoc/>
- protected override void Dispose (bool disposing)
- {
- if (disposing)
- {
- TitleChanged -= Shortcut_TitleChanged;
- if (CommandView.SuperView is null)
- {
- CommandView.Dispose ();
- }
- if (HelpView.SuperView is null)
- {
- HelpView.Dispose ();
- }
- if (KeyView.SuperView is null)
- {
- KeyView.Dispose ();
- }
- }
- base.Dispose (disposing);
- }
- }
|