Merge pull request #12906 from vnen/import-options-refresh

Refresh import options when changing importer
This commit is contained in:
Rémi Verschelde 2017-11-13 21:25:48 +01:00 committed by GitHub
commit f1a8520c45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 24 deletions

View File

@ -87,23 +87,7 @@ void ImportDock::set_edit_path(const String &p_path) {
return;
}
List<ResourceImporter::ImportOption> options;
params->importer->get_import_options(&options);
params->properties.clear();
params->values.clear();
for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) {
params->properties.push_back(E->get().option);
if (config->has_section_key("params", E->get().option.name)) {
params->values[E->get().option.name] = config->get_value("params", E->get().option.name);
} else {
params->values[E->get().option.name] = E->get().default_value;
}
}
params->update();
_update_options(config);
List<Ref<ResourceImporter> > importers;
ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_path.get_extension(), &importers);
@ -125,6 +109,34 @@ void ImportDock::set_edit_path(const String &p_path) {
}
}
params->paths.clear();
params->paths.push_back(p_path);
import->set_disabled(false);
import_as->set_disabled(false);
imported->set_text(p_path.get_file());
}
void ImportDock::_update_options(const Ref<ConfigFile> &p_config) {
List<ResourceImporter::ImportOption> options;
params->importer->get_import_options(&options);
params->properties.clear();
params->values.clear();
for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) {
params->properties.push_back(E->get().option);
if (p_config.is_valid() && p_config->has_section_key("params", E->get().option.name)) {
params->values[E->get().option.name] = p_config->get_value("params", E->get().option.name);
} else {
params->values[E->get().option.name] = E->get().default_value;
}
}
params->update();
preset->get_popup()->clear();
if (params->importer->get_preset_count() == 0) {
@ -142,13 +154,6 @@ void ImportDock::set_edit_path(const String &p_path) {
preset->get_popup()->add_separator();
preset->get_popup()->add_item(vformat(TTR("Clear Default for '%s'"), params->importer->get_visible_name()), ITEM_CLEAR_DEFAULT);
}
params->paths.clear();
params->paths.push_back(p_path);
import->set_disabled(false);
import_as->set_disabled(false);
imported->set_text(p_path.get_file());
}
void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
@ -269,6 +274,16 @@ void ImportDock::_importer_selected(int i_idx) {
ERR_FAIL_COND(importer.is_null());
params->importer = importer;
Ref<ConfigFile> config;
if (params->paths.size()) {
config.instance();
Error err = config->load(params->paths[0] + ".import");
if (err != OK) {
config.unref();
}
}
_update_options(config);
}
void ImportDock::_preset_selected(int p_idx) {

View File

@ -55,6 +55,7 @@ class ImportDock : public VBoxContainer {
void _preset_selected(int p_idx);
void _importer_selected(int i_idx);
void _update_options(const Ref<ConfigFile> &p_config = Ref<ConfigFile>());
void _reimport();