Add open all menu action

This commit is contained in:
Ray Berezowski
2026-06-03 17:17:29 -04:00
parent 15a7f81a28
commit f3955b0ffc
2 changed files with 98 additions and 12 deletions

View File

@@ -17,13 +17,15 @@ public partial class LauncherPopup : Window
private readonly LauncherConfig config;
private readonly Action<LauncherItem> launchItem;
private readonly Action<LauncherItem> openAllItems;
private readonly Action showSettings;
public LauncherPopup(LauncherConfig config, Action<LauncherItem> launchItem, Action showSettings)
public LauncherPopup(LauncherConfig config, Action<LauncherItem> launchItem, Action<LauncherItem> openAllItems, Action showSettings)
{
InitializeComponent();
this.config = config;
this.launchItem = launchItem;
this.openAllItems = openAllItems;
this.showSettings = showSettings;
BuildItems();
SizeChanged += (_, _) => QueueReposition();
@@ -102,7 +104,7 @@ public partial class LauncherPopup : Window
{
Expander expander = new()
{
Header = item.Title,
Header = CreateMenuHeader(item),
IsExpanded = expandMenusByDefault,
Margin = new Thickness(depth * 12, 4, 0, 4)
};
@@ -143,6 +145,34 @@ public partial class LauncherPopup : Window
return button;
}
private TextBlock CreateMenuHeader(LauncherItem item)
{
System.Windows.Controls.MenuItem openAllMenuItem = new()
{
Header = "Open All",
IsEnabled = item.Children.Any(IsLaunchable)
};
openAllMenuItem.Click += (_, e) =>
{
openAllItems(item);
e.Handled = true;
};
System.Windows.Controls.ContextMenu contextMenu = new();
contextMenu.Items.Add(openAllMenuItem);
return new TextBlock
{
Text = item.Title,
ContextMenu = contextMenu
};
}
private static bool IsLaunchable(LauncherItem item)
{
return item.Type != LauncherItemType.Menu && !string.IsNullOrWhiteSpace(item.Target);
}
private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)
{
string query = SearchBox.Text.Trim();