Skip to content

Commit

Permalink
[Windows] Fix root and current folder in native file dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruvzg committed Nov 25, 2024
1 parent 0c45ace commit adba8b1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
10 changes: 7 additions & 3 deletions editor/gui/editor_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ void EditorFileDialog::_native_dialog_cb(bool p_ok, const Vector<String> &p_file
selected_options = p_selected_options;

String f = files[0];

filter->select(p_filter);
dir->set_text(f.get_base_dir());
file->set_text(f.get_file());
_dir_submitted(f.get_base_dir());

if (mode == FILE_MODE_OPEN_FILES) {
emit_signal(SNAME("files_selected"), files);
} else {
Expand Down Expand Up @@ -145,9 +151,6 @@ void EditorFileDialog::_native_dialog_cb(bool p_ok, const Vector<String> &p_file
emit_signal(SNAME("dir_selected"), f);
}
}
file->set_text(f);
dir->set_text(f.get_base_dir());
filter->select(p_filter);
}

void EditorFileDialog::popup_file_dialog() {
Expand Down Expand Up @@ -363,6 +366,7 @@ Vector<String> EditorFileDialog::get_selected_files() const {
}

void EditorFileDialog::update_dir() {
full_dir = dir_access->get_current_dir();
if (drives->is_visible()) {
if (dir_access->get_current_dir().is_network_share_path()) {
_update_drives(false);
Expand Down
1 change: 1 addition & 0 deletions editor/gui/editor_file_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class EditorFileDialog : public ConfirmationDialog {
Vector<Option> options;
Dictionary selected_options;
bool options_dirty = false;
String full_dir;

void update_dir();
void update_file_name();
Expand Down
5 changes: 1 addition & 4 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,7 @@ void DisplayServerWindows::_thread_fd_monitor(void *p_ud) {
}
}
dir = dir.simplify_path();
dir = dir.replace("/", "\\");
if (!dir.is_network_share_path() && !dir.begins_with(R"(\\?\)")) {
dir = R"(\\?\)" + dir;
}
dir = dir.trim_prefix(R"(\\?\)").replace("/", "\\");

IShellItem *shellitem = nullptr;
hr = SHCreateItemFromParsingName((LPCWSTR)dir.utf16().ptr(), nullptr, IID_IShellItem, (void **)&shellitem);
Expand Down
17 changes: 11 additions & 6 deletions scene/gui/file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ void FileDialog::_focus_file_text() {
void FileDialog::_native_popup() {
// Show native dialog directly.
String root;
if (access == ACCESS_RESOURCES) {
if (!root_prefix.is_empty()) {
root = ProjectSettings::get_singleton()->globalize_path(root_prefix);
} else if (access == ACCESS_RESOURCES) {
root = ProjectSettings::get_singleton()->get_resource_path();
} else if (access == ACCESS_USERDATA) {
root = OS::get_singleton()->get_user_data_dir();
}
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE_EXTRA)) {
DisplayServer::get_singleton()->file_dialog_with_options_show(get_translated_title(), ProjectSettings::get_singleton()->globalize_path(dir->get_text()), root, file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), processed_filters, _get_options(), callable_mp(this, &FileDialog::_native_dialog_cb_with_options));
DisplayServer::get_singleton()->file_dialog_with_options_show(get_translated_title(), ProjectSettings::get_singleton()->globalize_path(full_dir), root, file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), processed_filters, _get_options(), callable_mp(this, &FileDialog::_native_dialog_cb_with_options));
} else {
DisplayServer::get_singleton()->file_dialog_show(get_translated_title(), ProjectSettings::get_singleton()->globalize_path(dir->get_text()), file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), processed_filters, callable_mp(this, &FileDialog::_native_dialog_cb));
DisplayServer::get_singleton()->file_dialog_show(get_translated_title(), ProjectSettings::get_singleton()->globalize_path(full_dir), file->get_text().get_file(), show_hidden_files, DisplayServer::FileDialogMode(mode), processed_filters, callable_mp(this, &FileDialog::_native_dialog_cb));
}
}

Expand Down Expand Up @@ -143,6 +145,11 @@ void FileDialog::_native_dialog_cb_with_options(bool p_ok, const Vector<String>
selected_options = p_selected_options;

String f = files[0];
filter->select(p_filter);
dir->set_text(f.get_base_dir());
file->set_text(f.get_file());
_change_dir(f.get_base_dir());

if (mode == FILE_MODE_OPEN_FILES) {
emit_signal(SNAME("files_selected"), files);
} else {
Expand Down Expand Up @@ -171,9 +178,6 @@ void FileDialog::_native_dialog_cb_with_options(bool p_ok, const Vector<String>
emit_signal(SNAME("dir_selected"), f);
}
}
file->set_text(f);
dir->set_text(f.get_base_dir());
filter->select(p_filter);
}

VBoxContainer *FileDialog::get_vbox() {
Expand Down Expand Up @@ -365,6 +369,7 @@ Vector<String> FileDialog::get_selected_files() const {
}

void FileDialog::update_dir() {
full_dir = dir_access->get_current_dir();
if (root_prefix.is_empty()) {
dir->set_text(dir_access->get_current_dir(false));
} else {
Expand Down
1 change: 1 addition & 0 deletions scene/gui/file_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class FileDialog : public ConfirmationDialog {
Vector<Option> options;
Dictionary selected_options;
bool options_dirty = false;
String full_dir;

void update_dir();
void update_file_name();
Expand Down

0 comments on commit adba8b1

Please sign in to comment.