4 Commits

Author SHA1 Message Date
Ray Berezowski
c606573900 Add menu sort action 2026-08-26 21:41:45 -04:00
Ray Berezowski
86f667f595 Add selected item import export 2026-08-26 21:38:57 -04:00
Ray Berezowski
8ec53ff9d6 Move target validation to top of config menu 2026-08-26 21:34:16 -04:00
Ray Berezowski
691cb405fd Add target validation action 2026-08-26 21:30:13 -04:00
6 changed files with 364 additions and 2 deletions

View File

@@ -60,11 +60,15 @@
Margin="0,0,8,0">
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="Validate Targets" Click="ValidateTargets_Click"/>
<Separator/>
<MenuItem Header="Backup Config" Click="BackupConfig_Click"/>
<MenuItem Header="Restore from Backup" Click="RestoreConfig_Click"/>
<Separator/>
<MenuItem Header="Export Config" Click="ExportConfig_Click"/>
<MenuItem Header="Import Config" Click="ImportConfig_Click"/>
<MenuItem Header="Export Selected Item" Click="ExportSelectedItem_Click"/>
<MenuItem Header="Import Item" Click="ImportItem_Click"/>
<Separator/>
<MenuItem Header="Reset to Defaults" Click="ResetConfig_Click"/>
<MenuItem Header="Reload Config" Click="ReloadConfig_Click"/>

View File

@@ -22,6 +22,7 @@ public partial class MainWindow : Window
private List<int>? selectedPath;
private string? loadedAutoIconPath;
private System.Windows.Point dragStartPoint;
private sealed record TargetValidationIssue(string ItemPath, string Problem);
public MainWindow()
{
@@ -106,6 +107,12 @@ public partial class MainWindow : Window
var duplicateMenuItem = new System.Windows.Controls.MenuItem { Header = "Duplicate Item" };
duplicateMenuItem.Click += DuplicateItem_Click;
var sortMenuItem = new System.Windows.Controls.MenuItem
{
Header = item.Type == LauncherItemType.Menu ? "Sort This Menu" : "Sort This Level"
};
sortMenuItem.Click += SortSelected_Click;
var treeItem = new TreeViewItem
{
Header = $"{GetTreeStatusPrefix(item)}{item.Title} ({item.Type})",
@@ -116,6 +123,7 @@ public partial class MainWindow : Window
treeItem.ContextMenu.Items.Add(disableMenuItem);
treeItem.ContextMenu.Items.Add(openContainingFolderMenuItem);
treeItem.ContextMenu.Items.Add(duplicateMenuItem);
treeItem.ContextMenu.Items.Add(sortMenuItem);
treeItem.PreviewMouseRightButtonDown += (_, e) =>
{
treeItem.IsSelected = true;
@@ -1045,6 +1053,46 @@ public partial class MainWindow : Window
RefreshView(selectedItem);
}
private void SortSelected_Click(object sender, RoutedEventArgs e)
{
if (controller is null || selectedItem is null)
{
return;
}
ApplyCurrentItem();
LauncherItem itemToSelect = selectedItem;
if (selectedItem.Type == LauncherItemType.Menu)
{
SortItems(selectedItem.Children);
RefreshView(itemToSelect);
StatusText.Text = $"Sorted {itemToSelect.Title}. Click Save to keep it.";
return;
}
List<LauncherItem>? siblings = FindSiblings(controller.Config.Items, selectedItem);
if (siblings is null)
{
return;
}
SortItems(siblings);
RefreshView(itemToSelect);
StatusText.Text = $"Sorted this level. Click Save to keep it.";
}
private static void SortItems(List<LauncherItem> items)
{
List<LauncherItem> sortedItems = items
.OrderByDescending(item => item.IsFavorite)
.ThenBy(item => item.Title, StringComparer.CurrentCultureIgnoreCase)
.ThenBy(item => item.Type)
.ToList();
items.Clear();
items.AddRange(sortedItems);
}
private static bool RemoveItem(List<LauncherItem> items, LauncherItem item)
{
if (items.Remove(item))
@@ -1259,6 +1307,114 @@ public partial class MainWindow : Window
}
}
private void ExportSelectedItem_Click(object sender, RoutedEventArgs e)
{
if (selectedItem is null)
{
MessageBox.Show("Select an item or menu to export first.", "Taskbar Launcher");
return;
}
ApplyCurrentItem();
string safeTitle = MakeSafeFileName(string.IsNullOrWhiteSpace(selectedItem.Title) ? "launcher-item" : selectedItem.Title);
using SaveFileDialog dialog = new()
{
Title = "Export selected launcher item",
Filter = "JSON item files|*.json|All files|*.*",
FileName = $"{safeTitle}-{DateTime.Now:yyyyMMdd-HHmmss}.json",
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
};
if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
try
{
string exportPath = ConfigService.ExportItemTo(dialog.FileName, selectedItem);
StatusText.Text = $"Exported {selectedItem.Title} to {exportPath}";
}
catch (Exception ex)
{
MessageBox.Show($"Could not export selected item.\n\n{ex.Message}", "Taskbar Launcher");
}
}
private void ImportItem_Click(object sender, RoutedEventArgs e)
{
if (controller is null)
{
return;
}
using OpenFileDialog dialog = new()
{
Title = "Import launcher item",
Filter = "JSON item files|*.json|All files|*.*",
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
};
if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
try
{
ApplyCurrentItem();
LauncherItem importedItem = ConfigService.ImportItemFrom(dialog.FileName);
AddImportedItem(importedItem);
selectedPath = FindItemPath(importedItem);
RefreshView(importedItem);
StatusText.Text = $"Imported {importedItem.Title}. Click Save to keep it.";
}
catch (Exception ex)
{
MessageBox.Show($"Could not import item.\n\n{ex.Message}", "Taskbar Launcher");
}
}
private void AddImportedItem(LauncherItem importedItem)
{
if (controller is null)
{
return;
}
if (selectedItem is null)
{
controller.Config.Items.Add(importedItem);
return;
}
if (selectedItem.Type == LauncherItemType.Menu)
{
selectedItem.Children.Add(importedItem);
return;
}
List<LauncherItem>? siblings = FindSiblings(controller.Config.Items, selectedItem);
if (siblings is null)
{
controller.Config.Items.Add(importedItem);
return;
}
int selectedIndex = siblings.IndexOf(selectedItem);
siblings.Insert(selectedIndex + 1, importedItem);
}
private static string MakeSafeFileName(string fileName)
{
foreach (char invalidChar in Path.GetInvalidFileNameChars())
{
fileName = fileName.Replace(invalidChar, '-');
}
return fileName.Trim();
}
private void ResetConfig_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult result = MessageBox.Show(
@@ -1343,6 +1499,159 @@ public partial class MainWindow : Window
ConfigService.OpenConfigFolder();
}
private void ValidateTargets_Click(object sender, RoutedEventArgs e)
{
if (controller is null)
{
return;
}
ApplyConfigFields();
List<TargetValidationIssue> issues = [];
ValidateTargets(controller.Config.Items, [], issues);
if (issues.Count == 0)
{
StatusText.Text = "Validation complete. No broken targets found.";
MessageBox.Show("No broken targets found.", "Taskbar Launcher");
return;
}
string message = $"Found {issues.Count} possible broken target(s):\n\n" +
string.Join("\n", issues.Take(20).Select(issue => $"- {issue.ItemPath}: {issue.Problem}"));
if (issues.Count > 20)
{
message += $"\n\nShowing first 20 of {issues.Count}.";
}
StatusText.Text = $"Validation found {issues.Count} possible broken target(s).";
MessageBox.Show(message, "Taskbar Launcher");
}
private static void ValidateTargets(IEnumerable<LauncherItem> items, List<string> parentNames, List<TargetValidationIssue> issues)
{
foreach (LauncherItem item in items)
{
List<string> itemPath = [.. parentNames, string.IsNullOrWhiteSpace(item.Title) ? "Untitled" : item.Title];
if (!item.IsDisabled && TryGetTargetIssue(item, out string? problem) && problem is not null)
{
issues.Add(new TargetValidationIssue(string.Join(" > ", itemPath), problem));
}
if (item.Children.Count > 0)
{
ValidateTargets(item.Children, itemPath, issues);
}
}
}
private static bool TryGetTargetIssue(LauncherItem item, out string? problem)
{
problem = null;
if (item.Type == LauncherItemType.Menu || item.IsDisabled)
{
return false;
}
if (string.IsNullOrWhiteSpace(item.Target))
{
problem = "Target is blank.";
return true;
}
string target = Environment.ExpandEnvironmentVariables(item.Target.Trim());
switch (item.Type)
{
case LauncherItemType.Folder:
if (!Directory.Exists(target))
{
problem = "Folder does not exist.";
return true;
}
return false;
case LauncherItemType.Website:
if (!Uri.TryCreate(target, UriKind.Absolute, out Uri? uri) ||
(uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps))
{
problem = "Website target is not a valid http or https URL.";
return true;
}
return false;
case LauncherItemType.App:
if (!File.Exists(target) && !CommandExistsOnPath(target))
{
problem = "Application or shortcut was not found.";
return true;
}
return false;
case LauncherItemType.File:
if (!File.Exists(target))
{
problem = "File does not exist.";
return true;
}
return false;
default:
problem = "Item type is not recognized.";
return true;
}
}
private static bool CommandExistsOnPath(string target)
{
if (target.IndexOfAny([Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar]) >= 0)
{
return false;
}
string? pathValue = Environment.GetEnvironmentVariable("PATH");
if (string.IsNullOrWhiteSpace(pathValue))
{
return false;
}
string extension = Path.GetExtension(target);
IEnumerable<string> candidateNames = string.IsNullOrWhiteSpace(extension)
? GetExecutableCandidateNames(target)
: [target];
foreach (string directory in pathValue.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
{
foreach (string candidateName in candidateNames)
{
string candidatePath = Path.Combine(directory, candidateName);
if (File.Exists(candidatePath))
{
return true;
}
}
}
return false;
}
private static IEnumerable<string> GetExecutableCandidateNames(string target)
{
string? pathExtValue = Environment.GetEnvironmentVariable("PATHEXT");
string[] extensions = string.IsNullOrWhiteSpace(pathExtValue)
? [".EXE", ".CMD", ".BAT", ".COM"]
: pathExtValue.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
foreach (string extension in extensions)
{
yield return target + extension;
}
}
private void About_Click(object sender, RoutedEventArgs e)
{
AboutWindow aboutWindow = new()

View File

@@ -19,6 +19,9 @@ Download the compiled Windows release from:
- Right-click launcher entries to pin or unpin them from the top
- Right-click launcher entries or Settings items to temporarily disable them
- Right-click app/file entries to open their containing folder
- Validate missing app, file, and folder targets from Settings
- Export and import selected items or menu sections
- Sort a selected menu or item level alphabetically
- Right-click item duplication in Settings
- Right-click items in Settings to pin them to the top of their menu
- Per-item icon and display mode

View File

@@ -80,6 +80,49 @@ public static class ConfigService
return destinationPath;
}
public static string ExportItemTo(string destinationPath, LauncherItem item)
{
if (string.IsNullOrWhiteSpace(destinationPath))
{
throw new ArgumentException("Choose a destination path for the exported item.", nameof(destinationPath));
}
string? destinationFolder = Path.GetDirectoryName(destinationPath);
if (!string.IsNullOrWhiteSpace(destinationFolder))
{
Directory.CreateDirectory(destinationFolder);
}
NormalizeDisplayModes(item);
string json = JsonSerializer.Serialize(item, JsonOptions);
File.WriteAllText(destinationPath, json);
return destinationPath;
}
public static LauncherItem ImportItemFrom(string sourcePath)
{
if (!File.Exists(sourcePath))
{
throw new FileNotFoundException("The selected item file was not found.", sourcePath);
}
string json = File.ReadAllText(sourcePath);
LauncherItem item;
try
{
item = JsonSerializer.Deserialize<LauncherItem>(json, JsonOptions)
?? throw new InvalidDataException("The selected item file could not be read.");
}
catch (JsonException ex)
{
throw new InvalidDataException("The selected file is not a valid Taskbar Launcher item export.", ex);
}
ValidateItem(item);
NormalizeDisplayModes(item);
return item;
}
public static LauncherConfig ImportFrom(string sourcePath)
{
LauncherConfig config = ReadConfigFile(sourcePath);

View File

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

View File

@@ -41,6 +41,9 @@ From Settings you can:
- Right-click an item and choose **Pin to Top** to show it first in its menu
- Right-click an item and choose **Disable Item** or **Enable Item** to hide or restore it
- Right-click an app or file item and choose **Open Containing Folder**
- Use **Config... > Validate Targets** to check for missing app, file, and folder targets
- Use **Config... > Export Selected Item** or **Import Item** to share one item or menu section
- Right-click an item and choose **Sort This Menu** or **Sort This Level**
- Set per-item icon sizes
- Back up and restore `config.json`
- Enable Start with Windows