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
This commit is contained in:
Robert Borghese 2024-05-26 19:55:35 -04:00 committed by GitHub
parent 9e3a182177
commit 9cc5ba86d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<IFileSaveDialog> {
let dialog: IFileSaveDialog = CoCreateInstance(&FileSaveDialog, None, CLSCTX_ALL)?;
let bind_context = CreateBindCtx(0)?;