Skip to content

Commit de22141

Browse files
authored
Merge branch 'main' into ya/RemovedGetThumbnailAsync
2 parents 8d49edc + d2e8980 commit de22141

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

src/Files.App/Helpers/Interop/InteropHelpers.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.UI.Xaml;
66
using System.Reflection;
77
using System.Runtime.InteropServices;
8+
using System.Text;
89
using Vanara.PInvoke;
910
using static Vanara.PInvoke.User32;
1011

@@ -73,6 +74,25 @@ public static IntPtr SetWindowLong(HWND hWnd, WindowLongFlags nIndex, IntPtr dwN
7374

7475
[DllImport("User32.dll")]
7576
public extern static short GetKeyState(int n);
77+
78+
[DllImport("shell32.dll")]
79+
public static extern IntPtr SHBrowseForFolder(ref BROWSEINFO lpbi);
80+
81+
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
82+
public static extern bool SHGetPathFromIDList(IntPtr pidl, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszPath);
83+
84+
[StructLayout(LayoutKind.Sequential)]
85+
public struct BROWSEINFO
86+
{
87+
public IntPtr hwndOwner;
88+
public IntPtr pidlRoot;
89+
public string pszDisplayName;
90+
public string lpszTitle;
91+
public uint ulFlags;
92+
public IntPtr lpfn;
93+
public int lParam;
94+
public IntPtr iImage;
95+
}
7696
}
7797

7898
[ComImport]

src/Files.App/ViewModels/Dialogs/CreateShortcutDialogViewModel.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.Core.Extensions;
54
using System.IO;
5+
using System.Runtime.InteropServices;
6+
using System.Text;
67
using System.Windows.Input;
78
using Windows.Storage.Pickers;
89

@@ -84,18 +85,27 @@ public CreateShortcutDialogViewModel(string workingDirectory)
8485
WorkingDirectory = workingDirectory;
8586
_destinationItemPath = string.Empty;
8687

87-
SelectDestinationCommand = new AsyncRelayCommand(SelectDestinationAsync);
88+
SelectDestinationCommand = new AsyncRelayCommand(SelectDestination);
8889
PrimaryButtonCommand = new AsyncRelayCommand(CreateShortcutAsync);
8990
}
9091

91-
private async Task SelectDestinationAsync()
92+
private Task SelectDestination()
9293
{
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+
}
95107

96-
var selectedFolder = await folderPicker.PickSingleFolderAsync();
97-
if (selectedFolder is not null)
98-
DestinationItemPath = selectedFolder.Path;
108+
return Task.CompletedTask;
99109
}
100110

101111
private FolderPicker InitializeWithWindow(FolderPicker obj)

src/Files.App/Views/Layouts/BaseLayoutPage.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,19 +1294,21 @@ private void UpdateCollectionViewSource()
12941294

12951295
if (ParentShellPageInstance.FilesystemViewModel.FilesAndFolders.IsGrouped)
12961296
{
1297-
CollectionViewSource = new()
1297+
var newSource = new CollectionViewSource()
12981298
{
12991299
IsSourceGrouped = true,
13001300
Source = ParentShellPageInstance.FilesystemViewModel.FilesAndFolders.GroupedCollection
13011301
};
1302+
CollectionViewSource = newSource;
13021303
}
13031304
else
13041305
{
1305-
CollectionViewSource = new()
1306+
var newSource = new CollectionViewSource()
13061307
{
13071308
IsSourceGrouped = false,
13081309
Source = ParentShellPageInstance.FilesystemViewModel.FilesAndFolders
13091310
};
1311+
CollectionViewSource = newSource;
13101312
}
13111313
}
13121314

0 commit comments

Comments
 (0)