Pārlūkot izejas kodu

Fixed Dialog/Messagebox issues

Tig 1 gadu atpakaļ
vecāks
revīzija
d4ee1b0859

+ 5 - 5
Terminal.Gui/Drawing/Aligner.cs

@@ -14,7 +14,7 @@ public class Aligner : INotifyPropertyChanged
     /// </summary>
     /// <remarks>
     ///     <para>
-    ///         <see cref="AlignmentMode"/> provides additional options for aligning items in a container.
+    ///         <see cref="AlignmentModes"/> provides additional options for aligning items in a container.
     ///     </para>
     /// </remarks>
     public Alignment Alignment
@@ -32,13 +32,13 @@ public class Aligner : INotifyPropertyChanged
     /// <summary>
     ///     Gets or sets the modes controlling <see cref="Alignment"/>.
     /// </summary>
-    public AlignmentModes AlignmentMode
+    public AlignmentModes AlignmentModes
     {
         get => _alignmentMode;
         set
         {
             _alignmentMode = value;
-            PropertyChanged?.Invoke (this, new (nameof (AlignmentMode)));
+            PropertyChanged?.Invoke (this, new (nameof (AlignmentModes)));
         }
     }
 
@@ -62,11 +62,11 @@ public class Aligner : INotifyPropertyChanged
 
     /// <summary>
     ///     Takes a list of item sizes and returns a list of the positions of those items when aligned within <see name="ContainerSize"/>
-    ///     using the <see cref="Alignment"/> and <see cref="AlignmentMode"/> settings.
+    ///     using the <see cref="Alignment"/> and <see cref="AlignmentModes"/> settings.
     /// </summary>
     /// <param name="sizes">The sizes of the items to align.</param>
     /// <returns>The locations of the items, from left/top to right/bottom.</returns>
-    public int [] Align (int [] sizes) { return Align (Alignment, AlignmentMode, ContainerSize, sizes); }
+    public int [] Align (int [] sizes) { return Align (Alignment, AlignmentModes, ContainerSize, sizes); }
 
     /// <summary>
     ///     Takes a list of item sizes and returns a list of the  positions of those items when aligned within <paramref name="containerSize"/>

+ 1 - 0
Terminal.Gui/Resources/config.json

@@ -25,6 +25,7 @@
     {
       "Default": {
         "Dialog.DefaultButtonAlignment": "End",
+        "Dialog.DefaultButtonAlignmentModes": "AddSpaceBetweenItems",
         "FrameView.DefaultBorderStyle": "Single",
         "Window.DefaultBorderStyle": "Single",
         "ColorSchemes": [

+ 3 - 3
Terminal.Gui/View/Layout/Pos.cs

@@ -145,15 +145,15 @@ public abstract class Pos
     ///     Creates a <see cref="Pos"/> object that aligns a set of views according to the specified alignment setting.
     /// </summary>
     /// <param name="alignment">The alignment.</param>
-    /// <param name="mode">The optional alignment modes.</param>
+    /// <param name="modes">The optional alignment modes.</param>
     /// <param name="groupId">
     ///     The optional, unique identifier for the set of views to align according to
     ///     <paramref name="alignment"/>.
     /// </param>
     /// <returns></returns>
-    public static Pos Align (Alignment alignment, AlignmentModes mode = AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems, int groupId = 0)
+    public static Pos Align (Alignment alignment, AlignmentModes modes = AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems, int groupId = 0)
     {
-        return new PosAlign (alignment, mode, groupId);
+        return new PosAlign (alignment, modes, groupId);
     }
 
     /// <summary>

+ 3 - 3
Terminal.Gui/View/Layout/PosAlign.cs

@@ -114,12 +114,12 @@ public class PosAlign : Pos
     ///     Enables alignment of a set of views.
     /// </summary>
     /// <param name="alignment"></param>
-    /// <param name="mode"></param>
+    /// <param name="modes"></param>
     /// <param name="groupId">The unique identifier for the set of views to align according to <paramref name="alignment"/>.</param>
-    public PosAlign (Alignment alignment, AlignmentModes mode = AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems, int groupId = 0)
+    public PosAlign (Alignment alignment, AlignmentModes modes = AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems, int groupId = 0)
     {
         Aligner.Alignment = alignment;
-        Aligner.AlignmentMode = mode;
+        Aligner.AlignmentModes = modes;
         _groupId = groupId;
         Aligner.PropertyChanged += Aligner_PropertyChanged;
     }

+ 14 - 1
Terminal.Gui/Views/Dialog.cs

@@ -52,6 +52,7 @@ public class Dialog : Window
 
         Modal = true;
         ButtonAlignment = DefaultButtonAlignment;
+        ButtonAlignmentModes = DefaultButtonAlignmentModes;
 
         AddCommand (
                     Command.QuitToplevel,
@@ -100,6 +101,11 @@ public class Dialog : Window
     /// <summary>Determines how the <see cref="Dialog"/> <see cref="Button"/>s are aligned along the bottom of the dialog.</summary>
     public Alignment ButtonAlignment { get; set; }
 
+    /// <summary>
+    /// Gets or sets the alignment modes for the dialog's buttons.
+    /// </summary>
+    public AlignmentModes ButtonAlignmentModes { get; set; }
+
     /// <summary>Optional buttons to lay out at the bottom of the dialog.</summary>
     public Button [] Buttons
     {
@@ -124,6 +130,12 @@ public class Dialog : Window
     [JsonConverter (typeof (JsonStringEnumConverter))]
     public static Alignment DefaultButtonAlignment { get; set; } = Alignment.End;
 
+    /// <summary>The default <see cref="Alignment"/> for <see cref="Dialog"/>.</summary>
+    /// <remarks>This property can be set in a Theme.</remarks>
+    [SerializableConfigurationProperty (Scope = typeof (ThemeScope))]
+    [JsonConverter (typeof (JsonStringEnumConverter))]
+    public static AlignmentModes DefaultButtonAlignmentModes { get; set; } = AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems;
+
     /// <summary>
     ///     Adds a <see cref="Button"/> to the <see cref="Dialog"/>, its layout will be controlled by the
     ///     <see cref="Dialog"/>
@@ -136,7 +148,8 @@ public class Dialog : Window
             return;
         }
 
-        button.X = Pos.Align (ButtonAlignment);
+        // Use a distinct GroupId so users can use Pos.Align for other views in the Dialog
+        button.X = Pos.Align (ButtonAlignment, ButtonAlignmentModes, groupId: GetHashCode ());
         button.Y = Pos.AnchorEnd ();
 
         _buttons.Add (button);

+ 2 - 3
Terminal.Gui/Views/MessageBox.cs

@@ -340,17 +340,16 @@ public static class MessageBox
             }
         }
 
-        Alignment buttonJust = Dialog.DefaultButtonAlignment;
-        Dialog.DefaultButtonAlignment = Alignment.Center;
         var d = new Dialog
         {
+            ButtonAlignment = Alignment.Center,
+            ButtonAlignmentModes = AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems,
             Buttons = buttonList.ToArray (),
             Title = title,
             BorderStyle = DefaultBorderStyle,
             Width = Dim.Auto (DimAutoStyle.Content, minimumContentDim: Dim.Percent(60)),
             Height = Dim.Auto (DimAutoStyle.Content),
         };
-        Dialog.DefaultButtonAlignment = buttonJust;
 
         if (width != 0)
         {

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

@@ -67,7 +67,8 @@ public class Wizard : Dialog
     public Wizard ()
     {
         // TODO: LastEndRestStart will enable a "Quit" button to always appear at the far left
-       // ButtonAlignment = Alignment.LastEndRestStart;
+        ButtonAlignment = Alignment.Start;
+        ButtonAlignmentModes |= AlignmentModes.IgnoreFirstOrLast;
         BorderStyle = LineStyle.Double;
 
         //// Add a horiz separator

+ 1 - 1
UICatalog/Scenarios/Dialogs.cs

@@ -146,7 +146,7 @@ public class Dialogs : Scenario
         };
         frame.Add (label);
 
-        var labels = new [] { "Start", "End", "Center", "Fill", "FirstStartRestEnd", "LastEndRestStart" };
+        var labels = Enum.GetNames<Alignment> ();
         var alignmentGroup = new RadioGroup
         {
             X = Pos.Right (label) + 1,

+ 22 - 22
UICatalog/Scenarios/PosAlignDemo.cs

@@ -85,13 +85,13 @@ public sealed class PosAlignDemo : Scenario
 
         if (dimension == Dimension.Width)
         {
-            ignoreFirstOrLast.Checked = _horizAligner.AlignmentMode.HasFlag (AlignmentModes.IgnoreFirstOrLast);
+            ignoreFirstOrLast.Checked = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.IgnoreFirstOrLast);
             ignoreFirstOrLast.X = Pos.Align (_horizAligner.Alignment);
             ignoreFirstOrLast.Y = Pos.Top (alignRadioGroup);
         }
         else
         {
-            ignoreFirstOrLast.Checked = _vertAligner.AlignmentMode.HasFlag (AlignmentModes.IgnoreFirstOrLast);
+            ignoreFirstOrLast.Checked = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.IgnoreFirstOrLast);
             ignoreFirstOrLast.X = Pos.Left (alignRadioGroup);
             ignoreFirstOrLast.Y = Pos.Align (_vertAligner.Alignment);
         }
@@ -100,18 +100,18 @@ public sealed class PosAlignDemo : Scenario
                                {
                                    if (dimension == Dimension.Width)
                                    {
-                                       _horizAligner.AlignmentMode = e.NewValue is { } &&
+                                       _horizAligner.AlignmentModes = e.NewValue is { } &&
                                                                  e.NewValue.Value ?
-                                                                     _horizAligner.AlignmentMode | AlignmentModes.IgnoreFirstOrLast :
-                                                                     _horizAligner.AlignmentMode & ~AlignmentModes.IgnoreFirstOrLast;
+                                                                     _horizAligner.AlignmentModes | AlignmentModes.IgnoreFirstOrLast :
+                                                                     _horizAligner.AlignmentModes & ~AlignmentModes.IgnoreFirstOrLast;
                                        UpdatePosAlignObjects (appWindow, dimension, _horizAligner);
                                    }
                                    else
                                    {
-                                       _vertAligner.AlignmentMode = e.NewValue is { } &&
+                                       _vertAligner.AlignmentModes = e.NewValue is { } &&
                                                                  e.NewValue.Value ?
-                                                                     _vertAligner.AlignmentMode | AlignmentModes.IgnoreFirstOrLast :
-                                                                     _vertAligner.AlignmentMode & ~AlignmentModes.IgnoreFirstOrLast;
+                                                                     _vertAligner.AlignmentModes | AlignmentModes.IgnoreFirstOrLast :
+                                                                     _vertAligner.AlignmentModes & ~AlignmentModes.IgnoreFirstOrLast;
                                        UpdatePosAlignObjects (appWindow, dimension, _vertAligner);
                                    }
                                };
@@ -125,13 +125,13 @@ public sealed class PosAlignDemo : Scenario
 
         if (dimension == Dimension.Width)
         {
-            addSpacesBetweenItems.Checked = _horizAligner.AlignmentMode.HasFlag (AlignmentModes.AddSpaceBetweenItems);
+            addSpacesBetweenItems.Checked = _horizAligner.AlignmentModes.HasFlag (AlignmentModes.AddSpaceBetweenItems);
             addSpacesBetweenItems.X = Pos.Align (_horizAligner.Alignment);
             addSpacesBetweenItems.Y = Pos.Top (alignRadioGroup);
         }
         else
         {
-            addSpacesBetweenItems.Checked = _vertAligner.AlignmentMode.HasFlag (AlignmentModes.AddSpaceBetweenItems);
+            addSpacesBetweenItems.Checked = _vertAligner.AlignmentModes.HasFlag (AlignmentModes.AddSpaceBetweenItems);
             addSpacesBetweenItems.X = Pos.Left (alignRadioGroup);
             addSpacesBetweenItems.Y = Pos.Align (_vertAligner.Alignment);
         }
@@ -140,18 +140,18 @@ public sealed class PosAlignDemo : Scenario
                              {
                                  if (dimension == Dimension.Width)
                                  {
-                                     _horizAligner.AlignmentMode = e.NewValue is { } &&
+                                     _horizAligner.AlignmentModes = e.NewValue is { } &&
                                                              e.NewValue.Value ?
-                                                                 _horizAligner.AlignmentMode | AlignmentModes.AddSpaceBetweenItems :
-                                                                 _horizAligner.AlignmentMode & ~AlignmentModes.AddSpaceBetweenItems;
+                                                                 _horizAligner.AlignmentModes | AlignmentModes.AddSpaceBetweenItems :
+                                                                 _horizAligner.AlignmentModes & ~AlignmentModes.AddSpaceBetweenItems;
                                      UpdatePosAlignObjects (appWindow, dimension, _horizAligner);
                                  }
                                  else
                                  {
-                                     _vertAligner.AlignmentMode = e.NewValue is { } &&
+                                     _vertAligner.AlignmentModes = e.NewValue is { } &&
                                                              e.NewValue.Value ?
-                                                                 _vertAligner.AlignmentMode | AlignmentModes.AddSpaceBetweenItems :
-                                                                 _vertAligner.AlignmentMode & ~AlignmentModes.AddSpaceBetweenItems;
+                                                                 _vertAligner.AlignmentModes | AlignmentModes.AddSpaceBetweenItems :
+                                                                 _vertAligner.AlignmentModes & ~AlignmentModes.AddSpaceBetweenItems;
                                      UpdatePosAlignObjects (appWindow, dimension, _vertAligner);
                                  }
 
@@ -282,7 +282,7 @@ public sealed class PosAlignDemo : Scenario
                     PosAlign posAlign = view.X as PosAlign;
                     view.X = new PosAlign (
                                            aligner.Alignment,
-                                           aligner.AlignmentMode,
+                                           aligner.AlignmentModes,
                                            posAlign!.GroupId);
                     view.Margin.Thickness = new (_leftMargin, 0, 0, 0);
 
@@ -292,7 +292,7 @@ public sealed class PosAlignDemo : Scenario
                     PosAlign posAlign = view.Y as PosAlign;
                     view.Y = new PosAlign (
                                            aligner.Alignment,
-                                           aligner.AlignmentMode,
+                                           aligner.AlignmentModes,
                                            posAlign!.GroupId);
 
 
@@ -322,7 +322,7 @@ public sealed class PosAlignDemo : Scenario
         container.Padding.Thickness = new Thickness (8, 1, 0, 0);
         container.Padding.ColorScheme = Colors.ColorSchemes ["error"];
 
-        Aligner widthAligner = new () { AlignmentMode = AlignmentModes.StartToEnd };
+        Aligner widthAligner = new () { AlignmentModes = AlignmentModes.StartToEnd };
         RadioGroup widthAlignRadioGroup = new ()
         {
             RadioLabels = Enum.GetNames<Alignment> (),
@@ -338,7 +338,7 @@ public sealed class PosAlignDemo : Scenario
             UpdatePosAlignObjects (container, Dimension.Width, widthAligner);
         };
 
-        Aligner heightAligner = new () { AlignmentMode = AlignmentModes.StartToEnd };
+        Aligner heightAligner = new () { AlignmentModes = AlignmentModes.StartToEnd };
         RadioGroup heightAlignRadioGroup = new ()
         {
             RadioLabels = Enum.GetNames<Alignment> (),
@@ -365,8 +365,8 @@ public sealed class PosAlignDemo : Scenario
                 Width = 5
             };
 
-            v.X = Pos.Align (widthAligner.Alignment, widthAligner.AlignmentMode, groupId: i / 3);
-            v.Y = Pos.Align (heightAligner.Alignment,heightAligner.AlignmentMode, groupId: i % 3 + 10);
+            v.X = Pos.Align (widthAligner.Alignment, widthAligner.AlignmentModes, groupId: i / 3);
+            v.Y = Pos.Align (heightAligner.Alignment,heightAligner.AlignmentModes, groupId: i % 3 + 10);
 
             container.Add (v);
         }

+ 1 - 1
UnitTests/Drawing/AlignerTests.cs

@@ -383,7 +383,7 @@ public class AlignerTests (ITestOutputHelper output)
         int [] positions = new Aligner
         {
             Alignment = alignment,
-            AlignmentMode = AlignmentModes.StartToEnd | modes,
+            AlignmentModes = AlignmentModes.StartToEnd | modes,
             ContainerSize = containerSize
         }.Align (sizes);
         AssertAlignment (alignment, sizes, containerSize, positions, expected);