From 9cc5ba86d1b7c0c26ee19229001627877ec7bd7b Mon Sep 17 00:00:00 2001 From: Robert Borghese <28355157+SomeRanDev@users.noreply.github.com> Date: Sun, 26 May 2024 19:55:35 -0400 Subject: [PATCH] windows: Make "Reveal in Finder" always open the file explorer (#12207) At the current moment, the "Reveal in Finder" behavior on Windows "opens" the file using direct execution. This causes files to be opened with whatever software they are associated with (i.e. will open Sublime Text instead of the file explorer). Release Notes: - Fixed "Reveal in Finder" on Windows to open with the File Explorer. The new behavior always opens the file explorer with the target folder/file pre-selected. https://github.com/zed-industries/zed/assets/28355157/b8ba471d-2f5b-4529-90c3-4dc59f308b99 --- crates/gpui/src/platform/windows/platform.rs | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs index 0b0c6ad3c2..5333682fad 100644 --- a/crates/gpui/src/platform/windows/platform.rs +++ b/crates/gpui/src/platform/windows/platform.rs @@ -435,7 +435,7 @@ impl Platform for WindowsPlatform { if path.is_empty() { return; } - open_target(path); + open_target_in_explorer(path); }) .detach(); } @@ -734,6 +734,25 @@ fn open_target(target: &str) { } } +fn open_target_in_explorer(target: &str) { + unsafe { + let ret = ShellExecuteW( + None, + windows::core::w!("open"), + windows::core::w!("explorer.exe"), + &HSTRING::from(format!("/select,{}", target).as_str()), + None, + SW_SHOWDEFAULT, + ); + if ret.0 <= 32 { + log::error!( + "Unable to open target in explorer: {}", + std::io::Error::last_os_error() + ); + } + } +} + unsafe fn show_savefile_dialog(directory: PathBuf) -> Result { let dialog: IFileSaveDialog = CoCreateInstance(&FileSaveDialog, None, CLSCTX_ALL)?; let bind_context = CreateBindCtx(0)?;