1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-29 16:16:38 +00:00

Fix "Import Defaults" selector not being initialized incorrectly

In ImportDefaultsEditor, delete 'Select Importer';
when first call the function, last_selected should
be the first one, directly show the settings for
"Animation Library"
This commit is contained in:
jsjtxietian
2023-08-23 12:58:37 +08:00
parent 7ba79d68bd
commit f997feed75

View File

@@ -169,15 +169,13 @@ void ImportDefaultsEditor::_importer_selected(int p_index) {
void ImportDefaultsEditor::clear() { void ImportDefaultsEditor::clear() {
String last_selected; String last_selected;
if (importers->get_selected() > 0) {
if (importers->get_selected() >= 0) {
last_selected = importers->get_item_text(importers->get_selected()); last_selected = importers->get_item_text(importers->get_selected());
} }
importers->clear(); importers->clear();
importers->add_item("<" + TTR("Select Importer") + ">");
importers->set_item_disabled(0, true);
List<Ref<ResourceImporter>> importer_list; List<Ref<ResourceImporter>> importer_list;
ResourceFormatImporter::get_singleton()->get_importers(&importer_list); ResourceFormatImporter::get_singleton()->get_importers(&importer_list);
Vector<String> names; Vector<String> names;
@@ -187,11 +185,17 @@ void ImportDefaultsEditor::clear() {
} }
names.sort(); names.sort();
// `last_selected.is_empty()` means it's the first time being called.
if (last_selected.is_empty() && !names.is_empty()) {
last_selected = names[0];
}
for (int i = 0; i < names.size(); i++) { for (int i = 0; i < names.size(); i++) {
importers->add_item(names[i]); importers->add_item(names[i]);
if (names[i] == last_selected) { if (names[i] == last_selected) {
importers->select(i + 1); importers->select(i);
_update_importer();
} }
} }
} }