From b9a00feb66b87d03f6384b06031ce2ae5a1a4ba9 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 19 Dec 2024 09:47:46 +0200 Subject: [PATCH] [Windows, FileDialog] Prepend drive letter to the absolute paths without drive letter. --- editor/gui/editor_file_dialog.cpp | 9 ++++++++- scene/gui/file_dialog.cpp | 12 +++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/editor/gui/editor_file_dialog.cpp b/editor/gui/editor_file_dialog.cpp index ae0d80038db..2b169b4768d 100644 --- a/editor/gui/editor_file_dialog.cpp +++ b/editor/gui/editor_file_dialog.cpp @@ -410,7 +410,14 @@ void EditorFileDialog::update_dir() { } void EditorFileDialog::_dir_submitted(const String &p_dir) { - dir_access->change_dir(p_dir); + String new_dir = p_dir; +#ifdef WINDOWS_ENABLED + if (drives->is_visible() && !new_dir.is_network_share_path() && new_dir.is_absolute_path() && new_dir.find(":/") == -1 && new_dir.find(":\\") == -1) { + // Non network path without X:/ prefix on Windows, add drive letter. + new_dir = drives->get_item_text(drives->get_selected()).path_join(new_dir); + } +#endif + dir_access->change_dir(new_dir); invalidate(); update_dir(); _push_history(); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 5512e74c043..bc943561f36 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -398,7 +398,17 @@ void FileDialog::update_dir() { } void FileDialog::_dir_submitted(String p_dir) { - _change_dir(root_prefix.path_join(p_dir)); + String new_dir = p_dir; +#ifdef WINDOWS_ENABLED + if (root_prefix.is_empty() && drives->is_visible() && !new_dir.is_network_share_path() && new_dir.is_absolute_path() && new_dir.find(":/") == -1 && new_dir.find(":\\") == -1) { + // Non network path without X:/ prefix on Windows, add drive letter. + new_dir = drives->get_item_text(drives->get_selected()).path_join(new_dir); + } +#endif + if (!root_prefix.is_empty()) { + new_dir = root_prefix.path_join(new_dir); + } + _change_dir(new_dir); file->set_text(""); _push_history(); }