2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_log.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 00:11:42 +02:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "editor_log.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "editor_node.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/gui/center_container.h"
|
|
|
|
#include "version.h"
|
2014-02-10 02:10:30 +01: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) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
EditorLog *self = (EditorLog *)p_self;
|
2017-08-07 12:17:31 +02:00
|
|
|
if (self->current != Thread::get_caller_id())
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
String err_str;
|
|
|
|
if (p_errorexp && p_errorexp[0]) {
|
2017-03-05 16:44:50 +01:00
|
|
|
err_str = p_errorexp;
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
err_str = String(p_file) + ":" + itos(p_line) + " - " + String(p_error);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
/*
|
|
|
|
if (!self->is_visible_in_tree())
|
|
|
|
self->emit_signal("show_request");
|
|
|
|
*/
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
err_str = " " + err_str;
|
|
|
|
self->add_message(err_str, true);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLog::_notification(int p_what) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
log->add_color_override("default_color", get_color("font_color", "Tree"));
|
2015-11-18 08:47:41 +01:00
|
|
|
//button->set_icon(get_icon("Console","EditorIcons"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-05-02 22:13:12 +02:00
|
|
|
if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
|
|
|
|
_override_logger_styles();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/*if (p_what==NOTIFICATION_DRAW) {
|
|
|
|
|
|
|
|
RID ci = get_canvas_item();
|
|
|
|
get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
|
|
|
|
int top_ofs = 20;
|
|
|
|
int border_ofs=4;
|
|
|
|
Ref<StyleBox> style = get_stylebox("normal","TextEdit");
|
|
|
|
|
|
|
|
style->draw(ci,Rect2( Point2(border_ofs,top_ofs),get_size()-Size2(border_ofs*2,top_ofs+border_ofs)));
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
2015-07-29 00:41:24 +02:00
|
|
|
void EditorLog::_clear_request() {
|
|
|
|
|
|
|
|
log->clear();
|
2015-07-30 00:03:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLog::clear() {
|
|
|
|
_clear_request();
|
2015-07-29 00:41:24 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void EditorLog::add_message(const String &p_msg, bool p_error) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-08 03:51:30 +02:00
|
|
|
log->add_newline();
|
2014-02-10 02:10:30 +01:00
|
|
|
if (p_error) {
|
2017-08-08 03:51:30 +02:00
|
|
|
log->push_color(get_color("fg_error", "Editor"));
|
2017-03-05 16:44:50 +01:00
|
|
|
Ref<Texture> icon = get_icon("Error", "EditorIcons");
|
|
|
|
log->add_image(icon);
|
2016-01-18 00:03:57 +01:00
|
|
|
//button->set_icon(icon);
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
2016-01-18 00:03:57 +01:00
|
|
|
//button->set_icon(Ref<Texture>());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
log->add_text(p_msg);
|
2017-01-14 12:26:56 +01:00
|
|
|
//button->set_text(p_msg);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (p_error)
|
|
|
|
log->pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
void EditorLog::_dragged(const Point2& p_ofs) {
|
|
|
|
|
|
|
|
int ofs = ec->get_minsize().height;
|
|
|
|
ofs = ofs-p_ofs.y;
|
|
|
|
if (ofs<50)
|
|
|
|
ofs=50;
|
|
|
|
if (ofs>300)
|
|
|
|
ofs=300;
|
|
|
|
ec->set_minsize(Size2(ec->get_minsize().width,ofs));
|
|
|
|
minimum_size_changed();
|
|
|
|
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void EditorLog::_undo_redo_cbk(void *p_self, const String &p_name) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
EditorLog *self = (EditorLog *)p_self;
|
2014-02-10 02:10:30 +01:00
|
|
|
self->add_message(p_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLog::_bind_methods() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_clear_request"), &EditorLog::_clear_request);
|
|
|
|
ClassDB::bind_method("_override_logger_styles", &EditorLog::_override_logger_styles);
|
2017-02-13 12:47:24 +01:00
|
|
|
//ClassDB::bind_method(D_METHOD("_dragged"),&EditorLog::_dragged );
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("clear_request"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorLog::EditorLog() {
|
|
|
|
|
2016-01-18 00:03:57 +01:00
|
|
|
VBoxContainer *vb = this;
|
2017-03-05 16:44:50 +01:00
|
|
|
add_constant_override("separation", get_constant("separation", "VBoxContainer"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
HBoxContainer *hb = memnew(HBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
vb->add_child(hb);
|
2017-03-05 16:44:50 +01:00
|
|
|
title = memnew(Label);
|
2017-08-08 04:55:24 +02:00
|
|
|
title->set_text(TTR("Output:"));
|
2014-02-10 02:10:30 +01:00
|
|
|
title->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
hb->add_child(title);
|
|
|
|
|
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-04 03:25:37 +02:00
|
|
|
clearbutton->set_text(TTR("Clear"));
|
2017-03-05 16:44:50 +01:00
|
|
|
clearbutton->connect("pressed", this, "_clear_request");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ec = memnew(Control);
|
2014-02-10 02:10:30 +01:00
|
|
|
vb->add_child(ec);
|
2017-08-08 04:55:24 +02:00
|
|
|
ec->set_custom_minimum_size(Size2(0, 180) * EDSCALE);
|
2014-02-10 02:10:30 +01:00
|
|
|
ec->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
pc = memnew(PanelContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
ec->add_child(pc);
|
|
|
|
pc->set_area_as_parent_rect();
|
2017-01-12 04:51:08 +01:00
|
|
|
pc->connect("tree_entered", this, "_override_logger_styles");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
log = memnew(RichTextLabel);
|
2014-02-10 02:10:30 +01:00
|
|
|
log->set_scroll_follow(true);
|
2014-09-22 05:50:48 +02:00
|
|
|
log->set_selection_enabled(true);
|
|
|
|
log->set_focus_mode(FOCUS_CLICK);
|
2014-02-10 02:10:30 +01:00
|
|
|
pc->add_child(log);
|
2017-03-05 16:44:50 +01:00
|
|
|
add_message(VERSION_FULL_NAME " (c) 2008-2017 Juan Linietsky, Ariel Manzur.");
|
2014-02-10 02:10:30 +01:00
|
|
|
//log->add_text("Initialization Complete.\n"); //because it looks cool.
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
eh.errfunc = _error_handler;
|
|
|
|
eh.userdata = this;
|
2014-02-10 02:10:30 +01:00
|
|
|
add_error_handler(&eh);
|
|
|
|
|
2017-08-07 12:17:31 +02:00
|
|
|
current = Thread::get_caller_id();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
EditorNode::get_undo_redo()->set_commit_notify_callback(_undo_redo_cbk, this);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLog::deinit() {
|
|
|
|
|
|
|
|
remove_error_handler(&eh);
|
|
|
|
}
|
|
|
|
|
2016-09-20 14:41:57 +02:00
|
|
|
void EditorLog::_override_logger_styles() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
pc->add_style_override("panel", get_stylebox("normal", "TextEdit"));
|
2016-09-20 14:41:57 +02:00
|
|
|
}
|
2015-07-30 00:03:25 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
EditorLog::~EditorLog() {
|
|
|
|
}
|