godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.46k stars 21.26k forks source link

Native FileDialog does not open `current_dir` on Windows #99598

Open RedMser opened 5 days ago

RedMser commented 5 days ago

Tested versions

Godot v4.4.dev5.official [9e6098432]

System information

Godot v4.4.dev5 - Windows 10.0.19044 - Multi-window, 3 monitors - OpenGL 3 (Compatibility) - NVIDIA GeForce RTX 2080 (NVIDIA; 32.0.15.5585) - Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz (12 threads)

Issue description

current_dir does not work on Windows when using native FileDialog.

As far as I can tell, this is because of this code:

https://github.com/godotengine/godot/blob/68f638c/scene/gui/file_dialog.cpp#L367-L372

The false parameter removes the drive letter from the path (so C:/Users/ turns to /Users/), which is fine when using the embedded file browser since that has a dropdown for drive letters. But on native file browser, it should use the full path, including drive letter.

Line 73 passes ProjectSettings::get_singleton()->globalize_path(dir->get_text()) along, which in the case of /Users/ as input does not touch the path at all.

I haven't done more testing with res:// and user:// paths, but those might be broken as well.

Steps to reproduce

On Windows: Set current_dir to a folder, then popup native FileDialog.

Minimal reproduction project (MRP)

native-file-dialog-currentdir.zip

Be aware that Windows remembers the last opened folder in the dialog, so you might want to change what you're setting current_dir to, to avoid it "looking like it works" but not actually updating due to your script's code.