Преглед изворни кода

Add scenario support for flipping button order

tznind пре 1 година
родитељ
комит
14fab61d35
2 измењених фајлова са 41 додато и 4 уклоњено
  1. 9 4
      Terminal.Gui/Views/FileDialog.cs
  2. 32 0
      UICatalog/Scenarios/FileDialogExamples.cs

+ 9 - 4
Terminal.Gui/Views/FileDialog.cs

@@ -648,11 +648,16 @@ namespace Terminal.Gui {
 			this.btnToggleSplitterCollapse.Text = this.GetToggleSplitterText (false);
 
 			if(Style.FlipOkCancelButtonLayoutOrder) {
-				var p1 = btnOk.X;
-				var p2 = btnCancel.X;
+				btnCancel.X = Pos.Function(this.CalculateOkButtonPosX);
+				btnOk.X = Pos.Right (btnCancel) + 1;
 
-				btnOk.X = p2;
-				btnCancel.X = p1;
+
+				// Flip tab order too for consistency
+				var p1 = this.btnOk.TabIndex;
+				var p2 = this.btnCancel.TabIndex;
+
+				this.btnOk.TabIndex = p2;
+				this.btnCancel.TabIndex = p1;
 			}
 
 			tbPath.Caption = Style.PathCaption;

+ 32 - 0
UICatalog/Scenarios/FileDialogExamples.cs

@@ -25,6 +25,9 @@ namespace UICatalog.Scenarios {
 		private RadioGroup rgIcons;
 		private RadioGroup rgAllowedTypes;
 
+		private TextField tbOkButton;
+		private TextField tbCancelButton;
+		private CheckBox cbFlipButtonOrder;
 		public override void Setup ()
 		{
 			var y = 0;
@@ -110,6 +113,25 @@ namespace UICatalog.Scenarios {
 			rgAllowedTypes.RadioLabels = new string [] { "Any", "Csv (Recommended)", "Csv (Strict)" };
 			Win.Add (rgAllowedTypes);
 
+			y = 5;
+			x = 45;
+
+			Win.Add (new LineView (Orientation.Vertical) {
+				X = x++,
+				Y = y + 1,
+				Height = 4
+			});
+			Win.Add (new Label ("Buttons") { X = x++, Y = y++ });
+
+			Win.Add(new Label("Ok Text:") { X = x, Y = y++ });
+			tbOkButton = new TextField () { X = x, Y = y++, Width = 12 };
+			Win.Add (tbOkButton);
+			Win.Add (new Label ("Cancel Text:") { X = x, Y = y++ });
+			tbCancelButton = new TextField () { X = x, Y = y++, Width = 12 };
+			Win.Add (tbCancelButton);
+			cbFlipButtonOrder = new CheckBox ("Flip Order") { X = x, Y = y++};
+			Win.Add (cbFlipButtonOrder);
+
 			var btn = new Button ($"Run Dialog") {
 				X = 1,
 				Y = 9
@@ -178,6 +200,16 @@ namespace UICatalog.Scenarios {
 
 			}
 
+			if (!string.IsNullOrWhiteSpace (tbOkButton.Text)) {
+				fd.Style.OkButtonText = tbOkButton.Text;
+			}
+			if (!string.IsNullOrWhiteSpace (tbCancelButton.Text)) {
+				fd.Style.CancelButtonText= tbCancelButton.Text;
+			}
+			if(cbFlipButtonOrder.Checked ?? false) {
+				fd.Style.FlipOkCancelButtonLayoutOrder = true;
+			}
+
 			Application.Run (fd);
 
 			if (fd.Canceled) {