Add open containing folder action
This commit is contained in:
@@ -20,8 +20,9 @@ public partial class LauncherPopup : Window
|
||||
private readonly Action<LauncherItem> openAllItems;
|
||||
private readonly Action showSettings;
|
||||
private readonly Action<LauncherItem> editItem;
|
||||
private readonly Action<LauncherItem> openContainingFolder;
|
||||
|
||||
public LauncherPopup(LauncherConfig config, Action<LauncherItem> launchItem, Action<LauncherItem> openAllItems, Action showSettings, Action<LauncherItem> editItem)
|
||||
public LauncherPopup(LauncherConfig config, Action<LauncherItem> launchItem, Action<LauncherItem> openAllItems, Action showSettings, Action<LauncherItem> editItem, Action<LauncherItem> openContainingFolder)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.config = config;
|
||||
@@ -29,6 +30,7 @@ public partial class LauncherPopup : Window
|
||||
this.openAllItems = openAllItems;
|
||||
this.showSettings = showSettings;
|
||||
this.editItem = editItem;
|
||||
this.openContainingFolder = openContainingFolder;
|
||||
BuildItems();
|
||||
SizeChanged += (_, _) => QueueReposition();
|
||||
}
|
||||
@@ -210,6 +212,7 @@ public partial class LauncherPopup : Window
|
||||
System.Windows.Controls.ContextMenu contextMenu = new();
|
||||
contextMenu.Items.Add(CreatePinMenuItem(item));
|
||||
contextMenu.Items.Add(CreateDisableMenuItem(item));
|
||||
contextMenu.Items.Add(CreateOpenContainingFolderMenuItem(item));
|
||||
contextMenu.Items.Add(CreateEditMenuItem(item));
|
||||
return contextMenu;
|
||||
}
|
||||
@@ -250,6 +253,22 @@ public partial class LauncherPopup : Window
|
||||
return disableMenuItem;
|
||||
}
|
||||
|
||||
private System.Windows.Controls.MenuItem CreateOpenContainingFolderMenuItem(LauncherItem item)
|
||||
{
|
||||
System.Windows.Controls.MenuItem openFolderMenuItem = new()
|
||||
{
|
||||
Header = "Open Containing Folder",
|
||||
IsEnabled = CanOpenContainingFolder(item)
|
||||
};
|
||||
openFolderMenuItem.Click += (_, e) =>
|
||||
{
|
||||
openContainingFolder(item);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
return openFolderMenuItem;
|
||||
}
|
||||
|
||||
private System.Windows.Controls.MenuItem CreateEditMenuItem(LauncherItem item)
|
||||
{
|
||||
System.Windows.Controls.MenuItem editMenuItem = new()
|
||||
@@ -271,6 +290,11 @@ public partial class LauncherPopup : Window
|
||||
return item.Type != LauncherItemType.Menu && !item.IsDisabled && !string.IsNullOrWhiteSpace(item.Target);
|
||||
}
|
||||
|
||||
private static bool CanOpenContainingFolder(LauncherItem item)
|
||||
{
|
||||
return item.Type is LauncherItemType.App or LauncherItemType.File && !string.IsNullOrWhiteSpace(item.Target);
|
||||
}
|
||||
|
||||
private static IEnumerable<LauncherItem> GetDisplayItems(IEnumerable<LauncherItem> items)
|
||||
{
|
||||
return items
|
||||
|
||||
Reference in New Issue
Block a user