Browse Source

Fix default button order ok/cancel to match windows and add flip option to FileDialogStyle

tznind 1 year ago
parent
commit
4036fb9926
2 changed files with 27 additions and 14 deletions
  1. 7 0
      Terminal.Gui/FileServices/FileDialogStyle.cs
  2. 20 14
      Terminal.Gui/Views/FileDialog.cs

+ 7 - 0
Terminal.Gui/FileServices/FileDialogStyle.cs

@@ -98,6 +98,13 @@ namespace Terminal.Gui {
 		/// </summary>
 		public string CancelButtonText { get; set; } = "Cancel";
 
+		/// <summary>
+		/// Gets or sets whether to flip the order of the Ok and Cancel buttons. Defaults
+		/// to false (Ok button then Cancel button). Set to true to show Cancel button on
+		/// left then Ok button instead.
+		/// </summary>
+		public bool FlipOkCancelButtonLayoutOrder { get; set; }
+
 		/// <summary>
 		/// Gets or sets error message when user attempts to select a file type that is not one of <see cref="FileDialog.AllowedTypes"/>
 		/// </summary>

+ 20 - 14
Terminal.Gui/Views/FileDialog.cs

@@ -142,11 +142,7 @@ namespace Terminal.Gui {
 
 			this.btnOk = new Button (Style.OkButtonText) {
 				Y = Pos.AnchorEnd (1),
-				X = Pos.Function (() =>
-					this.Bounds.Width
-					- btnOk.Bounds.Width
-					// TODO: Fiddle factor, seems the Bounds are wrong for someone
-					- 2)
+				X = Pos.Function (CalculateOkButtonPosX)
 			};
 			this.btnOk.Clicked += (s, e) => this.Accept (true);
 			this.btnOk.KeyPress += (s, k) => {
@@ -156,14 +152,7 @@ namespace Terminal.Gui {
 
 			this.btnCancel = new Button ("Cancel") {
 				Y = Pos.AnchorEnd (1),
-				X = Pos.Function (() =>
-					this.Bounds.Width
-					- btnOk.Bounds.Width
-					- btnCancel.Bounds.Width
-					- 1
-					// TODO: Fiddle factor, seems the Bounds are wrong for someone
-					- 2
-					)
+				X = Pos.Right (btnOk) + 1
 			};
 			this.btnCancel.KeyPress += (s, k) => {
 				this.NavigateIf (k, Key.CursorLeft, this.btnToggleSplitterCollapse);
@@ -284,7 +273,6 @@ namespace Terminal.Gui {
 
 			tbFind = new TextField {
 				X = Pos.Right (this.btnToggleSplitterCollapse) + 1,
-				Caption = Style.SearchCaption,
 				CaptionColor = Color.Black,
 				Width = 30,
 				Y = Pos.AnchorEnd (1),
@@ -372,6 +360,16 @@ namespace Terminal.Gui {
 			this.Add (this.splitContainer);
 		}
 
+		private int CalculateOkButtonPosX ()
+		{
+			return this.Bounds.Width
+				- btnOk.Bounds.Width
+				- btnCancel.Bounds.Width
+				- 1
+				// TODO: Fiddle factor, seems the Bounds are wrong for someone
+				- 2;
+		}
+
 		private string AspectGetter (object o)
 		{
 			var fsi = (IFileSystemInfo)o;
@@ -649,6 +647,14 @@ namespace Terminal.Gui {
 			this.btnForward.Text = this.GetForwardButtonText ();
 			this.btnToggleSplitterCollapse.Text = this.GetToggleSplitterText (false);
 
+			if(Style.FlipOkCancelButtonLayoutOrder) {
+				var p1 = btnOk.X;
+				var p2 = btnCancel.X;
+
+				btnOk.X = p2;
+				btnCancel.X = p1;
+			}
+
 			tbPath.Caption = Style.PathCaption;
 			tbFind.Caption = Style.SearchCaption;