You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
[Windows] Fix root and current folder in native file dialog.
Co-authored-by: RedMser <redmser.jj2@gmail.com>
This commit is contained in:
committed by
Pāvels Nadtočajevs
parent
0c45ace151
commit
e0b4f3d314
@@ -117,6 +117,12 @@ void EditorFileDialog::_native_dialog_cb(bool p_ok, const Vector<String> &p_file
|
|||||||
selected_options = p_selected_options;
|
selected_options = p_selected_options;
|
||||||
|
|
||||||
String f = files[0];
|
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) {
|
if (mode == FILE_MODE_OPEN_FILES) {
|
||||||
emit_signal(SNAME("files_selected"), files);
|
emit_signal(SNAME("files_selected"), files);
|
||||||
} else {
|
} else {
|
||||||
@@ -145,9 +151,6 @@ void EditorFileDialog::_native_dialog_cb(bool p_ok, const Vector<String> &p_file
|
|||||||
emit_signal(SNAME("dir_selected"), f);
|
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() {
|
void EditorFileDialog::popup_file_dialog() {
|
||||||
@@ -363,6 +366,7 @@ Vector<String> EditorFileDialog::get_selected_files() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EditorFileDialog::update_dir() {
|
void EditorFileDialog::update_dir() {
|
||||||
|
full_dir = dir_access->get_current_dir();
|
||||||
if (drives->is_visible()) {
|
if (drives->is_visible()) {
|
||||||
if (dir_access->get_current_dir().is_network_share_path()) {
|
if (dir_access->get_current_dir().is_network_share_path()) {
|
||||||
_update_drives(false);
|
_update_drives(false);
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ private:
|
|||||||
Vector<Option> options;
|
Vector<Option> options;
|
||||||
Dictionary selected_options;
|
Dictionary selected_options;
|
||||||
bool options_dirty = false;
|
bool options_dirty = false;
|
||||||
|
String full_dir;
|
||||||
|
|
||||||
void update_dir();
|
void update_dir();
|
||||||
void update_file_name();
|
void update_file_name();
|
||||||
|
|||||||
@@ -572,10 +572,7 @@ void DisplayServerWindows::_thread_fd_monitor(void *p_ud) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dir = dir.simplify_path();
|
dir = dir.simplify_path();
|
||||||
dir = dir.replace("/", "\\");
|
dir = dir.trim_prefix(R"(\\?\)").replace("/", "\\");
|
||||||
if (!dir.is_network_share_path() && !dir.begins_with(R"(\\?\)")) {
|
|
||||||
dir = R"(\\?\)" + dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
IShellItem *shellitem = nullptr;
|
IShellItem *shellitem = nullptr;
|
||||||
hr = SHCreateItemFromParsingName((LPCWSTR)dir.utf16().ptr(), nullptr, IID_IShellItem, (void **)&shellitem);
|
hr = SHCreateItemFromParsingName((LPCWSTR)dir.utf16().ptr(), nullptr, IID_IShellItem, (void **)&shellitem);
|
||||||
|
|||||||
@@ -62,15 +62,17 @@ void FileDialog::_focus_file_text() {
|
|||||||
void FileDialog::_native_popup() {
|
void FileDialog::_native_popup() {
|
||||||
// Show native dialog directly.
|
// Show native dialog directly.
|
||||||
String root;
|
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();
|
root = ProjectSettings::get_singleton()->get_resource_path();
|
||||||
} else if (access == ACCESS_USERDATA) {
|
} else if (access == ACCESS_USERDATA) {
|
||||||
root = OS::get_singleton()->get_user_data_dir();
|
root = OS::get_singleton()->get_user_data_dir();
|
||||||
}
|
}
|
||||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_DIALOG_FILE_EXTRA)) {
|
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 {
|
} 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,6 +145,11 @@ void FileDialog::_native_dialog_cb_with_options(bool p_ok, const Vector<String>
|
|||||||
selected_options = p_selected_options;
|
selected_options = p_selected_options;
|
||||||
|
|
||||||
String f = files[0];
|
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) {
|
if (mode == FILE_MODE_OPEN_FILES) {
|
||||||
emit_signal(SNAME("files_selected"), files);
|
emit_signal(SNAME("files_selected"), files);
|
||||||
} else {
|
} else {
|
||||||
@@ -171,9 +178,6 @@ void FileDialog::_native_dialog_cb_with_options(bool p_ok, const Vector<String>
|
|||||||
emit_signal(SNAME("dir_selected"), f);
|
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() {
|
VBoxContainer *FileDialog::get_vbox() {
|
||||||
@@ -365,6 +369,7 @@ Vector<String> FileDialog::get_selected_files() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileDialog::update_dir() {
|
void FileDialog::update_dir() {
|
||||||
|
full_dir = dir_access->get_current_dir();
|
||||||
if (root_prefix.is_empty()) {
|
if (root_prefix.is_empty()) {
|
||||||
dir->set_text(dir_access->get_current_dir(false));
|
dir->set_text(dir_access->get_current_dir(false));
|
||||||
} else {
|
} else {
|
||||||
@@ -970,7 +975,7 @@ String FileDialog::get_filename_filter() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String FileDialog::get_current_dir() const {
|
String FileDialog::get_current_dir() const {
|
||||||
return dir->get_text();
|
return full_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
String FileDialog::get_current_file() const {
|
String FileDialog::get_current_file() const {
|
||||||
@@ -978,7 +983,7 @@ String FileDialog::get_current_file() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String FileDialog::get_current_path() const {
|
String FileDialog::get_current_path() const {
|
||||||
return dir->get_text().path_join(file->get_text());
|
return full_dir.path_join(file->get_text());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileDialog::set_current_dir(const String &p_dir) {
|
void FileDialog::set_current_dir(const String &p_dir) {
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ private:
|
|||||||
Vector<Option> options;
|
Vector<Option> options;
|
||||||
Dictionary selected_options;
|
Dictionary selected_options;
|
||||||
bool options_dirty = false;
|
bool options_dirty = false;
|
||||||
|
String full_dir;
|
||||||
|
|
||||||
void update_dir();
|
void update_dir();
|
||||||
void update_file_name();
|
void update_file_name();
|
||||||
|
|||||||
Reference in New Issue
Block a user