You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-21 14:57:09 +00:00
Prevent saving files with no name and only an extension.
Fixes #69768. Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
This commit is contained in:
committed by
Rémi Verschelde
parent
15a97a2e84
commit
010ddfbc16
@@ -472,6 +472,14 @@ void EditorFileDialog::_action_pressed() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// First check we're not having an empty name.
|
||||||
|
String file_name = file_text.strip_edges().get_file();
|
||||||
|
if (file_name.is_empty()) {
|
||||||
|
error_dialog->set_text(TTR("Cannot save file with an empty filename."));
|
||||||
|
error_dialog->popup_centered(Size2(250, 80) * EDSCALE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Add first extension of filter if no valid extension is found.
|
// Add first extension of filter if no valid extension is found.
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
int idx = filter->get_selected();
|
int idx = filter->get_selected();
|
||||||
@@ -480,9 +488,15 @@ void EditorFileDialog::_action_pressed() {
|
|||||||
f += "." + ext;
|
f += "." + ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (file_name.begins_with(".")) { // Could still happen if typed manually.
|
||||||
|
error_dialog->set_text(TTR("Cannot save file with a name starting with a dot."));
|
||||||
|
error_dialog->popup_centered(Size2(250, 80) * EDSCALE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (dir_access->file_exists(f) && !disable_overwrite_warning) {
|
if (dir_access->file_exists(f) && !disable_overwrite_warning) {
|
||||||
confirm_save->set_text(TTR("File exists, overwrite?"));
|
confirm_save->set_text(vformat(TTR("File \"%s\" already exists.\nDo you want to overwrite it?"), f));
|
||||||
confirm_save->popup_centered(Size2(200, 80));
|
confirm_save->popup_centered(Size2(250, 80) * EDSCALE);
|
||||||
} else {
|
} else {
|
||||||
_save_to_recent();
|
_save_to_recent();
|
||||||
hide();
|
hide();
|
||||||
|
|||||||
@@ -347,14 +347,15 @@ void FileDialog::_action_pressed() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid) {
|
String file_name = file_text.strip_edges().get_file();
|
||||||
|
if (!valid || file_name.is_empty()) {
|
||||||
exterr->popup_centered(Size2(250, 80));
|
exterr->popup_centered(Size2(250, 80));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir_access->file_exists(f)) {
|
if (dir_access->file_exists(f)) {
|
||||||
confirm_save->set_text(RTR("File exists, overwrite?"));
|
confirm_save->set_text(vformat(RTR("File \"%s\" already exists.\nDo you want to overwrite it?"), f));
|
||||||
confirm_save->popup_centered(Size2(200, 80));
|
confirm_save->popup_centered(Size2(250, 80));
|
||||||
} else {
|
} else {
|
||||||
emit_signal(SNAME("file_selected"), f);
|
emit_signal(SNAME("file_selected"), f);
|
||||||
hide();
|
hide();
|
||||||
@@ -1136,7 +1137,7 @@ FileDialog::FileDialog() {
|
|||||||
add_child(mkdirerr, false, INTERNAL_MODE_FRONT);
|
add_child(mkdirerr, false, INTERNAL_MODE_FRONT);
|
||||||
|
|
||||||
exterr = memnew(AcceptDialog);
|
exterr = memnew(AcceptDialog);
|
||||||
exterr->set_text(RTR("Must use a valid extension."));
|
exterr->set_text(RTR("Invalid extension, or empty filename."));
|
||||||
add_child(exterr, false, INTERNAL_MODE_FRONT);
|
add_child(exterr, false, INTERNAL_MODE_FRONT);
|
||||||
|
|
||||||
update_filters();
|
update_filters();
|
||||||
|
|||||||
Reference in New Issue
Block a user