Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Terminal.Gui/Views/FileDialogs/FileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ public override void EndInit ()
_typeFilterDropDown?.Visible = true;
_typeFilterDropDown?.Source = new ListWrapper<string> (new ObservableCollection<string> (AllowedTypes.Select (a => a.ToString ()!).ToList ()));
_typeFilterDropDown?.Value = AllowedTypes [0].ToString () ?? string.Empty;

if (State is { })
{
RefreshState ();
}
}

// if no path has been provided
Expand Down
30 changes: 30 additions & 0 deletions Tests/UnitTestsParallelizable/Views/FileDialogResultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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 ()
{
Expand Down