Add recent launcher items
This commit is contained in:
@@ -8,6 +8,8 @@ public sealed class LauncherConfig
|
||||
|
||||
public LauncherThemeScheme ThemeScheme { get; set; } = LauncherThemeScheme.MarkHaven;
|
||||
|
||||
public List<LauncherItem> RecentItems { get; set; } = [];
|
||||
|
||||
public List<LauncherItem> Items { get; set; } = [];
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ Download the compiled Windows release from:
|
||||
- System tray launcher
|
||||
- Global hotkey, default `Ctrl+Alt+Space`
|
||||
- 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
|
||||
- Right-click launcher entries to edit them in Settings
|
||||
- Right-click item duplication in Settings
|
||||
|
||||
@@ -190,10 +190,20 @@ public static class ConfigService
|
||||
throw new InvalidDataException("The selected config is missing launcher items.");
|
||||
}
|
||||
|
||||
if (config.RecentItems is null)
|
||||
{
|
||||
config.RecentItems = [];
|
||||
}
|
||||
|
||||
foreach (LauncherItem item in config.Items)
|
||||
{
|
||||
ValidateItem(item);
|
||||
}
|
||||
|
||||
foreach (LauncherItem item in config.RecentItems)
|
||||
{
|
||||
ValidateItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateItem(LauncherItem item)
|
||||
@@ -226,6 +236,14 @@ public static class ConfigService
|
||||
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)
|
||||
{
|
||||
NormalizeDisplayModes(item);
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace TaskbarLauncher.Services;
|
||||
|
||||
public sealed class LauncherController : IDisposable
|
||||
{
|
||||
private const int MaxRecentItems = 8;
|
||||
|
||||
private readonly HotkeyService hotkeyService = new();
|
||||
private NotifyIcon? notifyIcon;
|
||||
private LauncherPopup? popup;
|
||||
@@ -136,6 +138,7 @@ public sealed class LauncherController : IDisposable
|
||||
{
|
||||
if (TryLaunchItem(item, out string? error))
|
||||
{
|
||||
RecordRecentItem(item);
|
||||
popup?.Close();
|
||||
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)
|
||||
{
|
||||
List<string> failures = [];
|
||||
@@ -161,6 +201,7 @@ public sealed class LauncherController : IDisposable
|
||||
if (TryLaunchItem(child, out string? error))
|
||||
{
|
||||
launchedCount++;
|
||||
RecordRecentItem(child);
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
<Authors>Ray Berezowski</Authors>
|
||||
<ApplicationIcon>Assets\AppIcon.ico</ApplicationIcon>
|
||||
<Version>1.0.1</Version>
|
||||
<AssemblyVersion>1.0.1.4</AssemblyVersion>
|
||||
<FileVersion>1.0.1.4</FileVersion>
|
||||
<AssemblyVersion>1.0.1.5</AssemblyVersion>
|
||||
<FileVersion>1.0.1.5</FileVersion>
|
||||
<InformationalVersion>1.0.1</InformationalVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -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);
|
||||
if (allowEdit)
|
||||
{
|
||||
button.ContextMenu = CreateItemContextMenu(item);
|
||||
}
|
||||
|
||||
button.KeyDown += (_, e) =>
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
{
|
||||
"Hotkey": "Ctrl+Alt+Space",
|
||||
"DisplayMode": "CompactList",
|
||||
"ThemeScheme": "MarkHaven",
|
||||
"RecentItems": [],
|
||||
"Items": [
|
||||
{
|
||||
"Title": "Folders",
|
||||
|
||||
@@ -21,6 +21,8 @@ Install the **.NET Desktop Runtime** for **Windows x64**.
|
||||
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.
|
||||
|
||||
Recently launched entries appear in the launcher popup under **Recent**.
|
||||
|
||||
## Configure
|
||||
|
||||
Open the tray menu and choose **Settings**.
|
||||
|
||||
Reference in New Issue
Block a user