Add open containing folder action
This commit is contained in:
@@ -72,7 +72,7 @@ public sealed class LauncherController : IDisposable
|
||||
return;
|
||||
}
|
||||
|
||||
popup = new LauncherPopup(Config, LaunchItem, OpenAllItems, ShowSettings, ShowSettings);
|
||||
popup = new LauncherPopup(Config, LaunchItem, OpenAllItems, ShowSettings, ShowSettings, OpenContainingFolderFromPopup);
|
||||
popup.Closed += (_, _) => popup = null;
|
||||
popup.ShowNearTaskbar();
|
||||
}
|
||||
@@ -221,6 +221,50 @@ public sealed class LauncherController : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenContainingFolderFromPopup(LauncherItem item)
|
||||
{
|
||||
if (!OpenContainingFolder(item, out string? error) && !string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
System.Windows.MessageBox.Show(error, "Taskbar Launcher");
|
||||
}
|
||||
}
|
||||
|
||||
public static bool OpenContainingFolder(LauncherItem item, out string? error)
|
||||
{
|
||||
error = null;
|
||||
|
||||
if (item.Type == LauncherItemType.Menu || string.IsNullOrWhiteSpace(item.Target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string target = Environment.ExpandEnvironmentVariables(item.Target);
|
||||
string? folderPath = Directory.Exists(target)
|
||||
? target
|
||||
: Path.GetDirectoryName(target);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(folderPath) || !Directory.Exists(folderPath))
|
||||
{
|
||||
error = $"{item.Title}: Containing folder was not found.";
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = folderPath,
|
||||
UseShellExecute = true
|
||||
});
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = $"{item.Title}: {ex.Message}";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryLaunchItem(LauncherItem item, out string? error)
|
||||
{
|
||||
error = null;
|
||||
|
||||
Reference in New Issue
Block a user