瀏覽代碼

Enabled FileDialog IDesignable

Tig 9 月之前
父節點
當前提交
262bc0123b
共有 2 個文件被更改,包括 45 次插入20 次删除
  1. 44 19
      Terminal.Gui/Views/FileDialog.cs
  2. 1 1
      UICatalog/Scenarios/AllViewsTester.cs

+ 44 - 19
Terminal.Gui/Views/FileDialog.cs

@@ -8,7 +8,7 @@ namespace Terminal.Gui;
 ///     Modal dialog for selecting files/directories. Has auto-complete and expandable navigation pane (Recent, Root
 ///     drives etc).
 /// </summary>
-public class FileDialog : Dialog
+public class FileDialog : Dialog, IDesignable
 {
     private const int alignmentGroupInput = 32;
     private const int alignmentGroupComplete = 55;
@@ -78,20 +78,34 @@ public class FileDialog : Dialog
             Y = Pos.AnchorEnd (),
             IsDefault = true, Text = Style.OkButtonText
         };
-        _btnOk.Accepting += (s, e) => Accept (true);
+        _btnOk.Accepting += (s, e) =>
+                            {
+                                if (e.Cancel)
+                                {
+                                    return;
+                                }
+
+                                Accept (true);
+                            };
 
 
         _btnCancel = new Button
         {
             X = Pos.Align (Alignment.End, AlignmentModes.AddSpaceBetweenItems, alignmentGroupComplete),
-            Y = Pos.AnchorEnd(),
+            Y = Pos.AnchorEnd (),
             Text = Strings.btnCancel
         };
 
         _btnCancel.Accepting += (s, e) =>
         {
-            Canceled = true;
-            Application.RequestStop ();
+            if (e.Cancel)
+            {
+                return;
+            }
+            if (Modal)
+            {
+                Application.RequestStop ();
+            }
         };
 
         _btnUp = new Button { X = 0, Y = 1, NoPadding = true };
@@ -163,7 +177,7 @@ public class FileDialog : Dialog
         ColumnStyle typeStyle = Style.TableStyle.GetOrCreateColumnStyle (3);
         typeStyle.MinWidth = 6;
         typeStyle.ColorGetter = ColorGetter;
-        
+
         _treeView = new TreeView<IFileSystemInfo> { Width = Dim.Fill (), Height = Dim.Fill () };
 
         var fileDialogTreeBuilder = new FileSystemTreeBuilder ();
@@ -189,12 +203,12 @@ public class FileDialog : Dialog
                                                   bool newState = !tile.ContentView.Visible;
                                                   tile.ContentView.Visible = newState;
                                                   _btnToggleSplitterCollapse.Text = GetToggleSplitterText (newState);
-                                                  SetNeedsLayout();
+                                                  SetNeedsLayout ();
                                               };
 
         _tbFind = new TextField
         {
-            X = Pos.Align (Alignment.Start,AlignmentModes.AddSpaceBetweenItems, alignmentGroupInput),
+            X = Pos.Align (Alignment.Start, AlignmentModes.AddSpaceBetweenItems, alignmentGroupInput),
             CaptionColor = new Color (Color.Black),
             Width = 30,
             Y = Pos.Top (_btnToggleSplitterCollapse),
@@ -240,7 +254,7 @@ public class FileDialog : Dialog
         _tableView.KeyBindings.ReplaceCommands (Key.End, Command.End);
         _tableView.KeyBindings.ReplaceCommands (Key.Home.WithShift, Command.StartExtend);
         _tableView.KeyBindings.ReplaceCommands (Key.End.WithShift, Command.EndExtend);
-        
+
         AllowsMultipleSelection = false;
 
         UpdateNavigationVisibility ();
@@ -254,8 +268,8 @@ public class FileDialog : Dialog
         Add (_tbFind);
         Add (_spinnerView);
 
-        Add(_btnOk);
-        Add(_btnCancel);
+        Add (_btnOk);
+        Add (_btnCancel);
     }
 
     /// <summary>
@@ -494,8 +508,8 @@ public class FileDialog : Dialog
             MoveSubviewTowardsStart (_btnCancel);
         }
 
-        SetNeedsDisplay();
-        SetNeedsLayout();
+        SetNeedsDraw ();
+        SetNeedsLayout ();
     }
 
     /// <inheritdoc/>
@@ -636,7 +650,7 @@ public class FileDialog : Dialog
         if (!IsCompatibleWithOpenMode (f.FullName, out string reason))
         {
             _feedback = reason;
-            SetNeedsDisplay ();
+            SetNeedsDraw ();
 
             return;
         }
@@ -663,7 +677,7 @@ public class FileDialog : Dialog
             if (reason is { })
             {
                 _feedback = reason;
-                SetNeedsDisplay ();
+                SetNeedsDraw ();
             }
 
             return;
@@ -829,7 +843,11 @@ public class FileDialog : Dialog
         }
 
         Canceled = false;
-        Application.RequestStop ();
+
+        if (Modal)
+        {
+            Application.RequestStop ();
+        }
     }
 
     private string GetBackButtonText () { return Glyphs.LeftArrow + "-"; }
@@ -1117,7 +1135,7 @@ public class FileDialog : Dialog
             _tableView.RowOffset = 0;
             _tableView.SelectedRow = 0;
 
-            SetNeedsDisplay ();
+            SetNeedsDraw ();
             UpdateNavigationVisibility ();
         }
         finally
@@ -1402,7 +1420,7 @@ public class FileDialog : Dialog
         if (reason is { })
         {
             _feedback = reason;
-            SetNeedsDisplay ();
+            SetNeedsDraw ();
         }
 
         return false;
@@ -1590,9 +1608,16 @@ public class FileDialog : Dialog
                                     Parent.WriteStateToTableView ();
 
                                     Parent._spinnerView.Visible = true;
-                                    Parent._spinnerView.SetNeedsDisplay ();
+                                    Parent._spinnerView.SetNeedsDraw ();
                                 }
                                );
         }
     }
+
+    bool IDesignable.EnableForDesign ()
+    {
+        Modal = false;
+        OnLoaded ();
+        return true;
+    }
 }

+ 1 - 1
UICatalog/Scenarios/AllViewsTester.cs

@@ -254,6 +254,7 @@ public class AllViewsTester : Scenario
 
         // Instantiate view
         var view = (View)Activator.CreateInstance (type)!;
+        _eventLog!.ViewToLog = _curView;
 
         if (view is IDesignable designable)
         {
@@ -281,7 +282,6 @@ public class AllViewsTester : Scenario
         view.Id = "_curView";
         _curView = view;
 
-        _eventLog!.ViewToLog = _curView;
         _hostPane!.Add (_curView);
         _layoutEditor!.ViewToEdit = _curView;
         _curView.SetNeedsLayout ();