Browse Source

fxed color & focus issues

Tig 1 year ago
parent
commit
84971a2f06

+ 65 - 18
Terminal.Gui/View/ViewAdornments.cs

@@ -1,4 +1,6 @@
-namespace Terminal.Gui;
+using System.ComponentModel;
+
+namespace Terminal.Gui;
 
 
 public partial class View
 public partial class View
 {
 {
@@ -95,29 +97,74 @@ public partial class View
         get => Border?.LineStyle ?? LineStyle.Single;
         get => Border?.LineStyle ?? LineStyle.Single;
         set
         set
         {
         {
-            if (Border is null)
-            {
-                return;
-            }
+            StateEventArgs<LineStyle> e = new (Border?.LineStyle ?? LineStyle.None, value);
+            OnBorderStyleChanging (e);
 
 
-            if (value != LineStyle.None)
-            {
-                if (Border.Thickness == Thickness.Empty)
-                {
-                    Border.Thickness = new (1);
-                }
-            }
-            else
+        }
+    }
+
+    /// <summary>
+    /// Called when the <see cref="BorderStyle"/> is changing. Invokes <see cref="BorderStyleChanging"/>, which allows the event to be cancelled.
+    /// </summary>
+    /// <remarks>
+    ///     Override <see cref="SetBorderStyle"/> to prevent the <see cref="BorderStyle"/> from changing. Set <see cref="StateEventArgs{T}.Cancel"/> to `true` to cancel the event.
+    /// </remarks>
+    /// <param name="e"></param>
+    protected void OnBorderStyleChanging (StateEventArgs<LineStyle> e)
+    {
+        if (Border is null)
+        {
+            return;
+        }
+
+        BorderStyleChanging?.Invoke (this, e);
+        if (e.Cancel)
+        {
+            return;
+        }
+
+        SetBorderStyle (e.NewValue);
+        LayoutAdornments ();
+        SetNeedsLayout ();
+
+        return;
+    }
+
+    /// <summary>
+    ///     Sets the <see cref="BorderStyle"/> of the view to the specified value.
+    /// </summary>
+    /// <remarks>
+    ///     <para>
+    ///          <see cref="BorderStyle"/> is a helper for manipulating the view's <see cref="Border"/>. Setting this property to any value other
+    ///         than <see cref="LineStyle.None"/> is equivalent to setting <see cref="Border"/>'s
+    ///         <see cref="Adornment.Thickness"/> to `1` and <see cref="BorderStyle"/> to the value.
+    ///     </para>
+    ///     <para>
+    ///         Setting this property to <see cref="LineStyle.None"/> is equivalent to setting <see cref="Border"/>'s
+    ///         <see cref="Adornment.Thickness"/> to `0` and <see cref="BorderStyle"/> to <see cref="LineStyle.None"/>.
+    ///     </para>
+    ///     <para>For more advanced customization of the view's border, manipulate see <see cref="Border"/> directly.</para>
+    /// </remarks>
+    /// <param name="value"></param>
+    public virtual void SetBorderStyle (LineStyle value)
+    {
+        if (value != LineStyle.None)
+        {
+            if (Border.Thickness == Thickness.Empty)
             {
             {
-                Border.Thickness = new (0);
+                Border.Thickness = new (1);
             }
             }
-
-            Border.LineStyle = value;
-            LayoutAdornments ();
-            SetNeedsLayout ();
         }
         }
+        else
+        {
+            Border.Thickness = new (0);
+        }
+
+        Border.LineStyle = value;
     }
     }
 
 
+    public event EventHandler<StateEventArgs<LineStyle>> BorderStyleChanging;
+
     /// <summary>
     /// <summary>
     ///     The <see cref="Adornment"/> inside of the view that offsets the <see cref="Viewport"/>
     ///     The <see cref="Adornment"/> inside of the view that offsets the <see cref="Viewport"/>
     ///     from the <see cref="Border"/>.
     ///     from the <see cref="Border"/>.

+ 5 - 5
Terminal.Gui/View/ViewDrawing.cs

@@ -640,17 +640,17 @@ public partial class View
     {
     {
         SubViewNeedsDisplay = true;
         SubViewNeedsDisplay = true;
 
 
+        if (this is Adornment adornment)
+        {
+            adornment.Parent?.SetSubViewNeedsDisplay ();
+        }
+
         if (SuperView is { SubViewNeedsDisplay: false })
         if (SuperView is { SubViewNeedsDisplay: false })
         {
         {
             SuperView.SetSubViewNeedsDisplay ();
             SuperView.SetSubViewNeedsDisplay ();
 
 
             return;
             return;
         }
         }
-
-        if (this is Adornment adornment)
-        {
-            adornment.Parent?.SetSubViewNeedsDisplay ();
-        }
     }
     }
 
 
     /// <summary>Clears <see cref="NeedsDisplay"/> and <see cref="SubViewNeedsDisplay"/>.</summary>
     /// <summary>Clears <see cref="NeedsDisplay"/> and <see cref="SubViewNeedsDisplay"/>.</summary>

+ 89 - 53
Terminal.Gui/Views/Bar.cs

@@ -1,5 +1,6 @@
 using System;
 using System;
 using System.Linq;
 using System.Linq;
+using Microsoft.CodeAnalysis;
 
 
 namespace Terminal.Gui;
 namespace Terminal.Gui;
 
 
@@ -8,12 +9,33 @@ namespace Terminal.Gui;
 /// </summary>
 /// </summary>
 /// <remarks>
 /// <remarks>
 /// </remarks>
 /// </remarks>
-public class Bar : View
+public class Bar : Toplevel
 {
 {
     /// <inheritdoc/>
     /// <inheritdoc/>
     public Bar ()
     public Bar ()
     {
     {
-        SetInitialProperties ();
+        CanFocus = true;
+
+        Width = Dim.Auto ();
+        Height = Dim.Auto ();
+
+        LayoutStarted += Bar_LayoutStarted;
+
+        Initialized += Bar_Initialized;
+
+    }
+
+    private void Bar_Initialized (object sender, EventArgs e)
+    {
+        ColorScheme = Colors.ColorSchemes ["Menu"];
+        AdjustSubviewBorders();
+    }
+
+    /// <inheritdoc />
+    public override void SetBorderStyle (LineStyle value)
+    {
+        // The default changes the thickness. We don't want that. We just set the style.
+        Border.LineStyle = value;
     }
     }
 
 
     /// <summary>
     /// <summary>
@@ -31,46 +53,59 @@ public class Bar : View
             //view.AutoSize = true;
             //view.AutoSize = true;
         }
         }
 
 
-        //if (StatusBarStyle)
-        //{
-        //    // Light up right border
-        //    view.BorderStyle = LineStyle.Single;
-        //    view.Border.Thickness = new Thickness (0, 0, 1, 0);
-        //}
-
-        //if (view is not Shortcut)
-        //{
-        //    if (StatusBarStyle)
-        //    {
-        //        view.Padding.Thickness = new Thickness (0, 0, 1, 0);
-        //    }
-
-        //    view.Margin.Thickness = new Thickness (1, 0, 0, 0);
-        //}
-
-        //view.ColorScheme = ColorScheme;
-
-        // Add any HotKey keybindings to our bindings
-        //IEnumerable<KeyValuePair<Key, KeyBinding>> bindings = view.KeyBindings.Bindings.Where (b => b.Value.Scope == KeyBindingScope.HotKey);
-
-        //foreach (KeyValuePair<Key, KeyBinding> binding in bindings)
-        //{
-        //    AddCommand (
-        //                binding.Value.Commands [0],
-        //                () =>
-        //                {
-        //                    if (view is Shortcut shortcut)
-        //                    {
-        //                        return shortcut.CommandView.InvokeCommands (binding.Value.Commands);
-        //                    }
-
-        //                    return false;
-        //                });
-        //    KeyBindings.Add (binding.Key, binding.Value);
-        //}
+        base.Add (view);
+        AdjustSubviewBorders ();
 
 
+    }
 
 
-        base.Add (view);
+    /// <inheritdoc />
+    public override void Remove (View view)
+    {
+        base.Remove (view);
+        AdjustSubviewBorders ();
+    }
+
+    private void AdjustSubviewBorders ()
+    {
+        for (var index = 0; index < Subviews.Count; index++)
+        {
+            View barItem = Subviews [index];
+
+            barItem.Border.LineStyle = BorderStyle;
+            barItem.SuperViewRendersLineCanvas = true;
+            barItem.ColorScheme = ColorScheme;
+
+
+            if (!barItem.Visible)
+            {
+                continue;
+            }
+
+            if (StatusBarStyle)
+            {
+                if (index == 0)
+                {
+                    barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
+                } 
+
+                if (index == Subviews.Count - 1)
+                {
+                    barItem.Border.Thickness = new Thickness (0, 0, 0, 0);
+                }
+            }
+            else
+            {
+                if (index == 0)
+                {
+                    barItem.Border.Thickness = new Thickness (1, 1, 1, 0);
+                }
+
+                if (index == Subviews.Count - 1)
+                {
+                    barItem.Border.Thickness = new Thickness (1, 0, 1, 1);
+                }
+            }
+        }
     }
     }
 
 
     private void Bar_LayoutStarted (object sender, LayoutEventArgs e)
     private void Bar_LayoutStarted (object sender, LayoutEventArgs e)
@@ -89,7 +124,15 @@ public class Bar : View
                         continue;
                         continue;
                     }
                     }
 
 
-                    barItem.BorderStyle = LineStyle.Dashed;
+                    if (StatusBarStyle)
+                    {
+                        barItem.BorderStyle = LineStyle.Dashed;
+                    }
+                    else
+                    {
+                        barItem.BorderStyle = LineStyle.None;
+                    }
+
                     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);
@@ -99,7 +142,7 @@ public class Bar : View
                         barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
                         barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
                     }
                     }
 
 
-                    barItem.X = Pos.Align (Alignment.Start, AlignmentModes.IgnoreFirstOrLast);
+                    barItem.X = Pos.Align (Alignment.Start, StatusBarStyle ? AlignmentModes.IgnoreFirstOrLast : 0);
                     barItem.Y = Pos.Center ();
                     barItem.Y = Pos.Center ();
                     prevBarItem = barItem;
                     prevBarItem = barItem;
                 }
                 }
@@ -126,6 +169,7 @@ public class Bar : View
 
 
                 // Set the overall size of the Bar and arrange the views vertically
                 // Set the overall size of the Bar and arrange the views vertically
                 var maxBarItemWidth = 0;
                 var maxBarItemWidth = 0;
+                var totalHeight = 0;
 
 
                 for (var index = 0; index < Subviews.Count; index++)
                 for (var index = 0; index < Subviews.Count; index++)
                 {
                 {
@@ -148,7 +192,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 = index;
+                        barItem.Y = Pos.Bottom(prevBarItem);
                     }
                     }
 
 
                     prevBarItem = barItem;
                     prevBarItem = barItem;
@@ -163,6 +207,7 @@ public class Bar : View
                     }
                     }
 
 
                     barItem.X = 0;
                     barItem.X = 0;
+                    totalHeight += barItem.Frame.Height;
                 }
                 }
 
 
                 foreach (Shortcut shortcut in shortcuts)
                 foreach (Shortcut shortcut in shortcuts)
@@ -170,20 +215,11 @@ public class Bar : View
                     shortcut.Width = maxBarItemWidth;
                     shortcut.Width = maxBarItemWidth;
                 }
                 }
 
 
-                Height = Subviews.Count;
+                Height = Dim.Auto (DimAutoStyle.Content, minimumContentDim: totalHeight);
 
 
                 break;
                 break;
         }
         }
     }
     }
 
 
-    private void SetInitialProperties ()
-    {
-        ColorScheme = Colors.ColorSchemes ["Menu"];
-        CanFocus = true;
-
-        Width = Dim.Auto ();
-        Height = Dim.Auto ();
 
 
-        LayoutStarted += Bar_LayoutStarted;
-    }
 }
 }

+ 64 - 51
Terminal.Gui/Views/Shortcut.cs

@@ -45,8 +45,8 @@ public class Shortcut : View
     public Shortcut ()
     public Shortcut ()
     {
     {
         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,6 +80,7 @@ public class Shortcut : View
         KeyView.MouseClick += Shortcut_MouseClick;
         KeyView.MouseClick += Shortcut_MouseClick;
 
 
         LayoutStarted += OnLayoutStarted;
         LayoutStarted += OnLayoutStarted;
+        DrawContent += Shortcut_DrawContent;
 
 
         Initialized += OnInitialized;
         Initialized += OnInitialized;
 
 
@@ -98,17 +99,7 @@ public class Shortcut : View
             _minimumDimAutoWidth = Frame.Width;
             _minimumDimAutoWidth = Frame.Width;
             Width = savedDim;
             Width = savedDim;
 
 
-            // Set KeyView's colors to show "hot"
-            if (ColorScheme != null)
-            {
-                var cs = new ColorScheme (ColorScheme)
-                {
-                    Normal = ColorScheme.HotNormal,
-                    HotNormal = ColorScheme.Normal
-                };
-
-                KeyView.ColorScheme = cs;
-            }
+            //SetColorScheme ();
         }
         }
 
 
         // Helper to set Width consistently
         // Helper to set Width consistently
@@ -119,6 +110,11 @@ public class Shortcut : View
         }
         }
     }
     }
 
 
+    private void Shortcut_DrawContent (object sender, DrawEventArgs e)
+    {
+       //SetColorScheme();
+    }
+
 
 
     /// <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
@@ -139,12 +135,12 @@ public class Shortcut : View
             Add (CommandView);
             Add (CommandView);
         }
         }
 
 
-        if (!string.IsNullOrEmpty (HelpView.Text))
+        if (HelpView.Visible && !string.IsNullOrEmpty (HelpView.Text))
         {
         {
             Add (HelpView);
             Add (HelpView);
         }
         }
 
 
-        if (Key != Key.Empty)
+        if (KeyView.Visible && Key != Key.Empty)
         {
         {
             Add (KeyView);
             Add (KeyView);
         }
         }
@@ -273,8 +269,6 @@ public class Shortcut : View
         {
         {
             CommandView.InvokeCommand (Command.Accept);
             CommandView.InvokeCommand (Command.Accept);
             e.Handled = true;
             e.Handled = true;
-
-            return;
         }
         }
 
 
         if (!e.Handled)
         if (!e.Handled)
@@ -568,7 +562,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.IgnoreFirstOrLast);
         //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));
@@ -645,50 +639,69 @@ public class Shortcut : View
     /// <inheritdoc/>
     /// <inheritdoc/>
     public override ColorScheme ColorScheme
     public override ColorScheme ColorScheme
     {
     {
-        get
-        {
-            if (base.ColorScheme == null)
-            {
-                return SuperView?.ColorScheme ?? base.ColorScheme;
-            }
-
-            return base.ColorScheme;
-        }
+        get => base.ColorScheme;
         set
         set
         {
         {
             base.ColorScheme = value;
             base.ColorScheme = value;
+            SetColorScheme ();
+        }
+    }
 
 
-            if (CommandView.CanFocus)
-            {
-                CommandView.ColorScheme = SuperView?.ColorScheme ?? ColorScheme;
-            }
+    public void SetColorScheme ()
+    {
+        // Border should match superview.
+        Border.ColorScheme = SuperView?.ColorScheme;
 
 
-            if (ColorScheme != null)
+        if (HasFocus)
+        {
+            // When we have focus, we invert the SuperView's colors
+            base.ColorScheme = new (base.ColorScheme)
             {
             {
-                var cs = new ColorScheme (ColorScheme)
-                {
-                    Normal = ColorScheme.HotNormal,
-                    HotNormal = ColorScheme.Normal
-                };
-                KeyView.ColorScheme = cs;
-            }
-
-            Border.ColorScheme = SuperView?.ColorScheme ?? ColorScheme;
+                Normal = base.ColorScheme.Focus,
+                HotNormal = base.ColorScheme.HotFocus,
+                HotFocus = base.ColorScheme.HotNormal,
+                Focus = base.ColorScheme.Normal
+            };
+        }
+        else
+        {
+            base.ColorScheme = SuperView?.ColorScheme;
         }
         }
-    }
 
 
-    /// <inheritdoc/>
-    public override bool OnEnter (View view)
-    {
-        if (SuperView is { })
+        //// If the command view is focusable, invert the focus colors
+        if (CommandView.CanFocus)
         {
         {
-            ColorScheme = new (SuperView?.ColorScheme)
+            ColorScheme commandViewCS = new (base.ColorScheme)
             {
             {
-                Normal = SuperView.ColorScheme.Focus,
-                HotNormal = SuperView.ColorScheme.HotFocus
+                Normal = base.ColorScheme.Focus,
+                HotNormal = base.ColorScheme.HotFocus,
+                HotFocus = base.ColorScheme.HotNormal,
+                Focus = base.ColorScheme.Normal
             };
             };
+            CommandView.ColorScheme = commandViewCS;
         }
         }
+        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/>
+    public override bool OnEnter (View view)
+    {
+        SetColorScheme ();
         return base.OnEnter (view);
         return base.OnEnter (view);
     }
     }
 
 
@@ -696,8 +709,8 @@ public class Shortcut : View
     public override bool OnLeave (View view)
     public override bool OnLeave (View view)
     {
     {
         // Reset the color scheme (to SuperView).
         // Reset the color scheme (to SuperView).
-        ColorScheme = null;
-
+        //ColorScheme = null;
+        SetColorScheme ();
         return base.OnLeave (view);
         return base.OnLeave (view);
     }
     }
 
 

+ 2 - 1
Terminal.Gui/Views/Slider.cs

@@ -1377,7 +1377,8 @@ public class Slider<T> : View
 
 
             SetNeedsDisplay ();
             SetNeedsDisplay ();
 
 
-            return true;
+            mouseEvent.Handled = true;
+            return OnMouseClick (new (mouseEvent));
         }
         }
 
 
         return false;
         return false;

+ 101 - 92
UICatalog/Scenarios/Bars.cs

@@ -110,6 +110,7 @@ public class Bars : Scenario
             Y = 2,
             Y = 2,
             Orientation = Orientation.Vertical,
             Orientation = Orientation.Vertical,
             StatusBarStyle = false,
             StatusBarStyle = false,
+            BorderStyle = LineStyle.Rounded
         };
         };
         bar.Add (shortcut1, shortcut2);
         bar.Add (shortcut1, shortcut2);
 
 
@@ -132,9 +133,9 @@ public class Bars : Scenario
         // BUGBUG: This should not be needed
         // BUGBUG: This should not be needed
         Application.Top.LayoutSubviews ();
         Application.Top.LayoutSubviews ();
 
 
-        //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)!)
         {
         {
@@ -298,103 +299,111 @@ public class Bars : Scenario
         ((View)(sender)).LayoutSubviews ();
         ((View)(sender)).LayoutSubviews ();
     }
     }
 
 
-    //private void SetupMenuBar ()
-    //{
-    //    var menuBar = new Bar
-    //    {
-    //        Id = "menuBar",
+    private void SetupMenuBar ()
+    {
+        var menuBar = new Bar
+        {
+            Id = "menuBar",
+            Width = Dim.Fill (),
+            Height = 1,//Dim.Auto (DimAutoStyle.Content),
+            Orientation = Orientation.Horizontal,
+            StatusBarStyle = false,
+        };
 
 
-    //        X = 0,
-    //        Y = 0,
-    //        Width = Dim.Fill (),
-    //        Height = Dim.Auto (DimAutoStyle.Content),
-    //        StatusBarStyle = true
-    //    };
+        var fileMenuBarItem = new Shortcut
+        {
+            Title = "_File",
+            KeyBindingScope = KeyBindingScope.Application,
+            Key = Key.F.WithAlt,
+        };
+        fileMenuBarItem.KeyView.Visible = false;
+        
+        var editMenuBarItem = new Shortcut
+        {
+            Title = "_Edit",
 
 
-    //    var fileMenu = new Shortcut
-    //    {
-    //        Title = "_File",
-    //        Key = Key.F.WithAlt,
-    //        KeyBindingScope = KeyBindingScope.HotKey,
-    //        Command = Command.Accept,
-    //    };
-    //    fileMenu.HelpView.Visible = false;
-    //    fileMenu.KeyView.Visible = false;
-
-    //    fileMenu.Accept += (s, e) =>
-    //                       {
-    //                           fileMenu.SetFocus ();
-
-    //                           if (s is View view)
-    //                           {
-    //                               var menu = new Bar
-    //                               {
-    //                                   X = view.Frame.X + 1,
-    //                                   Y = view.Frame.Y + 1,
-    //                                   ColorScheme = view.ColorScheme,
-    //                                   Orientation = Orientation.Vertical,
-    //                                   StatusBarStyle = false,
-    //                                   BorderStyle = LineStyle.Dotted,
-    //                                   Width = Dim.Auto (DimAutoStyle.Content),
-    //                                   Height = Dim.Auto (DimAutoStyle.Content),
-    //                               };
-
-    //                               menu.KeyBindings.Add (Key.Esc, Command.QuitToplevel);
-
-    //                               var newMenu = new Shortcut
-    //                               {
-    //                                   Title = "_New...",
-    //                                   Text = "Create a new file",
-    //                                   Key = Key.N.WithCtrl
-    //                               };
-
-    //                               var open = new Shortcut
-    //                               {
-    //                                   Title = "_Open...",
-    //                                   Text = "Show the File Open Dialog",
-    //                                   Key = Key.O.WithCtrl
-    //                               };
-
-    //                               var save = new Shortcut
-    //                               {
-    //                                   Title = "_Save...",
-    //                                   Text = "Save",
-    //                                   Key = Key.S.WithCtrl
-    //                               };
-
-    //                               menu.Add (newMenu, open, save);
-
-    //                               // BUGBUG: this is all bad
-    //                               menu.Initialized += Menu_Initialized;
-    //                               open.Initialized += Menu_Initialized;
-    //                               save.Initialized += Menu_Initialized;
-    //                               newMenu.Initialized += Menu_Initialized;
-
-    //                               Application.Run (menu);
-    //                               menu.Dispose ();
-    //                               Application.Refresh ();
-    //                           }
-    //                       };
-
-    //    var editMenu = new Shortcut
-    //    {
-    //        Title = "_Edit",
+            KeyBindingScope = KeyBindingScope.HotKey,
+        };
 
 
-    //        //Key = Key.E.WithAlt,
-    //        KeyBindingScope = KeyBindingScope.HotKey,
-    //        Command = Command.Accept
-    //    };
+        editMenuBarItem.Accept += (s, e) => { };
+        //editMenu.HelpView.Visible = false;
+        //editMenu.KeyView.Visible = false;
 
 
-    //    editMenu.Accept += (s, e) => { };
-    //    editMenu.HelpView.Visible = false;
-    //    editMenu.KeyView.Visible = false;
+        menuBar.Add (fileMenuBarItem, editMenuBarItem);
+        menuBar.Initialized += Menu_Initialized;
+        Application.Top.Add (menuBar);
 
 
-    //    menuBar.Add (fileMenu, editMenu);
+        var fileMenu = new Bar
+        {
+            X = 1,
+            Y = 1,
+            Orientation = Orientation.Vertical,
+            StatusBarStyle = false,
+            Modal = true,
+            Visible = false,
+        };
+
+        var newShortcut = new Shortcut
+        {
+            Title = "_New...",
+            Text = "Create a new file",
+            Key = Key.N.WithCtrl
+        };
+        newShortcut.Border.Thickness = new Thickness (0, 1, 0, 0);
 
 
-    //    menuBar.Initialized += Menu_Initialized;
+        var openShortcut = new Shortcut
+        {
+            Title = "_Open...",
+            Text = "Show the File Open Dialog",
+            Key = Key.O.WithCtrl
+        };
 
 
-    //    Application.Top.Add (menuBar);
-    //}
+        var saveShortcut = new Shortcut
+        {
+            Title = "_Save...",
+            Text = "Save",
+            Key = Key.S.WithCtrl,
+            Enabled = false
+        };
+
+        var exitShortcut = new Shortcut
+        {
+            Title = "E_xit",
+            Text = "Exit",
+            Key = Key.X.WithCtrl,
+        };
+        exitShortcut.Border.Thickness = new Thickness (0, 1, 0, 1);
+
+        fileMenu.Add (newShortcut, openShortcut, saveShortcut, exitShortcut);
+
+        View prevFocus = null;
+        fileMenuBarItem.Accept += (s, e) =>
+                              {
+                                  if (fileMenu.Visible)
+                                  {
+                                      fileMenu.RequestStop ();
+                                      prevFocus?.SetFocus ();
+                                      return;
+                                  }
+
+                                  //fileMenu.Visible = !fileMenu.Visible;
+                                  var sender = s as Shortcut;
+                                  var screen = sender.FrameToScreen ();
+                                  fileMenu.X = screen.X;
+                                  fileMenu.Y = screen.Y + 1;
+                                  fileMenu.Visible = true;
+                                  prevFocus = Application.Top.Focused;
+                                  fileMenuBarItem.SetFocus ();
+                                  Application.Run (fileMenu);
+                                  fileMenu.Visible = false;
+                              };
+
+        Application.Top.Closed += (s, e) =>
+        {
+            fileMenu.Dispose ();
+        };
+
+    }
 
 
     private void SetupStatusBar ()
     private void SetupStatusBar ()
     {
     {

+ 20 - 15
UICatalog/Scenarios/Shortcuts.cs

@@ -1,6 +1,7 @@
 using System;
 using System;
 using System.Collections.ObjectModel;
 using System.Collections.ObjectModel;
 using System.Linq;
 using System.Linq;
+using System.Threading.Tasks;
 using System.Timers;
 using System.Timers;
 using Terminal.Gui;
 using Terminal.Gui;
 
 
@@ -81,14 +82,14 @@ public class Shortcuts : Scenario
         vShortcut2.Accept += (o, args) =>
         vShortcut2.Accept += (o, args) =>
                             {
                             {
                                 // Cycle to next item. If at end, set 0
                                 // Cycle to next item. If at end, set 0
-                                if (((RadioGroup)vShortcut2.CommandView).SelectedItem < ((RadioGroup)vShortcut2.CommandView).RadioLabels.Length - 1)
-                                {
-                                    ((RadioGroup)vShortcut2.CommandView).SelectedItem++;
-                                }
-                                else
-                                {
-                                    ((RadioGroup)vShortcut2.CommandView).SelectedItem = 0;
-                                }
+                                //if (((RadioGroup)vShortcut2.CommandView).SelectedItem < ((RadioGroup)vShortcut2.CommandView).RadioLabels.Length - 1)
+                                //{
+                                //    ((RadioGroup)vShortcut2.CommandView).SelectedItem++;
+                                //}
+                                //else
+                                //{
+                                //    ((RadioGroup)vShortcut2.CommandView).SelectedItem = 0;
+                                //}
                             };
                             };
         vShortcut2.Border.Thickness = new (1, 1, 1, 1);
         vShortcut2.Border.Thickness = new (1, 1, 1, 1);
         Application.Top.Add (vShortcut2);
         Application.Top.Add (vShortcut2);
@@ -99,7 +100,7 @@ public class Shortcuts : Scenario
             X = 0,
             X = 0,
             Y = Pos.Bottom (vShortcut2),
             Y = Pos.Bottom (vShortcut2),
             CommandView = new CheckBox { Text = "_Align" },
             CommandView = new CheckBox { Text = "_Align" },
-            Key = Key.F3,
+            Key = Key.F5.WithCtrl.WithAlt.WithShift,
             HelpText = "Width is Fill",
             HelpText = "Width is Fill",
             Width = Dim.Fill () - Dim.Width (eventLog),
             Width = Dim.Fill () - Dim.Width (eventLog),
             KeyBindingScope = KeyBindingScope.HotKey,
             KeyBindingScope = KeyBindingScope.HotKey,
@@ -161,7 +162,7 @@ public class Shortcuts : Scenario
             Y = Pos.Bottom (vShortcut4),
             Y = Pos.Bottom (vShortcut4),
             Width = Dim.Width (vShortcut4),
             Width = Dim.Width (vShortcut4),
 
 
-            Key = Key.F5.WithCtrl.WithAlt.WithShift,
+            Key = Key.F4,
             HelpText = "CommandView.CanFocus",
             HelpText = "CommandView.CanFocus",
             KeyBindingScope = KeyBindingScope.HotKey,
             KeyBindingScope = KeyBindingScope.HotKey,
             BorderStyle = LineStyle.Rounded,
             BorderStyle = LineStyle.Rounded,
@@ -178,8 +179,11 @@ public class Shortcuts : Scenario
 
 
                                                              foreach (Shortcut peer in Application.Top.Subviews.Where (v => v is Shortcut)!)
                                                              foreach (Shortcut peer in Application.Top.Subviews.Where (v => v is Shortcut)!)
                                                              {
                                                              {
-                                                                 peer.CanFocus = e.NewValue == true;
-                                                                 peer.CommandView.CanFocus = e.NewValue == true;
+                                                                 if (peer.CanFocus)
+                                                                 {
+                                                                     peer.CommandView.CanFocus = e.NewValue == true;
+                                                                     peer.SetColorScheme ();
+                                                                 }
                                                              }
                                                              }
                                                          }
                                                          }
                                                      };
                                                      };
@@ -224,13 +228,14 @@ public class Shortcuts : Scenario
 
 
             Title = "_No Key",
             Title = "_No Key",
             HelpText = "Keyless",
             HelpText = "Keyless",
-            BorderStyle = LineStyle.Rounded
+            BorderStyle = LineStyle.Rounded,
         };
         };
         vShortcut6.Border.Thickness = new (1, 1, 1, 1);
         vShortcut6.Border.Thickness = new (1, 1, 1, 1);
 
 
         Application.Top.Add (vShortcut6);
         Application.Top.Add (vShortcut6);
+        vShortcut6.SetFocus ();
 
 
-        ((CheckBox)vShortcut3.CommandView).OnToggled();
+        ((CheckBox)vShortcut3.CommandView).OnToggled ();
 
 
         // Horizontal
         // Horizontal
         var hShortcut1 = new Shortcut
         var hShortcut1 = new Shortcut
@@ -303,7 +308,7 @@ public class Shortcuts : Scenario
 
 
         var hShortcutBG = new Shortcut
         var hShortcutBG = new Shortcut
         {
         {
-            X = Pos.Align (Alignment.Start, AlignmentModes.IgnoreFirstOrLast, 1)-1,
+            X = Pos.Align (Alignment.Start, AlignmentModes.IgnoreFirstOrLast, 1) - 1,
             Y = Pos.Top (hShortcut2),
             Y = Pos.Top (hShortcut2),
             Key = Key.F9,
             Key = Key.F9,
             HelpText = "BG Color",
             HelpText = "BG Color",