浏览代码

Added prototype close button

Tig Kindel 1 年之前
父节点
当前提交
f86b6b1ff3

+ 3 - 0
Terminal.Gui/View/Adornment/Border.cs

@@ -49,10 +49,13 @@ public class Border : Adornment
     { /* Do nothing; A parameter-less constructor is required to support all views unit tests. */
     { /* Do nothing; A parameter-less constructor is required to support all views unit tests. */
     }
     }
 
 
+    public Button CloseButton { get; internal set; }
+
     /// <inheritdoc/>
     /// <inheritdoc/>
     public Border (View parent) : base (parent)
     public Border (View parent) : base (parent)
     {
     {
         /* Do nothing; View.CreateAdornment requires a constructor that takes a parent */
         /* Do nothing; View.CreateAdornment requires a constructor that takes a parent */
+        Parent = parent;
     }
     }
 
 
     /// <summary>
     /// <summary>

+ 21 - 0
Terminal.Gui/View/View.cs

@@ -242,6 +242,11 @@ public partial class View : Responder, ISupportInitializeNotification
 
 
         Margin?.Dispose ();
         Margin?.Dispose ();
         Margin = null;
         Margin = null;
+
+        if (Border?.CloseButton is { })
+        {
+            Border?.CloseButton.Dispose ();
+        }
         Border?.Dispose ();
         Border?.Dispose ();
         Border = null;
         Border = null;
         Padding?.Dispose ();
         Padding?.Dispose ();
@@ -460,7 +465,23 @@ public partial class View : Responder, ISupportInitializeNotification
         _oldCanFocus = CanFocus;
         _oldCanFocus = CanFocus;
         _oldTabIndex = _tabIndex;
         _oldTabIndex = _tabIndex;
         Margin?.BeginInit ();
         Margin?.BeginInit ();
+
         Border?.BeginInit ();
         Border?.BeginInit ();
+        if (Border is { })
+        {
+            Border.CloseButton = new Button ()
+            {
+                Text = "X",
+                X = Pos.AnchorEnd (1),
+                Y = 0,
+                CanFocus = true,
+                //NoDecorations = true,
+                Visible = true,
+            };
+            Border.Add (Border.CloseButton);
+            Border.CloseButton.Accept += (s, e) => { Border.Parent.InvokeCommand (Command.Accept); };
+        }
+
         Padding?.BeginInit ();
         Padding?.BeginInit ();
 
 
         if (_subviews?.Count > 0)
         if (_subviews?.Count > 0)

+ 1 - 1
Terminal.Gui/View/ViewSubViews.cs

@@ -322,7 +322,7 @@ public partial class View
     public bool HasFocus
     public bool HasFocus
     {
     {
         set => SetHasFocus (value, this, true);
         set => SetHasFocus (value, this, true);
-        get { return _hasFocus; }
+        get => _hasFocus;
     }
     }
 
 
     private void SetHasFocus (bool value, View view, bool force = false)
     private void SetHasFocus (bool value, View view, bool force = false)

+ 1 - 1
Terminal.Gui/Views/Window.cs

@@ -39,7 +39,7 @@ public class Window : Toplevel
                             return true;
                             return true;
                         }
                         }
 
 
-                        return false;
+                        return OnAccept ();
                     }
                     }
                    );
                    );
 
 

+ 2 - 0
UICatalog/Scenarios/Adornments.cs

@@ -97,6 +97,8 @@ public class Adornments : Scenario
         btnButtonInPadding.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", "Button in Padding Pressed!", "Ok");
         btnButtonInPadding.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", "Button in Padding Pressed!", "Ok");
         view.Padding.Add (btnButtonInPadding);
         view.Padding.Add (btnButtonInPadding);
 
 
+        view.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", "Window Close Button Pressed!", "Ok");
+
         Application.Run (editor);
         Application.Run (editor);
         Application.Shutdown ();
         Application.Shutdown ();
     }
     }