Auto-change file extension in EditorFileDialog when filter changes
This commit is contained in:
parent
3942c939e3
commit
eeabb132ec
@ -672,6 +672,18 @@ bool EditorFileDialog::_is_open_should_be_disabled() {
|
|||||||
return false;
|
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.
|
// DO NOT USE THIS FUNCTION UNLESS NEEDED, CALL INVALIDATE() INSTEAD.
|
||||||
void EditorFileDialog::update_file_list() {
|
void EditorFileDialog::update_file_list() {
|
||||||
|
|
||||||
@ -865,7 +877,7 @@ void EditorFileDialog::update_file_list() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EditorFileDialog::_filter_selected(int) {
|
void EditorFileDialog::_filter_selected(int) {
|
||||||
|
update_file_name();
|
||||||
update_file_list();
|
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("_select_drive"), &EditorFileDialog::_select_drive);
|
||||||
ClassDB::bind_method(D_METHOD("_make_dir"), &EditorFileDialog::_make_dir);
|
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("_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_file_list"), &EditorFileDialog::update_file_list);
|
||||||
ClassDB::bind_method(D_METHOD("_update_dir"), &EditorFileDialog::update_dir);
|
ClassDB::bind_method(D_METHOD("_update_dir"), &EditorFileDialog::update_dir);
|
||||||
ClassDB::bind_method(D_METHOD("_thumbnail_done"), &EditorFileDialog::_thumbnail_done);
|
ClassDB::bind_method(D_METHOD("_thumbnail_done"), &EditorFileDialog::_thumbnail_done);
|
||||||
|
@ -148,6 +148,7 @@ private:
|
|||||||
bool invalidated;
|
bool invalidated;
|
||||||
|
|
||||||
void update_dir();
|
void update_dir();
|
||||||
|
void update_file_name();
|
||||||
void update_file_list();
|
void update_file_list();
|
||||||
void update_filters();
|
void update_filters();
|
||||||
|
|
||||||
|
@ -381,6 +381,18 @@ void FileDialog::_tree_item_activated() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileDialog::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.strip_edges().to_lower();
|
||||||
|
file->set_text(file_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FileDialog::update_file_list() {
|
void FileDialog::update_file_list() {
|
||||||
|
|
||||||
tree->clear();
|
tree->clear();
|
||||||
@ -506,6 +518,7 @@ void FileDialog::update_file_list() {
|
|||||||
|
|
||||||
void FileDialog::_filter_selected(int) {
|
void FileDialog::_filter_selected(int) {
|
||||||
|
|
||||||
|
update_file_name();
|
||||||
update_file_list();
|
update_file_list();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -797,6 +810,7 @@ void FileDialog::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("_select_drive"), &FileDialog::_select_drive);
|
ClassDB::bind_method(D_METHOD("_select_drive"), &FileDialog::_select_drive);
|
||||||
ClassDB::bind_method(D_METHOD("_make_dir"), &FileDialog::_make_dir);
|
ClassDB::bind_method(D_METHOD("_make_dir"), &FileDialog::_make_dir);
|
||||||
ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &FileDialog::_make_dir_confirm);
|
ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &FileDialog::_make_dir_confirm);
|
||||||
|
ClassDB::bind_method(D_METHOD("_update_file_name"), &FileDialog::update_file_name);
|
||||||
ClassDB::bind_method(D_METHOD("_update_file_list"), &FileDialog::update_file_list);
|
ClassDB::bind_method(D_METHOD("_update_file_list"), &FileDialog::update_file_list);
|
||||||
ClassDB::bind_method(D_METHOD("_update_dir"), &FileDialog::update_dir);
|
ClassDB::bind_method(D_METHOD("_update_dir"), &FileDialog::update_dir);
|
||||||
ClassDB::bind_method(D_METHOD("_go_up"), &FileDialog::_go_up);
|
ClassDB::bind_method(D_METHOD("_go_up"), &FileDialog::_go_up);
|
||||||
|
@ -102,6 +102,7 @@ private:
|
|||||||
bool invalidated;
|
bool invalidated;
|
||||||
|
|
||||||
void update_dir();
|
void update_dir();
|
||||||
|
void update_file_name();
|
||||||
void update_file_list();
|
void update_file_list();
|
||||||
void update_filters();
|
void update_filters();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user