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

@@ -8,6 +8,8 @@ public sealed class LauncherConfig
public LauncherThemeScheme ThemeScheme { get; set; } = LauncherThemeScheme.MarkHaven; public LauncherThemeScheme ThemeScheme { get; set; } = LauncherThemeScheme.MarkHaven;
public List<LauncherItem> RecentItems { get; set; } = [];
public List<LauncherItem> Items { get; set; } = []; public List<LauncherItem> Items { get; set; } = [];
} }

View File

@@ -13,6 +13,7 @@ Download the compiled Windows release from:
- System tray launcher - System tray launcher
- Global hotkey, default `Ctrl+Alt+Space` - Global hotkey, default `Ctrl+Alt+Space`
- Search/filter in the launcher popup - Search/filter in the launcher popup
- Recent items section for quickly relaunching entries
- Nested menus, drag/drop ordering, and drag/drop item creation in Settings - Nested menus, drag/drop ordering, and drag/drop item creation in Settings
- Right-click launcher entries to edit them in Settings - Right-click launcher entries to edit them in Settings
- Right-click item duplication in Settings - Right-click item duplication in Settings

View File

@@ -190,10 +190,20 @@ public static class ConfigService
throw new InvalidDataException("The selected config is missing launcher items."); throw new InvalidDataException("The selected config is missing launcher items.");
} }
if (config.RecentItems is null)
{
config.RecentItems = [];
}
foreach (LauncherItem item in config.Items) foreach (LauncherItem item in config.Items)
{ {
ValidateItem(item); ValidateItem(item);
} }
foreach (LauncherItem item in config.RecentItems)
{
ValidateItem(item);
}
} }
private static void ValidateItem(LauncherItem item) private static void ValidateItem(LauncherItem item)
@@ -226,6 +236,14 @@ public static class ConfigService
config.ThemeScheme = LauncherThemeScheme.MarkHaven; config.ThemeScheme = LauncherThemeScheme.MarkHaven;
} }
config.RecentItems ??= [];
config.RecentItems.RemoveAll(item => item.Type == LauncherItemType.Menu || string.IsNullOrWhiteSpace(item.Target));
foreach (LauncherItem item in config.RecentItems)
{
item.Children = [];
NormalizeDisplayModes(item);
}
foreach (LauncherItem item in config.Items) foreach (LauncherItem item in config.Items)
{ {
NormalizeDisplayModes(item); NormalizeDisplayModes(item);

View File

@@ -9,6 +9,8 @@ namespace TaskbarLauncher.Services;
public sealed class LauncherController : IDisposable public sealed class LauncherController : IDisposable
{ {
private const int MaxRecentItems = 8;
private readonly HotkeyService hotkeyService = new(); private readonly HotkeyService hotkeyService = new();
private NotifyIcon? notifyIcon; private NotifyIcon? notifyIcon;
private LauncherPopup? popup; private LauncherPopup? popup;
@@ -136,6 +138,7 @@ public sealed class LauncherController : IDisposable
{ {
if (TryLaunchItem(item, out string? error)) if (TryLaunchItem(item, out string? error))
{ {
RecordRecentItem(item);
popup?.Close(); popup?.Close();
return; return;
} }
@@ -146,6 +149,43 @@ public sealed class LauncherController : IDisposable
} }
} }
private void RecordRecentItem(LauncherItem item)
{
if (item.Type == LauncherItemType.Menu || string.IsNullOrWhiteSpace(item.Target))
{
return;
}
Config.RecentItems.RemoveAll(recent => IsSameRecentItem(recent, item));
Config.RecentItems.Insert(0, CreateRecentItem(item));
if (Config.RecentItems.Count > MaxRecentItems)
{
Config.RecentItems.RemoveRange(MaxRecentItems, Config.RecentItems.Count - MaxRecentItems);
}
ConfigService.Save(Config);
}
private static bool IsSameRecentItem(LauncherItem recent, LauncherItem item)
{
return string.Equals(recent.Target, item.Target, StringComparison.OrdinalIgnoreCase) &&
string.Equals(recent.Arguments ?? "", item.Arguments ?? "", StringComparison.OrdinalIgnoreCase);
}
private static LauncherItem CreateRecentItem(LauncherItem item)
{
return new LauncherItem
{
Title = item.Title,
Type = item.Type,
Target = item.Target,
Arguments = item.Arguments,
IconPath = item.IconPath,
DisplayMode = item.DisplayMode,
Children = []
};
}
private void OpenAllItems(LauncherItem menuItem) private void OpenAllItems(LauncherItem menuItem)
{ {
List<string> failures = []; List<string> failures = [];
@@ -161,6 +201,7 @@ public sealed class LauncherController : IDisposable
if (TryLaunchItem(child, out string? error)) if (TryLaunchItem(child, out string? error))
{ {
launchedCount++; launchedCount++;
RecordRecentItem(child);
} }
else if (!string.IsNullOrWhiteSpace(error)) else if (!string.IsNullOrWhiteSpace(error))
{ {

View File

@@ -12,8 +12,8 @@
<Authors>Ray Berezowski</Authors> <Authors>Ray Berezowski</Authors>
<ApplicationIcon>Assets\AppIcon.ico</ApplicationIcon> <ApplicationIcon>Assets\AppIcon.ico</ApplicationIcon>
<Version>1.0.1</Version> <Version>1.0.1</Version>
<AssemblyVersion>1.0.1.4</AssemblyVersion> <AssemblyVersion>1.0.1.5</AssemblyVersion>
<FileVersion>1.0.1.4</FileVersion> <FileVersion>1.0.1.5</FileVersion>
<InformationalVersion>1.0.1</InformationalVersion> <InformationalVersion>1.0.1</InformationalVersion>
</PropertyGroup> </PropertyGroup>

View File

@@ -93,6 +93,12 @@ public partial class LauncherPopup : Window
{ {
ItemsPanel.Children.Clear(); ItemsPanel.Children.Clear();
visibleLaunchButtons.Clear(); visibleLaunchButtons.Clear();
if (config.RecentItems.Count > 0)
{
ItemsPanel.Children.Add(CreateRecentItemsControl());
}
bool expandMenusByDefault = config.Items.Count <= 2; bool expandMenusByDefault = config.Items.Count <= 2;
foreach (LauncherItem item in config.Items) 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) if (item.Type == LauncherItemType.Menu)
{ {
@@ -114,7 +139,7 @@ public partial class LauncherPopup : Window
StackPanel children = new(); StackPanel children = new();
foreach (LauncherItem child in item.Children) 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; expander.Content = children;
@@ -131,7 +156,11 @@ public partial class LauncherPopup : Window
}; };
button.Click += (_, _) => launchItem(item); button.Click += (_, _) => launchItem(item);
button.ContextMenu = CreateItemContextMenu(item); if (allowEdit)
{
button.ContextMenu = CreateItemContextMenu(item);
}
button.KeyDown += (_, e) => button.KeyDown += (_, e) =>
{ {
if (e.Key == Key.Enter) if (e.Key == Key.Enter)

View File

@@ -1,6 +1,8 @@
{ {
"Hotkey": "Ctrl+Alt+Space", "Hotkey": "Ctrl+Alt+Space",
"DisplayMode": "CompactList", "DisplayMode": "CompactList",
"ThemeScheme": "MarkHaven",
"RecentItems": [],
"Items": [ "Items": [
{ {
"Title": "Folders", "Title": "Folders",

View File

@@ -21,6 +21,8 @@ Install the **.NET Desktop Runtime** for **Windows x64**.
4. Press `Ctrl+Alt+Space` to open the launcher. 4. Press `Ctrl+Alt+Space` to open the launcher.
5. Right-click a launcher entry and choose **Edit in Settings** to jump to that item. 5. Right-click a launcher entry and choose **Edit in Settings** to jump to that item.
Recently launched entries appear in the launcher popup under **Recent**.
## Configure ## Configure
Open the tray menu and choose **Settings**. Open the tray menu and choose **Settings**.