From 4c77f4806764bd4d2b17394e9f1e14fc7e9b7045 Mon Sep 17 00:00:00 2001 From: George Marques Date: Mon, 13 Nov 2017 17:31:00 -0200 Subject: Refresh import options when changing importer --- editor/import_dock.cpp | 63 +++++++++++++++++++++++++++++++------------------- editor/import_dock.h | 1 + 2 files changed, 40 insertions(+), 24 deletions(-) (limited to 'editor') 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 options; - params->importer->get_import_options(&options); - - params->properties.clear(); - params->values.clear(); - - for (List::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 > 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 &p_config) { + + List options; + params->importer->get_import_options(&options); + + params->properties.clear(); + params->values.clear(); + + for (List::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 &p_paths) { @@ -269,6 +274,16 @@ void ImportDock::_importer_selected(int i_idx) { ERR_FAIL_COND(importer.is_null()); params->importer = importer; + + Ref 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 &p_config = Ref()); void _reimport(); -- cgit v1.2.3