diff --git a/Terminal.Gui/Views/FileDialogs/FileDialog.cs b/Terminal.Gui/Views/FileDialogs/FileDialog.cs index 21f82efdc5..4402d4955b 100644 --- a/Terminal.Gui/Views/FileDialogs/FileDialog.cs +++ b/Terminal.Gui/Views/FileDialogs/FileDialog.cs @@ -318,6 +318,11 @@ public override void EndInit () _typeFilterDropDown?.Visible = true; _typeFilterDropDown?.Source = new ListWrapper (new ObservableCollection (AllowedTypes.Select (a => a.ToString ()!).ToList ())); _typeFilterDropDown?.Value = AllowedTypes [0].ToString () ?? string.Empty; + + if (State is { }) + { + RefreshState (); + } } // if no path has been provided diff --git a/Tests/UnitTestsParallelizable/Views/FileDialogResultTests.cs b/Tests/UnitTestsParallelizable/Views/FileDialogResultTests.cs index ffd72df94e..b9bc5a6e0e 100644 --- a/Tests/UnitTestsParallelizable/Views/FileDialogResultTests.cs +++ b/Tests/UnitTestsParallelizable/Views/FileDialogResultTests.cs @@ -221,6 +221,36 @@ public void FileDialog_PathField_BadChars_AreSuppressed (char badChar) Assert.Equal (insertionPointBefore, tbPath.InsertionPoint); } + [Fact] + public void FileDialog_MixedMode_PathSetBeforeEndInit_RespectsAllowedTypes () + { + // Copilot + MockFileSystem fs = new (); + fs.AddDirectory ("/testdir"); + fs.AddDirectory ("/testdir/subdir"); + fs.AddFile ("/testdir/allowed.Designer.cs", new MockFileData ("allowed")); + fs.AddFile ("/testdir/blocked.txt", new MockFileData ("blocked")); + using FileDialog fd = new TestableFileDialog (fs) + { + OpenMode = OpenMode.Mixed, + AllowedTypes = [new AllowedType ("View", ".Designer.cs")] + }; + + fd.Path = "/testdir"; + fd.EndInit (); + + Assert.NotNull (fd.CurrentFilter); + Assert.NotNull (fd.State); + + List visibleEntries = fd.State!.Children + .Where (c => !c.IsParent) + .Select (c => c.Name) + .OrderBy (name => name) + .ToList (); + + Assert.Equal (["allowed.Designer.cs", "subdir"], visibleEntries); + } + [Fact] public void FileDialog_Accepting_Directory_From_Table_Keeps_Path_On_Opened_Directory () {