Skip to content

Commit dd2c623

Browse files
committed
ValidatingFileTypeChoicesMap
1 parent 698d862 commit dd2c623

12 files changed

+226
-73
lines changed

dev/Interop/StoragePickers/FileOpenPicker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
#include "PickerCommon.h"
1414
#include "PickFileResult.h"
1515
#include "PickerLocalization.h"
16-
#include "ValidatingFileTypeFilterVector.h"
16+
#include "FileTypeFilterVector.h"
1717

1818
namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
1919
{
2020
FileOpenPicker::FileOpenPicker(winrt::Microsoft::UI::WindowId const& windowId)
21-
: m_windowId(windowId), m_fileTypeFilter(make<ValidatingFileTypeFilterVector>())
21+
: m_windowId(windowId), m_fileTypeFilter(make<FileTypeFilterVector>())
2222
{
2323
THROW_HR_IF(E_NOTIMPL, !::Microsoft::Windows::Storage::Pickers::Feature_StoragePickers::IsEnabled());
2424
}

dev/Interop/StoragePickers/FileSavePicker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
#include "PickerCommon.h"
1919
#include "PickerLocalization.h"
2020
#include "PickFileResult.h"
21+
#include "FileTypeChoicesMap.h"
2122

2223
namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
2324
{
2425

2526
FileSavePicker::FileSavePicker(winrt::Microsoft::UI::WindowId const& windowId)
26-
: m_windowId(windowId)
27+
: m_windowId(windowId), m_fileTypeChoices(make<FileTypeChoicesMap>())
2728
{
2829
THROW_HR_IF(E_NOTIMPL, !::Microsoft::Windows::Storage::Pickers::Feature_StoragePickers::IsEnabled());
2930
}

dev/Interop/StoragePickers/FileSavePicker.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Microsoft.Windows.Storage.Pickers.FileSavePicker.g.h"
66
#include "PickerCommon.h"
77
#include "StoragePickersTelemetryHelper.h"
8+
#include "FileTypeChoicesMap.h"
89

910
namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
1011
{
@@ -41,7 +42,7 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
4142
hstring m_settingsIdentifier{};
4243
PickerLocationId m_suggestedStartLocation{ PickerLocationId::Unspecified };
4344
hstring m_commitButtonText{};
44-
winrt::Windows::Foundation::Collections::IMap<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>> m_fileTypeChoices{ winrt::single_threaded_map<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>>() };
45+
winrt::Windows::Foundation::Collections::IMap<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>> m_fileTypeChoices;
4546
hstring m_defaultFileExtension{};
4647
hstring m_suggestedSaveFilePath{};
4748
hstring m_suggestedFileName{};
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) Microsoft Corporation and Contributors.
2+
// Licensed under the MIT License.
3+
4+
#include "pch.h"
5+
#include "FileTypeChoicesMap.h"
6+
#include "FileTypeFilterVector.h"
7+
8+
namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
9+
{
10+
FileTypeChoicesMap::FileTypeChoicesMap()
11+
{
12+
}
13+
14+
bool FileTypeChoicesMap::Insert(hstring const& key, winrt::Windows::Foundation::Collections::IVector<hstring> const& value)
15+
{
16+
// Create a new FileTypeFilterVector and copy all values from the input vector
17+
auto validatingVector = make<FileTypeFilterVector>();
18+
19+
if (value)
20+
{
21+
// Each Append call will validate the extension
22+
for (auto const& item : value)
23+
{
24+
validatingVector.as<winrt::Windows::Foundation::Collections::IVector<hstring>>().Append(item);
25+
}
26+
}
27+
28+
return m_innerMap.Insert(key, validatingVector);
29+
}
30+
31+
winrt::Windows::Foundation::Collections::IVector<hstring> FileTypeChoicesMap::Lookup(hstring const& key) const
32+
{
33+
return m_innerMap.Lookup(key);
34+
}
35+
36+
uint32_t FileTypeChoicesMap::Size() const
37+
{
38+
return m_innerMap.Size();
39+
}
40+
41+
bool FileTypeChoicesMap::HasKey(hstring const& key) const
42+
{
43+
return m_innerMap.HasKey(key);
44+
}
45+
46+
winrt::Windows::Foundation::Collections::IMapView<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>> FileTypeChoicesMap::GetView() const
47+
{
48+
return m_innerMap.GetView();
49+
}
50+
51+
void FileTypeChoicesMap::Remove(hstring const& key)
52+
{
53+
m_innerMap.Remove(key);
54+
}
55+
56+
void FileTypeChoicesMap::Clear()
57+
{
58+
m_innerMap.Clear();
59+
}
60+
61+
winrt::Windows::Foundation::Collections::IIterator<winrt::Windows::Foundation::Collections::IKeyValuePair<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>>> FileTypeChoicesMap::First() const
62+
{
63+
return m_innerMap.First();
64+
}
65+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Microsoft Corporation and Contributors.
2+
// Licensed under the MIT License.
3+
4+
#pragma once
5+
#include <winrt/Windows.Foundation.Collections.h>
6+
#include "FileTypeFilterVector.h"
7+
8+
namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
9+
{
10+
struct FileTypeChoicesMap : implements<FileTypeChoicesMap,
11+
winrt::Windows::Foundation::Collections::IMap<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>>,
12+
winrt::Windows::Foundation::Collections::IIterable<winrt::Windows::Foundation::Collections::IKeyValuePair<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>>>>
13+
{
14+
FileTypeChoicesMap();
15+
16+
// IMap<hstring, IVector<hstring>>
17+
winrt::Windows::Foundation::Collections::IVector<hstring> Lookup(hstring const& key) const;
18+
uint32_t Size() const;
19+
bool HasKey(hstring const& key) const;
20+
winrt::Windows::Foundation::Collections::IMapView<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>> GetView() const;
21+
bool Insert(hstring const& key, winrt::Windows::Foundation::Collections::IVector<hstring> const& value);
22+
void Remove(hstring const& key);
23+
void Clear();
24+
25+
// IIterable<IKeyValuePair<hstring, IVector<hstring>>>
26+
winrt::Windows::Foundation::Collections::IIterator<winrt::Windows::Foundation::Collections::IKeyValuePair<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>>> First() const;
27+
28+
private:
29+
winrt::Windows::Foundation::Collections::IMap<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>> m_innerMap{
30+
single_threaded_map<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>>() };
31+
};
32+
}

dev/Interop/StoragePickers/ValidatingFileTypeFilterVector.cpp renamed to dev/Interop/StoragePickers/FileTypeFilterVector.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@
22
// Licensed under the MIT License.
33

44
#include "pch.h"
5-
#include "ValidatingFileTypeFilterVector.h"
5+
#include "FileTypeFilterVector.h"
66
#include "PickerCommon.h"
77

88
namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
99
{
10-
ValidatingFileTypeFilterVector::ValidatingFileTypeFilterVector()
10+
FileTypeFilterVector::FileTypeFilterVector()
1111
{
1212
}
1313

14-
void ValidatingFileTypeFilterVector::SetAt(uint32_t index, hstring const& value)
14+
void FileTypeFilterVector::SetAt(uint32_t index, hstring const& value)
1515
{
1616
PickerCommon::ValidateSingleFileTypeFilterElement(value);
1717
m_innerVector.SetAt(index, value);
1818
}
1919

20-
void ValidatingFileTypeFilterVector::InsertAt(uint32_t index, hstring const& value)
20+
void FileTypeFilterVector::InsertAt(uint32_t index, hstring const& value)
2121
{
2222
PickerCommon::ValidateSingleFileTypeFilterElement(value);
2323
m_innerVector.InsertAt(index, value);
2424
}
2525

26-
void ValidatingFileTypeFilterVector::Append(hstring const& value)
26+
void FileTypeFilterVector::Append(hstring const& value)
2727
{
2828
PickerCommon::ValidateSingleFileTypeFilterElement(value);
2929
m_innerVector.Append(value);
3030
}
3131

32-
void ValidatingFileTypeFilterVector::ReplaceAll(array_view<hstring const> items)
32+
void FileTypeFilterVector::ReplaceAll(array_view<hstring const> items)
3333
{
3434
// Validate all items before replacing
3535
for (auto const& item : items)
@@ -39,47 +39,47 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
3939
m_innerVector.ReplaceAll(items);
4040
}
4141

42-
hstring ValidatingFileTypeFilterVector::GetAt(uint32_t index) const
42+
hstring FileTypeFilterVector::GetAt(uint32_t index) const
4343
{
4444
return m_innerVector.GetAt(index);
4545
}
4646

47-
uint32_t ValidatingFileTypeFilterVector::Size() const
47+
uint32_t FileTypeFilterVector::Size() const
4848
{
4949
return m_innerVector.Size();
5050
}
5151

52-
winrt::Windows::Foundation::Collections::IVectorView<hstring> ValidatingFileTypeFilterVector::GetView() const
52+
winrt::Windows::Foundation::Collections::IVectorView<hstring> FileTypeFilterVector::GetView() const
5353
{
5454
return m_innerVector.GetView();
5555
}
5656

57-
bool ValidatingFileTypeFilterVector::IndexOf(hstring const& value, uint32_t& index) const
57+
bool FileTypeFilterVector::IndexOf(hstring const& value, uint32_t& index) const
5858
{
5959
return m_innerVector.IndexOf(value, index);
6060
}
6161

62-
void ValidatingFileTypeFilterVector::RemoveAt(uint32_t index)
62+
void FileTypeFilterVector::RemoveAt(uint32_t index)
6363
{
6464
m_innerVector.RemoveAt(index);
6565
}
6666

67-
void ValidatingFileTypeFilterVector::RemoveAtEnd()
67+
void FileTypeFilterVector::RemoveAtEnd()
6868
{
6969
m_innerVector.RemoveAtEnd();
7070
}
7171

72-
void ValidatingFileTypeFilterVector::Clear()
72+
void FileTypeFilterVector::Clear()
7373
{
7474
m_innerVector.Clear();
7575
}
7676

77-
uint32_t ValidatingFileTypeFilterVector::GetMany(uint32_t startIndex, array_view<hstring> items) const
77+
uint32_t FileTypeFilterVector::GetMany(uint32_t startIndex, array_view<hstring> items) const
7878
{
7979
return m_innerVector.GetMany(startIndex, items);
8080
}
8181

82-
winrt::Windows::Foundation::Collections::IIterator<hstring> ValidatingFileTypeFilterVector::First() const
82+
winrt::Windows::Foundation::Collections::IIterator<hstring> FileTypeFilterVector::First() const
8383
{
8484
return m_innerVector.First();
8585
}

dev/Interop/StoragePickers/ValidatingFileTypeFilterVector.h renamed to dev/Interop/StoragePickers/FileTypeFilterVector.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
#pragma once
55
#include <winrt/Windows.Foundation.Collections.h>
6-
// #include "PickerCommon.h"
76

87
namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
98
{
10-
struct ValidatingFileTypeFilterVector : implements<ValidatingFileTypeFilterVector,
11-
winrt::Windows::Foundation::Collections::IVector<hstring>,
9+
struct FileTypeFilterVector : implements<FileTypeFilterVector,
10+
winrt::Windows::Foundation::Collections::IVector<hstring>,
1211
winrt::Windows::Foundation::Collections::IIterable<hstring>>
1312
{
14-
ValidatingFileTypeFilterVector();
13+
FileTypeFilterVector();
1514

1615
// IVector<hstring>
1716
hstring GetAt(uint32_t index) const;

dev/Interop/StoragePickers/PickerCommon.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -197,27 +197,27 @@ namespace PickerCommon {
197197
}
198198
}
199199

200-
void ValidateFileTypeFilter(winrt::Windows::Foundation::Collections::IVectorView<winrt::hstring> filters)
201-
{
202-
if (filters.Size() > 0)
203-
{
204-
for (const auto& filter : filters)
205-
{
206-
ValidateSingleFileTypeFilterElement(filter);
207-
}
208-
}
209-
}
210-
211-
void ValidateFileTypeChoices(winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::Windows::Foundation::Collections::IVector<winrt::hstring>> filters)
212-
{
213-
if (filters.Size() > 0)
214-
{
215-
for (const auto& filter : filters)
216-
{
217-
ValidateFileTypeFilter(filter.Value().GetView());
218-
}
219-
}
220-
}
200+
//void ValidateFileTypeFilter(winrt::Windows::Foundation::Collections::IVectorView<winrt::hstring> filters)
201+
//{
202+
// if (filters.Size() > 0)
203+
// {
204+
// for (const auto& filter : filters)
205+
// {
206+
// ValidateSingleFileTypeFilterElement(filter);
207+
// }
208+
// }
209+
//}
210+
211+
//void ValidateFileTypeChoices(winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::Windows::Foundation::Collections::IVector<winrt::hstring>> filters)
212+
//{
213+
// if (filters.Size() > 0)
214+
// {
215+
// for (const auto& filter : filters)
216+
// {
217+
// ValidateFileTypeFilter(filter.Value().GetView());
218+
// }
219+
// }
220+
//}
221221

222222
void ValidateSuggestedFileName(winrt::hstring const& suggestedFileName)
223223
{

dev/Interop/StoragePickers/PickerCommon.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ namespace PickerCommon {
2020
void ValidateViewMode(winrt::Microsoft::Windows::Storage::Pickers::PickerViewMode const& value);
2121
void ValidateSuggestedStartLocation(winrt::Microsoft::Windows::Storage::Pickers::PickerLocationId const& value);
2222
void ValidateSingleFileTypeFilterElement(winrt::hstring filter);
23-
void ValidateFileTypeFilter(winrt::Windows::Foundation::Collections::IVectorView<winrt::hstring> filters);
24-
void ValidateFileTypeChoices(winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::Windows::Foundation::Collections::IVector<winrt::hstring>> filters);
23+
//void ValidateFileTypeFilter(winrt::Windows::Foundation::Collections::IVectorView<winrt::hstring> filters);
24+
//void ValidateFileTypeChoices(winrt::Windows::Foundation::Collections::IMapView<winrt::hstring, winrt::Windows::Foundation::Collections::IVector<winrt::hstring>> filters);
2525
void ValidateSuggestedFileName(winrt::hstring const& suggestedFileName);
2626

2727
struct PickerParameters {

dev/Interop/StoragePickers/StoragePickers.vcxitems

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
<ClCompile Include="$(MSBuildThisFileDirectory)PickerLocalization.cpp" />
1919
<ClCompile Include="$(MSBuildThisFileDirectory)PickFileResult.cpp" />
2020
<ClCompile Include="$(MSBuildThisFileDirectory)PickFolderResult.cpp" />
21-
<ClCompile Include="$(MSBuildThisFileDirectory)ValidatingFileTypeFilterVector.cpp" />
21+
<ClCompile Include="$(MSBuildThisFileDirectory)FileTypeFilterVector.cpp" />
22+
<ClCompile Include="$(MSBuildThisFileDirectory)FileTypeChoicesMap.cpp" />
2223
</ItemGroup>
2324
<ItemGroup>
2425
<ClInclude Include="$(MSBuildThisFileDirectory)PickerCommon.h" />
@@ -27,7 +28,8 @@
2728
<ClInclude Include="$(MSBuildThisFileDirectory)PickFolderResult.h" />
2829
<ClInclude Include="$(MSBuildThisFileDirectory)StoragePickersTelemetry.h" />
2930
<ClInclude Include="$(MSBuildThisFileDirectory)StoragePickersTelemetryHelper.h" />
30-
<ClInclude Include="$(MSBuildThisFileDirectory)ValidatingFileTypeFilterVector.h" />
31+
<ClInclude Include="$(MSBuildThisFileDirectory)FileTypeFilterVector.h" />
32+
<ClInclude Include="$(MSBuildThisFileDirectory)FileTypeChoicesMap.h" />
3133
</ItemGroup>
3234
<ItemGroup>
3335
<ClCompile Include="$(MSBuildThisFileDirectory)FileOpenPicker.cpp" />

0 commit comments

Comments
 (0)