Skip to content

Commit 9a2af4e

Browse files
committed
unioned FileTypeChoices
1 parent 61f4319 commit 9a2af4e

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

dev/Interop/StoragePickers/PickerCommon.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ namespace PickerCommon {
349349
FileTypeFilterData.clear();
350350
FileTypeFilterData.reserve(resultSize * 2);
351351

352-
winrt::Windows::Foundation::Collections::IVector<hstring> unionedExtensionVector;
352+
winrt::Windows::Foundation::Collections::IVector<hstring> unionedExtensionVector{ single_threaded_vector<hstring>() };
353353

354354
for (const auto& filter : filters)
355355
{
@@ -370,6 +370,7 @@ namespace PickerCommon {
370370
}
371371
else if (unionChoices)
372372
{
373+
// when filters not defined, "All files" category is the union of all extensions defined in FileTypeChoices
373374
FileTypeFilterData.push_back(AllFilesText);
374375
FileTypeFilterData.push_back(JoinExtensions(unionedExtensionVector.GetView()));
375376
}

test/StoragePickersTests/PickerCommonTests.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,35 @@ namespace Test::PickerCommonTests
237237
L"*.png;*.jpg;*.jpeg;*.bmp");
238238
}
239239

240+
TEST_METHOD(VerifyFilters_FileSavePickerWhenUnionChoicesExpectMatchingSpec)
241+
{
242+
// Arrange.
243+
winrt::Microsoft::UI::WindowId windowId{};
244+
winrt::Microsoft::Windows::Storage::Pickers::FileSavePicker picker(windowId);
245+
246+
picker.FileTypeChoices().Insert(
247+
L"Documents", winrt::single_threaded_vector<winrt::hstring>({ L".txt", L".doc", L".docx" }));
248+
picker.FileTypeChoices().Insert(
249+
L"Pictures", winrt::single_threaded_vector<winrt::hstring>({ L".png", L".jpg", L".jpeg", L".bmp" }));
250+
251+
// Act.
252+
PickerParameters parameters{};
253+
parameters.CaptureFilterSpec(picker.FileTypeChoices().GetView(), true);
254+
255+
// Assert.
256+
VERIFY_ARE_EQUAL(parameters.FileTypeFilterPara.size(), 3);
257+
258+
VERIFY_ARE_EQUAL(
259+
std::wstring(parameters.FileTypeFilterPara[0].pszSpec),
260+
L"*.txt;*.doc;*.docx");
261+
VERIFY_ARE_EQUAL(
262+
std::wstring(parameters.FileTypeFilterPara[1].pszSpec),
263+
L"*.png;*.jpg;*.jpeg;*.bmp");
264+
VERIFY_ARE_EQUAL(
265+
std::wstring(parameters.FileTypeFilterPara[2].pszSpec),
266+
L"*.txt;*.doc;*.docx;*.png;*.jpg;*.jpeg;*.bmp");
267+
}
268+
240269
TEST_METHOD(VerifyFilters_FileSavePickerWhenNoFileTypeChoicesDefinedExpectAsteriskSpec)
241270
{
242271
// Note that is is a different behavior than the UWP pickers, where FileTypeChoices are required.

0 commit comments

Comments
 (0)