From ecb7144b9571d8f99fb0cef19ae2ce554d2862ce Mon Sep 17 00:00:00 2001 From: Junkui Zhang <364772080@qq.com> Date: Tue, 1 Oct 2024 07:26:20 +0800 Subject: [PATCH] windows: Fix can not set folder for `FileSaveDialog` (#17708) Closes #17622 Closes #17682 The story here is that `SHCreateItemFromParsingName` dose not accept UNC path. Video: https://github.com/user-attachments/assets/f4f7f671-5ab5-4965-9158-e7a79ac02654 Release Notes: - N/A --- crates/gpui/src/platform/windows/platform.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs index d9f08c2247..a900d0114b 100644 --- a/crates/gpui/src/platform/windows/platform.rs +++ b/crates/gpui/src/platform/windows/platform.rs @@ -664,10 +664,11 @@ fn file_save_dialog(directory: PathBuf) -> Result> { let dialog: IFileSaveDialog = unsafe { CoCreateInstance(&FileSaveDialog, None, CLSCTX_ALL)? }; if !directory.to_string_lossy().is_empty() { if let Some(full_path) = directory.canonicalize().log_err() { - let full_path = full_path.to_string_lossy().to_string(); - if !full_path.is_empty() { + let full_path = full_path.to_string_lossy(); + let full_path_str = full_path.trim_start_matches("\\\\?\\"); + if !full_path_str.is_empty() { let path_item: IShellItem = - unsafe { SHCreateItemFromParsingName(&HSTRING::from(&full_path), None)? }; + unsafe { SHCreateItemFromParsingName(&HSTRING::from(full_path_str), None)? }; unsafe { dialog.SetFolder(&path_item).log_err() }; } }