| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/os/thread.h" |
| 34 |
#include "editor/docks/editor_dock.h" |
| 35 |
#include "scene/gui/button.h" |
| 36 |
#include "scene/gui/line_edit.h" |
| 37 |
#include "scene/gui/rich_text_label.h" |
| 38 |
|
| 39 |
class Timer; |
| 40 |
class UndoRedo; |
| 41 |
|
| 42 |
class EditorLog : public EditorDock { |
| 43 |
GDCLASS(EditorLog, EditorDock); |
| 44 |
|
| 45 |
public: |
| 46 |
enum MessageType { |
| 47 |
MSG_TYPE_STD, |
| 48 |
MSG_TYPE_ERROR, |
| 49 |
MSG_TYPE_STD_RICH, |
| 50 |
MSG_TYPE_WARNING, |
| 51 |
MSG_TYPE_EDITOR, |
| 52 |
}; |
| 53 |
|
| 54 |
private: |
| 55 |
struct LogMessage { |
| 56 |
String text; |
| 57 |
MessageType type; |
| 58 |
int count = 1; |
| 59 |
bool clear = true; |
| 60 |
|
| 61 |
LogMessage() {} |
| 62 |
|
| 63 |
LogMessage(const String &p_text, MessageType p_type, bool p_clear) : |
| 64 |
text(p_text), |
| 65 |
type(p_type), |
| 66 |
clear(p_clear) { |
| 67 |
} |
| 68 |
}; |
| 69 |
|
| 70 |
struct { |
| 71 |
Color error_color; |
| 72 |
Ref<Texture2D> error_icon; |
| 73 |
|
| 74 |
Color warning_color; |
| 75 |
Ref<Texture2D> warning_icon; |
| 76 |
|
| 77 |
Color message_color; |
| 78 |
} theme_cache; |
| 79 |
|
| 80 |
|
| 81 |
struct LogFilter { |
| 82 |
private: |
| 83 |
|
| 84 |
int message_count = 0; |
| 85 |
bool active = true; |
| 86 |
|
| 87 |
public: |
| 88 |
MessageType type; |
| 89 |
Button *toggle_button = nullptr; |
| 90 |
|
| 91 |
void initialize_button(const String &p_name, const String &p_tooltip, Callable p_toggled_callback) { |
| 92 |
toggle_button = memnew(Button); |
| 93 |
toggle_button->set_toggle_mode(true); |
| 94 |
toggle_button->set_pressed(true); |
| 95 |
toggle_button->set_text(itos(message_count)); |
| 96 |
toggle_button->set_accessibility_name(TTRGET(p_name)); |
| 97 |
toggle_button->set_tooltip_text(TTRGET(p_tooltip)); |
| 98 |
toggle_button->set_focus_mode(FOCUS_ACCESSIBILITY); |
| 99 |
|
| 100 |
toggle_button->connect(SceneStringName(toggled), p_toggled_callback.bind(type)); |
| 101 |
} |
| 102 |
|
| 103 |
int get_message_count() { |
| 104 |
return message_count; |
| 105 |
} |
| 106 |
|
| 107 |
void set_message_count(int p_count) { |
| 108 |
message_count = p_count; |
| 109 |
toggle_button->set_text(itos(message_count)); |
| 110 |
} |
| 111 |
|
| 112 |
bool is_active() { |
| 113 |
return active; |
| 114 |
} |
| 115 |
|
| 116 |
void set_active(bool p_active) { |
| 117 |
toggle_button->set_pressed(p_active); |
| 118 |
active = p_active; |
| 119 |
} |
| 120 |
|
| 121 |
LogFilter(MessageType p_type) : |
| 122 |
type(p_type) { |
| 123 |
} |
| 124 |
}; |
| 125 |
|
| 126 |
int line_limit = 10000; |
| 127 |
|
| 128 |
Vector<LogMessage> messages; |
| 129 |
|
| 130 |
HashMap<MessageType, LogFilter *> type_filter_map; |
| 131 |
|
| 132 |
RichTextLabel *log = nullptr; |
| 133 |
|
| 134 |
Button *clear_button = nullptr; |
| 135 |
Button *copy_button = nullptr; |
| 136 |
|
| 137 |
Button *collapse_button = nullptr; |
| 138 |
bool collapse = false; |
| 139 |
|
| 140 |
Button *show_search_button = nullptr; |
| 141 |
LineEdit *search_box = nullptr; |
| 142 |
|
| 143 |
|
| 144 |
RichTextLabel *bbcode_parser = nullptr; |
| 145 |
|
| 146 |
bool is_loading_state = false; |
| 147 |
Timer *save_state_timer = nullptr; |
| 148 |
|
| 149 |
static void _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); |
| 150 |
|
| 151 |
ErrorHandlerList eh; |
| 152 |
|
| 153 |
|
| 154 |
void _meta_clicked(const String &p_meta); |
| 155 |
void _clear_request(); |
| 156 |
void _copy_request(); |
| 157 |
static void _undo_redo_cbk(void *p_self, const String &p_name); |
| 158 |
|
| 159 |
void _rebuild_log(); |
| 160 |
void _add_log_line(LogMessage &p_message, bool p_replace_previous = false); |
| 161 |
bool _check_display_message(LogMessage &p_message); |
| 162 |
|
| 163 |
void _set_filter_active(bool p_active, MessageType p_message_type); |
| 164 |
void _set_search_visible(bool p_visible); |
| 165 |
void _search_changed(const String &p_text); |
| 166 |
|
| 167 |
void _process_message(const String &p_msg, MessageType p_type, bool p_clear); |
| 168 |
void _reset_message_counts(); |
| 169 |
void _set_dock_tab_icon(Ref<Texture2D> p_icon); |
| 170 |
|
| 171 |
void _set_collapse(bool p_collapse); |
| 172 |
|
| 173 |
void _start_state_save_timer(); |
| 174 |
void _save_state(); |
| 175 |
void _load_state(); |
| 176 |
|
| 177 |
void _update_theme(); |
| 178 |
void _editor_settings_changed(); |
| 179 |
|
| 180 |
protected: |
| 181 |
void _notification(int p_what); |
| 182 |
|
| 183 |
public: |
| 184 |
void add_message(const String &p_msg, MessageType p_type = MSG_TYPE_STD); |
| 185 |
void register_undo_redo(UndoRedo *p_undo_redo); |
| 186 |
void deinit(); |
| 187 |
|
| 188 |
void clear(); |
| 189 |
|
| 190 |
EditorLog(); |
| 191 |
~EditorLog(); |
| 192 |
}; |
| 193 |
|
| 194 |
VARIANT_ENUM_CAST(EditorLog::MessageType); |