| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  editor_log.cpp                                                       */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03: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).   */ | 
					
						
							| 
									
										
										
										
											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.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "editor_log.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-16 08:04:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 11:41:38 +01:00
										 |  |  | #include "core/os/keyboard.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/version.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "editor_node.h"
 | 
					
						
							| 
									
										
										
										
											2019-12-24 15:17:23 +08:00
										 |  |  | #include "editor_scale.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "scene/gui/center_container.h"
 | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | #include "scene/resources/font.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorLog::_error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, ErrorHandlerType p_type) { | 
					
						
							|  |  |  | 	EditorLog *self = (EditorLog *)p_self; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (self->current != Thread::get_caller_id()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String err_str; | 
					
						
							|  |  |  | 	if (p_errorexp && p_errorexp[0]) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		err_str = p_errorexp; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		err_str = String(p_file) + ":" + itos(p_line) + " - " + String(p_error); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-13 18:04:38 +03:00
										 |  |  | 	if (p_type == ERR_HANDLER_WARNING) { | 
					
						
							|  |  |  | 		self->add_message(err_str, MSG_TYPE_WARNING); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		self->add_message(err_str, MSG_TYPE_ERROR); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorLog::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_ENTER_TREE) { | 
					
						
							| 
									
										
										
										
											2015-11-18 04:47:41 -03:00
										 |  |  | 		//button->set_icon(get_icon("Console","EditorIcons"));
 | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 		log->add_theme_font_override("normal_font", get_theme_font("output_source", "EditorFonts")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		log->add_theme_font_size_override("normal_font_size", get_theme_font_size("output_source_size", "EditorFonts")); | 
					
						
							| 
									
										
										
										
											2020-05-10 16:31:44 +02:00
										 |  |  | 		log->add_theme_color_override("selection_color", get_theme_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); | 
					
						
							| 
									
										
										
										
											2017-09-25 23:12:17 +09:00
										 |  |  | 	} else if (p_what == NOTIFICATION_THEME_CHANGED) { | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		Ref<Font> df_output_code = get_theme_font("output_source", "EditorFonts"); | 
					
						
							| 
									
										
										
										
											2017-09-25 23:12:17 +09:00
										 |  |  | 		if (df_output_code.is_valid()) { | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 			if (log != nullptr) { | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 				log->add_theme_font_override("normal_font", get_theme_font("output_source", "EditorFonts")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 				log->add_theme_font_size_override("normal_font_size", get_theme_font_size("output_source_size", "EditorFonts")); | 
					
						
							| 
									
										
										
										
											2020-05-10 16:31:44 +02:00
										 |  |  | 				log->add_theme_color_override("selection_color", get_theme_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); | 
					
						
							| 
									
										
										
										
											2017-12-30 16:11:00 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-09-25 23:12:17 +09:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-29 00:41:24 +02:00
										 |  |  | void EditorLog::_clear_request() { | 
					
						
							|  |  |  | 	log->clear(); | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 	tool_button->set_icon(Ref<Texture2D>()); | 
					
						
							| 
									
										
										
										
											2015-07-30 00:03:25 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-14 04:55:31 -04:00
										 |  |  | void EditorLog::_copy_request() { | 
					
						
							| 
									
										
										
										
											2020-09-14 21:14:27 +03:00
										 |  |  | 	String text = log->get_selected_text(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (text == "") { | 
					
						
							|  |  |  | 		text = log->get_text(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (text != "") { | 
					
						
							|  |  |  | 		DisplayServer::get_singleton()->clipboard_set(text); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-14 04:55:31 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-30 00:03:25 +02:00
										 |  |  | void EditorLog::clear() { | 
					
						
							|  |  |  | 	_clear_request(); | 
					
						
							| 
									
										
										
										
											2015-07-29 00:41:24 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-14 04:55:31 -04:00
										 |  |  | void EditorLog::copy() { | 
					
						
							|  |  |  | 	_copy_request(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-13 18:04:38 +03:00
										 |  |  | void EditorLog::add_message(const String &p_msg, MessageType p_type) { | 
					
						
							|  |  |  | 	bool restore = p_type != MSG_TYPE_STD; | 
					
						
							|  |  |  | 	switch (p_type) { | 
					
						
							| 
									
										
										
										
											2018-09-26 13:13:56 +02:00
										 |  |  | 		case MSG_TYPE_STD: { | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2018-08-13 18:04:38 +03:00
										 |  |  | 		case MSG_TYPE_ERROR: { | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 			log->push_color(get_theme_color("error_color", "Editor")); | 
					
						
							|  |  |  | 			Ref<Texture2D> icon = get_theme_icon("Error", "EditorIcons"); | 
					
						
							| 
									
										
										
										
											2018-08-13 18:04:38 +03:00
										 |  |  | 			log->add_image(icon); | 
					
						
							|  |  |  | 			log->add_text(" "); | 
					
						
							|  |  |  | 			tool_button->set_icon(icon); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case MSG_TYPE_WARNING: { | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 			log->push_color(get_theme_color("warning_color", "Editor")); | 
					
						
							|  |  |  | 			Ref<Texture2D> icon = get_theme_icon("Warning", "EditorIcons"); | 
					
						
							| 
									
										
										
										
											2018-08-13 18:04:38 +03:00
										 |  |  | 			log->add_image(icon); | 
					
						
							|  |  |  | 			log->add_text(" "); | 
					
						
							|  |  |  | 			tool_button->set_icon(icon); | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2019-09-20 01:56:09 +02:00
										 |  |  | 		case MSG_TYPE_EDITOR: { | 
					
						
							|  |  |  | 			// Distinguish editor messages from messages printed by the project
 | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 			log->push_color(get_theme_color("font_color", "Editor") * Color(1, 1, 1, 0.6)); | 
					
						
							| 
									
										
										
										
											2019-09-20 01:56:09 +02:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	log->add_text(p_msg); | 
					
						
							| 
									
										
										
										
											2021-01-04 15:46:30 +03:00
										 |  |  | 	log->add_newline(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (restore) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		log->pop(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | void EditorLog::set_tool_button(Button *p_tool_button) { | 
					
						
							| 
									
										
										
										
											2018-03-11 14:20:32 +01:00
										 |  |  | 	tool_button = p_tool_button; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void EditorLog::_undo_redo_cbk(void *p_self, const String &p_name) { | 
					
						
							|  |  |  | 	EditorLog *self = (EditorLog *)p_self; | 
					
						
							| 
									
										
										
										
											2019-09-20 01:56:09 +02:00
										 |  |  | 	self->add_message(p_name, EditorLog::MSG_TYPE_EDITOR); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorLog::_bind_methods() { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("clear_request")); | 
					
						
							| 
									
										
										
										
											2019-04-14 04:55:31 -04:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("copy_request")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EditorLog::EditorLog() { | 
					
						
							| 
									
										
										
										
											2016-01-17 20:03:57 -03:00
										 |  |  | 	VBoxContainer *vb = this; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	HBoxContainer *hb = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	vb->add_child(hb); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	title = memnew(Label); | 
					
						
							| 
									
										
										
										
											2017-08-07 21:55:24 -05:00
										 |  |  | 	title->set_text(TTR("Output:")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	title->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	hb->add_child(title); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-14 04:55:31 -04:00
										 |  |  | 	copybutton = memnew(Button); | 
					
						
							|  |  |  | 	hb->add_child(copybutton); | 
					
						
							|  |  |  | 	copybutton->set_text(TTR("Copy")); | 
					
						
							|  |  |  | 	copybutton->set_shortcut(ED_SHORTCUT("editor/copy_output", TTR("Copy Selection"), KEY_MASK_CMD | KEY_C)); | 
					
						
							| 
									
										
										
										
											2020-09-17 11:40:00 +10:00
										 |  |  | 	copybutton->set_shortcut_context(this); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	copybutton->connect("pressed", callable_mp(this, &EditorLog::_copy_request)); | 
					
						
							| 
									
										
										
										
											2019-04-14 04:55:31 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	clearbutton = memnew(Button); | 
					
						
							| 
									
										
										
										
											2015-07-29 00:41:24 +02:00
										 |  |  | 	hb->add_child(clearbutton); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	clearbutton->set_text(TTR("Clear")); | 
					
						
							| 
									
										
										
										
											2017-12-26 11:41:38 +01:00
										 |  |  | 	clearbutton->set_shortcut(ED_SHORTCUT("editor/clear_output", TTR("Clear Output"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_K)); | 
					
						
							| 
									
										
										
										
											2020-09-17 11:40:00 +10:00
										 |  |  | 	clearbutton->set_shortcut_context(this); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	clearbutton->connect("pressed", callable_mp(this, &EditorLog::_clear_request)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	log = memnew(RichTextLabel); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	log->set_scroll_follow(true); | 
					
						
							| 
									
										
										
										
											2014-09-22 00:50:48 -03:00
										 |  |  | 	log->set_selection_enabled(true); | 
					
						
							|  |  |  | 	log->set_focus_mode(FOCUS_CLICK); | 
					
						
							| 
									
										
										
										
											2017-09-08 15:39:41 -05:00
										 |  |  | 	log->set_custom_minimum_size(Size2(0, 180) * EDSCALE); | 
					
						
							|  |  |  | 	log->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	log->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	vb->add_child(log); | 
					
						
							| 
									
										
										
										
											2021-01-01 20:13:46 +01:00
										 |  |  | 	add_message(VERSION_FULL_NAME " (c) 2007-2021 Juan Linietsky, Ariel Manzur & Godot Contributors."); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	eh.errfunc = _error_handler; | 
					
						
							|  |  |  | 	eh.userdata = this; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	add_error_handler(&eh); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-07 17:17:31 +07:00
										 |  |  | 	current = Thread::get_caller_id(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 	add_theme_constant_override("separation", get_theme_constant("separation", "VBoxContainer")); | 
					
						
							| 
									
										
										
										
											2019-02-01 15:30:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	EditorNode::get_undo_redo()->set_commit_notify_callback(_undo_redo_cbk, this); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditorLog::deinit() { | 
					
						
							|  |  |  | 	remove_error_handler(&eh); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EditorLog::~EditorLog() { | 
					
						
							|  |  |  | } |