Skip to content

Commit

Permalink
Merge branch 'main' into ya/RemovedGetThumbnailAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 committed Jan 12, 2024
2 parents 8d49edc + d2e8980 commit de22141
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
20 changes: 20 additions & 0 deletions src/Files.App/Helpers/Interop/InteropHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.UI.Xaml;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Vanara.PInvoke;
using static Vanara.PInvoke.User32;

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

[DllImport("User32.dll")]
public extern static short GetKeyState(int n);

[DllImport("shell32.dll")]
public static extern IntPtr SHBrowseForFolder(ref BROWSEINFO lpbi);

[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
public static extern bool SHGetPathFromIDList(IntPtr pidl, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszPath);

[StructLayout(LayoutKind.Sequential)]
public struct BROWSEINFO
{
public IntPtr hwndOwner;
public IntPtr pidlRoot;
public string pszDisplayName;
public string lpszTitle;
public uint ulFlags;
public IntPtr lpfn;
public int lParam;
public IntPtr iImage;
}
}

[ComImport]
Expand Down
26 changes: 18 additions & 8 deletions src/Files.App/ViewModels/Dialogs/CreateShortcutDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.Core.Extensions;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Input;
using Windows.Storage.Pickers;

Expand Down Expand Up @@ -84,18 +85,27 @@ public CreateShortcutDialogViewModel(string workingDirectory)
WorkingDirectory = workingDirectory;
_destinationItemPath = string.Empty;

SelectDestinationCommand = new AsyncRelayCommand(SelectDestinationAsync);
SelectDestinationCommand = new AsyncRelayCommand(SelectDestination);
PrimaryButtonCommand = new AsyncRelayCommand(CreateShortcutAsync);
}

private async Task SelectDestinationAsync()
private Task SelectDestination()
{
var folderPicker = InitializeWithWindow(new FolderPicker());
folderPicker.FileTypeFilter.Add("*");
InteropHelpers.BROWSEINFO bi = new InteropHelpers.BROWSEINFO();
bi.ulFlags = 0x00004000;
bi.lpszTitle = "Select a folder";
nint pidl = InteropHelpers.SHBrowseForFolder(ref bi);
if (pidl != nint.Zero)
{
StringBuilder path = new StringBuilder(260);
if (InteropHelpers.SHGetPathFromIDList(pidl, path))
{
DestinationItemPath = path.ToString();
}
Marshal.FreeCoTaskMem(pidl);
}

var selectedFolder = await folderPicker.PickSingleFolderAsync();
if (selectedFolder is not null)
DestinationItemPath = selectedFolder.Path;
return Task.CompletedTask;
}

private FolderPicker InitializeWithWindow(FolderPicker obj)
Expand Down
6 changes: 4 additions & 2 deletions src/Files.App/Views/Layouts/BaseLayoutPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,19 +1294,21 @@ private void UpdateCollectionViewSource()

if (ParentShellPageInstance.FilesystemViewModel.FilesAndFolders.IsGrouped)
{
CollectionViewSource = new()
var newSource = new CollectionViewSource()
{
IsSourceGrouped = true,
Source = ParentShellPageInstance.FilesystemViewModel.FilesAndFolders.GroupedCollection
};
CollectionViewSource = newSource;
}
else
{
CollectionViewSource = new()
var newSource = new CollectionViewSource()
{
IsSourceGrouped = false,
Source = ParentShellPageInstance.FilesystemViewModel.FilesAndFolders
};
CollectionViewSource = newSource;
}
}

Expand Down

0 comments on commit de22141

Please sign in to comment.