Skip to content

Commit

Permalink
improve open in file manager
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Jul 29, 2024
1 parent 1842bd3 commit 020d60b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
31 changes: 21 additions & 10 deletions src/OneWare.Essentials/Helpers/PlatformHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,28 @@ public static void OpenExplorerPath(string path)
{
try
{
if (Path.HasExtension(path)) path = Path.GetDirectoryName(path) ?? "";
else path = Path.GetFullPath(path);

if (string.IsNullOrEmpty(path)) return;

Process.Start(new ProcessStartInfo
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
FileName = path,
UseShellExecute = true,
Verb = "open"
});
// On Windows, use "explorer /select," to open the folder and select the file
Process.Start(new ProcessStartInfo("explorer", $"/select,\"{path}\"") { UseShellExecute = true });
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", $"-R \"{path}\"");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// Try opening the directory if the path is a file
if (System.IO.File.Exists(path))
{
path = Path.GetDirectoryName(path) ?? throw new NullReferenceException(nameof(path));
}
Process.Start("xdg-open", $"\"{path}\"");
}
else
{
throw new NotSupportedException("Operating system not supported");
}
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public void ConstructContextMenu(TopLevel topLevel)

menuItems.Add(new MenuItemViewModel("OpenFileViewer")
{
Header = "Open in File Viewer",
Header = "Open in File Manager",
Command = new RelayCommand(() => PlatformHelper.OpenExplorerPath(entry.FullPath)),
IconObservable = Application.Current!.GetResourceObservable("VsImageLib.OpenFolder16Xc")
});
Expand Down
11 changes: 0 additions & 11 deletions src/OneWare.ProjectSystem/Models/ProjectEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,4 @@ public bool IsValid()
{
return true;
}

public virtual IEnumerable<MenuItemViewModel> GetContextMenu(IProjectExplorerService projectExplorerService)
{
yield return new MenuItemViewModel("OpenFileViewer")
{
Header = "Open in File Viewer",
Command = new RelayCommand(() => PlatformHelper.OpenExplorerPath(FullPath)),
IconObservable = Application.Current!.GetResourceObservable("VsImageLib.OpenFolder16Xc"),
Priority = 1000
};
}
}
2 changes: 1 addition & 1 deletion studio/OneWare.Studio.Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private static AppBuilder BuildAvaloniaApp()
.With(new X11PlatformOptions
{
EnableMultiTouch = true,
WmClass = "OneWare"
WmClass = "OneWare",
})
.With(new Win32PlatformOptions
{
Expand Down

0 comments on commit 020d60b

Please sign in to comment.