editor_log.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /**************************************************************************/
  2. /* editor_log.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_log.h"
  31. #include "core/object/undo_redo.h"
  32. #include "core/os/keyboard.h"
  33. #include "core/version.h"
  34. #include "editor/editor_node.h"
  35. #include "editor/editor_paths.h"
  36. #include "editor/editor_settings.h"
  37. #include "editor/editor_string_names.h"
  38. #include "editor/themes/editor_scale.h"
  39. #include "scene/gui/center_container.h"
  40. #include "scene/gui/separator.h"
  41. #include "scene/resources/font.h"
  42. 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, bool p_editor_notify, ErrorHandlerType p_type) {
  43. EditorLog *self = static_cast<EditorLog *>(p_self);
  44. String err_str;
  45. if (p_errorexp && p_errorexp[0]) {
  46. err_str = String::utf8(p_errorexp);
  47. } else {
  48. err_str = String::utf8(p_file) + ":" + itos(p_line) + " - " + String::utf8(p_error);
  49. }
  50. MessageType message_type = p_type == ERR_HANDLER_WARNING ? MSG_TYPE_WARNING : MSG_TYPE_ERROR;
  51. if (!Thread::is_main_thread()) {
  52. MessageQueue::get_main_singleton()->push_callable(callable_mp(self, &EditorLog::add_message), err_str, message_type);
  53. } else {
  54. self->add_message(err_str, message_type);
  55. }
  56. }
  57. void EditorLog::_update_theme() {
  58. const Ref<Font> normal_font = get_theme_font(SNAME("output_source"), EditorStringName(EditorFonts));
  59. if (normal_font.is_valid()) {
  60. log->add_theme_font_override("normal_font", normal_font);
  61. }
  62. const Ref<Font> bold_font = get_theme_font(SNAME("output_source_bold"), EditorStringName(EditorFonts));
  63. if (bold_font.is_valid()) {
  64. log->add_theme_font_override("bold_font", bold_font);
  65. }
  66. const Ref<Font> italics_font = get_theme_font(SNAME("output_source_italic"), EditorStringName(EditorFonts));
  67. if (italics_font.is_valid()) {
  68. log->add_theme_font_override("italics_font", italics_font);
  69. }
  70. const Ref<Font> bold_italics_font = get_theme_font(SNAME("output_source_bold_italic"), EditorStringName(EditorFonts));
  71. if (bold_italics_font.is_valid()) {
  72. log->add_theme_font_override("bold_italics_font", bold_italics_font);
  73. }
  74. const Ref<Font> mono_font = get_theme_font(SNAME("output_source_mono"), EditorStringName(EditorFonts));
  75. if (mono_font.is_valid()) {
  76. log->add_theme_font_override("mono_font", mono_font);
  77. }
  78. // Disable padding for highlighted background/foreground to prevent highlights from overlapping on close lines.
  79. // This also better matches terminal output, which does not use any form of padding.
  80. log->add_theme_constant_override("text_highlight_h_padding", 0);
  81. log->add_theme_constant_override("text_highlight_v_padding", 0);
  82. const int font_size = get_theme_font_size(SNAME("output_source_size"), EditorStringName(EditorFonts));
  83. log->begin_bulk_theme_override();
  84. log->add_theme_font_size_override("normal_font_size", font_size);
  85. log->add_theme_font_size_override("bold_font_size", font_size);
  86. log->add_theme_font_size_override("italics_font_size", font_size);
  87. log->add_theme_font_size_override("mono_font_size", font_size);
  88. log->end_bulk_theme_override();
  89. type_filter_map[MSG_TYPE_STD]->toggle_button->set_button_icon(get_editor_theme_icon(SNAME("Popup")));
  90. type_filter_map[MSG_TYPE_ERROR]->toggle_button->set_button_icon(get_editor_theme_icon(SNAME("StatusError")));
  91. type_filter_map[MSG_TYPE_WARNING]->toggle_button->set_button_icon(get_editor_theme_icon(SNAME("StatusWarning")));
  92. type_filter_map[MSG_TYPE_EDITOR]->toggle_button->set_button_icon(get_editor_theme_icon(SNAME("Edit")));
  93. type_filter_map[MSG_TYPE_STD]->toggle_button->set_theme_type_variation("EditorLogFilterButton");
  94. type_filter_map[MSG_TYPE_ERROR]->toggle_button->set_theme_type_variation("EditorLogFilterButton");
  95. type_filter_map[MSG_TYPE_WARNING]->toggle_button->set_theme_type_variation("EditorLogFilterButton");
  96. type_filter_map[MSG_TYPE_EDITOR]->toggle_button->set_theme_type_variation("EditorLogFilterButton");
  97. clear_button->set_button_icon(get_editor_theme_icon(SNAME("Clear")));
  98. copy_button->set_button_icon(get_editor_theme_icon(SNAME("ActionCopy")));
  99. collapse_button->set_button_icon(get_editor_theme_icon(SNAME("CombineLines")));
  100. show_search_button->set_button_icon(get_editor_theme_icon(SNAME("Search")));
  101. search_box->set_right_icon(get_editor_theme_icon(SNAME("Search")));
  102. theme_cache.error_color = get_theme_color(SNAME("error_color"), EditorStringName(Editor));
  103. theme_cache.error_icon = get_editor_theme_icon(SNAME("Error"));
  104. theme_cache.warning_color = get_theme_color(SNAME("warning_color"), EditorStringName(Editor));
  105. theme_cache.warning_icon = get_editor_theme_icon(SNAME("Warning"));
  106. theme_cache.message_color = get_theme_color(SceneStringName(font_color), EditorStringName(Editor)) * Color(1, 1, 1, 0.6);
  107. }
  108. void EditorLog::_editor_settings_changed() {
  109. int new_line_limit = int(EDITOR_GET("run/output/max_lines"));
  110. if (new_line_limit != line_limit) {
  111. line_limit = new_line_limit;
  112. _rebuild_log();
  113. }
  114. }
  115. void EditorLog::_notification(int p_what) {
  116. switch (p_what) {
  117. case NOTIFICATION_ENTER_TREE: {
  118. _update_theme();
  119. _load_state();
  120. } break;
  121. case NOTIFICATION_THEME_CHANGED: {
  122. _update_theme();
  123. _rebuild_log();
  124. } break;
  125. }
  126. }
  127. void EditorLog::_set_collapse(bool p_collapse) {
  128. collapse = p_collapse;
  129. _start_state_save_timer();
  130. _rebuild_log();
  131. }
  132. void EditorLog::_start_state_save_timer() {
  133. if (!is_loading_state) {
  134. save_state_timer->start();
  135. }
  136. }
  137. void EditorLog::_save_state() {
  138. Ref<ConfigFile> config;
  139. config.instantiate();
  140. // Load and amend existing config if it exists.
  141. config->load(EditorPaths::get_singleton()->get_project_settings_dir().path_join("editor_layout.cfg"));
  142. const String section = "editor_log";
  143. for (const KeyValue<MessageType, LogFilter *> &E : type_filter_map) {
  144. config->set_value(section, "log_filter_" + itos(E.key), E.value->is_active());
  145. }
  146. config->set_value(section, "collapse", collapse);
  147. config->set_value(section, "show_search", search_box->is_visible());
  148. config->save(EditorPaths::get_singleton()->get_project_settings_dir().path_join("editor_layout.cfg"));
  149. }
  150. void EditorLog::_load_state() {
  151. is_loading_state = true;
  152. Ref<ConfigFile> config;
  153. config.instantiate();
  154. config->load(EditorPaths::get_singleton()->get_project_settings_dir().path_join("editor_layout.cfg"));
  155. // 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.
  156. const String section = "editor_log";
  157. for (const KeyValue<MessageType, LogFilter *> &E : type_filter_map) {
  158. E.value->set_active(config->get_value(section, "log_filter_" + itos(E.key), true));
  159. }
  160. collapse = config->get_value(section, "collapse", false);
  161. collapse_button->set_pressed(collapse);
  162. bool show_search = config->get_value(section, "show_search", true);
  163. search_box->set_visible(show_search);
  164. show_search_button->set_pressed(show_search);
  165. is_loading_state = false;
  166. }
  167. void EditorLog::_meta_clicked(const String &p_meta) {
  168. OS::get_singleton()->shell_open(p_meta);
  169. }
  170. void EditorLog::_clear_request() {
  171. log->clear();
  172. messages.clear();
  173. _reset_message_counts();
  174. tool_button->set_button_icon(Ref<Texture2D>());
  175. }
  176. void EditorLog::_copy_request() {
  177. String text = log->get_selected_text();
  178. if (text.is_empty()) {
  179. text = log->get_parsed_text();
  180. }
  181. if (!text.is_empty()) {
  182. DisplayServer::get_singleton()->clipboard_set(text);
  183. }
  184. }
  185. void EditorLog::clear() {
  186. _clear_request();
  187. }
  188. void EditorLog::_process_message(const String &p_msg, MessageType p_type, bool p_clear) {
  189. if (messages.size() > 0 && messages[messages.size() - 1].text == p_msg && messages[messages.size() - 1].type == p_type) {
  190. // If previous message is the same as the new one, increase previous count rather than adding another
  191. // instance to the messages list.
  192. LogMessage &previous = messages.write[messages.size() - 1];
  193. previous.count++;
  194. _add_log_line(previous, collapse);
  195. } else {
  196. // Different message to the previous one received.
  197. LogMessage message(p_msg, p_type, p_clear);
  198. _add_log_line(message);
  199. messages.push_back(message);
  200. }
  201. type_filter_map[p_type]->set_message_count(type_filter_map[p_type]->get_message_count() + 1);
  202. }
  203. void EditorLog::add_message(const String &p_msg, MessageType p_type) {
  204. // Make text split by new lines their own message.
  205. // See #41321 for reasoning. At time of writing, multiple print()'s in running projects
  206. // get grouped together and sent to the editor log as one message. This can mess with the
  207. // search functionality (see the comments on the PR above for more details). This behavior
  208. // also matches that of other IDE's.
  209. Vector<String> lines = p_msg.split("\n", true);
  210. int line_count = lines.size();
  211. for (int i = 0; i < line_count; i++) {
  212. _process_message(lines[i], p_type, i == line_count - 1);
  213. }
  214. }
  215. void EditorLog::set_tool_button(Button *p_tool_button) {
  216. tool_button = p_tool_button;
  217. }
  218. void EditorLog::register_undo_redo(UndoRedo *p_undo_redo) {
  219. p_undo_redo->set_commit_notify_callback(_undo_redo_cbk, this);
  220. }
  221. void EditorLog::_undo_redo_cbk(void *p_self, const String &p_name) {
  222. EditorLog *self = static_cast<EditorLog *>(p_self);
  223. self->add_message(p_name, EditorLog::MSG_TYPE_EDITOR);
  224. }
  225. void EditorLog::_rebuild_log() {
  226. if (messages.is_empty()) {
  227. return;
  228. }
  229. log->clear();
  230. int line_count = 0;
  231. int start_message_index = 0;
  232. int initial_skip = 0;
  233. // Search backward for starting place.
  234. for (start_message_index = messages.size() - 1; start_message_index >= 0; start_message_index--) {
  235. LogMessage msg = messages[start_message_index];
  236. if (collapse) {
  237. if (_check_display_message(msg)) {
  238. line_count++;
  239. }
  240. } else {
  241. // If not collapsing, log each instance on a line.
  242. for (int i = 0; i < msg.count; i++) {
  243. if (_check_display_message(msg)) {
  244. line_count++;
  245. }
  246. }
  247. }
  248. if (line_count >= line_limit) {
  249. initial_skip = line_count - line_limit;
  250. break;
  251. }
  252. if (start_message_index == 0) {
  253. break;
  254. }
  255. }
  256. for (int msg_idx = start_message_index; msg_idx < messages.size(); msg_idx++) {
  257. LogMessage msg = messages[msg_idx];
  258. if (collapse) {
  259. // If collapsing, only log one instance of the message.
  260. _add_log_line(msg);
  261. } else {
  262. // If not collapsing, log each instance on a line.
  263. for (int i = initial_skip; i < msg.count; i++) {
  264. initial_skip = 0;
  265. _add_log_line(msg);
  266. }
  267. }
  268. }
  269. }
  270. bool EditorLog::_check_display_message(LogMessage &p_message) {
  271. bool filter_active = type_filter_map[p_message.type]->is_active();
  272. String search_text = search_box->get_text();
  273. bool search_match = search_text.is_empty() || p_message.text.containsn(search_text);
  274. return filter_active && search_match;
  275. }
  276. void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) {
  277. if (!is_inside_tree()) {
  278. // The log will be built all at once when it enters the tree and has its theme items.
  279. return;
  280. }
  281. if (unlikely(log->is_updating())) {
  282. // The new message arrived during log RTL text processing/redraw (invalid BiDi control characters / font error), ignore it to avoid RTL data corruption.
  283. return;
  284. }
  285. // Only add the message to the log if it passes the filters.
  286. if (!_check_display_message(p_message)) {
  287. return;
  288. }
  289. if (p_replace_previous) {
  290. // Remove last line if replacing, as it will be replace by the next added line.
  291. // 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,
  292. // but it still counts as a line. So if you remove the last line (count - 1) you are actually removing nothing...
  293. log->remove_paragraph(log->get_paragraph_count() - 2);
  294. }
  295. switch (p_message.type) {
  296. case MSG_TYPE_STD: {
  297. } break;
  298. case MSG_TYPE_STD_RICH: {
  299. } break;
  300. case MSG_TYPE_ERROR: {
  301. log->push_color(theme_cache.error_color);
  302. Ref<Texture2D> icon = theme_cache.error_icon;
  303. log->add_image(icon);
  304. log->push_bold();
  305. log->add_text(" ERROR: ");
  306. log->pop(); // bold
  307. tool_button->set_button_icon(icon);
  308. } break;
  309. case MSG_TYPE_WARNING: {
  310. log->push_color(theme_cache.warning_color);
  311. Ref<Texture2D> icon = theme_cache.warning_icon;
  312. log->add_image(icon);
  313. log->push_bold();
  314. log->add_text(" WARNING: ");
  315. log->pop(); // bold
  316. tool_button->set_button_icon(icon);
  317. } break;
  318. case MSG_TYPE_EDITOR: {
  319. // Distinguish editor messages from messages printed by the project
  320. log->push_color(theme_cache.message_color);
  321. } break;
  322. }
  323. // If collapsing, add the count of this message in bold at the start of the line.
  324. if (collapse && p_message.count > 1) {
  325. log->push_bold();
  326. log->add_text(vformat("(%s) ", itos(p_message.count)));
  327. log->pop();
  328. }
  329. if (p_message.type == MSG_TYPE_STD_RICH) {
  330. log->append_text(p_message.text);
  331. } else {
  332. log->add_text(p_message.text);
  333. }
  334. if (p_message.clear || p_message.type != MSG_TYPE_STD_RICH) {
  335. log->pop_all(); // Pop all unclosed tags.
  336. }
  337. log->add_newline();
  338. if (p_replace_previous) {
  339. // Force sync last line update (skip if number of unprocessed log messages is too large to avoid editor lag).
  340. if (log->get_pending_paragraphs() < 100) {
  341. while (!log->is_finished()) {
  342. ::OS::get_singleton()->delay_usec(1);
  343. }
  344. }
  345. }
  346. while (log->get_paragraph_count() > line_limit + 1) {
  347. log->remove_paragraph(0, true);
  348. }
  349. }
  350. void EditorLog::_set_filter_active(bool p_active, MessageType p_message_type) {
  351. type_filter_map[p_message_type]->set_active(p_active);
  352. _start_state_save_timer();
  353. _rebuild_log();
  354. }
  355. void EditorLog::_set_search_visible(bool p_visible) {
  356. search_box->set_visible(p_visible);
  357. if (p_visible) {
  358. search_box->grab_focus();
  359. }
  360. _start_state_save_timer();
  361. }
  362. void EditorLog::_search_changed(const String &p_text) {
  363. _rebuild_log();
  364. }
  365. void EditorLog::_reset_message_counts() {
  366. for (const KeyValue<MessageType, LogFilter *> &E : type_filter_map) {
  367. E.value->set_message_count(0);
  368. }
  369. }
  370. EditorLog::EditorLog() {
  371. save_state_timer = memnew(Timer);
  372. save_state_timer->set_wait_time(2);
  373. save_state_timer->set_one_shot(true);
  374. save_state_timer->connect("timeout", callable_mp(this, &EditorLog::_save_state));
  375. add_child(save_state_timer);
  376. line_limit = int(EDITOR_GET("run/output/max_lines"));
  377. EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorLog::_editor_settings_changed));
  378. HBoxContainer *hb = this;
  379. VBoxContainer *vb_left = memnew(VBoxContainer);
  380. vb_left->set_custom_minimum_size(Size2(0, 180) * EDSCALE);
  381. vb_left->set_v_size_flags(SIZE_EXPAND_FILL);
  382. vb_left->set_h_size_flags(SIZE_EXPAND_FILL);
  383. hb->add_child(vb_left);
  384. // Log - Rich Text Label.
  385. log = memnew(RichTextLabel);
  386. log->set_threaded(true);
  387. log->set_use_bbcode(true);
  388. log->set_scroll_follow(true);
  389. log->set_selection_enabled(true);
  390. log->set_context_menu_enabled(true);
  391. log->set_focus_mode(FOCUS_CLICK);
  392. log->set_v_size_flags(SIZE_EXPAND_FILL);
  393. log->set_h_size_flags(SIZE_EXPAND_FILL);
  394. log->set_deselect_on_focus_loss_enabled(false);
  395. log->connect("meta_clicked", callable_mp(this, &EditorLog::_meta_clicked));
  396. vb_left->add_child(log);
  397. // Search box
  398. search_box = memnew(LineEdit);
  399. search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  400. search_box->set_placeholder(TTR("Filter Messages"));
  401. search_box->set_clear_button_enabled(true);
  402. search_box->set_visible(true);
  403. search_box->connect(SceneStringName(text_changed), callable_mp(this, &EditorLog::_search_changed));
  404. vb_left->add_child(search_box);
  405. VBoxContainer *vb_right = memnew(VBoxContainer);
  406. hb->add_child(vb_right);
  407. // Tools grid
  408. HBoxContainer *hb_tools = memnew(HBoxContainer);
  409. hb_tools->set_h_size_flags(SIZE_SHRINK_CENTER);
  410. vb_right->add_child(hb_tools);
  411. // Clear.
  412. clear_button = memnew(Button);
  413. clear_button->set_theme_type_variation(SceneStringName(FlatButton));
  414. clear_button->set_focus_mode(FOCUS_NONE);
  415. clear_button->set_shortcut(ED_SHORTCUT("editor/clear_output", TTR("Clear Output"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::ALT | Key::K));
  416. clear_button->connect(SceneStringName(pressed), callable_mp(this, &EditorLog::_clear_request));
  417. hb_tools->add_child(clear_button);
  418. // Copy.
  419. copy_button = memnew(Button);
  420. copy_button->set_theme_type_variation(SceneStringName(FlatButton));
  421. copy_button->set_focus_mode(FOCUS_NONE);
  422. copy_button->set_shortcut(ED_SHORTCUT("editor/copy_output", TTR("Copy Selection"), KeyModifierMask::CMD_OR_CTRL | Key::C));
  423. copy_button->set_shortcut_context(this);
  424. copy_button->connect(SceneStringName(pressed), callable_mp(this, &EditorLog::_copy_request));
  425. hb_tools->add_child(copy_button);
  426. // Separate toggle buttons from normal buttons.
  427. vb_right->add_child(memnew(HSeparator));
  428. // A second hbox to make a 2x2 grid of buttons.
  429. HBoxContainer *hb_tools2 = memnew(HBoxContainer);
  430. hb_tools2->set_h_size_flags(SIZE_SHRINK_CENTER);
  431. vb_right->add_child(hb_tools2);
  432. // Collapse.
  433. collapse_button = memnew(Button);
  434. collapse_button->set_theme_type_variation(SceneStringName(FlatButton));
  435. collapse_button->set_focus_mode(FOCUS_NONE);
  436. collapse_button->set_tooltip_text(TTR("Collapse duplicate messages into one log entry. Shows number of occurrences."));
  437. collapse_button->set_toggle_mode(true);
  438. collapse_button->set_pressed(false);
  439. collapse_button->connect(SceneStringName(toggled), callable_mp(this, &EditorLog::_set_collapse));
  440. hb_tools2->add_child(collapse_button);
  441. // Show Search.
  442. show_search_button = memnew(Button);
  443. show_search_button->set_theme_type_variation(SceneStringName(FlatButton));
  444. show_search_button->set_focus_mode(FOCUS_NONE);
  445. show_search_button->set_toggle_mode(true);
  446. show_search_button->set_pressed(true);
  447. show_search_button->set_shortcut(ED_SHORTCUT("editor/open_search", TTR("Focus Search/Filter Bar"), KeyModifierMask::CMD_OR_CTRL | Key::F));
  448. show_search_button->set_shortcut_context(this);
  449. show_search_button->connect(SceneStringName(toggled), callable_mp(this, &EditorLog::_set_search_visible));
  450. hb_tools2->add_child(show_search_button);
  451. // Message Type Filters.
  452. vb_right->add_child(memnew(HSeparator));
  453. LogFilter *std_filter = memnew(LogFilter(MSG_TYPE_STD));
  454. std_filter->initialize_button(TTR("Toggle visibility of standard output messages."), callable_mp(this, &EditorLog::_set_filter_active));
  455. vb_right->add_child(std_filter->toggle_button);
  456. type_filter_map.insert(MSG_TYPE_STD, std_filter);
  457. type_filter_map.insert(MSG_TYPE_STD_RICH, std_filter);
  458. LogFilter *error_filter = memnew(LogFilter(MSG_TYPE_ERROR));
  459. error_filter->initialize_button(TTR("Toggle visibility of errors."), callable_mp(this, &EditorLog::_set_filter_active));
  460. vb_right->add_child(error_filter->toggle_button);
  461. type_filter_map.insert(MSG_TYPE_ERROR, error_filter);
  462. LogFilter *warning_filter = memnew(LogFilter(MSG_TYPE_WARNING));
  463. warning_filter->initialize_button(TTR("Toggle visibility of warnings."), callable_mp(this, &EditorLog::_set_filter_active));
  464. vb_right->add_child(warning_filter->toggle_button);
  465. type_filter_map.insert(MSG_TYPE_WARNING, warning_filter);
  466. LogFilter *editor_filter = memnew(LogFilter(MSG_TYPE_EDITOR));
  467. editor_filter->initialize_button(TTR("Toggle visibility of editor messages."), callable_mp(this, &EditorLog::_set_filter_active));
  468. vb_right->add_child(editor_filter->toggle_button);
  469. type_filter_map.insert(MSG_TYPE_EDITOR, editor_filter);
  470. add_message(VERSION_FULL_NAME " (c) 2007-present Juan Linietsky, Ariel Manzur & Godot Contributors.");
  471. eh.errfunc = _error_handler;
  472. eh.userdata = this;
  473. add_error_handler(&eh);
  474. }
  475. void EditorLog::deinit() {
  476. remove_error_handler(&eh);
  477. }
  478. EditorLog::~EditorLog() {
  479. for (const KeyValue<MessageType, LogFilter *> &E : type_filter_map) {
  480. // MSG_TYPE_STD_RICH is connected to the std_filter button, so we do this
  481. // to avoid it from being deleted twice, causing a crash on closing.
  482. if (E.key != MSG_TYPE_STD_RICH) {
  483. memdelete(E.value);
  484. }
  485. }
  486. }