Explorar o código

StatusBar conversion progress.
Fixed CSvEditor

Tig hai 1 ano
pai
achega
9e6a00bf3a

+ 84 - 23
Terminal.Gui/Views/Bar.cs

@@ -12,7 +12,10 @@ namespace Terminal.Gui;
 public class Bar : View
 public class Bar : View
 {
 {
     /// <inheritdoc/>
     /// <inheritdoc/>
-    public Bar ()
+    public Bar () : this ([]) { }
+
+    /// <inheritdoc />
+    public Bar (IEnumerable<Shortcut> shortcuts)
     {
     {
         CanFocus = true;
         CanFocus = true;
 
 
@@ -23,12 +26,16 @@ public class Bar : View
 
 
         Initialized += Bar_Initialized;
         Initialized += Bar_Initialized;
 
 
+        foreach (Shortcut shortcut in shortcuts)
+        {
+            Add (shortcut);
+        }
     }
     }
 
 
     private void Bar_Initialized (object sender, EventArgs e)
     private void Bar_Initialized (object sender, EventArgs e)
     {
     {
         ColorScheme = Colors.ColorSchemes ["Menu"];
         ColorScheme = Colors.ColorSchemes ["Menu"];
-        AdjustSubviewBorders();
+        AdjustSubviewBorders ();
     }
     }
 
 
     /// <inheritdoc />
     /// <inheritdoc />
@@ -44,7 +51,10 @@ public class Bar : View
     /// </summary>
     /// </summary>
     public Orientation Orientation { get; set; } = Orientation.Horizontal;
     public Orientation Orientation { get; set; } = Orientation.Horizontal;
 
 
-
+    /// <summary>
+    ///      Gets or sets the <see cref="AlignmentModes"/> for this <see cref="Bar"/>. The default is <see cref="AlignmentModes.StartToEnd"/>.
+    /// </summary>
+    public AlignmentModes AlignmentModes { get; set; } = AlignmentModes.StartToEnd;
 
 
     public bool StatusBarStyle { get; set; } = true;
     public bool StatusBarStyle { get; set; } = true;
 
 
@@ -52,7 +62,6 @@ public class Bar : View
     {
     {
         base.Add (view);
         base.Add (view);
         AdjustSubviewBorders ();
         AdjustSubviewBorders ();
-
     }
     }
 
 
     /// <inheritdoc />
     /// <inheritdoc />
@@ -62,6 +71,49 @@ public class Bar : View
         AdjustSubviewBorders ();
         AdjustSubviewBorders ();
     }
     }
 
 
+
+    /// <summary>Inserts a <see cref="Shortcut"/> in the specified index of <see cref="Items"/>.</summary>
+    /// <param name="index">The zero-based index at which item should be inserted.</param>
+    /// <param name="item">The item to insert.</param>
+    public void AddShortcutAt (int index, Shortcut item)
+    {
+        List<View> savedSubViewList = Subviews.ToList ();
+        int count = savedSubViewList.Count;
+        RemoveAll ();
+        for (int i = 0; i < count; i++)
+        {
+            if (i == index)
+            {
+                Add (item);
+            }
+            Add (savedSubViewList [i]);
+        }
+        SetNeedsDisplay ();
+    }
+
+    /// <summary>Removes a <see cref="Shortcut"/> at specified index of <see cref="Items"/>.</summary>
+    /// <param name="index">The zero-based index of the item to remove.</param>
+    /// <returns>The <see cref="Shortcut"/> removed.</returns>
+    public Shortcut RemoveShortcut (int index)
+    {
+        View toRemove = null;
+        for (int i = 0; i < Subviews.Count; i++)
+        {
+            if (i == index)
+            {
+                toRemove = Subviews [i];
+            }
+        }
+
+        if (toRemove is { })
+        {
+            Remove (toRemove);
+            SetNeedsDisplay ();
+        }
+
+        return toRemove as Shortcut;
+    }
+
     private void AdjustSubviewBorders ()
     private void AdjustSubviewBorders ()
     {
     {
         for (var index = 0; index < Subviews.Count; index++)
         for (var index = 0; index < Subviews.Count; index++)
@@ -72,7 +124,6 @@ public class Bar : View
             barItem.SuperViewRendersLineCanvas = true;
             barItem.SuperViewRendersLineCanvas = true;
             barItem.ColorScheme = ColorScheme;
             barItem.ColorScheme = ColorScheme;
 
 
-
             if (!barItem.Visible)
             if (!barItem.Visible)
             {
             {
                 continue;
                 continue;
@@ -80,18 +131,20 @@ public class Bar : View
 
 
             if (StatusBarStyle)
             if (StatusBarStyle)
             {
             {
-                if (index == 0)
-                {
-                    barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
-                } 
+                barItem.BorderStyle = LineStyle.Dashed;
 
 
                 if (index == Subviews.Count - 1)
                 if (index == Subviews.Count - 1)
                 {
                 {
                     barItem.Border.Thickness = new Thickness (0, 0, 0, 0);
                     barItem.Border.Thickness = new Thickness (0, 0, 0, 0);
                 }
                 }
+                else
+                {
+                    barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
+                }
             }
             }
             else
             else
             {
             {
+                barItem.BorderStyle = LineStyle.None;
                 if (index == 0)
                 if (index == 0)
                 {
                 {
                     barItem.Border.Thickness = new Thickness (1, 1, 1, 0);
                     barItem.Border.Thickness = new Thickness (1, 1, 1, 0);
@@ -121,25 +174,33 @@ public class Bar : View
                         continue;
                         continue;
                     }
                     }
 
 
-                    if (StatusBarStyle)
-                    {
-                        barItem.BorderStyle = LineStyle.Dashed;
-                    }
-                    else
-                    {
-                        barItem.BorderStyle = LineStyle.None;
-                    }
+                    //if (StatusBarStyle)
+                    //{
+                    //    barItem.BorderStyle = LineStyle.Dashed;
+                    //}
+                    //else
+                    //{
+                    //    barItem.BorderStyle = LineStyle.None;
+                    //}
+
+                    //if (index == Subviews.Count - 1)
+                    //{
+                    //    barItem.Border.Thickness = new Thickness (0, 0, 0, 0);
+                    //}
+                    //else
+                    //{
+                    //    barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
+                    //}
 
 
-                    if (index == Subviews.Count - 1)
+                    if (barItem is Shortcut shortcut)
                     {
                     {
-                        barItem.Border.Thickness = new Thickness (0, 0, 0, 0);
+                        shortcut.X = Pos.Align (Alignment.Start, AlignmentModes);
                     }
                     }
                     else
                     else
                     {
                     {
-                        barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
+                        barItem.X = Pos.Align (Alignment.Start, AlignmentModes);
                     }
                     }
-
-                    barItem.X = Pos.Align (Alignment.Start, StatusBarStyle ? AlignmentModes.IgnoreFirstOrLast : 0);
+                        
                     barItem.Y = Pos.Center ();
                     barItem.Y = Pos.Center ();
                     prevBarItem = barItem;
                     prevBarItem = barItem;
                 }
                 }
@@ -189,7 +250,7 @@ public class Bar : View
                     else
                     else
                     {
                     {
                         // Align the view to the bottom of the previous view
                         // Align the view to the bottom of the previous view
-                        barItem.Y = Pos.Bottom(prevBarItem);
+                        barItem.Y = Pos.Bottom (prevBarItem);
                     }
                     }
 
 
                     prevBarItem = barItem;
                     prevBarItem = barItem;

+ 86 - 78
Terminal.Gui/Views/Shortcut.cs

@@ -53,14 +53,18 @@ public enum ShortcutStyles
 /// </remarks>
 /// </remarks>
 public class Shortcut : View
 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 ()
+    /// <param name="key"></param>
+    /// <param name="command"></param>
+    /// <param name="action"></param>
+    public Shortcut (Key key, string commandText, Action action, string helpText = null)
     {
     {
         Id = "_shortcut";
         Id = "_shortcut";
-        //HighlightStyle = HighlightStyle.Pressed;
-        //Highlight += Shortcut_Highlight;
+        HighlightStyle = HighlightStyle.Pressed;
+        Highlight += Shortcut_Highlight;
         CanFocus = true;
         CanFocus = true;
         Width = GetWidthDimAuto ();
         Width = GetWidthDimAuto ();
         Height = Dim.Auto (DimAutoStyle.Content, 1);
         Height = Dim.Auto (DimAutoStyle.Content, 1);
@@ -80,23 +84,24 @@ public class Shortcut : View
 
 
         HelpView.Id = "_helpView";
         HelpView.Id = "_helpView";
         HelpView.CanFocus = false;
         HelpView.CanFocus = false;
-        SetHelpViewDefaultLayout ();
+        HelpView.Text = helpText;
         Add (HelpView);
         Add (HelpView);
 
 
         KeyView.Id = "_keyView";
         KeyView.Id = "_keyView";
         KeyView.CanFocus = false;
         KeyView.CanFocus = false;
-        SetKeyViewDefaultLayout ();
         Add (KeyView);
         Add (KeyView);
 
 
         // 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;
         HelpView.MouseClick += Shortcut_MouseClick;
         KeyView.MouseClick += Shortcut_MouseClick;
         KeyView.MouseClick += Shortcut_MouseClick;
-
         LayoutStarted += OnLayoutStarted;
         LayoutStarted += OnLayoutStarted;
-
         Initialized += OnInitialized;
         Initialized += OnInitialized;
 
 
+        Key = key;
+        Title = commandText;
+        Action = action;
+
         return;
         return;
 
 
         void OnInitialized (object sender, EventArgs e)
         void OnInitialized (object sender, EventArgs e)
@@ -112,17 +117,26 @@ public class Shortcut : View
             _minimumDimAutoWidth = Frame.Width;
             _minimumDimAutoWidth = Frame.Width;
             Width = savedDim;
             Width = savedDim;
 
 
-            //SetColorScheme ();
+            SetCommandViewDefaultLayout ();
+            SetHelpViewDefaultLayout ();
+            SetKeyViewDefaultLayout ();
+
+            SetColorScheme ();
         }
         }
 
 
         // Helper to set Width consistently
         // Helper to set Width consistently
         Dim GetWidthDimAuto ()
         Dim GetWidthDimAuto ()
         {
         {
             // TODO: PosAlign.CalculateMinDimension is a hack. Need to figure out a better way of doing this.
             // TODO: PosAlign.CalculateMinDimension is a hack. Need to figure out a better way of doing this.
-            return Dim.Auto (DimAutoStyle.Content, maximumContentDim: Dim.Func (() => PosAlign.CalculateMinDimension (0, Subviews, Dimension.Width)));
+            return Dim.Auto (DimAutoStyle.Content, minimumContentDim: Dim.Func (() => PosAlign.CalculateMinDimension (0, Subviews, Dimension.Width)), maximumContentDim: Dim.Func (() => PosAlign.CalculateMinDimension (0, Subviews, Dimension.Width)));
         }
         }
     }
     }
 
 
+    /// <summary>
+    ///     Creates a new instance of <see cref="Shortcut"/>.
+    /// </summary>
+    public Shortcut () : this (Gui.Key.Empty, string.Empty, null) { }
+
     /// <summary>
     /// <summary>
     ///     Gets or sets the <see cref="Orientation"/> for this <see cref="Shortcut"/>. The default is
     ///     Gets or sets the <see cref="Orientation"/> for this <see cref="Shortcut"/>. The default is
     ///     <see cref="Orientation.Horizontal"/>, which is ideal for status bars and toolbars. If set to <see cref="Orientation.Vertical"/>,
     ///     <see cref="Orientation.Horizontal"/>, which is ideal for status bars and toolbars. If set to <see cref="Orientation.Vertical"/>,
@@ -130,6 +144,23 @@ public class Shortcut : View
     /// </summary>
     /// </summary>
     public Orientation Orientation { get; set; } = Orientation.Horizontal;
     public Orientation Orientation { get; set; } = Orientation.Horizontal;
 
 
+    private AlignmentModes _alignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast;
+
+    /// <summary>
+    ///      Gets or sets the <see cref="AlignmentModes"/> for this <see cref="Shortcut"/>. The default is <see cref="AlignmentModes.StartToEnd"/>.
+    /// </summary>
+    public AlignmentModes AlignmentModes
+    {
+        get => _alignmentModes;
+        set
+        {
+            _alignmentModes = value;
+            SetCommandViewDefaultLayout ();
+            SetHelpViewDefaultLayout ();
+            SetKeyViewDefaultLayout ();
+        }
+    }
+
     public ShortcutStyles ShortcutStyle { get; set; } = ShortcutStyles.None;
     public ShortcutStyles ShortcutStyle { get; set; } = ShortcutStyles.None;
 
 
     // When one of the subviews is "empty" we don't want to show it. So we
     // When one of the subviews is "empty" we don't want to show it. So we
@@ -211,7 +242,7 @@ public class Shortcut : View
 
 
                 if (maxHelpWidth > 0)
                 if (maxHelpWidth > 0)
                 {
                 {
-                    HelpView.X = Pos.Align (Alignment.End, AlignmentModes.IgnoreFirstOrLast);
+                    HelpView.X = Pos.Align (Alignment.End, AlignmentModes);
 
 
                     // Leverage Dim.Auto's max:
                     // Leverage Dim.Auto's max:
                     HelpView.Width = Dim.Auto (DimAutoStyle.Text, maximumContentDim: maxHelpWidth);
                     HelpView.Width = Dim.Auto (DimAutoStyle.Text, maximumContentDim: maxHelpWidth);
@@ -221,7 +252,9 @@ public class Shortcut : View
             else
             else
             {
             {
                 // Reset to default
                 // Reset to default
+                //SetCommandViewDefaultLayout();
                 SetHelpViewDefaultLayout ();
                 SetHelpViewDefaultLayout ();
+                //SetKeyViewDefaultLayout ();
             }
             }
         }
         }
     }
     }
@@ -246,23 +279,23 @@ public class Shortcut : View
         {
         {
             if (!_savedForeColor.HasValue)
             if (!_savedForeColor.HasValue)
             {
             {
-                _savedForeColor = ColorScheme.Normal.Foreground;
+                _savedForeColor = base.ColorScheme.Normal.Foreground;
             }
             }
 
 
-            var cs = new ColorScheme (ColorScheme)
+            var cs = new ColorScheme (base.ColorScheme)
             {
             {
-                Normal = new (ColorScheme.Normal.Foreground.GetHighlightColor (), ColorScheme.Normal.Background)
+                Normal = new (ColorScheme.Normal.Foreground.GetHighlightColor (), base.ColorScheme.Normal.Background)
             };
             };
-            ColorScheme = cs;
+            base.ColorScheme = cs;
         }
         }
 
 
         if (e.HighlightStyle == HighlightStyle.None && _savedForeColor.HasValue)
         if (e.HighlightStyle == HighlightStyle.None && _savedForeColor.HasValue)
         {
         {
-            var cs = new ColorScheme (ColorScheme)
+            var cs = new ColorScheme (base.ColorScheme)
             {
             {
-                Normal = new (_savedForeColor.Value, ColorScheme.Normal.Background)
+                Normal = new (_savedForeColor.Value, base.ColorScheme.Normal.Background)
             };
             };
-            ColorScheme = cs;
+            base.ColorScheme = cs;
         }
         }
 
 
         SuperView?.SetNeedsDisplay ();
         SuperView?.SetNeedsDisplay ();
@@ -365,29 +398,8 @@ public class Shortcut : View
             _commandView = value;
             _commandView = value;
             _commandView.Id = "_commandView";
             _commandView.Id = "_commandView";
 
 
-            // TODO: Determine if it makes sense to allow the CommandView to be focusable.
-            // Right now, we don't set CanFocus to false here.
-            //_commandView.CanFocus = true;
-
-            //// Bar will set the width of all CommandViews to the width of the widest CommandViews.
-            ////if (_commandView.Width == Dim.Absolute(0))
-            //{
-            //    _commandView.Width = Dim.Auto ();
-            //}
-
-            ////if (_commandView.Height == Dim.Absolute (0))
-            //{
-            //    _commandView.Height = Dim.Auto ();
-            //}
-
-            _commandView.X = Pos.Align (Alignment.End, AlignmentModes.IgnoreFirstOrLast);
-            _commandView.Y = 0; //Pos.Center ();
-
             _commandView.MouseClick += Shortcut_MouseClick;
             _commandView.MouseClick += Shortcut_MouseClick;
             _commandView.Accept += CommandViewAccept;
             _commandView.Accept += CommandViewAccept;
-
-            _commandView.Margin.Thickness = GetMarginThickness ();
-
             _commandView.HotKeyChanged += (s, e) =>
             _commandView.HotKeyChanged += (s, e) =>
                                           {
                                           {
                                               if (e.NewKey != Key.Empty)
                                               if (e.NewKey != Key.Empty)
@@ -401,6 +413,7 @@ public class Shortcut : View
 
 
             Title = _commandView.Text;
             Title = _commandView.Text;
 
 
+            SetCommandViewDefaultLayout ();
             SetHelpViewDefaultLayout ();
             SetHelpViewDefaultLayout ();
             SetKeyViewDefaultLayout ();
             SetKeyViewDefaultLayout ();
             ShowHide ();
             ShowHide ();
@@ -431,6 +444,14 @@ public class Shortcut : View
         }
         }
     }
     }
 
 
+    private void SetCommandViewDefaultLayout ()
+    {
+        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)
     private void Shortcut_TitleChanged (object sender, StateEventArgs<string> e)
     {
     {
         // If the Title changes, update the CommandView text.
         // If the Title changes, update the CommandView text.
@@ -451,7 +472,7 @@ public class Shortcut : View
     private void SetHelpViewDefaultLayout ()
     private void SetHelpViewDefaultLayout ()
     {
     {
         HelpView.Margin.Thickness = GetMarginThickness ();
         HelpView.Margin.Thickness = GetMarginThickness ();
-        HelpView.X = Pos.Align (Alignment.End, AlignmentModes.IgnoreFirstOrLast);
+        HelpView.X = Pos.Align (Alignment.End, AlignmentModes);
         HelpView.Y = 0; //Pos.Center (),    
         HelpView.Y = 0; //Pos.Center (),    
         HelpView.Width = Dim.Auto (DimAutoStyle.Text);
         HelpView.Width = Dim.Auto (DimAutoStyle.Text);
         HelpView.Height = CommandView?.IsAdded == true ? Dim.Height (CommandView) : 1;
         HelpView.Height = CommandView?.IsAdded == true ? Dim.Height (CommandView) : 1;
@@ -546,6 +567,7 @@ public class Shortcut : View
 
 
     private int _minimumKeyViewSize;
     private int _minimumKeyViewSize;
 
 
+
     /// <summary>
     /// <summary>
     /// </summary>
     /// </summary>
     public int MinimumKeyViewSize
     public int MinimumKeyViewSize
@@ -572,7 +594,7 @@ public class Shortcut : View
     private void SetKeyViewDefaultLayout ()
     private void SetKeyViewDefaultLayout ()
     {
     {
         KeyView.Margin.Thickness = GetMarginThickness ();
         KeyView.Margin.Thickness = GetMarginThickness ();
-        KeyView.X = Pos.Align (Alignment.End, AlignmentModes.IgnoreFirstOrLast);
+        KeyView.X = Pos.Align (Alignment.End, AlignmentModes);
         //KeyView.Y = Pos.Center ();
         //KeyView.Y = Pos.Center ();
         KeyView.Width = Dim.Auto (DimAutoStyle.Text, Dim.Func (GetMinimumKeyViewSize));
         KeyView.Width = Dim.Auto (DimAutoStyle.Text, Dim.Func (GetMinimumKeyViewSize));
         KeyView.Height = CommandView?.IsAdded == true ? Dim.Height (CommandView) : 1;
         KeyView.Height = CommandView?.IsAdded == true ? Dim.Height (CommandView) : 1;
@@ -631,25 +653,31 @@ public class Shortcut : View
                 break;
                 break;
         }
         }
 
 
-        if (AcceptAction is null)
-        {
-            AcceptAction = () =>
-                           {
-                               var args = new HandledEventArgs ();
-                               Accept?.Invoke (this, args);
-                           };
-        }
 
 
         if (handled == false)
         if (handled == false)
         {
         {
-            AcceptAction.Invoke();
+            var args = new HandledEventArgs ();
+            Accept?.Invoke (this, args);
+
+            if (args.Handled is false)
+            {
+                Action?.Invoke ();
+            }
+
+            args.Handled = true;
         }
         }
 
 
         return true;
         return 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="Accept"/> event is fired first, and if cancelled, <see cref="Action"/> will not be invoked.
+    /// </remarks>
     [CanBeNull]
     [CanBeNull]
-    public Action AcceptAction { get; set; }
+    public Action Action { get; set; }
 
 
     #endregion Accept Handling
     #endregion Accept Handling
 
 
@@ -673,7 +701,7 @@ public class Shortcut : View
 
 
         if (HasFocus)
         if (HasFocus)
         {
         {
-            // When we have focus, we invert the SuperView's colors
+            // When we have focus, we invert the colors
             base.ColorScheme = new (base.ColorScheme)
             base.ColorScheme = new (base.ColorScheme)
             {
             {
                 Normal = base.ColorScheme.Focus,
                 Normal = base.ColorScheme.Focus,
@@ -687,34 +715,16 @@ public class Shortcut : View
             base.ColorScheme = SuperView?.ColorScheme;
             base.ColorScheme = SuperView?.ColorScheme;
         }
         }
 
 
-        //// If the command view is focusable, invert the focus colors
-        if (CommandView.CanFocus)
+        // Set KeyView's colors to show "hot"
+        if (IsInitialized)
         {
         {
-            ColorScheme commandViewCS = new (base.ColorScheme)
+            var cs = new ColorScheme (base.ColorScheme)
             {
             {
-                Normal = base.ColorScheme.Focus,
-                HotNormal = base.ColorScheme.HotFocus,
-                HotFocus = base.ColorScheme.HotNormal,
-                Focus = base.ColorScheme.Normal
+                Normal = base.ColorScheme.HotNormal,
+                HotNormal = base.ColorScheme.Normal
             };
             };
-            CommandView.ColorScheme = commandViewCS;
+            KeyView.ColorScheme = cs;
         }
         }
-        else
-        {
-            CommandView.ColorScheme = base.ColorScheme;
-        }
-
-        //HelpView.ColorScheme = base.ColorScheme;
-
-        //// Set KeyView's colors to show "hot"
-        //var cs = new ColorScheme (ColorScheme)
-        //{
-        //    Normal = base.ColorScheme.HotNormal,
-        //    HotNormal = base.ColorScheme.Normal
-        //};
-
-        //KeyView.ColorScheme = cs;
-
     }
     }
 
 
     /// <inheritdoc/>
     /// <inheritdoc/>
@@ -727,8 +737,6 @@ public class Shortcut : View
     /// <inheritdoc/>
     /// <inheritdoc/>
     public override bool OnLeave (View view)
     public override bool OnLeave (View view)
     {
     {
-        // Reset the color scheme (to SuperView).
-        //ColorScheme = null;
         SetColorScheme ();
         SetColorScheme ();
         return base.OnLeave (view);
         return base.OnLeave (view);
     }
     }

+ 9 - 41
Terminal.Gui/Views/StatusBar.cs

@@ -9,60 +9,28 @@ namespace Terminal.Gui;
 /// </summary>
 /// </summary>
 public class StatusBar : Bar
 public class StatusBar : Bar
 {
 {
+    /// <inheritdoc />
+    public StatusBar () : this ([]) { }
 
 
-    public StatusBar ()
+    /// <inheritdoc />
+    public StatusBar (IEnumerable<Shortcut> shortcuts) : base (shortcuts)
     {
     {
         Orientation = Orientation.Horizontal;
         Orientation = Orientation.Horizontal;
         Y = Pos.AnchorEnd ();
         Y = Pos.AnchorEnd ();
         Width = Dim.Fill ();
         Width = Dim.Fill ();
+        StatusBarStyle = true;
     }
     }
 
 
     /// <inheritdoc />
     /// <inheritdoc />
     public override void Add (View view)
     public override void Add (View view)
     {
     {
         view.CanFocus = false;
         view.CanFocus = false;
-        base.Add (view);
-    }
-
-    /// <summary>Inserts a <see cref="Shortcut"/> in the specified index of <see cref="Items"/>.</summary>
-    /// <param name="index">The zero-based index at which item should be inserted.</param>
-    /// <param name="item">The item to insert.</param>
-    public void AddShortcutAt (int index, Shortcut item)
-    {
-        List<View> savedSubViewList = Subviews.ToList ();
-        int count = savedSubViewList.Count;
-        RemoveAll ();
-        for (int i = 0; i < count; i++)
+        if (view is Shortcut shortcut)
         {
         {
-            if (i == index)
-            {
-                Add (item);
-            }
-            Add (savedSubViewList [i]);
+            shortcut.KeyBindingScope = KeyBindingScope.Application;
+            shortcut.AlignmentModes = AlignmentModes.EndToStart | AlignmentModes.IgnoreFirstOrLast;
         }
         }
-        SetNeedsDisplay ();
+        base.Add (view);
     }
     }
 
 
-    /// <summary>Removes a <see cref="Shortcut"/> at specified index of <see cref="Items"/>.</summary>
-    /// <param name="index">The zero-based index of the item to remove.</param>
-    /// <returns>The <see cref="Shortcut"/> removed.</returns>
-    public Shortcut RemoveItem (int index)
-    {
-        View toRemove = null;
-        for (int i = 0; i < Subviews.Count; i++)
-        {
-            if (i == index)
-            {
-                toRemove = Subviews [i];
-            }
-        }
-
-        if (toRemove is { })
-        {
-            Remove (toRemove);
-            SetNeedsDisplay ();
-        }
-
-        return toRemove as Shortcut;
-    }
 }
 }

+ 1 - 1
UICatalog/Scenarios/Bars.cs

@@ -135,7 +135,7 @@ public class Bars : Scenario
 
 
        // SetupMenuBar ();
        // SetupMenuBar ();
         //SetupContentMenu ();
         //SetupContentMenu ();
-       // SetupStatusBar ();
+        SetupStatusBar ();
 
 
         foreach (Bar barView in Application.Top.Subviews.Where (b => b is Bar)!)
         foreach (Bar barView in Application.Top.Subviews.Where (b => b is Bar)!)
         {
         {

+ 8 - 8
UICatalog/Scenarios/ConfigurationEditor.cs

@@ -41,6 +41,7 @@ public class ConfigurationEditor : Scenario
         Application.Init ();
         Application.Init ();
 
 
         Toplevel top = new ();
         Toplevel top = new ();
+
         _tileView = new TileView (0)
         _tileView = new TileView (0)
         {
         {
             Width = Dim.Fill (), Height = Dim.Fill (1), Orientation = Orientation.Vertical, LineStyle = LineStyle.Single
             Width = Dim.Fill (), Height = Dim.Fill (1), Orientation = Orientation.Vertical, LineStyle = LineStyle.Single
@@ -57,25 +58,24 @@ public class ConfigurationEditor : Scenario
         {
         {
             Key = Application.QuitKey,
             Key = Application.QuitKey,
             Title = $"{Application.QuitKey} Quit",
             Title = $"{Application.QuitKey} Quit",
-            AcceptAction = Quit
+            Action = Quit
         };
         };
 
 
         var reloadShortcut = new Shortcut ()
         var reloadShortcut = new Shortcut ()
         {
         {
-            Key = KeyCode.F5,
+            Key = Key.F5.WithShift,
             Title = "Reload",
             Title = "Reload",
-            AcceptAction = Reload
         };
         };
+        reloadShortcut.Accept += (s, e) => { Reload (); };
+
         var saveShortcut = new Shortcut ()
         var saveShortcut = new Shortcut ()
         {
         {
-            Key = Key.S.WithCtrl,
+            Key = Key.F4,
             Title = "Save",
             Title = "Save",
-            AcceptAction = Save
+            Action = Save
         };
         };
 
 
-
-        var statusBar = new StatusBar ();
-        statusBar.Add (quitShortcut, reloadShortcut, saveShortcut, _lenShortcut);
+        var statusBar = new StatusBar ([quitShortcut, reloadShortcut, saveShortcut, _lenShortcut]);
 
 
         top.Add (statusBar);
         top.Add (statusBar);
 
 

+ 103 - 97
UICatalog/Scenarios/CsvEditor.cs

@@ -1,11 +1,11 @@
 using System;
 using System;
-using System.Collections.Generic;
 using System.Data;
 using System.Data;
 using System.Globalization;
 using System.Globalization;
 using System.IO;
 using System.IO;
 using System.Linq;
 using System.Linq;
 using System.Text.RegularExpressions;
 using System.Text.RegularExpressions;
 using CsvHelper;
 using CsvHelper;
+using SixLabors.ImageSharp.ColorSpaces;
 using Terminal.Gui;
 using Terminal.Gui;
 
 
 namespace UICatalog.Scenarios;
 namespace UICatalog.Scenarios;
@@ -26,16 +26,23 @@ public class CsvEditor : Scenario
     private MenuItem _miCentered;
     private MenuItem _miCentered;
     private MenuItem _miLeft;
     private MenuItem _miLeft;
     private MenuItem _miRight;
     private MenuItem _miRight;
-    private TextField _selectedCellLabel;
+    private TextField _selectedCellTextField;
     private TableView _tableView;
     private TableView _tableView;
 
 
-    public override void Setup ()
+    public override void Main ()
     {
     {
-        Win.Title = GetName ();
-        Win.Y = 1; // menu
-        Win.Height = Dim.Fill (1); // status bar
+        // Init
+        Application.Init ();
 
 
-        _tableView = new TableView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (1) };
+        // Setup - Create a top-level application window and configure it.
+        Toplevel appWindow = new ()
+        {
+            Title = $"{GetName ()}"
+        };
+
+        //appWindow.Height = Dim.Fill (1); // status bar
+
+        _tableView = new () { X = 0, Y = 1, Width = Dim.Fill (), Height = Dim.Fill (2) };
 
 
         var fileMenu = new MenuBarItem (
         var fileMenu = new MenuBarItem (
                                         "_File",
                                         "_File",
@@ -53,99 +60,96 @@ public class CsvEditor : Scenario
             Menus =
             Menus =
             [
             [
                 fileMenu,
                 fileMenu,
-                new MenuBarItem (
-                                 "_Edit",
-                                 new MenuItem []
-                                 {
-                                     new ("_New Column", "", () => AddColumn ()),
-                                     new ("_New Row", "", () => AddRow ()),
-                                     new (
-                                          "_Rename Column",
-                                          "",
-                                          () => RenameColumn ()
-                                         ),
-                                     new ("_Delete Column", "", () => DeleteColum ()),
-                                     new ("_Move Column", "", () => MoveColumn ()),
-                                     new ("_Move Row", "", () => MoveRow ()),
-                                     new ("_Sort Asc", "", () => Sort (true)),
-                                     new ("_Sort Desc", "", () => Sort (false))
-                                 }
-                                ),
-                new MenuBarItem (
-                                 "_View",
-                                 new []
-                                 {
-                                     _miLeft = new MenuItem (
-                                                             "_Align Left",
-                                                             "",
-                                                             () => Align (Alignment.Start)
-                                                            ),
-                                     _miRight = new MenuItem (
-                                                              "_Align Right",
-                                                              "",
-                                                              () => Align (Alignment.End)
-                                                             ),
-                                     _miCentered = new MenuItem (
-                                                                 "_Align Centered",
-                                                                 "",
-                                                                 () => Align (Alignment.Center)
-                                                                ),
-
-                                     // Format requires hard typed data table, when we read a CSV everything is untyped (string) so this only works for new columns in this demo
-                                     _miCentered = new MenuItem (
-                                                                 "_Set Format Pattern",
-                                                                 "",
-                                                                 () => SetFormat ()
-                                                                )
-                                 }
-                                )
+                new (
+                     "_Edit",
+                     new MenuItem []
+                     {
+                         new ("_New Column", "", () => AddColumn ()),
+                         new ("_New Row", "", () => AddRow ()),
+                         new (
+                              "_Rename Column",
+                              "",
+                              () => RenameColumn ()
+                             ),
+                         new ("_Delete Column", "", () => DeleteColum ()),
+                         new ("_Move Column", "", () => MoveColumn ()),
+                         new ("_Move Row", "", () => MoveRow ()),
+                         new ("_Sort Asc", "", () => Sort (true)),
+                         new ("_Sort Desc", "", () => Sort (false))
+                     }
+                    ),
+                new (
+                     "_View",
+                     new []
+                     {
+                         _miLeft = new (
+                                        "_Align Left",
+                                        "",
+                                        () => Align (Alignment.Start)
+                                       ),
+                         _miRight = new (
+                                         "_Align Right",
+                                         "",
+                                         () => Align (Alignment.End)
+                                        ),
+                         _miCentered = new (
+                                            "_Align Centered",
+                                            "",
+                                            () => Align (Alignment.Center)
+                                           ),
+
+                         // Format requires hard typed data table, when we read a CSV everything is untyped (string) so this only works for new columns in this demo
+                         _miCentered = new (
+                                            "_Set Format Pattern",
+                                            "",
+                                            () => SetFormat ()
+                                           )
+                     }
+                    )
             ]
             ]
         };
         };
-        Top.Add (menu);
-
-#if V2_STATUSBAR
-        var statusBar = new StatusBar (
-                                       new StatusItem []
-                                       {
-                                           new (
-                                                KeyCode.CtrlMask | KeyCode.O,
-                                                "~^O~ Open",
-                                                () => Open ()
-                                               ),
-                                           new (
-                                                KeyCode.CtrlMask | KeyCode.S,
-                                                "~^S~ Save",
-                                                () => Save ()
-                                               ),
-                                           new (
-                                                Application.QuitKey,
-                                                $"{Application.QuitKey} to Quit",
-                                                () => Quit ()
-                                               )
-                                       }
-                                      );
-        Top.Add (statusBar);
-#endif
+        appWindow.Add (menu);
 
 
-        Win.Add (_tableView);
-
-        _selectedCellLabel = new TextField
+        _selectedCellTextField = new ()
         {
         {
-            X = 0,
-            Y = Pos.Bottom (_tableView),
             Text = "0,0",
             Text = "0,0",
-            Width = Dim.Fill (),
-            TextAlignment = Alignment.End
+            Width = 10,
+            Height = 1,
+        };
+        _selectedCellTextField.TextChanged += SelectedCellLabel_TextChanged;
+
+        var statusBar = new StatusBar (
+                                       [
+                                           new (Application.QuitKey, "Quit", Quit, "Quit!"),
+                                           new (Key.O.WithCtrl, "Open", Open, "Open a file."),
+                                           new (Key.S.WithCtrl, "Save", Save, "Save current."),
+                                           new ()
+                                           {
+                                               HelpText = "Cell:",
+                                               CommandView = _selectedCellTextField,
+                                               AlignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast,
+                                               Enabled = false
+                                           }
+                                       ])
+        {
+            AlignmentModes = AlignmentModes.IgnoreFirstOrLast
         };
         };
-        _selectedCellLabel.TextChanged += SelectedCellLabel_TextChanged;
+        appWindow.Add (statusBar);
 
 
-        Win.Add (_selectedCellLabel);
+        appWindow.Add (_tableView);
 
 
         _tableView.SelectedCellChanged += OnSelectedCellChanged;
         _tableView.SelectedCellChanged += OnSelectedCellChanged;
         _tableView.CellActivated += EditCurrentCell;
         _tableView.CellActivated += EditCurrentCell;
         _tableView.KeyDown += TableViewKeyPress;
         _tableView.KeyDown += TableViewKeyPress;
 
 
         SetupScrollBar ();
         SetupScrollBar ();
+
+        // Run - Start the application.
+        Application.Run (appWindow);
+        appWindow.Dispose ();
+
+        // Shutdown - Calling Application.Shutdown is required.
+        Application.Shutdown ();
     }
     }
 
 
     private void AddColumn ()
     private void AddColumn ()
@@ -302,10 +306,10 @@ public class CsvEditor : Scenario
         var ok = new Button { Text = "Ok", IsDefault = true };
         var ok = new Button { Text = "Ok", IsDefault = true };
 
 
         ok.Accept += (s, e) =>
         ok.Accept += (s, e) =>
-                      {
-                          okPressed = true;
-                          Application.RequestStop ();
-                      };
+                     {
+                         okPressed = true;
+                         Application.RequestStop ();
+                     };
         var cancel = new Button { Text = "Cancel" };
         var cancel = new Button { Text = "Cancel" };
         cancel.Accept += (s, e) => { Application.RequestStop (); };
         cancel.Accept += (s, e) => { Application.RequestStop (); };
         var d = new Dialog { Title = title, Buttons = [ok, cancel] };
         var d = new Dialog { Title = title, Buttons = [ok, cancel] };
@@ -427,9 +431,9 @@ public class CsvEditor : Scenario
     private void OnSelectedCellChanged (object sender, SelectedCellChangedEventArgs e)
     private void OnSelectedCellChanged (object sender, SelectedCellChangedEventArgs e)
     {
     {
         // only update the text box if the user is not manually editing it
         // only update the text box if the user is not manually editing it
-        if (!_selectedCellLabel.HasFocus)
+        if (!_selectedCellTextField.HasFocus)
         {
         {
-            _selectedCellLabel.Text = $"{_tableView.SelectedRow},{_tableView.SelectedColumn}";
+            _selectedCellTextField.Text = $"{_tableView.SelectedRow},{_tableView.SelectedColumn}";
         }
         }
 
 
         if (_tableView.Table == null || _tableView.SelectedColumn == -1)
         if (_tableView.Table == null || _tableView.SelectedColumn == -1)
@@ -448,7 +452,7 @@ public class CsvEditor : Scenario
     {
     {
         var ofd = new FileDialog
         var ofd = new FileDialog
         {
         {
-            AllowedTypes = new List<IAllowedType> { new AllowedType ("Comma Separated Values", ".csv") }
+            AllowedTypes = new () { new AllowedType ("Comma Separated Values", ".csv") }
         };
         };
         ofd.Style.OkButtonText = "Open";
         ofd.Style.OkButtonText = "Open";
 
 
@@ -458,6 +462,7 @@ public class CsvEditor : Scenario
         {
         {
             Open (ofd.Path);
             Open (ofd.Path);
         }
         }
+
         ofd.Dispose ();
         ofd.Dispose ();
     }
     }
 
 
@@ -498,7 +503,8 @@ public class CsvEditor : Scenario
 
 
             // Only set the current filename if we successfully loaded the entire file
             // Only set the current filename if we successfully loaded the entire file
             _currentFile = filename;
             _currentFile = filename;
-            Win.Title = $"{GetName ()} - {Path.GetFileName (_currentFile)}";
+            _selectedCellTextField.SuperView.Enabled = true;
+            Application.Top.Title = $"{GetName ()} - {Path.GetFileName (_currentFile)}";
         }
         }
         catch (Exception ex)
         catch (Exception ex)
         {
         {
@@ -563,13 +569,13 @@ public class CsvEditor : Scenario
     private void SelectedCellLabel_TextChanged (object sender, StateEventArgs<string> e)
     private void SelectedCellLabel_TextChanged (object sender, StateEventArgs<string> e)
     {
     {
         // if user is in the text control and editing the selected cell
         // if user is in the text control and editing the selected cell
-        if (!_selectedCellLabel.HasFocus)
+        if (!_selectedCellTextField.HasFocus)
         {
         {
             return;
             return;
         }
         }
 
 
         // change selected cell to the one the user has typed into the box
         // change selected cell to the one the user has typed into the box
-        Match match = Regex.Match (_selectedCellLabel.Text, "^(\\d+),(\\d+)$");
+        Match match = Regex.Match (_selectedCellTextField.Text, "^(\\d+),(\\d+)$");
 
 
         if (match.Success)
         if (match.Success)
         {
         {

+ 10 - 17
UICatalog/Scenarios/Editor.cs

@@ -237,29 +237,23 @@ public class Editor : Scenario
         };
         };
 
 
         _appWindow.Add (menu);
         _appWindow.Add (menu);
-#if V2_STATUSBAR
 
 
-        var siCursorPosition = new StatusItem (KeyCode.Null, "", null);
+        var siCursorPosition = new Shortcut(KeyCode.Null, "", null);
 
 
         var statusBar = new StatusBar (
         var statusBar = new StatusBar (
                                        new []
                                        new []
                                        {
                                        {
+                                           new (Application.QuitKey, $"Quit", Quit),
+                                           new (Key.F2, "Open", Open),
+                                           new (Key.F3, "Save", () => Save ()),
+                                           new (Key.F4, "Save As", () => SaveAs ()),
+                                           new (Key.Empty, $"OS Clipboard IsSupported : {Clipboard.IsSupported}", null),
                                            siCursorPosition,
                                            siCursorPosition,
-                                           new (KeyCode.F2, "~F2~ Open", () => Open ()),
-                                           new (KeyCode.F3, "~F3~ Save", () => Save ()),
-                                           new (KeyCode.F4, "~F4~ Save As", () => SaveAs ()),
-                                           new (
-                                                Application.QuitKey,
-                                                $"{Application.QuitKey} to Quit",
-                                                () => Quit ()
-                                               ),
-                                           new (
-                                                KeyCode.Null,
-                                                $"OS Clipboard IsSupported : {Clipboard.IsSupported}",
-                                                null
-                                               )
                                        }
                                        }
-                                      );
+                                      )
+        {
+            AlignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast
+        };
 
 
         _textView.UnwrappedCursorPosition += (s, e) =>
         _textView.UnwrappedCursorPosition += (s, e) =>
                                              {
                                              {
@@ -267,7 +261,6 @@ public class Editor : Scenario
                                              };
                                              };
 
 
         _appWindow.Add (statusBar);
         _appWindow.Add (statusBar);
-#endif
 
 
         _scrollBar = new (_textView, true);
         _scrollBar = new (_textView, true);
 
 

+ 9 - 2
UICatalog/Scenarios/Shortcuts.cs

@@ -261,6 +261,8 @@ public class Shortcuts : Scenario
         hShortcut1.CommandView.Width = 10;
         hShortcut1.CommandView.Width = 10;
         hShortcut1.CommandView.Height = 1;
         hShortcut1.CommandView.Height = 1;
         hShortcut1.CommandView.CanFocus = false;
         hShortcut1.CommandView.CanFocus = false;
+        hShortcut1.AlignmentModes = AlignmentModes.EndToStart | AlignmentModes.IgnoreFirstOrLast;
+
         Timer timer = new (10)
         Timer timer = new (10)
         {
         {
             AutoReset = true,
             AutoReset = true,
@@ -297,11 +299,12 @@ public class Shortcuts : Scenario
             X = Pos.Align (Alignment.Start, AlignmentModes.IgnoreFirstOrLast, 1),
             X = Pos.Align (Alignment.Start, AlignmentModes.IgnoreFirstOrLast, 1),
             Y = Pos.Top (hShortcut1),
             Y = Pos.Top (hShortcut1),
             Key = Key.F8,
             Key = Key.F8,
-            HelpText = "Edit",
+            HelpText = "TextField",
             CanFocus = true,
             CanFocus = true,
-            BorderStyle = LineStyle.Dashed,
             CommandView = textField,
             CommandView = textField,
+            BorderStyle = LineStyle.Dashed,
         };
         };
+        hShortcut2.AlignmentModes = AlignmentModes.EndToStart | AlignmentModes.IgnoreFirstOrLast;
         hShortcut2.Border.Thickness = new (0, 0, 1, 0);
         hShortcut2.Border.Thickness = new (0, 0, 1, 0);
 
 
         Application.Top.Add (hShortcut2);
         Application.Top.Add (hShortcut2);
@@ -331,6 +334,7 @@ public class Shortcuts : Scenario
                                 };
                                 };
         hShortcutBG.CommandView = bgColor;
         hShortcutBG.CommandView = bgColor;
         hShortcutBG.Border.Thickness = new (1, 0, 1, 0);
         hShortcutBG.Border.Thickness = new (1, 0, 1, 0);
+        hShortcutBG.AlignmentModes = AlignmentModes.EndToStart | AlignmentModes.IgnoreFirstOrLast;
 
 
         Application.Top.Add (hShortcutBG);
         Application.Top.Add (hShortcutBG);
 
 
@@ -365,6 +369,9 @@ public class Shortcuts : Scenario
                                    };
                                    };
             }
             }
         }
         }
+
+        ((CheckBox)vShortcut5.CommandView).OnToggled ();
+        ((CheckBox)vShortcut5.CommandView).OnToggled ();
     }
     }
 
 
     private void Button_Clicked (object sender, EventArgs e) { MessageBox.Query ("Hi", $"You clicked {sender}"); }
     private void Button_Clicked (object sender, EventArgs e) { MessageBox.Query ("Hi", $"You clicked {sender}"); }

+ 8 - 12
UICatalog/UICatalog.cs

@@ -347,6 +347,7 @@ internal class UICatalogApp
         // 'app' closed cleanly.
         // 'app' closed cleanly.
         foreach (Responder? inst in Responder.Instances)
         foreach (Responder? inst in Responder.Instances)
         {
         {
+            
             Debug.Assert (inst.WasDisposed);
             Debug.Assert (inst.WasDisposed);
         }
         }
 
 
@@ -457,14 +458,13 @@ internal class UICatalogApp
             StatusBar = new ()
             StatusBar = new ()
             {
             {
                 Visible = ShowStatusBar,
                 Visible = ShowStatusBar,
+                AlignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast
             };
             };
 
 
             Shortcut statusBarShortcut = new Shortcut ()
             Shortcut statusBarShortcut = new Shortcut ()
             {
             {
                 Key = Key.F10,
                 Key = Key.F10,
-                KeyBindingScope = KeyBindingScope.Application,
-                Title = "Status Bar",
-                CanFocus = false,
+                Title = "Show/Hide Status Bar",
             };
             };
             statusBarShortcut.Accept += (sender, args) =>
             statusBarShortcut.Accept += (sender, args) =>
                                         {
                                         {
@@ -473,15 +473,13 @@ internal class UICatalogApp
 
 
             ShForce16Colors = new Shortcut ()
             ShForce16Colors = new Shortcut ()
             {
             {
-                Key = Key.F6,
-                KeyBindingScope = KeyBindingScope.Application,
-                CommandView = new CheckBox()
+                CommandView = new CheckBox ()
                 {
                 {
-                    Title ="16 Colors",
+                    Title = "16 color mode",
                     Checked = Application.Force16Colors,
                     Checked = Application.Force16Colors,
                     CanFocus = false,
                     CanFocus = false,
-                },
-                CanFocus = false,
+                }, HelpText = "",
+                Key = Key.F6,
             };
             };
             ShForce16Colors.Accept += (sender, args) =>
             ShForce16Colors.Accept += (sender, args) =>
                                             {
                                             {
@@ -508,8 +506,6 @@ internal class UICatalogApp
                 {
                 {
                     Title = "Quit",
                     Title = "Quit",
                     Key = Application.QuitKey,
                     Key = Application.QuitKey,
-                    KeyBindingScope = KeyBindingScope.Application,
-                    CanFocus = false,
                 },
                 },
                 statusBarShortcut,
                 statusBarShortcut,
                 ShForce16Colors,
                 ShForce16Colors,
@@ -542,7 +538,7 @@ internal class UICatalogApp
                 X = Pos.Right (CategoryList) - 1,
                 X = Pos.Right (CategoryList) - 1,
                 Y = 1,
                 Y = 1,
                 Width = Dim.Fill (),
                 Width = Dim.Fill (),
-                Height = Dim.Height(CategoryList),
+                Height = Dim.Height (CategoryList),
 
 
                 //AllowsMarking = false,
                 //AllowsMarking = false,
                 CanFocus = true,
                 CanFocus = true,