Add open all menu action
This commit is contained in:
@@ -62,7 +62,7 @@ public sealed class LauncherController : IDisposable
|
||||
return;
|
||||
}
|
||||
|
||||
popup = new LauncherPopup(Config, LaunchItem, ShowSettings);
|
||||
popup = new LauncherPopup(Config, LaunchItem, OpenAllItems, ShowSettings);
|
||||
popup.Closed += (_, _) => popup = null;
|
||||
popup.ShowNearTaskbar();
|
||||
}
|
||||
@@ -126,22 +126,78 @@ public sealed class LauncherController : IDisposable
|
||||
|
||||
private void LaunchItem(LauncherItem item)
|
||||
{
|
||||
if (TryLaunchItem(item, out string? error))
|
||||
{
|
||||
popup?.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
System.Windows.MessageBox.Show(error, "Taskbar Launcher");
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenAllItems(LauncherItem menuItem)
|
||||
{
|
||||
List<string> failures = [];
|
||||
int launchedCount = 0;
|
||||
|
||||
foreach (LauncherItem child in menuItem.Children)
|
||||
{
|
||||
if (child.Type == LauncherItemType.Menu || string.IsNullOrWhiteSpace(child.Target))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (TryLaunchItem(child, out string? error))
|
||||
{
|
||||
launchedCount++;
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
failures.Add(error);
|
||||
}
|
||||
}
|
||||
|
||||
popup?.Close();
|
||||
|
||||
if (failures.Count > 0)
|
||||
{
|
||||
string message = $"Opened {launchedCount} item(s), but {failures.Count} item(s) failed:\n\n" +
|
||||
string.Join("\n\n", failures.Take(5));
|
||||
System.Windows.MessageBox.Show(message, "Taskbar Launcher");
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryLaunchItem(LauncherItem item, out string? error)
|
||||
{
|
||||
error = null;
|
||||
|
||||
if (item.Type == LauncherItemType.Menu || string.IsNullOrWhiteSpace(item.Target))
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
string target = Environment.ExpandEnvironmentVariables(item.Target);
|
||||
|
||||
ProcessStartInfo startInfo = new()
|
||||
try
|
||||
{
|
||||
FileName = target,
|
||||
Arguments = item.Arguments ?? "",
|
||||
UseShellExecute = true,
|
||||
WorkingDirectory = Directory.Exists(target) ? target : ConfigService.AppFolder
|
||||
};
|
||||
ProcessStartInfo startInfo = new()
|
||||
{
|
||||
FileName = target,
|
||||
Arguments = item.Arguments ?? "",
|
||||
UseShellExecute = true,
|
||||
WorkingDirectory = Directory.Exists(target) ? target : ConfigService.AppFolder
|
||||
};
|
||||
|
||||
Process.Start(startInfo);
|
||||
popup?.Close();
|
||||
Process.Start(startInfo);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = $"{item.Title}: {ex.Message}";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user