| 
									
										
										
										
											2017-03-05 15:47:28 +01:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  import_dock.cpp                                                      */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2017-03-05 15:47:28 +01:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2021-01-01 20:13:46 +01:00
										 |  |  | /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2017-03-05 15:47:28 +01:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | #include "import_dock.h"
 | 
					
						
							| 
									
										
										
										
											2017-08-04 20:16:04 +02:00
										 |  |  | #include "editor_node.h"
 | 
					
						
							| 
									
										
										
										
											2019-12-24 15:17:23 +08:00
										 |  |  | #include "editor_resource_preview.h"
 | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | class ImportDockParameters : public Object { | 
					
						
							| 
									
										
										
										
											2019-03-19 14:35:57 -04:00
										 |  |  | 	GDCLASS(ImportDockParameters, Object); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Map<StringName, Variant> values; | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	List<PropertyInfo> properties; | 
					
						
							|  |  |  | 	Ref<ResourceImporter> importer; | 
					
						
							|  |  |  | 	Vector<String> paths; | 
					
						
							| 
									
										
										
										
											2018-10-30 13:11:54 -03:00
										 |  |  | 	Set<StringName> checked; | 
					
						
							|  |  |  | 	bool checking; | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	bool _set(const StringName &p_name, const Variant &p_value) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		if (values.has(p_name)) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			values[p_name] = p_value; | 
					
						
							| 
									
										
										
										
											2018-10-30 13:11:54 -03:00
										 |  |  | 			if (checking) { | 
					
						
							|  |  |  | 				checked.insert(p_name); | 
					
						
							| 
									
										
										
										
											2021-02-10 17:18:45 -03:00
										 |  |  | 				notify_property_list_changed(); | 
					
						
							| 
									
										
										
										
											2018-10-30 13:11:54 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	bool _get(const StringName &p_name, Variant &r_ret) const { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		if (values.has(p_name)) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			r_ret = values[p_name]; | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	void _get_property_list(List<PropertyInfo> *p_list) const { | 
					
						
							|  |  |  | 		for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (!importer->get_option_visibility(E->get().name, values)) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 				continue; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-10-30 13:11:54 -03:00
										 |  |  | 			PropertyInfo pi = E->get(); | 
					
						
							|  |  |  | 			if (checking) { | 
					
						
							|  |  |  | 				pi.usage |= PROPERTY_USAGE_CHECKABLE; | 
					
						
							|  |  |  | 				if (checked.has(E->get().name)) { | 
					
						
							|  |  |  | 					pi.usage |= PROPERTY_USAGE_CHECKED; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			p_list->push_back(pi); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void update() { | 
					
						
							| 
									
										
										
										
											2021-02-10 17:18:45 -03:00
										 |  |  | 		notify_property_list_changed(); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-30 13:11:54 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ImportDockParameters() { | 
					
						
							|  |  |  | 		checking = false; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void ImportDock::set_edit_path(const String &p_path) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	Ref<ConfigFile> config; | 
					
						
							|  |  |  | 	config.instance(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Error err = config->load(p_path + ".import"); | 
					
						
							|  |  |  | 	if (err != OK) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		clear(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 	String importer_name = config->get_value("remap", "importer"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	params->importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-28 00:03:55 -03:00
										 |  |  | 	params->paths.clear(); | 
					
						
							|  |  |  | 	params->paths.push_back(p_path); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 17:31:00 -02:00
										 |  |  | 	_update_options(config); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | 	List<Ref<ResourceImporter>> importers; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_path.get_extension(), &importers); | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | 	List<Pair<String, String>> importer_names; | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | 	for (List<Ref<ResourceImporter>>::Element *E = importers.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		importer_names.push_back(Pair<String, String>(E->get()->get_visible_name(), E->get()->get_importer_name())); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | 	importer_names.sort_custom<PairSort<String, String>>(); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	import_as->clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | 	for (List<Pair<String, String>>::Element *E = importer_names.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		import_as->add_item(E->get().first); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		import_as->set_item_metadata(import_as->get_item_count() - 1, E->get().second); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 		if (E->get().second == importer_name) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			import_as->select(import_as->get_item_count() - 1); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 	import_as->add_separator(); | 
					
						
							|  |  |  | 	import_as->add_item(TTR("Keep File (No Import)")); | 
					
						
							|  |  |  | 	import_as->set_item_metadata(import_as->get_item_count() - 1, "keep"); | 
					
						
							|  |  |  | 	if (importer_name == "keep") { | 
					
						
							|  |  |  | 		import_as->select(import_as->get_item_count() - 1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 17:31:00 -02:00
										 |  |  | 	import->set_disabled(false); | 
					
						
							|  |  |  | 	import_as->set_disabled(false); | 
					
						
							| 
									
										
										
										
											2019-09-04 02:20:57 -03:00
										 |  |  | 	preset->set_disabled(false); | 
					
						
							| 
									
										
										
										
											2017-11-13 17:31:00 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	imported->set_text(p_path.get_file()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ImportDock::_update_options(const Ref<ConfigFile> &p_config) { | 
					
						
							|  |  |  | 	List<ResourceImporter::ImportOption> options; | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (params->importer.is_valid()) { | 
					
						
							|  |  |  | 		params->importer->get_import_options(&options); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-13 17:31:00 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	params->properties.clear(); | 
					
						
							|  |  |  | 	params->values.clear(); | 
					
						
							| 
									
										
										
										
											2020-02-28 00:03:55 -03:00
										 |  |  | 	params->checking = params->paths.size() > 1; | 
					
						
							| 
									
										
										
										
											2018-10-30 13:11:54 -03:00
										 |  |  | 	params->checked.clear(); | 
					
						
							| 
									
										
										
										
											2017-11-13 17:31:00 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	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(); | 
					
						
							| 
									
										
										
										
											2020-02-13 22:58:19 -03:00
										 |  |  | 	_update_preset_menu(); | 
					
						
							| 
									
										
										
										
											2021-03-19 09:57:52 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 	if (params->importer.is_valid() && params->paths.size() == 1 && params->importer->has_advanced_options()) { | 
					
						
							| 
									
										
										
										
											2021-03-19 09:57:52 -03:00
										 |  |  | 		advanced->show(); | 
					
						
							|  |  |  | 		advanced_spacer->show(); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		advanced->hide(); | 
					
						
							|  |  |  | 		advanced_spacer->hide(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-22 08:35:03 +01:00
										 |  |  | 	// Use the value that is repeated the most.
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Map<String, Dictionary> value_frequency; | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < p_paths.size(); i++) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		Ref<ConfigFile> config; | 
					
						
							|  |  |  | 		config.instance(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Error err = config->load(p_paths[i] + ".import"); | 
					
						
							|  |  |  | 		ERR_CONTINUE(err != OK); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (i == 0) { | 
					
						
							|  |  |  | 			params->importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(config->get_value("remap", "importer")); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 			if (params->importer.is_null()) { | 
					
						
							|  |  |  | 				clear(); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-26 10:05:25 +08:00
										 |  |  | 		if (!config->has_section("params")) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		List<String> keys; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		config->get_section_keys("params", &keys); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (List<String>::Element *E = keys.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 			if (!value_frequency.has(E->get())) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				value_frequency[E->get()] = Dictionary(); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			Variant value = config->get_value("params", E->get()); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (value_frequency[E->get()].has(value)) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				value_frequency[E->get()][value] = int(value_frequency[E->get()][value]) + 1; | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				value_frequency[E->get()][value] = 1; | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(params->importer.is_null()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	List<ResourceImporter::ImportOption> options; | 
					
						
							|  |  |  | 	params->importer->get_import_options(&options); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	params->properties.clear(); | 
					
						
							|  |  |  | 	params->values.clear(); | 
					
						
							| 
									
										
										
										
											2018-10-30 13:11:54 -03:00
										 |  |  | 	params->checking = true; | 
					
						
							|  |  |  | 	params->checked.clear(); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		params->properties.push_back(E->get().option); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (value_frequency.has(E->get().option.name)) { | 
					
						
							|  |  |  | 			Dictionary d = value_frequency[E->get().option.name]; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			int freq = 0; | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 			List<Variant> v; | 
					
						
							|  |  |  | 			d.get_key_list(&v); | 
					
						
							|  |  |  | 			Variant value; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			for (List<Variant>::Element *F = v.front(); F; F = F->next()) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 				int f = d[F->get()]; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (f > freq) { | 
					
						
							|  |  |  | 					value = F->get(); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			params->values[E->get().option.name] = value; | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			params->values[E->get().option.name] = E->get().default_value; | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	params->update(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | 	List<Ref<ResourceImporter>> importers; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_paths[0].get_extension(), &importers); | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | 	List<Pair<String, String>> importer_names; | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | 	for (List<Ref<ResourceImporter>>::Element *E = importers.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		importer_names.push_back(Pair<String, String>(E->get()->get_visible_name(), E->get()->get_importer_name())); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | 	importer_names.sort_custom<PairSort<String, String>>(); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	import_as->clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 07:33:00 +01:00
										 |  |  | 	for (List<Pair<String, String>>::Element *E = importer_names.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		import_as->add_item(E->get().first); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		import_as->set_item_metadata(import_as->get_item_count() - 1, E->get().second); | 
					
						
							|  |  |  | 		if (E->get().second == params->importer->get_importer_name()) { | 
					
						
							|  |  |  | 			import_as->select(import_as->get_item_count() - 1); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-13 22:58:19 -03:00
										 |  |  | 	_update_preset_menu(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	params->paths = p_paths; | 
					
						
							|  |  |  | 	import->set_disabled(false); | 
					
						
							|  |  |  | 	import_as->set_disabled(false); | 
					
						
							|  |  |  | 	preset->set_disabled(false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 09:58:34 +01:00
										 |  |  | 	imported->set_text(vformat(TTR("%d Files"), p_paths.size())); | 
					
						
							| 
									
										
										
										
											2021-03-19 09:57:52 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (params->paths.size() == 1 && params->importer->has_advanced_options()) { | 
					
						
							|  |  |  | 		advanced->show(); | 
					
						
							|  |  |  | 		advanced_spacer->show(); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		advanced->hide(); | 
					
						
							|  |  |  | 		advanced_spacer->hide(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-02-13 22:58:19 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ImportDock::_update_preset_menu() { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	preset->get_popup()->clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 	if (params->importer.is_null()) { | 
					
						
							|  |  |  | 		preset->get_popup()->add_item(TTR("Default")); | 
					
						
							|  |  |  | 		preset->hide(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	preset->show(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (params->importer->get_preset_count() == 0) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		preset->get_popup()->add_item(TTR("Default")); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int i = 0; i < params->importer->get_preset_count(); i++) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 			preset->get_popup()->add_item(params->importer->get_preset_name(i)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-13 22:58:19 -03:00
										 |  |  | 	preset->get_popup()->add_separator(); | 
					
						
							|  |  |  | 	preset->get_popup()->add_item(vformat(TTR("Set as Default for '%s'"), params->importer->get_visible_name()), ITEM_SET_AS_DEFAULT); | 
					
						
							|  |  |  | 	if (ProjectSettings::get_singleton()->has_setting("importer_defaults/" + params->importer->get_importer_name())) { | 
					
						
							|  |  |  | 		preset->get_popup()->add_item(TTR("Load Default"), ITEM_LOAD_DEFAULT); | 
					
						
							|  |  |  | 		preset->get_popup()->add_separator(); | 
					
						
							|  |  |  | 		preset->get_popup()->add_item(vformat(TTR("Clear Default for '%s'"), params->importer->get_visible_name()), ITEM_CLEAR_DEFAULT); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-10 15:53:01 -05:00
										 |  |  | void ImportDock::_importer_selected(int i_idx) { | 
					
						
							|  |  |  | 	String name = import_as->get_selected_metadata(); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 	if (name == "keep") { | 
					
						
							|  |  |  | 		params->importer.unref(); | 
					
						
							|  |  |  | 		_update_options(Ref<ConfigFile>()); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(name); | 
					
						
							|  |  |  | 		ERR_FAIL_COND(importer.is_null()); | 
					
						
							| 
									
										
										
										
											2017-11-10 15:53:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 		params->importer = importer; | 
					
						
							| 
									
										
										
										
											2017-11-13 17:31:00 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 		Ref<ConfigFile> config; | 
					
						
							|  |  |  | 		if (params->paths.size()) { | 
					
						
							|  |  |  | 			config.instance(); | 
					
						
							|  |  |  | 			Error err = config->load(params->paths[0] + ".import"); | 
					
						
							|  |  |  | 			if (err != OK) { | 
					
						
							|  |  |  | 				config.unref(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-13 17:31:00 -02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 		_update_options(config); | 
					
						
							| 
									
										
										
										
											2017-11-13 17:31:00 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-10 15:53:01 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | void ImportDock::_preset_selected(int p_idx) { | 
					
						
							| 
									
										
										
										
											2017-08-31 11:55:54 -03:00
										 |  |  | 	int item_id = preset->get_popup()->get_item_id(p_idx); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-31 11:55:54 -03:00
										 |  |  | 	switch (item_id) { | 
					
						
							|  |  |  | 		case ITEM_SET_AS_DEFAULT: { | 
					
						
							| 
									
										
										
										
											2017-07-23 18:48:05 -03:00
										 |  |  | 			Dictionary d; | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-31 11:55:54 -03:00
										 |  |  | 			for (const List<PropertyInfo>::Element *E = params->properties.front(); E; E = E->next()) { | 
					
						
							|  |  |  | 				d[E->get().name] = params->values[E->get().name]; | 
					
						
							| 
									
										
										
										
											2017-07-23 18:48:05 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-23 18:48:05 -03:00
										 |  |  | 			ProjectSettings::get_singleton()->set("importer_defaults/" + params->importer->get_importer_name(), d); | 
					
						
							|  |  |  | 			ProjectSettings::get_singleton()->save(); | 
					
						
							| 
									
										
										
										
											2020-02-13 22:58:19 -03:00
										 |  |  | 			_update_preset_menu(); | 
					
						
							| 
									
										
										
										
											2017-07-23 18:48:05 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case ITEM_LOAD_DEFAULT: { | 
					
						
							| 
									
										
										
										
											2017-10-05 15:34:34 -03:00
										 |  |  | 			ERR_FAIL_COND(!ProjectSettings::get_singleton()->has_setting("importer_defaults/" + params->importer->get_importer_name())); | 
					
						
							| 
									
										
										
										
											2017-07-23 18:48:05 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			Dictionary d = ProjectSettings::get_singleton()->get("importer_defaults/" + params->importer->get_importer_name()); | 
					
						
							|  |  |  | 			List<Variant> v; | 
					
						
							|  |  |  | 			d.get_key_list(&v); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-13 22:58:19 -03:00
										 |  |  | 			if (params->checking) { | 
					
						
							|  |  |  | 				params->checked.clear(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-07-23 18:48:05 -03:00
										 |  |  | 			for (List<Variant>::Element *E = v.front(); E; E = E->next()) { | 
					
						
							|  |  |  | 				params->values[E->get()] = d[E->get()]; | 
					
						
							| 
									
										
										
										
											2020-02-13 22:58:19 -03:00
										 |  |  | 				if (params->checking) { | 
					
						
							|  |  |  | 					params->checked.insert(E->get()); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-07-23 18:48:05 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			params->update(); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case ITEM_CLEAR_DEFAULT: { | 
					
						
							|  |  |  | 			ProjectSettings::get_singleton()->set("importer_defaults/" + params->importer->get_importer_name(), Variant()); | 
					
						
							|  |  |  | 			ProjectSettings::get_singleton()->save(); | 
					
						
							| 
									
										
										
										
											2020-02-13 22:58:19 -03:00
										 |  |  | 			_update_preset_menu(); | 
					
						
							| 
									
										
										
										
											2017-07-23 18:48:05 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		default: { | 
					
						
							|  |  |  | 			List<ResourceImporter::ImportOption> options; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			params->importer->get_import_options(&options, p_idx); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-13 22:58:19 -03:00
										 |  |  | 			if (params->checking) { | 
					
						
							|  |  |  | 				params->checked.clear(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-07-23 18:48:05 -03:00
										 |  |  | 			for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) { | 
					
						
							|  |  |  | 				params->values[E->get().option.name] = E->get().default_value; | 
					
						
							| 
									
										
										
										
											2020-02-13 22:58:19 -03:00
										 |  |  | 				if (params->checking) { | 
					
						
							|  |  |  | 					params->checked.insert(E->get().option.name); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-07-23 18:48:05 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			params->update(); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ImportDock::clear() { | 
					
						
							|  |  |  | 	imported->set_text(""); | 
					
						
							|  |  |  | 	import->set_disabled(true); | 
					
						
							|  |  |  | 	import_as->clear(); | 
					
						
							|  |  |  | 	import_as->set_disabled(true); | 
					
						
							| 
									
										
										
										
											2019-09-04 02:20:57 -03:00
										 |  |  | 	preset->set_disabled(true); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	params->values.clear(); | 
					
						
							|  |  |  | 	params->properties.clear(); | 
					
						
							|  |  |  | 	params->update(); | 
					
						
							|  |  |  | 	preset->get_popup()->clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-25 17:23:56 -03:00
										 |  |  | static bool _find_owners(EditorFileSystemDirectory *efsd, const String &p_path) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!efsd) { | 
					
						
							| 
									
										
										
										
											2019-01-25 17:23:56 -03:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-01-25 17:23:56 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < efsd->get_subdir_count(); i++) { | 
					
						
							|  |  |  | 		if (_find_owners(efsd->get_subdir(i), p_path)) { | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < efsd->get_file_count(); i++) { | 
					
						
							|  |  |  | 		Vector<String> deps = efsd->get_file_deps(i); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (deps.find(p_path) != -1) { | 
					
						
							| 
									
										
										
										
											2019-01-25 17:23:56 -03:00
										 |  |  | 			return true; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-01-25 17:23:56 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-25 17:23:56 -03:00
										 |  |  | void ImportDock::_reimport_attempt() { | 
					
						
							|  |  |  | 	bool need_restart = false; | 
					
						
							|  |  |  | 	bool used_in_resources = false; | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String importer_name; | 
					
						
							|  |  |  | 	if (params->importer.is_valid()) { | 
					
						
							|  |  |  | 		importer_name = params->importer->get_importer_name(); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		importer_name = "keep"; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-01-25 17:23:56 -03:00
										 |  |  | 	for (int i = 0; i < params->paths.size(); i++) { | 
					
						
							|  |  |  | 		Ref<ConfigFile> config; | 
					
						
							|  |  |  | 		config.instance(); | 
					
						
							|  |  |  | 		Error err = config->load(params->paths[i] + ".import"); | 
					
						
							|  |  |  | 		ERR_CONTINUE(err != OK); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		String imported_with = config->get_value("remap", "importer"); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 		if (imported_with != importer_name) { | 
					
						
							| 
									
										
										
										
											2019-01-25 17:23:56 -03:00
										 |  |  | 			need_restart = true; | 
					
						
							|  |  |  | 			if (_find_owners(EditorFileSystem::get_singleton()->get_filesystem(), params->paths[i])) { | 
					
						
							|  |  |  | 				used_in_resources = true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (need_restart) { | 
					
						
							|  |  |  | 		label_warning->set_visible(used_in_resources); | 
					
						
							| 
									
										
										
										
											2020-03-06 14:00:16 -03:00
										 |  |  | 		reimport_confirm->popup_centered(); | 
					
						
							| 
									
										
										
										
											2019-01-25 17:23:56 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_reimport(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ImportDock::_reimport_and_restart() { | 
					
						
							|  |  |  | 	EditorNode::get_singleton()->save_all_scenes(); | 
					
						
							| 
									
										
										
										
											2019-02-13 09:23:29 +01:00
										 |  |  | 	EditorResourcePreview::get_singleton()->stop(); //don't try to re-create previews after import
 | 
					
						
							| 
									
										
										
										
											2019-01-25 17:23:56 -03:00
										 |  |  | 	_reimport(); | 
					
						
							|  |  |  | 	EditorNode::get_singleton()->restart_editor(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 09:57:52 -03:00
										 |  |  | void ImportDock::_advanced_options() { | 
					
						
							|  |  |  | 	if (params->paths.size() == 1 && params->importer.is_valid()) { | 
					
						
							|  |  |  | 		params->importer->show_advanced_options(params->paths[0]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | void ImportDock::_reimport() { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < params->paths.size(); i++) { | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 		Ref<ConfigFile> config; | 
					
						
							|  |  |  | 		config.instance(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Error err = config->load(params->paths[i] + ".import"); | 
					
						
							|  |  |  | 		ERR_CONTINUE(err != OK); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 		if (params->importer.is_valid()) { | 
					
						
							|  |  |  | 			String importer_name = params->importer->get_importer_name(); | 
					
						
							| 
									
										
										
										
											2019-04-19 15:54:33 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 			if (params->checking && config->get_value("remap", "importer") == params->importer->get_importer_name()) { | 
					
						
							|  |  |  | 				//update only what is edited (checkboxes) if the importer is the same
 | 
					
						
							|  |  |  | 				for (List<PropertyInfo>::Element *E = params->properties.front(); E; E = E->next()) { | 
					
						
							|  |  |  | 					if (params->checked.has(E->get().name)) { | 
					
						
							|  |  |  | 						config->set_value("params", E->get().name, params->values[E->get().name]); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				//override entirely
 | 
					
						
							|  |  |  | 				config->set_value("remap", "importer", importer_name); | 
					
						
							|  |  |  | 				if (config->has_section("params")) { | 
					
						
							|  |  |  | 					config->erase_section("params"); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				for (List<PropertyInfo>::Element *E = params->properties.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2018-10-30 13:11:54 -03:00
										 |  |  | 					config->set_value("params", E->get().name, params->values[E->get().name]); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 			//handle group file
 | 
					
						
							|  |  |  | 			Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name); | 
					
						
							|  |  |  | 			ERR_CONTINUE(!importer.is_valid()); | 
					
						
							|  |  |  | 			String group_file_property = importer->get_option_group_file(); | 
					
						
							|  |  |  | 			if (group_file_property != String()) { | 
					
						
							|  |  |  | 				//can import from a group (as in, atlas)
 | 
					
						
							|  |  |  | 				ERR_CONTINUE(!params->values.has(group_file_property)); | 
					
						
							|  |  |  | 				String group_file = params->values[group_file_property]; | 
					
						
							|  |  |  | 				config->set_value("remap", "group_file", group_file); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				config->set_value("remap", "group_file", Variant()); //clear group file if unused
 | 
					
						
							| 
									
										
										
										
											2018-10-30 13:11:54 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-19 15:54:33 -03:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2021-03-22 16:41:47 -03:00
										 |  |  | 			//set to no import
 | 
					
						
							|  |  |  | 			config->clear(); | 
					
						
							|  |  |  | 			config->set_value("remap", "importer", "keep"); | 
					
						
							| 
									
										
										
										
											2019-04-19 15:54:33 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		config->save(params->paths[i] + ".import"); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	EditorFileSystem::get_singleton()->reimport_files(params->paths); | 
					
						
							|  |  |  | 	EditorFileSystem::get_singleton()->emit_signal("filesystem_changed"); //it changed, so force emitting the signal
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-31 16:58:43 +02:00
										 |  |  | void ImportDock::_notification(int p_what) { | 
					
						
							|  |  |  | 	switch (p_what) { | 
					
						
							|  |  |  | 		case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 			imported->add_theme_style_override("normal", get_theme_stylebox("normal", "LineEdit")); | 
					
						
							| 
									
										
										
										
											2017-08-31 16:58:43 +02:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2017-11-10 12:16:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case NOTIFICATION_ENTER_TREE: { | 
					
						
							|  |  |  | 			import_opts->edit(params); | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 			label_warning->add_theme_color_override("font_color", get_theme_color("warning_color", "Editor")); | 
					
						
							| 
									
										
										
										
											2017-11-10 12:16:58 +02:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2017-08-31 16:58:43 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-10-30 13:11:54 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void ImportDock::_property_toggled(const StringName &p_prop, bool p_checked) { | 
					
						
							|  |  |  | 	if (p_checked) { | 
					
						
							|  |  |  | 		params->checked.insert(p_prop); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		params->checked.erase(p_prop); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | void ImportDock::_bind_methods() { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_reimport"), &ImportDock::_reimport); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-23 21:44:42 +07:00
										 |  |  | void ImportDock::initialize_import_options() const { | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!import_opts || !params); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	import_opts->edit(params); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | ImportDock::ImportDock() { | 
					
						
							| 
									
										
										
										
											2017-11-25 23:59:31 -02:00
										 |  |  | 	set_name("Import"); | 
					
						
							| 
									
										
										
										
											2017-08-04 20:16:04 +02:00
										 |  |  | 	imported = memnew(Label); | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 	imported->add_theme_style_override("normal", EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox("normal", "LineEdit")); | 
					
						
							| 
									
										
										
										
											2018-05-22 16:56:16 +09:00
										 |  |  | 	imported->set_clip_text(true); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	add_child(imported); | 
					
						
							|  |  |  | 	HBoxContainer *hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	add_margin_child(TTR("Import As:"), hb); | 
					
						
							|  |  |  | 	import_as = memnew(OptionButton); | 
					
						
							| 
									
										
										
										
											2019-09-04 02:20:57 -03:00
										 |  |  | 	import_as->set_disabled(true); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	import_as->connect("item_selected", callable_mp(this, &ImportDock::_importer_selected)); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	hb->add_child(import_as); | 
					
						
							|  |  |  | 	import_as->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	preset = memnew(MenuButton); | 
					
						
							| 
									
										
										
										
											2019-09-04 02:20:57 -03:00
										 |  |  | 	preset->set_text(TTR("Preset")); | 
					
						
							|  |  |  | 	preset->set_disabled(true); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	preset->get_popup()->connect("index_pressed", callable_mp(this, &ImportDock::_preset_selected)); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	hb->add_child(preset); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-18 15:07:23 +02:00
										 |  |  | 	import_opts = memnew(EditorInspector); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	add_child(import_opts); | 
					
						
							|  |  |  | 	import_opts->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	import_opts->connect("property_toggled", callable_mp(this, &ImportDock::_property_toggled)); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	add_child(hb); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	import = memnew(Button); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	import->set_text(TTR("Reimport")); | 
					
						
							| 
									
										
										
										
											2019-09-04 02:20:57 -03:00
										 |  |  | 	import->set_disabled(true); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	import->connect("pressed", callable_mp(this, &ImportDock::_reimport_attempt)); | 
					
						
							| 
									
										
										
										
											2021-03-19 09:57:52 -03:00
										 |  |  | 	if (!DisplayServer::get_singleton()->get_swap_cancel_ok()) { | 
					
						
							|  |  |  | 		advanced_spacer = hb->add_spacer(); | 
					
						
							|  |  |  | 		advanced = memnew(Button); | 
					
						
							|  |  |  | 		advanced->set_text(TTR("Advanced...")); | 
					
						
							|  |  |  | 		hb->add_child(advanced); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | 	hb->add_spacer(); | 
					
						
							|  |  |  | 	hb->add_child(import); | 
					
						
							|  |  |  | 	hb->add_spacer(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 09:57:52 -03:00
										 |  |  | 	if (DisplayServer::get_singleton()->get_swap_cancel_ok()) { | 
					
						
							|  |  |  | 		advanced = memnew(Button); | 
					
						
							|  |  |  | 		advanced->set_text(TTR("Advanced...")); | 
					
						
							|  |  |  | 		hb->add_child(advanced); | 
					
						
							|  |  |  | 		advanced_spacer = hb->add_spacer(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	advanced->hide(); | 
					
						
							|  |  |  | 	advanced_spacer->hide(); | 
					
						
							|  |  |  | 	advanced->connect("pressed", callable_mp(this, &ImportDock::_advanced_options)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-25 17:23:56 -03:00
										 |  |  | 	reimport_confirm = memnew(ConfirmationDialog); | 
					
						
							| 
									
										
										
										
											2020-12-14 18:37:30 +00:00
										 |  |  | 	reimport_confirm->get_ok_button()->set_text(TTR("Save Scenes, Re-Import, and Restart")); | 
					
						
							| 
									
										
										
										
											2019-01-25 17:23:56 -03:00
										 |  |  | 	add_child(reimport_confirm); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	reimport_confirm->connect("confirmed", callable_mp(this, &ImportDock::_reimport_and_restart)); | 
					
						
							| 
									
										
										
										
											2019-01-25 17:23:56 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	VBoxContainer *vbc_confirm = memnew(VBoxContainer()); | 
					
						
							|  |  |  | 	vbc_confirm->add_child(memnew(Label(TTR("Changing the type of an imported file requires editor restart.")))); | 
					
						
							|  |  |  | 	label_warning = memnew(Label(TTR("WARNING: Assets exist that use this resource, they may stop loading properly."))); | 
					
						
							|  |  |  | 	vbc_confirm->add_child(label_warning); | 
					
						
							|  |  |  | 	reimport_confirm->add_child(vbc_confirm); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	params = memnew(ImportDockParameters); | 
					
						
							| 
									
										
										
										
											2017-02-01 09:45:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ImportDock::~ImportDock() { | 
					
						
							|  |  |  | 	memdelete(params); | 
					
						
							|  |  |  | } |