Kaynağa Gözat

Default button just is now Right

Tig 1 yıl önce
ebeveyn
işleme
831eecbd28

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

@@ -24,7 +24,7 @@
   "Themes": [
     {
       "Default": {
-        "Dialog.DefaultButtonAlignment": "Centered",
+        "Dialog.DefaultButtonJustification": "Right",
         "FrameView.DefaultBorderStyle": "Single",
         "Window.DefaultBorderStyle": "Single",
         "ColorSchemes": [

+ 2 - 2
Terminal.Gui/Views/Dialog.cs

@@ -51,7 +51,7 @@ public class Dialog : Window
         ColorScheme = Colors.ColorSchemes ["Dialog"];
 
         Modal = true;
-        ButtonAlignment = DefaultButtonAlignment;
+        ButtonAlignment = DefaultButtonJustification;
 
         AddCommand (
                     Command.QuitToplevel,
@@ -122,7 +122,7 @@ public class Dialog : Window
     /// <remarks>This property can be set in a Theme.</remarks>
     [SerializableConfigurationProperty (Scope = typeof (ThemeScope))]
     [JsonConverter (typeof (JsonStringEnumConverter))]
-    public static Justification DefaultButtonAlignment { get; set; } = Justification.Centered;
+    public static Justification DefaultButtonJustification { get; set; } = Justification.Right;
 
     /// <summary>
     ///     Adds a <see cref="Button"/> to the <see cref="Dialog"/>, its layout will be controlled by the

+ 5 - 6
Terminal.Gui/Views/MessageBox.cs

@@ -327,9 +327,7 @@ public static class MessageBox
             {
                 var b = new Button
                 {
-                    Text = s, 
-                    Y = Pos.AnchorEnd (), 
-                    X = Pos.Justify (Justification.Centered)
+                    Text = s,
                 };
 
                 if (count == defaultButton)
@@ -342,9 +340,9 @@ public static class MessageBox
             }
         }
 
-        Dialog d;
-
-        d = new Dialog
+        Justification buttonJust = Dialog.DefaultButtonJustification;
+        Dialog.DefaultButtonJustification = Justification.Centered;
+        var d = new Dialog
         {
             Buttons = buttonList.ToArray (),
             Title = title,
@@ -352,6 +350,7 @@ public static class MessageBox
             Width = Dim.Percent (60),
             Height = 5 // Border + one line of text + vspace + buttons
         };
+        Dialog.DefaultButtonJustification = buttonJust;
 
         if (width != 0)
         {

+ 3 - 1
UICatalog/Scenarios/Dialogs.cs

@@ -145,13 +145,15 @@ public class Dialogs : Scenario
             }
         }
 
+        var labels = GetUniqueEnumNames<Justification> ();
         var styleRadioGroup = new RadioGroup
         {
             X = Pos.Right (label) + 1,
             Y = Pos.Top (label),
-            RadioLabels = GetUniqueEnumNames<Justification> ().ToArray (),
+            RadioLabels = labels.ToArray (),
         };
         frame.Add (styleRadioGroup);
+        styleRadioGroup.SelectedItem = labels.ToList().IndexOf (Dialog.DefaultButtonJustification.ToString());
 
         frame.ValidatePosDim = true;
 

+ 3 - 3
UnitTests/Configuration/ThemeScopeTests.cs

@@ -29,12 +29,12 @@ public class ThemeScopeTests
     {
         Reset ();
         Assert.NotEmpty (Themes);
-        Assert.Equal (Justification.Centered, Dialog.DefaultButtonAlignment);
+        Assert.Equal (Justification.Right, Dialog.DefaultButtonJustification);
 
-        Themes ["Default"] ["Dialog.DefaultButtonAlignment"].PropertyValue = Justification.Right;
+        Themes ["Default"] ["Dialog.DefaultButtonJustification"].PropertyValue = Justification.Centered;
 
         ThemeManager.Themes! [ThemeManager.SelectedTheme]!.Apply ();
-        Assert.Equal (Justification.Right, Dialog.DefaultButtonAlignment);
+        Assert.Equal (Justification.Centered, Dialog.DefaultButtonJustification);
         Reset ();
     }
 

+ 2 - 2
UnitTests/Configuration/ThemeTests.cs

@@ -77,7 +77,7 @@ public class ThemeTests
     public void TestSerialize_RoundTrip ()
     {
         var theme = new ThemeScope ();
-        theme ["Dialog.DefaultButtonAlignment"].PropertyValue = Justification.Right;
+        theme ["Dialog.DefaultButtonJustification"].PropertyValue = Justification.Right;
 
         string json = JsonSerializer.Serialize (theme, _jsonOptions);
 
@@ -85,7 +85,7 @@ public class ThemeTests
 
         Assert.Equal (
                       Justification.Right,
-                      (Justification)deserialized ["Dialog.DefaultButtonAlignment"].PropertyValue
+                      (Justification)deserialized ["Dialog.DefaultButtonJustification"].PropertyValue
                      );
         Reset ();
     }

+ 3 - 0
UnitTests/Dialogs/DialogTests.cs

@@ -889,6 +889,7 @@ public class DialogTests
 
         win.Loaded += (s, a) =>
                       {
+                          Dialog.DefaultButtonJustification = Justification.Centered;
                           var dlg = new Dialog { Width = 18, Height = 3, Buttons = [new () { Text = "Ok" }] };
 
                           dlg.Loaded += (s, a) =>
@@ -972,6 +973,7 @@ public class DialogTests
         var win = new Window ();
 
         int iterations = -1;
+        Dialog.DefaultButtonJustification = Justification.Centered;
 
         Iteration += (s, a) =>
                      {
@@ -1006,6 +1008,7 @@ public class DialogTests
     public void Dialog_Opened_From_Another_Dialog ()
     {
         ((FakeDriver)Driver).SetBufferSize (30, 10);
+        Dialog.DefaultButtonJustification = Justification.Centered;
 
         var btn1 = new Button { Text = "press me 1" };
         Button btn2 = null;