Skip to content

Commit 054f9d7

Browse files
committed
Use Windows.Storage.Pickers.PickerLocationId instead of built-in PickerLocationId
1 parent 6e21d87 commit 054f9d7

4 files changed

Lines changed: 18 additions & 31 deletions

File tree

dev/DevWinUI/Common/Picker/FilePicker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class FilePicker
1515
public string? SuggestedFileName { get; set; }
1616
public string? DefaultFileExtension { get; set; }
1717
public string? InitialDirectory { get; set; }
18-
public PickerLocationId SuggestedStartLocation { get; set; } = PickerLocationId.Unspecified;
18+
public Windows.Storage.Pickers.PickerLocationId SuggestedStartLocation { get; set; } = Windows.Storage.Pickers.PickerLocationId.Unspecified;
1919
public string? Title { get; set; }
2020
public Dictionary<string, IList<string>> FileTypeChoices { get; set; } = new();
2121
public bool ShowAllFilesOption { get; set; } = true;
@@ -79,7 +79,7 @@ private unsafe List<string> OpenFileDialog(IntPtr hwnd, bool allowMultiple)
7979
dialog->SetOkButtonLabel(CommitButtonText);
8080
}
8181

82-
if (SuggestedStartLocation != PickerLocationId.Unspecified)
82+
if (SuggestedStartLocation != Windows.Storage.Pickers.PickerLocationId.Unspecified)
8383
{
8484
InitialDirectory = PathHelper.GetKnownFolderPath(SuggestedStartLocation);
8585
}

dev/DevWinUI/Common/Picker/FolderPicker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class FolderPicker
1212
public string? CommitButtonText { get; set; }
1313
public string? SuggestedFileName { get; set; }
1414
public string? InitialDirectory { get; set; }
15-
public PickerLocationId SuggestedStartLocation { get; set; } = PickerLocationId.Unspecified;
15+
public Windows.Storage.Pickers.PickerLocationId SuggestedStartLocation { get; set; } = Windows.Storage.Pickers.PickerLocationId.Unspecified;
1616
public string? Title { get; set; }
1717

1818
public string PickSingleFolder(Microsoft.UI.Xaml.Window window) => PickSingleFolder(WindowNative.GetWindowHandle(window));
@@ -73,7 +73,7 @@ private unsafe List<string> OpenFolderDialog(IntPtr hwnd, bool allowMultiple)
7373
dialog->SetOkButtonLabel(CommitButtonText);
7474
}
7575

76-
if (SuggestedStartLocation != PickerLocationId.Unspecified)
76+
if (SuggestedStartLocation != Windows.Storage.Pickers.PickerLocationId.Unspecified)
7777
{
7878
InitialDirectory = PathHelper.GetKnownFolderPath(SuggestedStartLocation);
7979
}

dev/DevWinUI/Common/Picker/SavePicker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class SavePicker
1515
public string? SuggestedFileName { get; set; }
1616
public string? DefaultFileExtension { get; set; }
1717
public string? InitialDirectory { get; set; }
18-
public PickerLocationId SuggestedStartLocation { get; set; } = PickerLocationId.Unspecified;
18+
public Windows.Storage.Pickers.PickerLocationId SuggestedStartLocation { get; set; } = Windows.Storage.Pickers.PickerLocationId.Unspecified;
1919
public string? Title { get; set; }
2020
public Dictionary<string, IList<string>> FileTypeChoices { get; set; } = new();
2121
public bool ShowAllFilesOption { get; set; } = true;
@@ -77,7 +77,7 @@ private async Task<StorageFile> GetStorageFileOrCreateAsync(string filePath)
7777
dialog->SetOkButtonLabel(CommitButtonText);
7878
}
7979

80-
if (SuggestedStartLocation != PickerLocationId.Unspecified)
80+
if (SuggestedStartLocation != Windows.Storage.Pickers.PickerLocationId.Unspecified)
8181
{
8282
InitialDirectory = PathHelper.GetKnownFolderPath(SuggestedStartLocation);
8383
}

dev/DevWinUI/Helpers/PathHelper.cs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,61 +71,48 @@ public static string GetExecutablePathNative()
7171
}
7272
}
7373

74-
public static string GetKnownFolderPath(PickerLocationId pickerLocationId)
74+
public static string GetKnownFolderPath(Windows.Storage.Pickers.PickerLocationId pickerLocationId)
7575
{
7676
Guid folderId;
7777

7878
switch (pickerLocationId)
7979
{
80-
case PickerLocationId.DocumentsLibrary:
80+
case Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary:
8181
folderId = new Guid("FDD39AD0-238F-46AF-ADB4-6C85480369C7"); // FOLDERID_Documents
8282
break;
83-
case PickerLocationId.ComputerFolder:
83+
case Windows.Storage.Pickers.PickerLocationId.ComputerFolder:
8484
folderId = new Guid("0AC0837C-BBF8-452A-850D-79D08E667CA7"); // FOLDERID_ComputerFolder
8585
break;
86-
case PickerLocationId.Desktop:
86+
case Windows.Storage.Pickers.PickerLocationId.Desktop:
8787
folderId = new Guid("B4BFCC3A-DB2C-424C-B029-7FE99A87C641"); // FOLDERID_Desktop
8888
break;
89-
case PickerLocationId.Downloads:
89+
case Windows.Storage.Pickers.PickerLocationId.Downloads:
9090
folderId = new Guid("374DE290-123F-4565-9164-39C4925E467B"); // FOLDERID_Downloads
9191
break;
92-
case PickerLocationId.HomeGroup:
92+
case Windows.Storage.Pickers.PickerLocationId.HomeGroup:
9393
folderId = new Guid("52528A6B-B9E3-4ADD-B60D-588C2DBA842D"); // FOLDERID_HomeGroup
9494
break;
95-
case PickerLocationId.MusicLibrary:
95+
case Windows.Storage.Pickers.PickerLocationId.MusicLibrary:
9696
folderId = new Guid("4BD8D571-6D19-48D3-BE97-422220080E43"); // FOLDERID_MusicLibrary
9797
break;
98-
case PickerLocationId.PicturesLibrary:
98+
case Windows.Storage.Pickers.PickerLocationId.PicturesLibrary:
9999
folderId = new Guid("33E28130-4E1E-4676-835A-98395C3BC3BB"); // FOLDERID_PicturesLibrary
100100
break;
101-
case PickerLocationId.VideosLibrary:
101+
case Windows.Storage.Pickers.PickerLocationId.VideosLibrary:
102102
folderId = new Guid("18989B1D-99B5-455B-841C-AB7C74E4DDFC"); // FOLDERID_VideosLibrary
103103
break;
104-
case PickerLocationId.Objects3D:
104+
case Windows.Storage.Pickers.PickerLocationId.Objects3D:
105105
folderId = new Guid("31C0DD25-9439-4F12-BF41-7FF4EDA38722"); // FOLDERID_Objects3D
106106
break;
107-
case PickerLocationId.Unspecified:
107+
case Windows.Storage.Pickers.PickerLocationId.Unspecified:
108108
default:
109109
return string.Empty;
110110
}
111111

112112
PWSTR pszPath;
113-
int hr = PInvoke.SHGetKnownFolderPath(ref folderId, 0, null, out pszPath);
113+
int hr = PInvoke.SHGetKnownFolderPath(in folderId, 0, null, out pszPath);
114114
if (hr != 0) return string.Empty;
115115

116116
return pszPath.ToString();
117117
}
118118
}
119-
public enum PickerLocationId
120-
{
121-
DocumentsLibrary,
122-
ComputerFolder,
123-
Desktop,
124-
Downloads,
125-
HomeGroup,
126-
MusicLibrary,
127-
PicturesLibrary,
128-
VideosLibrary,
129-
Objects3D,
130-
Unspecified
131-
}

0 commit comments

Comments
 (0)