|
1 | 1 | // Copyright (c) 2023 Files Community |
2 | 2 | // Licensed under the MIT License. See the LICENSE. |
3 | 3 |
|
4 | | -using Files.Core.Extensions; |
5 | 4 | using System.IO; |
| 5 | +using System.Runtime.InteropServices; |
| 6 | +using System.Text; |
6 | 7 | using System.Windows.Input; |
7 | 8 | using Windows.Storage.Pickers; |
8 | 9 |
|
@@ -84,18 +85,27 @@ public CreateShortcutDialogViewModel(string workingDirectory) |
84 | 85 | WorkingDirectory = workingDirectory; |
85 | 86 | _destinationItemPath = string.Empty; |
86 | 87 |
|
87 | | - SelectDestinationCommand = new AsyncRelayCommand(SelectDestinationAsync); |
| 88 | + SelectDestinationCommand = new AsyncRelayCommand(SelectDestination); |
88 | 89 | PrimaryButtonCommand = new AsyncRelayCommand(CreateShortcutAsync); |
89 | 90 | } |
90 | 91 |
|
91 | | - private async Task SelectDestinationAsync() |
| 92 | + private Task SelectDestination() |
92 | 93 | { |
93 | | - var folderPicker = InitializeWithWindow(new FolderPicker()); |
94 | | - folderPicker.FileTypeFilter.Add("*"); |
| 94 | + InteropHelpers.BROWSEINFO bi = new InteropHelpers.BROWSEINFO(); |
| 95 | + bi.ulFlags = 0x00004000; |
| 96 | + bi.lpszTitle = "Select a folder"; |
| 97 | + nint pidl = InteropHelpers.SHBrowseForFolder(ref bi); |
| 98 | + if (pidl != nint.Zero) |
| 99 | + { |
| 100 | + StringBuilder path = new StringBuilder(260); |
| 101 | + if (InteropHelpers.SHGetPathFromIDList(pidl, path)) |
| 102 | + { |
| 103 | + DestinationItemPath = path.ToString(); |
| 104 | + } |
| 105 | + Marshal.FreeCoTaskMem(pidl); |
| 106 | + } |
95 | 107 |
|
96 | | - var selectedFolder = await folderPicker.PickSingleFolderAsync(); |
97 | | - if (selectedFolder is not null) |
98 | | - DestinationItemPath = selectedFolder.Path; |
| 108 | + return Task.CompletedTask; |
99 | 109 | } |
100 | 110 |
|
101 | 111 | private FolderPicker InitializeWithWindow(FolderPicker obj) |
|
0 commit comments