Skip to content

Commit

Permalink
Fix "Import Defaults" selector not being initialized incorrectly
Browse files Browse the repository at this point in the history
In ImportDefaultsEditor, delete 'Select Importer';
when first call the function, last_selected should
be the first one, directly show the settings for
"Animation Library"
  • Loading branch information
jsjtxietian committed Aug 25, 2023
1 parent 7ba79d6 commit f997fee
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions editor/import_defaults_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,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;
Expand All @@ -187,11 +185,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();
}
}
}
Expand Down

0 comments on commit f997fee

Please sign in to comment.