Merge pull request #80914 from jsjtxietian/init-importer-default-correctly

Fix "Import Defaults" selector not being initialized incorrectly
This commit is contained in:
Yuri Sizov 2023-08-25 21:26:34 +02:00
commit 3c71214a70

View file

@ -167,15 +167,13 @@ void ImportDefaultsEditor::_importer_selected(int p_index) {
void ImportDefaultsEditor::clear() {
String last_selected;
if (importers->get_selected() > 0) {
if (importers->get_selected() >= 0) {
last_selected = importers->get_item_text(importers->get_selected());
}
importers->clear();
importers->add_item("<" + TTR("Select Importer") + ">");
importers->set_item_disabled(0, true);
List<Ref<ResourceImporter>> importer_list;
ResourceFormatImporter::get_singleton()->get_importers(&importer_list);
Vector<String> names;
@ -185,11 +183,17 @@ void ImportDefaultsEditor::clear() {
}
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++) {
importers->add_item(names[i]);
if (names[i] == last_selected) {
importers->select(i + 1);
importers->select(i);
_update_importer();
}
}
}