Add recent launcher items

This commit is contained in:
Ray Berezowski
2026-08-26 19:58:03 -04:00
parent 32f08bc0fd
commit 749a856faa
8 changed files with 100 additions and 5 deletions

View File

@@ -93,6 +93,12 @@ public partial class LauncherPopup : Window
{
ItemsPanel.Children.Clear();
visibleLaunchButtons.Clear();
if (config.RecentItems.Count > 0)
{
ItemsPanel.Children.Add(CreateRecentItemsControl());
}
bool expandMenusByDefault = config.Items.Count <= 2;
foreach (LauncherItem item in config.Items)
{
@@ -100,7 +106,26 @@ public partial class LauncherPopup : Window
}
}
private FrameworkElement CreateItemControl(LauncherItem item, int depth, bool expandMenusByDefault)
private Expander CreateRecentItemsControl()
{
Expander expander = new()
{
Header = new TextBlock { Text = "Recent" },
IsExpanded = true,
Margin = new Thickness(0, 4, 0, 8)
};
StackPanel recentItems = new();
foreach (LauncherItem item in config.RecentItems)
{
recentItems.Children.Add(CreateItemControl(item, 1, expandMenusByDefault: false, allowEdit: false));
}
expander.Content = recentItems;
return expander;
}
private FrameworkElement CreateItemControl(LauncherItem item, int depth, bool expandMenusByDefault, bool allowEdit = true)
{
if (item.Type == LauncherItemType.Menu)
{
@@ -114,7 +139,7 @@ public partial class LauncherPopup : Window
StackPanel children = new();
foreach (LauncherItem child in item.Children)
{
children.Children.Add(CreateItemControl(child, depth + 1, expandMenusByDefault));
children.Children.Add(CreateItemControl(child, depth + 1, expandMenusByDefault, allowEdit));
}
expander.Content = children;
@@ -131,7 +156,11 @@ public partial class LauncherPopup : Window
};
button.Click += (_, _) => launchItem(item);
button.ContextMenu = CreateItemContextMenu(item);
if (allowEdit)
{
button.ContextMenu = CreateItemContextMenu(item);
}
button.KeyDown += (_, e) =>
{
if (e.Key == Key.Enter)