diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-11-13 21:25:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-13 21:25:48 +0100 |
commit | f1a8520c4541e86eb8e2bf932035a12f8bb5032f (patch) | |
tree | 07c6aca2b1ae3742ea2ff109e3bc165178977a2b | |
parent | 2a9e742c12deb8f4517d7aab1e3fb1fc4c51a35c (diff) | |
parent | 4c77f4806764bd4d2b17394e9f1e14fc7e9b7045 (diff) |
Merge pull request #12906 from vnen/import-options-refresh
Refresh import options when changing importer
-rw-r--r-- | editor/import_dock.cpp | 63 | ||||
-rw-r--r-- | editor/import_dock.h | 1 |
2 files changed, 40 insertions, 24 deletions
diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index df4254e2a3..84d55b4d14 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -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) { diff --git a/editor/import_dock.h b/editor/import_dock.h index a9bb22e568..28c29e4b20 100644 --- a/editor/import_dock.h +++ b/editor/import_dock.h @@ -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(); |