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
|
|
|
/*************************************************************************/
|
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-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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01: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-10 02:10:30 +01:00
|
|
|
#include "editor_node.h"
|
2019-12-24 08:17:23 +01:00
|
|
|
#include "editor_scale.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/gui/center_container.h"
|
2020-09-03 13:22:16 +02:00
|
|
|
#include "scene/resources/font.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) {
|
|
|
|
EditorLog *self = (EditorLog *)p_self;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (self->current != Thread::get_caller_id()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-08-13 17:04:38 +02: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-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2021-07-21 09:31:33 +02:00
|
|
|
void EditorLog::_update_theme() {
|
|
|
|
Ref<Font> normal_font = get_theme_font(SNAME("output_source"), SNAME("EditorFonts"));
|
|
|
|
if (normal_font.is_valid()) {
|
|
|
|
log->add_theme_font_override("normal_font", normal_font);
|
|
|
|
}
|
|
|
|
|
|
|
|
log->add_theme_font_size_override("normal_font_size", get_theme_font_size(SNAME("output_source_size"), SNAME("EditorFonts")));
|
|
|
|
log->add_theme_color_override("selection_color", get_theme_color(SNAME("accent_color"), SNAME("Editor")) * Color(1, 1, 1, 0.4));
|
|
|
|
|
|
|
|
Ref<Font> bold_font = get_theme_font(SNAME("bold"), SNAME("EditorFonts"));
|
|
|
|
if (bold_font.is_valid()) {
|
|
|
|
log->add_theme_font_override("bold_font", bold_font);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_filter_map[MSG_TYPE_STD]->toggle_button->set_icon(get_theme_icon(SNAME("Popup"), SNAME("EditorIcons")));
|
|
|
|
type_filter_map[MSG_TYPE_ERROR]->toggle_button->set_icon(get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons")));
|
|
|
|
type_filter_map[MSG_TYPE_WARNING]->toggle_button->set_icon(get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons")));
|
|
|
|
type_filter_map[MSG_TYPE_EDITOR]->toggle_button->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")));
|
|
|
|
|
|
|
|
clear_button->set_icon(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")));
|
|
|
|
copy_button->set_icon(get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons")));
|
|
|
|
collapse_button->set_icon(get_theme_icon(SNAME("CombineLines"), SNAME("EditorIcons")));
|
|
|
|
show_search_button->set_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void EditorLog::_notification(int p_what) {
|
2021-07-21 09:31:33 +02:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
|
|
_update_theme();
|
|
|
|
_load_state();
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
|
|
|
_update_theme();
|
|
|
|
_rebuild_log();
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-16 09:30:52 +02:00
|
|
|
void EditorLog::_set_collapse(bool p_collapse) {
|
|
|
|
collapse = p_collapse;
|
2021-05-05 03:05:09 +02:00
|
|
|
_start_state_save_timer();
|
2020-08-16 09:30:52 +02:00
|
|
|
_rebuild_log();
|
|
|
|
}
|
|
|
|
|
2021-05-05 03:05:09 +02:00
|
|
|
void EditorLog::_start_state_save_timer() {
|
|
|
|
if (!is_loading_state) {
|
|
|
|
save_state_timer->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLog::_save_state() {
|
|
|
|
Ref<ConfigFile> config;
|
2021-06-18 00:03:09 +02:00
|
|
|
config.instantiate();
|
2021-05-05 03:05:09 +02:00
|
|
|
// Load and amend existing config if it exists.
|
|
|
|
config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg"));
|
|
|
|
|
|
|
|
const String section = "editor_log";
|
|
|
|
for (Map<MessageType, LogFilter *>::Element *E = type_filter_map.front(); E; E = E->next()) {
|
|
|
|
config->set_value(section, "log_filter_" + itos(E->key()), E->get()->is_active());
|
|
|
|
}
|
|
|
|
|
|
|
|
config->set_value(section, "collapse", collapse);
|
|
|
|
config->set_value(section, "show_search", search_box->is_visible());
|
|
|
|
|
|
|
|
config->save(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLog::_load_state() {
|
|
|
|
is_loading_state = true;
|
|
|
|
|
|
|
|
Ref<ConfigFile> config;
|
2021-06-18 00:03:09 +02:00
|
|
|
config.instantiate();
|
2021-06-29 04:21:45 +02:00
|
|
|
config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg"));
|
2021-05-05 03:05:09 +02:00
|
|
|
|
2021-06-29 04:21:45 +02:00
|
|
|
// Run the below code even if config->load returns an error, since we want the defaults to be set even if the file does not exist yet.
|
|
|
|
const String section = "editor_log";
|
|
|
|
for (Map<MessageType, LogFilter *>::Element *E = type_filter_map.front(); E; E = E->next()) {
|
|
|
|
E->get()->set_active(config->get_value(section, "log_filter_" + itos(E->key()), true));
|
2021-05-05 03:05:09 +02:00
|
|
|
}
|
|
|
|
|
2021-06-29 04:21:45 +02:00
|
|
|
collapse = config->get_value(section, "collapse", false);
|
|
|
|
collapse_button->set_pressed(collapse);
|
|
|
|
bool show_search = config->get_value(section, "show_search", true);
|
|
|
|
search_box->set_visible(show_search);
|
|
|
|
show_search_button->set_pressed(show_search);
|
|
|
|
|
2021-05-05 03:05:09 +02:00
|
|
|
is_loading_state = false;
|
|
|
|
}
|
|
|
|
|
2015-07-29 00:41:24 +02:00
|
|
|
void EditorLog::_clear_request() {
|
|
|
|
log->clear();
|
2020-08-16 09:30:52 +02:00
|
|
|
messages.clear();
|
|
|
|
_reset_message_counts();
|
2019-06-11 20:43:37 +02:00
|
|
|
tool_button->set_icon(Ref<Texture2D>());
|
2015-07-30 00:03:25 +02:00
|
|
|
}
|
|
|
|
|
2019-04-14 10:55:31 +02:00
|
|
|
void EditorLog::_copy_request() {
|
2020-09-14 20:14:27 +02:00
|
|
|
String text = log->get_selected_text();
|
|
|
|
|
|
|
|
if (text == "") {
|
|
|
|
text = log->get_text();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text != "") {
|
|
|
|
DisplayServer::get_singleton()->clipboard_set(text);
|
|
|
|
}
|
2019-04-14 10:55:31 +02:00
|
|
|
}
|
|
|
|
|
2015-07-30 00:03:25 +02:00
|
|
|
void EditorLog::clear() {
|
|
|
|
_clear_request();
|
2015-07-29 00:41:24 +02:00
|
|
|
}
|
|
|
|
|
2020-08-16 09:30:52 +02:00
|
|
|
void EditorLog::_process_message(const String &p_msg, MessageType p_type) {
|
|
|
|
if (messages.size() > 0 && messages[messages.size() - 1].text == p_msg) {
|
|
|
|
// If previous message is the same as the new one, increase previous count rather than adding another
|
|
|
|
// instance to the messages list.
|
|
|
|
LogMessage &previous = messages.write[messages.size() - 1];
|
|
|
|
previous.count++;
|
|
|
|
|
2020-08-17 07:52:42 +02:00
|
|
|
_add_log_line(previous, collapse);
|
2020-08-16 09:30:52 +02:00
|
|
|
} else {
|
|
|
|
// Different message to the previous one received.
|
|
|
|
LogMessage message(p_msg, p_type);
|
|
|
|
_add_log_line(message);
|
|
|
|
messages.push_back(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_filter_map[p_type]->set_message_count(type_filter_map[p_type]->get_message_count() + 1);
|
2019-04-14 10:55:31 +02:00
|
|
|
}
|
|
|
|
|
2018-08-13 17:04:38 +02:00
|
|
|
void EditorLog::add_message(const String &p_msg, MessageType p_type) {
|
2020-08-16 09:30:52 +02:00
|
|
|
// Make text split by new lines their own message.
|
|
|
|
// See #41321 for reasoning. At time of writing, multiple print()'s in running projects
|
|
|
|
// get grouped together and sent to the editor log as one message. This can mess with the
|
|
|
|
// search functionality (see the comments on the PR above for more details). This behaviour
|
|
|
|
// also matches that of other IDE's.
|
|
|
|
Vector<String> lines = p_msg.split("\n", false);
|
|
|
|
|
|
|
|
for (int i = 0; i < lines.size(); i++) {
|
|
|
|
_process_message(lines[i], p_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLog::set_tool_button(Button *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, EditorLog::MSG_TYPE_EDITOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLog::_rebuild_log() {
|
|
|
|
log->clear();
|
|
|
|
|
|
|
|
for (int msg_idx = 0; msg_idx < messages.size(); msg_idx++) {
|
|
|
|
LogMessage msg = messages[msg_idx];
|
|
|
|
|
|
|
|
if (collapse) {
|
|
|
|
// If collapsing, only log one instance of the message.
|
|
|
|
_add_log_line(msg);
|
|
|
|
} else {
|
|
|
|
// If not collapsing, log each instance on a line.
|
|
|
|
for (int i = 0; i < msg.count; i++) {
|
|
|
|
_add_log_line(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) {
|
|
|
|
// Only add the message to the log if it passes the filters.
|
2021-05-05 03:05:09 +02:00
|
|
|
bool filter_active = type_filter_map[p_message.type]->is_active();
|
2020-08-16 09:30:52 +02:00
|
|
|
String search_text = search_box->get_text();
|
|
|
|
bool search_match = search_text == String() || p_message.text.findn(search_text) > -1;
|
|
|
|
|
|
|
|
if (!filter_active || !search_match) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_replace_previous) {
|
|
|
|
// Remove last line if replacing, as it will be replace by the next added line.
|
2021-05-25 13:48:28 +02:00
|
|
|
// Why "- 2"? RichTextLabel is weird. When you add a line with add_newline(), it also adds an element to the list of lines which is null/blank,
|
2021-05-22 16:14:56 +02:00
|
|
|
// but it still counts as a line. So if you remove the last line (count - 1) you are actually removing nothing...
|
2021-05-25 13:48:28 +02:00
|
|
|
log->remove_line(log->get_paragraph_count() - 2);
|
2020-08-16 09:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (p_message.type) {
|
2018-09-26 13:13:56 +02:00
|
|
|
case MSG_TYPE_STD: {
|
|
|
|
} break;
|
2018-08-13 17:04:38 +02:00
|
|
|
case MSG_TYPE_ERROR: {
|
2021-07-17 23:22:52 +02:00
|
|
|
log->push_color(get_theme_color(SNAME("error_color"), SNAME("Editor")));
|
|
|
|
Ref<Texture2D> icon = get_theme_icon(SNAME("Error"), SNAME("EditorIcons"));
|
2018-08-13 17:04:38 +02:00
|
|
|
log->add_image(icon);
|
|
|
|
log->add_text(" ");
|
|
|
|
tool_button->set_icon(icon);
|
|
|
|
} break;
|
|
|
|
case MSG_TYPE_WARNING: {
|
2021-07-17 23:22:52 +02:00
|
|
|
log->push_color(get_theme_color(SNAME("warning_color"), SNAME("Editor")));
|
|
|
|
Ref<Texture2D> icon = get_theme_icon(SNAME("Warning"), SNAME("EditorIcons"));
|
2018-08-13 17:04:38 +02: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
|
2021-07-17 23:22:52 +02:00
|
|
|
log->push_color(get_theme_color(SNAME("font_color"), SNAME("Editor")) * Color(1, 1, 1, 0.6));
|
2019-09-20 01:56:09 +02:00
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-08-16 09:30:52 +02:00
|
|
|
// If collapsing, add the count of this message in bold at the start of the line.
|
|
|
|
if (collapse && p_message.count > 1) {
|
|
|
|
log->push_bold();
|
|
|
|
log->add_text(vformat("(%s) ", itos(p_message.count)));
|
|
|
|
log->pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
log->add_text(p_message.text);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-08-16 09:30:52 +02:00
|
|
|
// Need to use pop() to exit out of the RichTextLabels current "push" stack.
|
2021-05-04 16:25:14 +02:00
|
|
|
// We only "push" in the above switch when message type != STD, so only pop when that is the case.
|
2020-08-16 09:30:52 +02:00
|
|
|
if (p_message.type != MSG_TYPE_STD) {
|
2014-02-10 02:10:30 +01:00
|
|
|
log->pop();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2021-05-25 13:48:28 +02:00
|
|
|
|
|
|
|
log->add_newline();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-08-16 09:30:52 +02:00
|
|
|
void EditorLog::_set_filter_active(bool p_active, MessageType p_message_type) {
|
2021-05-05 03:05:09 +02:00
|
|
|
type_filter_map[p_message_type]->set_active(p_active);
|
|
|
|
_start_state_save_timer();
|
2020-08-16 09:30:52 +02:00
|
|
|
_rebuild_log();
|
2018-03-11 14:20:32 +01:00
|
|
|
}
|
|
|
|
|
2020-08-16 09:30:52 +02:00
|
|
|
void EditorLog::_set_search_visible(bool p_visible) {
|
|
|
|
search_box->set_visible(p_visible);
|
|
|
|
if (p_visible) {
|
|
|
|
search_box->grab_focus();
|
|
|
|
}
|
2021-05-05 03:05:09 +02:00
|
|
|
_start_state_save_timer();
|
2020-08-16 09:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLog::_search_changed(const String &p_text) {
|
|
|
|
_rebuild_log();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLog::_reset_message_counts() {
|
|
|
|
for (Map<MessageType, LogFilter *>::Element *E = type_filter_map.front(); E; E = E->next()) {
|
|
|
|
E->value()->set_message_count(0);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLog::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("clear_request"));
|
2019-04-14 10:55:31 +02:00
|
|
|
ADD_SIGNAL(MethodInfo("copy_request"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorLog::EditorLog() {
|
2021-05-05 03:05:09 +02:00
|
|
|
save_state_timer = memnew(Timer);
|
|
|
|
save_state_timer->set_wait_time(2);
|
|
|
|
save_state_timer->set_one_shot(true);
|
|
|
|
save_state_timer->connect("timeout", callable_mp(this, &EditorLog::_save_state));
|
|
|
|
add_child(save_state_timer);
|
|
|
|
|
2020-08-16 09:30:52 +02:00
|
|
|
HBoxContainer *hb = this;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-08-16 09:30:52 +02:00
|
|
|
VBoxContainer *vb_left = memnew(VBoxContainer);
|
|
|
|
vb_left->set_custom_minimum_size(Size2(0, 180) * EDSCALE);
|
|
|
|
vb_left->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
vb_left->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
hb->add_child(vb_left);
|
|
|
|
|
|
|
|
// Log - Rich Text Label.
|
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);
|
2017-09-08 22:39:41 +02:00
|
|
|
log->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
log->set_h_size_flags(SIZE_EXPAND_FILL);
|
2020-08-16 09:30:52 +02:00
|
|
|
vb_left->add_child(log);
|
|
|
|
|
|
|
|
// Search box
|
|
|
|
search_box = memnew(LineEdit);
|
|
|
|
search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
search_box->set_placeholder(TTR("Filter messages"));
|
2021-07-17 23:22:52 +02:00
|
|
|
search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
|
2020-08-16 09:30:52 +02:00
|
|
|
search_box->set_clear_button_enabled(true);
|
|
|
|
search_box->set_visible(true);
|
|
|
|
search_box->connect("text_changed", callable_mp(this, &EditorLog::_search_changed));
|
|
|
|
vb_left->add_child(search_box);
|
|
|
|
|
|
|
|
VBoxContainer *vb_right = memnew(VBoxContainer);
|
|
|
|
hb->add_child(vb_right);
|
|
|
|
|
|
|
|
// Tools grid
|
|
|
|
HBoxContainer *hb_tools = memnew(HBoxContainer);
|
|
|
|
hb_tools->set_h_size_flags(SIZE_SHRINK_CENTER);
|
|
|
|
vb_right->add_child(hb_tools);
|
|
|
|
|
|
|
|
// Clear.
|
|
|
|
clear_button = memnew(Button);
|
|
|
|
clear_button->set_flat(true);
|
|
|
|
clear_button->set_focus_mode(FOCUS_NONE);
|
|
|
|
clear_button->set_shortcut(ED_SHORTCUT("editor/clear_output", TTR("Clear Output"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_K));
|
2021-05-04 16:25:14 +02:00
|
|
|
clear_button->set_shortcut_context(this);
|
2020-08-16 09:30:52 +02:00
|
|
|
clear_button->connect("pressed", callable_mp(this, &EditorLog::_clear_request));
|
|
|
|
hb_tools->add_child(clear_button);
|
|
|
|
|
|
|
|
// Copy.
|
|
|
|
copy_button = memnew(Button);
|
|
|
|
copy_button->set_flat(true);
|
|
|
|
copy_button->set_focus_mode(FOCUS_NONE);
|
|
|
|
copy_button->set_shortcut(ED_SHORTCUT("editor/copy_output", TTR("Copy Selection"), KEY_MASK_CMD | KEY_C));
|
2021-05-04 16:25:14 +02:00
|
|
|
copy_button->set_shortcut_context(this);
|
2020-08-16 09:30:52 +02:00
|
|
|
copy_button->connect("pressed", callable_mp(this, &EditorLog::_copy_request));
|
|
|
|
hb_tools->add_child(copy_button);
|
|
|
|
|
|
|
|
// A second hbox to make a 2x2 grid of buttons.
|
|
|
|
HBoxContainer *hb_tools2 = memnew(HBoxContainer);
|
|
|
|
hb_tools2->set_h_size_flags(SIZE_SHRINK_CENTER);
|
|
|
|
vb_right->add_child(hb_tools2);
|
|
|
|
|
|
|
|
// Collapse.
|
|
|
|
collapse_button = memnew(Button);
|
|
|
|
collapse_button->set_flat(true);
|
|
|
|
collapse_button->set_focus_mode(FOCUS_NONE);
|
2021-05-20 12:07:26 +02:00
|
|
|
collapse_button->set_tooltip(TTR("Collapse duplicate messages into one log entry. Shows number of occurrences."));
|
2020-08-16 09:30:52 +02:00
|
|
|
collapse_button->set_toggle_mode(true);
|
|
|
|
collapse_button->set_pressed(false);
|
|
|
|
collapse_button->connect("toggled", callable_mp(this, &EditorLog::_set_collapse));
|
|
|
|
hb_tools2->add_child(collapse_button);
|
|
|
|
|
|
|
|
// Show Search.
|
|
|
|
show_search_button = memnew(Button);
|
|
|
|
show_search_button->set_flat(true);
|
|
|
|
show_search_button->set_focus_mode(FOCUS_NONE);
|
|
|
|
show_search_button->set_toggle_mode(true);
|
|
|
|
show_search_button->set_pressed(true);
|
|
|
|
show_search_button->set_shortcut(ED_SHORTCUT("editor/open_search", TTR("Open the search box."), KEY_MASK_CMD | KEY_F));
|
2021-05-04 16:25:14 +02:00
|
|
|
show_search_button->set_shortcut_context(this);
|
2020-08-16 09:30:52 +02:00
|
|
|
show_search_button->connect("toggled", callable_mp(this, &EditorLog::_set_search_visible));
|
|
|
|
hb_tools2->add_child(show_search_button);
|
|
|
|
|
|
|
|
// Message Type Filters.
|
|
|
|
vb_right->add_child(memnew(HSeparator));
|
|
|
|
|
|
|
|
LogFilter *std_filter = memnew(LogFilter(MSG_TYPE_STD));
|
2021-07-19 21:10:05 +02:00
|
|
|
std_filter->initialize_button(TTR("Toggle visibility of standard output messages."), callable_mp(this, &EditorLog::_set_filter_active));
|
2020-08-16 09:30:52 +02:00
|
|
|
vb_right->add_child(std_filter->toggle_button);
|
|
|
|
type_filter_map.insert(MSG_TYPE_STD, std_filter);
|
|
|
|
|
|
|
|
LogFilter *error_filter = memnew(LogFilter(MSG_TYPE_ERROR));
|
2021-07-19 21:10:05 +02:00
|
|
|
error_filter->initialize_button(TTR("Toggle visibility of errors."), callable_mp(this, &EditorLog::_set_filter_active));
|
2020-08-16 09:30:52 +02:00
|
|
|
vb_right->add_child(error_filter->toggle_button);
|
|
|
|
type_filter_map.insert(MSG_TYPE_ERROR, error_filter);
|
|
|
|
|
|
|
|
LogFilter *warning_filter = memnew(LogFilter(MSG_TYPE_WARNING));
|
2021-07-19 21:10:05 +02:00
|
|
|
warning_filter->initialize_button(TTR("Toggle visibility of warnings."), callable_mp(this, &EditorLog::_set_filter_active));
|
2020-08-16 09:30:52 +02:00
|
|
|
vb_right->add_child(warning_filter->toggle_button);
|
|
|
|
type_filter_map.insert(MSG_TYPE_WARNING, warning_filter);
|
|
|
|
|
|
|
|
LogFilter *editor_filter = memnew(LogFilter(MSG_TYPE_EDITOR));
|
2021-07-19 21:10:05 +02:00
|
|
|
editor_filter->initialize_button(TTR("Toggle visibility of editor messages."), callable_mp(this, &EditorLog::_set_filter_active));
|
2020-08-16 09:30:52 +02:00
|
|
|
vb_right->add_child(editor_filter->toggle_button);
|
|
|
|
type_filter_map.insert(MSG_TYPE_EDITOR, editor_filter);
|
|
|
|
|
2021-01-01 20:13:46 +01:00
|
|
|
add_message(VERSION_FULL_NAME " (c) 2007-2021 Juan Linietsky, Ariel Manzur & Godot Contributors.");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorLog::~EditorLog() {
|
2020-08-16 09:30:52 +02:00
|
|
|
for (Map<MessageType, LogFilter *>::Element *E = type_filter_map.front(); E; E = E->next()) {
|
|
|
|
memdelete(E->get());
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|