summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-07-01 09:24:37 +0200
committerGitHub <noreply@github.com>2019-07-01 09:24:37 +0200
commitb62d315a7fea66357dbe3346218a720128121779 (patch)
tree37d8ba78700d19e5d6dc54dfcf8471389aa5a5ae /editor
parent89d537767eca3737297ff0abc6063087b03d3483 (diff)
parenteeabb132ec9cbc235d0afd6d7181dffbe9044488 (diff)
Merge pull request #30146 from Chaosus/editor_file_dlg_ex
Auto-change file extension in EditorFileDialog when filter changes
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_file_dialog.cpp15
-rw-r--r--editor/editor_file_dialog.h1
2 files changed, 15 insertions, 1 deletions
diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp
index 8025fc9795..24c5a788b6 100644
--- a/editor/editor_file_dialog.cpp
+++ b/editor/editor_file_dialog.cpp
@@ -672,6 +672,18 @@ bool EditorFileDialog::_is_open_should_be_disabled() {
return false;
}
+void EditorFileDialog::update_file_name() {
+ int idx = filter->get_selected() - 1;
+ if ((idx == -1 && filter->get_item_count() == 2) || (filter->get_item_count() > 2 && idx >= 0 && idx < filter->get_item_count() - 2)) {
+ if (idx == -1) idx += 1;
+ String filter_str = filters[idx];
+ String file_str = file->get_text();
+ String base_name = file_str.get_basename();
+ file_str = base_name + "." + filter_str.split(";")[1].strip_edges().to_lower();
+ file->set_text(file_str);
+ }
+}
+
// DO NOT USE THIS FUNCTION UNLESS NEEDED, CALL INVALIDATE() INSTEAD.
void EditorFileDialog::update_file_list() {
@@ -865,7 +877,7 @@ void EditorFileDialog::update_file_list() {
}
void EditorFileDialog::_filter_selected(int) {
-
+ update_file_name();
update_file_list();
}
@@ -1364,6 +1376,7 @@ void EditorFileDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("_select_drive"), &EditorFileDialog::_select_drive);
ClassDB::bind_method(D_METHOD("_make_dir"), &EditorFileDialog::_make_dir);
ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &EditorFileDialog::_make_dir_confirm);
+ ClassDB::bind_method(D_METHOD("_update_file_name"), &EditorFileDialog::update_file_name);
ClassDB::bind_method(D_METHOD("_update_file_list"), &EditorFileDialog::update_file_list);
ClassDB::bind_method(D_METHOD("_update_dir"), &EditorFileDialog::update_dir);
ClassDB::bind_method(D_METHOD("_thumbnail_done"), &EditorFileDialog::_thumbnail_done);
diff --git a/editor/editor_file_dialog.h b/editor/editor_file_dialog.h
index 6578be8563..86bf0f0eb3 100644
--- a/editor/editor_file_dialog.h
+++ b/editor/editor_file_dialog.h
@@ -148,6 +148,7 @@ private:
bool invalidated;
void update_dir();
+ void update_file_name();
void update_file_list();
void update_filters();