123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #include "editor_log.h"
- #include "core/os/keyboard.h"
- #include "core/version.h"
- #include "editor_node.h"
- #include "scene/gui/center_container.h"
- #include "scene/resources/dynamic_font.h"
- 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;
- if (self->current != Thread::get_caller_id())
- return;
- String err_str;
- if (p_errorexp && p_errorexp[0]) {
- err_str = p_errorexp;
- } else {
- err_str = String(p_file) + ":" + itos(p_line) + " - " + String(p_error);
- }
- if (p_type == ERR_HANDLER_WARNING) {
- self->add_message(err_str, MSG_TYPE_WARNING);
- } else {
- self->add_message(err_str, MSG_TYPE_ERROR);
- }
- }
- void EditorLog::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
-
- log->add_font_override("normal_font", get_font("output_source", "EditorFonts"));
- } else if (p_what == NOTIFICATION_THEME_CHANGED) {
- Ref<DynamicFont> df_output_code = get_font("output_source", "EditorFonts");
- if (df_output_code.is_valid()) {
- df_output_code->set_size(int(EDITOR_DEF("run/output/font_size", 13)) * EDSCALE);
- if (log != NULL) {
- log->add_font_override("normal_font", get_font("output_source", "EditorFonts"));
- }
- }
- }
- }
- void EditorLog::_clear_request() {
- log->clear();
- tool_button->set_icon(Ref<Texture>());
- }
- void EditorLog::clear() {
- _clear_request();
- }
- void EditorLog::add_message(const String &p_msg, MessageType p_type) {
- log->add_newline();
- bool restore = p_type != MSG_TYPE_STD;
- switch (p_type) {
- case MSG_TYPE_STD: {
- } break;
- case MSG_TYPE_ERROR: {
- log->push_color(get_color("error_color", "Editor"));
- Ref<Texture> icon = get_icon("Error", "EditorIcons");
- log->add_image(icon);
- log->add_text(" ");
- tool_button->set_icon(icon);
- } break;
- case MSG_TYPE_WARNING: {
- log->push_color(get_color("warning_color", "Editor"));
- Ref<Texture> icon = get_icon("Warning", "EditorIcons");
- log->add_image(icon);
- log->add_text(" ");
- tool_button->set_icon(icon);
- } break;
- }
- log->add_text(p_msg);
- if (restore)
- log->pop();
- }
- void EditorLog::set_tool_button(ToolButton *p_tool_button) {
- tool_button = p_tool_button;
- }
- void EditorLog::_undo_redo_cbk(void *p_self, const String &p_name) {
- EditorLog *self = (EditorLog *)p_self;
- self->add_message(p_name);
- }
- void EditorLog::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_clear_request"), &EditorLog::_clear_request);
- ADD_SIGNAL(MethodInfo("clear_request"));
- }
- EditorLog::EditorLog() {
- VBoxContainer *vb = this;
- add_constant_override("separation", get_constant("separation", "VBoxContainer"));
- HBoxContainer *hb = memnew(HBoxContainer);
- vb->add_child(hb);
- title = memnew(Label);
- title->set_text(TTR("Output:"));
- title->set_h_size_flags(SIZE_EXPAND_FILL);
- hb->add_child(title);
- clearbutton = memnew(Button);
- hb->add_child(clearbutton);
- clearbutton->set_text(TTR("Clear"));
- clearbutton->set_shortcut(ED_SHORTCUT("editor/clear_output", TTR("Clear Output"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_K));
- clearbutton->connect("pressed", this, "_clear_request");
- log = memnew(RichTextLabel);
- log->set_scroll_follow(true);
- log->set_selection_enabled(true);
- log->set_focus_mode(FOCUS_CLICK);
- 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);
- add_message(VERSION_FULL_NAME " (c) 2007-2019 Juan Linietsky, Ariel Manzur & Godot Contributors.");
- eh.errfunc = _error_handler;
- eh.userdata = this;
- add_error_handler(&eh);
- current = Thread::get_caller_id();
- EditorNode::get_undo_redo()->set_commit_notify_callback(_undo_redo_cbk, this);
- }
- void EditorLog::deinit() {
- remove_error_handler(&eh);
- }
- EditorLog::~EditorLog() {
- }
|