Skip to content

Commit

Permalink
added "open in new window" action
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegiacometti committed May 8, 2024
1 parent e407ce0 commit 20a1ad7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 15 deletions.
23 changes: 19 additions & 4 deletions Community.PowerToys.Run.Plugin.EdgeFavorite/Helpers/EdgeHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Davide Giacometti. All rights reserved.
// Copyright (c) Davide Giacometti. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
Expand All @@ -10,16 +10,31 @@ namespace Community.PowerToys.Run.Plugin.EdgeFavorite.Helpers
{
public static class EdgeHelpers
{
public static void OpenInEdge(FavoriteItem favorite, bool inPrivate)
public static void OpenInEdge(FavoriteItem favorite, bool inPrivate, bool newWindow)
{
var args = $"{favorite.Url}";
OpenInEdgeInternal(favorite.Profile, favorite.Url!, inPrivate, newWindow);
}

public static void OpenInEdge(ProfileInfo profileInfo, string urls, bool inPrivate, bool newWindow)
{
OpenInEdgeInternal(profileInfo, urls, inPrivate, newWindow);
}

private static void OpenInEdgeInternal(ProfileInfo profileInfo, string urls, bool inPrivate, bool newWindow)
{
var args = urls;

if (inPrivate)
{
args += " -inprivate";
}

args += $" -profile-directory=\"{favorite.Profile.Directory}\"";
if (newWindow)
{
args += " -new-window";
}

args += $" -profile-directory=\"{profileInfo.Directory}\"";

try
{
Expand Down
57 changes: 47 additions & 10 deletions Community.PowerToys.Run.Plugin.EdgeFavorite/Models/FavoriteItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Result CreateResult(IPublicAPI api, string actionKeyword, bool showProfil
QueryTextDisplay = searchTree ? Path : Name,
Action = _ =>
{
EdgeHelpers.OpenInEdge(this, false);
EdgeHelpers.OpenInEdge(this, false, false);
return true;
},
ToolTipData = new ToolTipData(Name, Url),
Expand All @@ -129,22 +129,32 @@ public List<ContextMenuResult> CreateContextMenuResult()
new()
{
Title = $"Open all ({childFavoritesCount}) (Ctrl+O)",
Glyph = "\xE8A7",
Glyph = "\xE737",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.O,
AcceleratorModifiers = ModifierKeys.Control,
PluginName = _pluginName,
Action = _ => OpenAll(childFavorites, false),
Action = _ => OpenAll(childFavorites, false, false),
},
new()
{
Title = $"Open all ({childFavoritesCount}) in InPrivate (Ctrl+P)",
Title = $"Open all ({childFavoritesCount}) in new window (Ctrl+N)",
Glyph = "\xE8A7",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.N,
AcceleratorModifiers = ModifierKeys.Control,
PluginName = _pluginName,
Action = _ => OpenAll(childFavorites, false, true),
},
new()
{
Title = $"Open all ({childFavoritesCount}) in InPrivate window (Ctrl+P)",
Glyph = "\xE727",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.P,
AcceleratorModifiers = ModifierKeys.Control,
PluginName = _pluginName,
Action = _ => OpenAll(childFavorites, true),
Action = _ => OpenAll(childFavorites, true, false),
},
};
}
Expand Down Expand Up @@ -177,15 +187,29 @@ public List<ContextMenuResult> CreateContextMenuResult()
},
new()
{
Title = "Open in InPrivate (Ctrl+P)",
Title = "Open in new window (Ctrl+N)",
Glyph = "\xE8A7",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.N,
AcceleratorModifiers = ModifierKeys.Control,
PluginName = _pluginName,
Action = _ =>
{
EdgeHelpers.OpenInEdge(this, false, true);
return true;
},
},
new()
{
Title = "Open in InPrivate window (Ctrl+P)",
Glyph = "\xE727",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.P,
AcceleratorModifiers = ModifierKeys.Control,
PluginName = _pluginName,
Action = _ =>
{
EdgeHelpers.OpenInEdge(this, true);
EdgeHelpers.OpenInEdge(this, true, false);
return true;
},
},
Expand All @@ -209,11 +233,24 @@ public static void SetIcons(Theme theme)
}
}

private static bool OpenAll(IEnumerable<FavoriteItem> favorites, bool inPrivate)
private static bool OpenAll(FavoriteItem[] favorites, bool inPrivate, bool newWindow)
{
foreach (var favorite in favorites)
if (favorites.Length == 0)
{
EdgeHelpers.OpenInEdge(favorite, inPrivate);
throw new InvalidOperationException("Favorites cannot be empty.");
}

// If there is no need to open in a new window, starting multiple processes is preferred to avoid long command line arguments
if (newWindow)
{
EdgeHelpers.OpenInEdge(favorites[0].Profile, string.Join(" ", favorites.Select(f => f.Url!)), inPrivate, newWindow);
}
else
{
foreach (var favorite in favorites)
{
EdgeHelpers.OpenInEdge(favorite, inPrivate, false);
}
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.5.0</Version>
<Version>0.5.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 20a1ad7

Please sign in to comment.