diff options
Diffstat (limited to 'editor/editor_log.cpp')
-rw-r--r-- | editor/editor_log.cpp | 71 |
1 files changed, 61 insertions, 10 deletions
diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index 667405ff10..166d09af30 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -59,7 +59,7 @@ void EditorLog::_error_handler(void *p_self, const char *p_func, const char *p_f MessageType message_type = p_type == ERR_HANDLER_WARNING ? MSG_TYPE_WARNING : MSG_TYPE_ERROR; if (self->current != Thread::get_caller_id()) { - callable_mp(self, &EditorLog::add_message).bind(err_str, message_type).call_deferred(); + callable_mp(self, &EditorLog::add_message).call_deferred(err_str, message_type); } else { self->add_message(err_str, message_type); } @@ -127,6 +127,14 @@ void EditorLog::_update_theme() { theme_cache.message_color = get_theme_color(SNAME("font_color"), EditorStringName(Editor)) * Color(1, 1, 1, 0.6); } +void EditorLog::_editor_settings_changed() { + int new_line_limit = int(EDITOR_GET("run/output/max_lines")); + if (new_line_limit != line_limit) { + line_limit = new_line_limit; + _rebuild_log(); + } +} + void EditorLog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { @@ -265,9 +273,41 @@ void EditorLog::_undo_redo_cbk(void *p_self, const String &p_name) { } void EditorLog::_rebuild_log() { + if (messages.is_empty()) { + return; + } + log->clear(); - for (int msg_idx = 0; msg_idx < messages.size(); msg_idx++) { + int line_count = 0; + int start_message_index = 0; + int initial_skip = 0; + + // Search backward for starting place. + for (start_message_index = messages.size() - 1; start_message_index >= 0; start_message_index--) { + LogMessage msg = messages[start_message_index]; + if (collapse) { + if (_check_display_message(msg)) { + line_count++; + } + } else { + // If not collapsing, log each instance on a line. + for (int i = 0; i < msg.count; i++) { + if (_check_display_message(msg)) { + line_count++; + } + } + } + if (line_count >= line_limit) { + initial_skip = line_count - line_limit; + break; + } + if (start_message_index == 0) { + break; + } + } + + for (int msg_idx = start_message_index; msg_idx < messages.size(); msg_idx++) { LogMessage msg = messages[msg_idx]; if (collapse) { @@ -275,13 +315,21 @@ void EditorLog::_rebuild_log() { _add_log_line(msg); } else { // If not collapsing, log each instance on a line. - for (int i = 0; i < msg.count; i++) { + for (int i = initial_skip; i < msg.count; i++) { + initial_skip = 0; _add_log_line(msg); } } } } +bool EditorLog::_check_display_message(LogMessage &p_message) { + bool filter_active = type_filter_map[p_message.type]->is_active(); + String search_text = search_box->get_text(); + bool search_match = search_text.is_empty() || p_message.text.containsn(search_text); + return filter_active && search_match; +} + void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) { if (!is_inside_tree()) { // The log will be built all at once when it enters the tree and has its theme items. @@ -294,11 +342,7 @@ void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) { } // Only add the message to the log if it passes the filters. - bool filter_active = type_filter_map[p_message.type]->is_active(); - String search_text = search_box->get_text(); - bool search_match = search_text.is_empty() || p_message.text.findn(search_text) > -1; - - if (!filter_active || !search_match) { + if (!_check_display_message(p_message)) { return; } @@ -359,6 +403,10 @@ void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) { } } } + + while (log->get_paragraph_count() > line_limit + 1) { + log->remove_paragraph(0, true); + } } void EditorLog::_set_filter_active(bool p_active, MessageType p_message_type) { @@ -392,6 +440,9 @@ EditorLog::EditorLog() { save_state_timer->connect("timeout", callable_mp(this, &EditorLog::_save_state)); add_child(save_state_timer); + line_limit = int(EDITOR_GET("run/output/max_lines")); + EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorLog::_editor_settings_changed)); + HBoxContainer *hb = this; VBoxContainer *vb_left = memnew(VBoxContainer); @@ -436,7 +487,7 @@ EditorLog::EditorLog() { clear_button->set_theme_type_variation("FlatButton"); clear_button->set_focus_mode(FOCUS_NONE); clear_button->set_shortcut(ED_SHORTCUT("editor/clear_output", TTR("Clear Output"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::ALT | Key::K)); - clear_button->connect("pressed", callable_mp(this, &EditorLog::_clear_request)); + clear_button->connect(SceneStringName(pressed), callable_mp(this, &EditorLog::_clear_request)); hb_tools->add_child(clear_button); // Copy. @@ -445,7 +496,7 @@ EditorLog::EditorLog() { copy_button->set_focus_mode(FOCUS_NONE); copy_button->set_shortcut(ED_SHORTCUT("editor/copy_output", TTR("Copy Selection"), KeyModifierMask::CMD_OR_CTRL | Key::C)); copy_button->set_shortcut_context(this); - copy_button->connect("pressed", callable_mp(this, &EditorLog::_copy_request)); + copy_button->connect(SceneStringName(pressed), callable_mp(this, &EditorLog::_copy_request)); hb_tools->add_child(copy_button); // Separate toggle buttons from normal buttons. |