Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When multiple files are selected, open them together #7557

Merged
merged 2 commits into from Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/Files/Helpers/NavigationHelpers.cs
Expand Up @@ -83,17 +83,29 @@ public static async void OpenSelectedItems(IShellPage associatedInstance, bool o
}

bool forceOpenInNewTab = false;
var selectedItems = associatedInstance.SlimContentPage.SelectedItems.ToList();
var opened = false;

foreach (ListedItem item in associatedInstance.SlimContentPage.SelectedItems.ToList())
if (!openViaApplicationPicker &&
selectedItems.Count > 1 &&
selectedItems.All(x => x.PrimaryItemAttribute == StorageItemTypes.File && !x.IsExecutable && !x.IsShortcutItem))
{
var type = item.PrimaryItemAttribute == StorageItemTypes.Folder ?
FilesystemItemType.Directory : FilesystemItemType.File;
// Multiple files are selected, open them together
opened = await Win32Helpers.InvokeWin32ComponentAsync(string.Join('|', selectedItems.Select(x => x.ItemPath)), associatedInstance);
}
if (!opened)
{
foreach (ListedItem item in selectedItems)
{
var type = item.PrimaryItemAttribute == StorageItemTypes.Folder ?
FilesystemItemType.Directory : FilesystemItemType.File;

await OpenPath(item.ItemPath, associatedInstance, type, false, openViaApplicationPicker, forceOpenInNewTab: forceOpenInNewTab);
await OpenPath(item.ItemPath, associatedInstance, type, false, openViaApplicationPicker, forceOpenInNewTab: forceOpenInNewTab);

if (type == FilesystemItemType.Directory)
{
forceOpenInNewTab = true;
if (type == FilesystemItemType.Directory)
{
forceOpenInNewTab = true;
}
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/Files/Helpers/Win32Helpers.cs
Expand Up @@ -4,18 +4,19 @@
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Windows.ApplicationModel.AppService;
using Windows.Foundation.Collections;

namespace Files.Helpers
{
public static class Win32Helpers
{
public static async Task InvokeWin32ComponentAsync(string applicationPath, IShellPage associatedInstance, string arguments = null, bool runAsAdmin = false, string workingDirectory = null)
public static async Task<bool> InvokeWin32ComponentAsync(string applicationPath, IShellPage associatedInstance, string arguments = null, bool runAsAdmin = false, string workingDirectory = null)
{
await InvokeWin32ComponentsAsync(applicationPath.CreateEnumerable(), associatedInstance, arguments, runAsAdmin, workingDirectory);
return await InvokeWin32ComponentsAsync(applicationPath.CreateEnumerable(), associatedInstance, arguments, runAsAdmin, workingDirectory);
}

public static async Task InvokeWin32ComponentsAsync(IEnumerable<string> applicationPaths, IShellPage associatedInstance, string arguments = null, bool runAsAdmin = false, string workingDirectory = null)
public static async Task<bool> InvokeWin32ComponentsAsync(IEnumerable<string> applicationPaths, IShellPage associatedInstance, string arguments = null, bool runAsAdmin = false, string workingDirectory = null)
{
Debug.WriteLine("Launching EXE in FullTrustProcess");

Expand Down Expand Up @@ -44,8 +45,10 @@ public static async Task InvokeWin32ComponentsAsync(IEnumerable<string> applicat
value.Add("Parameters", arguments);
}

await connection.SendMessageAsync(value);
return await connection.SendMessageAsync(value) == AppServiceResponseStatus.Success;
}

return false;
}
}
}