| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  resources_dock.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 "resources_dock.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-16 08:04:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "editor_node.h"
 | 
					
						
							|  |  |  | #include "io/resource_loader.h"
 | 
					
						
							|  |  |  | #include "io/resource_saver.h"
 | 
					
						
							|  |  |  | #include "editor_settings.h"
 | 
					
						
							|  |  |  | #include "project_settings.h"
 | 
					
						
							|  |  |  | #include "globals.h"
 | 
					
						
							|  |  |  | #include "editor_file_system.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourcesDock::_tool_selected(int p_tool) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	current_action=p_tool; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch(p_tool) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case TOOL_NEW: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			create_dialog->popup_centered_ratio(); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case TOOL_OPEN: { | 
					
						
							|  |  |  | 			editor->open_resource(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case TOOL_SAVE: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			TreeItem *ti = resources->get_selected(); | 
					
						
							|  |  |  | 			if (!ti) | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			Ref<Resource> current_res = ti->get_metadata(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (current_res->get_path()!="" && current_res->get_path().find("::")==-1) { | 
					
						
							|  |  |  | 				_file_action(current_res->get_path()); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		}; /* fallthrough */ | 
					
						
							|  |  |  | 		case TOOL_SAVE_AS: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			TreeItem *ti = resources->get_selected(); | 
					
						
							|  |  |  | 			if (!ti) | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-23 01:12:44 +02:00
										 |  |  | 			save_resource_as(ti->get_metadata(0)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case TOOL_MAKE_LOCAL: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			TreeItem *ti = resources->get_selected(); | 
					
						
							|  |  |  | 			if (!ti) | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			Ref<Resource> current_res = ti->get_metadata(0); | 
					
						
							|  |  |  | 			current_res->set_path(""); | 
					
						
							|  |  |  | 			_update_name(ti); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case TOOL_COPY: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			TreeItem *ti = resources->get_selected(); | 
					
						
							|  |  |  | 			if (!ti) | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			Ref<Resource> current_res = ti->get_metadata(0); | 
					
						
							|  |  |  | 			EditorSettings::get_singleton()->set_resource_clipboard(current_res); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case TOOL_PASTE: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			add_resource(EditorSettings::get_singleton()->get_resource_clipboard()); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourcesDock::_notification(int p_what) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch(p_what) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 		case NOTIFICATION_ENTER_TREE: { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			button_new->set_icon(get_icon("New","EditorIcons")); | 
					
						
							|  |  |  | 			button_open->set_icon(get_icon("Folder","EditorIcons")); | 
					
						
							|  |  |  | 			button_save->set_icon(get_icon("Save","EditorIcons")); | 
					
						
							|  |  |  | 			button_tools->set_icon(get_icon("Tools","EditorIcons")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourcesDock::save_resource(const String& p_path,const Ref<Resource>& p_resource) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 18:03:38 +01:00
										 |  |  | 	editor->get_editor_data().apply_changes_in_editors(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	int flg=0; | 
					
						
							|  |  |  | 	if (EditorSettings::get_singleton()->get("on_save/compress_binary_resources")) | 
					
						
							|  |  |  | 		flg|=ResourceSaver::FLAG_COMPRESS; | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	if (EditorSettings::get_singleton()->get("on_save/save_paths_as_relative")) | 
					
						
							|  |  |  | 		flg|=ResourceSaver::FLAG_RELATIVE_PATHS; | 
					
						
							|  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 09:16:00 -03:00
										 |  |  | 	String path = GlobalConfig::get_singleton()->localize_path(p_path); | 
					
						
							| 
									
										
										
										
											2014-06-27 23:21:45 -03:00
										 |  |  | 	Error err = ResourceSaver::save(path,p_resource,flg|ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (err!=OK) { | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 		accept->set_text(TTR("Error saving resource!")); | 
					
						
							| 
									
										
										
										
											2015-04-08 14:02:13 -03:00
										 |  |  | 		accept->popup_centered_minsize(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  |         return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 	//EditorFileSystem::get_singleton()->update_file(path,p_resource->get_type());
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	((Resource*)p_resource.ptr())->set_path(path); | 
					
						
							|  |  |  | 	editor->emit_signal("resource_saved",p_resource); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourcesDock::save_resource_as(const Ref<Resource>& p_resource) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-23 01:12:44 +02:00
										 |  |  | 	current_action=TOOL_SAVE_AS; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-23 01:12:44 +02:00
										 |  |  | 	RES res(p_resource); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-23 01:12:44 +02:00
										 |  |  | 	List<String> extensions; | 
					
						
							|  |  |  | 	ResourceSaver::get_recognized_extensions(res,&extensions); | 
					
						
							| 
									
										
										
										
											2015-05-31 01:59:42 -03:00
										 |  |  | 	file->set_mode(EditorFileDialog::MODE_SAVE_FILE); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-23 01:12:44 +02:00
										 |  |  | 	if (p_resource->get_path()!="" && p_resource->get_path().find("::")==-1) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-23 01:12:44 +02:00
										 |  |  | 		file->set_current_path(p_resource->get_path()); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-23 01:12:44 +02:00
										 |  |  | 		String existing; | 
					
						
							|  |  |  | 		if (extensions.size()) { | 
					
						
							| 
									
										
										
										
											2017-01-02 23:03:46 -03:00
										 |  |  | 			existing="new_"+res->get_class().to_lower()+"."+extensions.front()->get().to_lower(); | 
					
						
							| 
									
										
										
										
											2014-09-23 01:12:44 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-23 01:12:44 +02:00
										 |  |  | 		file->set_current_file(existing); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-23 01:12:44 +02:00
										 |  |  | 	file->clear_filters(); | 
					
						
							|  |  |  | 	for(int i=0;i<extensions.size();i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-23 01:12:44 +02:00
										 |  |  | 		file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-23 01:12:44 +02:00
										 |  |  | 	file->popup_centered_ratio(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourcesDock::_file_action(const String& p_path) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch(current_action) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case TOOL_OPEN: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case TOOL_SAVE: | 
					
						
							|  |  |  | 		case TOOL_SAVE_AS: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			TreeItem *ti = resources->get_selected(); | 
					
						
							|  |  |  | 			if (!ti) | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			Ref<Resource> current_res = ti->get_metadata(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			RES res(current_res); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			save_resource(p_path,res); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-23 01:52:54 +08:00
										 |  |  | 			_update_name(ti); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourcesDock::_update_name(TreeItem *item) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Ref<Resource> res = item->get_metadata(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (res->get_name()!="") | 
					
						
							|  |  |  | 		item->set_text(0,res->get_name()); | 
					
						
							|  |  |  | 	else if (res->get_path()!="" && res->get_path().find("::")==-1) | 
					
						
							|  |  |  | 		item->set_text(0,res->get_path().get_file()); | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2017-01-02 23:03:46 -03:00
										 |  |  | 		item->set_text(0,res->get_class()+" ("+itos(res->get_instance_ID())+")"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourcesDock::remove_resource(const Ref<Resource>& p_resource) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *root = resources->get_root(); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!root); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *existing=root->get_children(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while(existing) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Ref<Resource> r = existing->get_metadata(0); | 
					
						
							|  |  |  | 		if (r==p_resource) { | 
					
						
							|  |  |  | 			//existing->move_to_top();
 | 
					
						
							|  |  |  | 			memdelete(existing); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		existing=existing->get_next(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourcesDock::add_resource(const Ref<Resource>& p_resource) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (block_add) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	if (!p_resource.is_valid()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *root = resources->get_root(); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!root); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *existing=root->get_children(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while(existing) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Ref<Resource> r = existing->get_metadata(0); | 
					
						
							|  |  |  | 		if (r==p_resource) { | 
					
						
							|  |  |  | 			//existing->move_to_top();
 | 
					
						
							|  |  |  | 			existing->select(0); | 
					
						
							|  |  |  | 			resources->ensure_cursor_is_visible(); | 
					
						
							|  |  |  | 			return; // existing
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		existing=existing->get_next(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *res = resources->create_item(root); | 
					
						
							|  |  |  | 	res->set_metadata(0,p_resource); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 23:03:46 -03:00
										 |  |  | 	if (has_icon(p_resource->get_class(),"EditorIcons")) { | 
					
						
							|  |  |  | 		res->set_icon(0,get_icon(p_resource->get_class(),"EditorIcons")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_update_name(res); | 
					
						
							|  |  |  | 	res->add_button(0,get_icon("Del","EditorIcons")); | 
					
						
							|  |  |  | 	res->move_to_top(); | 
					
						
							|  |  |  | 	res->select(0); | 
					
						
							|  |  |  | 	resources->ensure_cursor_is_visible(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourcesDock::_resource_selected() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *sel = resources->get_selected(); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!sel); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Ref<Resource> r = sel->get_metadata(0); | 
					
						
							|  |  |  | 	if (r.is_null()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	block_add=true; | 
					
						
							|  |  |  | 	editor->push_item(r.ptr()); | 
					
						
							|  |  |  | 	block_add=false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourcesDock::_delete(Object* p_item, int p_column, int p_id) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TreeItem *ti = p_item->cast_to<TreeItem>(); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!ti); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	call_deferred("remove_resource",ti->get_metadata(0)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourcesDock::_create() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Object *c = create_dialog->instance_selected(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!c); | 
					
						
							|  |  |  | 	Resource *r = c->cast_to<Resource>(); | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!r); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	REF res( r ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	editor->push_item(c); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourcesDock::_bind_methods() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-13 12:47:24 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_tool_selected"),&ResourcesDock::_tool_selected); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_create"),&ResourcesDock::_create); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_resource_selected"),&ResourcesDock::_resource_selected); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_delete"),&ResourcesDock::_delete); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("remove_resource"),&ResourcesDock::remove_resource); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_file_action"),&ResourcesDock::_file_action); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourcesDock::cleanup() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	resources->clear(); | 
					
						
							|  |  |  | 	resources->create_item(); //root
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ResourcesDock::ResourcesDock(EditorNode *p_editor) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	editor=p_editor; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	VBoxContainer *vbc = this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	HBoxContainer *hbc = memnew( HBoxContainer ); | 
					
						
							|  |  |  | 	vbc->add_child(hbc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Button *b; | 
					
						
							|  |  |  | 	b = memnew( ToolButton ); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	b->set_tooltip(TTR("Create New Resource")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	b->connect("pressed",this,"_tool_selected",make_binds(TOOL_NEW)); | 
					
						
							|  |  |  | 	hbc->add_child( b ); | 
					
						
							|  |  |  | 	button_new=b; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	b = memnew( ToolButton ); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	b->set_tooltip(TTR("Open Resource")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	b->connect("pressed",this,"_tool_selected",make_binds(TOOL_OPEN)); | 
					
						
							|  |  |  | 	hbc->add_child( b ); | 
					
						
							|  |  |  | 	button_open=b; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MenuButton *mb = memnew( MenuButton ); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	mb->set_tooltip(TTR("Save Resource")); | 
					
						
							|  |  |  | 	mb->get_popup()->add_item(TTR("Save Resource"),TOOL_SAVE); | 
					
						
							|  |  |  | 	mb->get_popup()->add_item(TTR("Save Resource As.."),TOOL_SAVE_AS); | 
					
						
							| 
									
										
										
										
											2017-01-08 18:18:54 -03:00
										 |  |  | 	mb->get_popup()->connect("id_pressed",this,"_tool_selected" ); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child( mb ); | 
					
						
							|  |  |  | 	button_save=mb; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	hbc->add_spacer(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mb = memnew( MenuButton ); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	mb->set_tooltip(TTR("Resource Tools")); | 
					
						
							|  |  |  | 	mb->get_popup()->add_item(TTR("Make Local"),TOOL_MAKE_LOCAL); | 
					
						
							|  |  |  | 	mb->get_popup()->add_item(TTR("Copy"),TOOL_COPY); | 
					
						
							|  |  |  | 	mb->get_popup()->add_item(TTR("Paste"),TOOL_PASTE); | 
					
						
							| 
									
										
										
										
											2017-01-08 18:18:54 -03:00
										 |  |  | 	mb->get_popup()->connect("id_pressed",this,"_tool_selected" ); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	hbc->add_child( mb ); | 
					
						
							|  |  |  | 	button_tools=mb; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	resources = memnew( Tree ); | 
					
						
							|  |  |  | 	vbc->add_child(resources); | 
					
						
							|  |  |  | 	resources->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	resources->create_item(); //root
 | 
					
						
							|  |  |  | 	resources->set_hide_root(true); | 
					
						
							|  |  |  | 	resources->connect("cell_selected",this,"_resource_selected"); | 
					
						
							|  |  |  | 	resources->connect("button_pressed",this,"_delete"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	create_dialog = memnew( CreateDialog ); | 
					
						
							|  |  |  | 	add_child(create_dialog); | 
					
						
							|  |  |  | 	create_dialog->set_base_type("Resource"); | 
					
						
							|  |  |  | 	create_dialog->connect("create",this,"_create"); | 
					
						
							|  |  |  | 	accept = memnew (AcceptDialog); | 
					
						
							|  |  |  | 	add_child(accept); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-31 01:59:42 -03:00
										 |  |  | 	file = memnew( EditorFileDialog ); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_child(file); | 
					
						
							|  |  |  | 	file->connect("file_selected",this,"_file_action"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	block_add=false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |