| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  editor_reimport_dialog.cpp                                           */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							|  |  |  | /*                    http://www.godotengine.org                         */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2017-01-01 22:01:57 +01:00
										 |  |  | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03: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.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | #include "editor_reimport_dialog.h"
 | 
					
						
							|  |  |  | #include "editor_file_system.h"
 | 
					
						
							|  |  |  | #include "editor_node.h"
 | 
					
						
							|  |  |  | void EditorReImportDialog::popup_reimport() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (EditorFileSystem::get_singleton()->is_scanning()) { | 
					
						
							| 
									
										
										
										
											2016-05-21 01:18:35 +02:00
										 |  |  | 		error->set_text(TTR("Please wait for scan to complete.")); | 
					
						
							| 
									
										
										
										
											2015-04-08 14:02:13 -03:00
										 |  |  | 		error->popup_centered_minsize(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tree->clear(); | 
					
						
							|  |  |  | 	items.clear(); | 
					
						
							|  |  |  | 	List<String> ril; | 
					
						
							|  |  |  | 	EditorFileSystem::get_singleton()->get_changed_sources(&ril); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 	scene_must_save = false; | 
					
						
							| 
									
										
										
										
											2014-06-19 02:23:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	TreeItem *root = tree->create_item(); | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 	for (List<String>::Element *E = ril.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		TreeItem *item = tree->create_item(root); | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 		item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); | 
					
						
							|  |  |  | 		item->set_metadata(0, E->get()); | 
					
						
							|  |  |  | 		item->set_text(0, E->get().replace_first("res://", "")); | 
					
						
							|  |  |  | 		item->set_tooltip(0, E->get()); | 
					
						
							|  |  |  | 		item->set_checked(0, true); | 
					
						
							|  |  |  | 		item->set_editable(0, true); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		items.push_back(item); | 
					
						
							| 
									
										
										
										
											2014-06-19 02:23:03 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		String name = E->get(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 		if (EditorFileSystem::get_singleton()->get_file_type(name) == "PackedScene" && EditorNode::get_singleton()->is_scene_in_use(name)) { | 
					
						
							| 
									
										
										
										
											2014-06-19 02:23:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 			scene_must_save = true; | 
					
						
							| 
									
										
										
										
											2014-06-19 02:23:03 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-19 02:23:03 -03:00
										 |  |  | 	if (scene_must_save) { | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 		if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->get_filename() == "") { | 
					
						
							| 
									
										
										
										
											2014-06-19 02:23:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 			error->set_text(TTR("Current scene must be saved to re-import.")); | 
					
						
							| 
									
										
										
										
											2015-04-08 14:02:13 -03:00
										 |  |  | 			error->popup_centered_minsize(); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 			get_ok()->set_text(TTR("Re-Import")); | 
					
						
							| 
									
										
										
										
											2014-06-19 02:23:03 -03:00
										 |  |  | 			get_ok()->set_disabled(true); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		get_ok()->set_disabled(false); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 		get_ok()->set_text(TTR("Save & Re-Import")); | 
					
						
							| 
									
										
										
										
											2014-06-19 02:23:03 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 		get_ok()->set_text(TTR("Re-Import")); | 
					
						
							| 
									
										
										
										
											2014-06-19 02:23:03 -03:00
										 |  |  | 		get_ok()->set_disabled(false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 	popup_centered(Size2(600, 400)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorReImportDialog::ok_pressed() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (EditorFileSystem::get_singleton()->is_scanning()) { | 
					
						
							| 
									
										
										
										
											2016-05-21 01:18:35 +02:00
										 |  |  | 		error->set_text(TTR("Please wait for scan to complete.")); | 
					
						
							| 
									
										
										
										
											2015-04-08 14:02:13 -03:00
										 |  |  | 		error->popup_centered_minsize(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-19 02:23:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 	EditorProgress ep("reimport", TTR("Re-Importing"), items.size()); | 
					
						
							| 
									
										
										
										
											2014-06-19 02:23:03 -03:00
										 |  |  | 	String reload_fname; | 
					
						
							|  |  |  | 	if (scene_must_save && EditorNode::get_singleton()->get_edited_scene()) { | 
					
						
							|  |  |  | 		reload_fname = EditorNode::get_singleton()->get_edited_scene()->get_filename(); | 
					
						
							|  |  |  | 		EditorNode::get_singleton()->save_scene(reload_fname); | 
					
						
							|  |  |  | 		EditorNode::get_singleton()->clear_scene(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 	for (int i = 0; i < items.size(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		String it = items[i]->get_metadata(0); | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 		ep.step(items[i]->get_text(0), i); | 
					
						
							|  |  |  | 		print_line("reload import from: " + it); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(it); | 
					
						
							|  |  |  | 		ERR_CONTINUE(rimd.is_null()); | 
					
						
							|  |  |  | 		String editor = rimd->get_editor(); | 
					
						
							|  |  |  | 		Ref<EditorImportPlugin> eip = EditorImportExport::get_singleton()->get_import_plugin_by_name(editor); | 
					
						
							|  |  |  | 		ERR_CONTINUE(eip.is_null()); | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 		Error err = eip->import(it, rimd); | 
					
						
							|  |  |  | 		if (err != OK) { | 
					
						
							|  |  |  | 			EditorNode::add_io_error("Error Importing:\n  " + it); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 	if (reload_fname != "") { | 
					
						
							| 
									
										
										
										
											2014-06-19 02:23:03 -03:00
										 |  |  | 		EditorNode::get_singleton()->load_scene(reload_fname); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	EditorFileSystem::get_singleton()->scan_sources(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EditorReImportDialog::EditorReImportDialog() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 	tree = memnew(Tree); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(tree); | 
					
						
							|  |  |  | 	tree->set_hide_root(true); | 
					
						
							|  |  |  | 	set_child_rect(tree); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	set_title(TTR("Re-Import Changed Resources")); | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 	error = memnew(AcceptDialog); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(error); | 
					
						
							| 
									
										
										
										
											2017-03-19 00:36:26 +01:00
										 |  |  | 	scene_must_save = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } |