Skip to content

Commit

Permalink
When multiple files are selected, open them together (#7557)
Browse files Browse the repository at this point in the history
  • Loading branch information
gave92 committed Jan 13, 2022
1 parent ed67fbb commit fda07b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
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;
}
}
}

0 comments on commit fda07b2

Please sign in to comment.