File tree Expand file tree Collapse file tree 7 files changed +48
-21
lines changed
dev/Interop/StoragePickers Expand file tree Collapse file tree 7 files changed +48
-21
lines changed Original file line number Diff line number Diff line change @@ -81,15 +81,27 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
8181 {
8282 return m_fileTypeFilter;
8383 }
84- int FileOpenPicker::DefaultFileTypeIndex ()
84+ winrt::Windows::Foundation::IReference< uint32_t > FileOpenPicker::DefaultFileTypeIndex ()
8585 {
8686 THROW_HR_IF (E_NOTIMPL, !::Microsoft::Windows::Storage::Pickers::Feature_StoragePickers2::IsEnabled ());
87- return m_defaultFileTypeIndex;
87+ if (!m_defaultFileTypeIndex.has_value ())
88+ {
89+ return nullptr ;
90+ }
91+
92+ return winrt::box_value (*m_defaultFileTypeIndex).as <winrt::Windows::Foundation::IReference<uint32_t >>();
8893 }
89- void FileOpenPicker::DefaultFileTypeIndex (int value)
94+ void FileOpenPicker::DefaultFileTypeIndex (winrt::Windows::Foundation::IReference< uint32_t > const & value)
9095 {
9196 THROW_HR_IF (E_NOTIMPL, !::Microsoft::Windows::Storage::Pickers::Feature_StoragePickers2::IsEnabled ());
92- m_defaultFileTypeIndex = value;
97+ if (value)
98+ {
99+ m_defaultFileTypeIndex = value.Value ();
100+ }
101+ else
102+ {
103+ m_defaultFileTypeIndex.reset ();
104+ }
93105 }
94106 winrt::hstring FileOpenPicker::SuggestedFolder ()
95107 {
Original file line number Diff line number Diff line change 88#include < winrt/Windows.Foundation.Collections.h>
99#include " FileTypeChoicesMap.h"
1010#include " FileTypeFilterVector.h"
11+ #include < optional>
1112
1213namespace winrt ::Microsoft::Windows::Storage::Pickers::implementation
1314{
@@ -33,8 +34,8 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
3334 winrt::Windows::Foundation::Collections::IVector<winrt::hstring> FileTypeFilter ();
3435 winrt::Windows::Foundation::Collections::IMap<winrt::hstring, winrt::Windows::Foundation::Collections::IVector<winrt::hstring>> FileTypeChoices ();
3536
36- int DefaultFileTypeIndex ();
37- void DefaultFileTypeIndex (int value);
37+ winrt::Windows::Foundation::IReference< uint32_t > DefaultFileTypeIndex ();
38+ void DefaultFileTypeIndex (winrt::Windows::Foundation::IReference< uint32_t > const & value);
3839
3940 winrt::hstring SuggestedFolder ();
4041 void SuggestedFolder (winrt::hstring const & value);
@@ -63,7 +64,7 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
6364 }()
6465 };
6566
66- int m_defaultFileTypeIndex{ - 1 };
67+ std::optional< uint32_t > m_defaultFileTypeIndex{};
6768
6869 winrt::hstring m_suggestedFolder{};
6970 winrt::hstring m_suggestedStartFolder{};
Original file line number Diff line number Diff line change @@ -72,15 +72,27 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
7272 {
7373 return m_fileTypeChoices;
7474 }
75- int FileSavePicker::DefaultFileTypeIndex ()
75+ winrt::Windows::Foundation::IReference< uint32_t > FileSavePicker::DefaultFileTypeIndex ()
7676 {
7777 THROW_HR_IF (E_NOTIMPL, !::Microsoft::Windows::Storage::Pickers::Feature_StoragePickers2::IsEnabled ());
78- return m_defaultFileTypeIndex;
78+ if (!m_defaultFileTypeIndex.has_value ())
79+ {
80+ return nullptr ;
81+ }
82+
83+ return winrt::box_value (*m_defaultFileTypeIndex).as <winrt::Windows::Foundation::IReference<uint32_t >>();
7984 }
80- void FileSavePicker::DefaultFileTypeIndex (int value)
85+ void FileSavePicker::DefaultFileTypeIndex (winrt::Windows::Foundation::IReference< uint32_t > const & value)
8186 {
8287 THROW_HR_IF (E_NOTIMPL, !::Microsoft::Windows::Storage::Pickers::Feature_StoragePickers2::IsEnabled ());
83- m_defaultFileTypeIndex = value;
88+ if (value)
89+ {
90+ m_defaultFileTypeIndex = value.Value ();
91+ }
92+ else
93+ {
94+ m_defaultFileTypeIndex.reset ();
95+ }
8496 }
8597 hstring FileSavePicker::DefaultFileExtension ()
8698 {
Original file line number Diff line number Diff line change 66#include " PickerCommon.h"
77#include " StoragePickersTelemetryHelper.h"
88#include " FileTypeChoicesMap.h"
9+ #include < optional>
910
1011namespace winrt ::Microsoft::Windows::Storage::Pickers::implementation
1112{
@@ -29,8 +30,8 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
2930
3031 winrt::Windows::Foundation::Collections::IMap<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>> FileTypeChoices ();
3132
32- int DefaultFileTypeIndex ();
33- void DefaultFileTypeIndex (int value);
33+ winrt::Windows::Foundation::IReference< uint32_t > DefaultFileTypeIndex ();
34+ void DefaultFileTypeIndex (winrt::Windows::Foundation::IReference< uint32_t > const & value);
3435
3536 hstring DefaultFileExtension ();
3637 void DefaultFileExtension (hstring const & value);
@@ -59,7 +60,7 @@ namespace winrt::Microsoft::Windows::Storage::Pickers::implementation
5960 hstring m_title{};
6061 hstring m_settingsIdentifier{};
6162 winrt::Windows::Foundation::Collections::IMap<hstring, winrt::Windows::Foundation::Collections::IVector<hstring>> m_fileTypeChoices{ make<FileTypeChoicesMap>() };
62- int m_defaultFileTypeIndex{ - 1 };
63+ std::optional< uint32_t > m_defaultFileTypeIndex{};
6364 hstring m_defaultFileExtension{};
6465 bool m_showOverwritePrompt{ true };
6566 bool m_createNewFileIfNotExists{ true };
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ namespace Microsoft.Windows.Storage.Pickers
6060
6161 [contract(StoragePickersContract, 2.0)]
6262 [feature(Feature_StoragePickers2)]
63- Int32 DefaultFileTypeIndex;
63+ Windows.Foundation.IReference<UInt32> DefaultFileTypeIndex;
6464
6565 [contract(StoragePickersContract, 2.0)]
6666 [feature(Feature_StoragePickers2)]
@@ -94,7 +94,7 @@ namespace Microsoft.Windows.Storage.Pickers
9494
9595 [contract(StoragePickersContract, 2.0)]
9696 [feature(Feature_StoragePickers2)]
97- Int32 DefaultFileTypeIndex;
97+ Windows.Foundation.IReference<UInt32> DefaultFileTypeIndex;
9898
9999 String DefaultFileExtension;
100100 String SuggestedFileName;
Original file line number Diff line number Diff line change @@ -357,10 +357,10 @@ namespace PickerCommon {
357357 FileTypeFilterPara.push_back ({ FileTypeFilterData.at (i * 2 ).c_str (), FileTypeFilterData.at (i * 2 + 1 ).c_str () });
358358 }
359359
360- if (DefaultFileTypeIndex == - 1 )
360+ if (! DefaultFileTypeIndex. has_value () )
361361 {
362362 // If the DefaultFileTypeIndex is not specified by the user, set to focuse the last one ("All Files")
363- DefaultFileTypeIndex = static_cast <int >(resultSize) - 1 ;
363+ DefaultFileTypeIndex = static_cast <uint32_t >(resultSize - 1 ) ;
364364 }
365365 }
366366
@@ -468,9 +468,9 @@ namespace PickerCommon {
468468 {
469469 check_hresult (dialog->SetFileTypes ((UINT)FileTypeFilterPara.size (), FileTypeFilterPara.data ()));
470470
471- if (DefaultFileTypeIndex != - 1 && DefaultFileTypeIndex < static_cast <int >(FileTypeFilterPara.size ()))
471+ if (DefaultFileTypeIndex. has_value () && * DefaultFileTypeIndex < static_cast <uint32_t >(FileTypeFilterPara.size ()))
472472 {
473- check_hresult (dialog->SetFileTypeIndex (DefaultFileTypeIndex + 1 )); // COMDLG file type index is 1-based
473+ check_hresult (dialog->SetFileTypeIndex (static_cast <UINT>(* DefaultFileTypeIndex + 1 ) )); // COMDLG file type index is 1-based
474474 }
475475 }
476476
Original file line number Diff line number Diff line change 88#include < winrt/Windows.Security.Cryptography.h>
99#include < winrt/Windows.Security.Cryptography.Core.h>
1010#include < winrt/Microsoft.UI.Windowing.h>
11+ #include < optional>
1112
1213namespace PickerCommon {
1314 winrt::hstring GetPathFromShellItem (winrt::com_ptr<IShellItem> shellItem);
@@ -36,7 +37,7 @@ namespace PickerCommon {
3637 winrt::Microsoft::Windows::Storage::Pickers::PickerLocationId SuggestedStartLocation;
3738 std::vector<winrt::hstring> FileTypeFilterData{};
3839 std::vector<COMDLG_FILTERSPEC> FileTypeFilterPara{};
39- int DefaultFileTypeIndex{ - 1 };
40+ std::optional< uint32_t > DefaultFileTypeIndex{};
4041 winrt::hstring AllFilesText{ L" All Files" }; // initialize to All Files as a default value, will be updated by localization
4142
4243 winrt::hstring SuggestedFileName;
You can’t perform that action at this time.
0 commit comments