Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -315,6 +315,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.FileSystemInfo!.Name)
Comment thread
tig marked this conversation as resolved.
Outdated
.OrderBy (name => name)
.ToList ();

Assert.Equal (["allowed.Designer.cs", "subdir"], visibleEntries);
}

/// <summary>Testable subclass that exposes the internal file-system constructor.</summary>
private sealed class TestableFileDialog : FileDialog
{
Expand Down
Loading