summaryrefslogtreecommitdiff
path: root/editor/editor_file_dialog.cpp
diff options
context:
space:
mode:
authorNong Van Tinh <vannongtinh@gmail.com>2022-12-09 15:32:14 +0700
committerRémi Verschelde <rverschelde@gmail.com>2023-02-17 00:23:15 +0100
commit010ddfbc16e30723c7db44c71bc295b08e9febaf (patch)
tree3cd3eda3128f7e1000dacc401e4cb5281dae17f4 /editor/editor_file_dialog.cpp
parent15a97a2e8462ff76fe2eb44094f61320065b7dc8 (diff)
Prevent saving files with no name and only an extension.
Fixes #69768. Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
Diffstat (limited to 'editor/editor_file_dialog.cpp')
-rw-r--r--editor/editor_file_dialog.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp
index 4a1f0b4c09..80d1e9dcd7 100644
--- a/editor/editor_file_dialog.cpp
+++ b/editor/editor_file_dialog.cpp
@@ -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.
if (!valid) {
int idx = filter->get_selected();
@@ -480,9 +488,15 @@ void EditorFileDialog::_action_pressed() {
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) {
- confirm_save->set_text(TTR("File exists, overwrite?"));
- confirm_save->popup_centered(Size2(200, 80));
+ confirm_save->set_text(vformat(TTR("File \"%s\" already exists.\nDo you want to overwrite it?"), f));
+ confirm_save->popup_centered(Size2(250, 80) * EDSCALE);
} else {
_save_to_recent();
hide();