123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #ifndef EDITOR_LOG_H
- #define EDITOR_LOG_H
- #include "core/os/thread.h"
- #include "scene/gui/box_container.h"
- #include "scene/gui/button.h"
- #include "scene/gui/label.h"
- #include "scene/gui/line_edit.h"
- #include "scene/gui/panel_container.h"
- #include "scene/gui/rich_text_label.h"
- #include "scene/gui/texture_button.h"
- #include "scene/gui/texture_rect.h"
- class UndoRedo;
- class EditorLog : public HBoxContainer {
- GDCLASS(EditorLog, HBoxContainer);
- public:
- enum MessageType {
- MSG_TYPE_STD,
- MSG_TYPE_ERROR,
- MSG_TYPE_STD_RICH,
- MSG_TYPE_WARNING,
- MSG_TYPE_EDITOR,
- };
- private:
- struct LogMessage {
- String text;
- MessageType type;
- int count = 1;
- bool clear = true;
- LogMessage() {}
- LogMessage(const String &p_text, MessageType p_type, bool p_clear) :
- text(p_text),
- type(p_type),
- clear(p_clear) {
- }
- };
- struct {
- Color error_color;
- Ref<Texture2D> error_icon;
- Color warning_color;
- Ref<Texture2D> warning_icon;
- Color message_color;
- } theme_cache;
-
- struct LogFilter {
- private:
-
- int message_count = 0;
- bool active = true;
- public:
- MessageType type;
- Button *toggle_button = nullptr;
- void initialize_button(const String &p_tooltip, Callable p_toggled_callback) {
- toggle_button = memnew(Button);
- toggle_button->set_toggle_mode(true);
- toggle_button->set_pressed(true);
- toggle_button->set_text(itos(message_count));
- toggle_button->set_tooltip_text(TTR(p_tooltip));
- toggle_button->set_focus_mode(FOCUS_NONE);
-
- toggle_button->connect(SceneStringName(toggled), p_toggled_callback.bind(type));
- }
- int get_message_count() {
- return message_count;
- }
- void set_message_count(int p_count) {
- message_count = p_count;
- toggle_button->set_text(itos(message_count));
- }
- bool is_active() {
- return active;
- }
- void set_active(bool p_active) {
- toggle_button->set_pressed(p_active);
- active = p_active;
- }
- LogFilter(MessageType p_type) :
- type(p_type) {
- }
- };
- int line_limit = 10000;
- Vector<LogMessage> messages;
-
- HashMap<MessageType, LogFilter *> type_filter_map;
- RichTextLabel *log = nullptr;
- Button *clear_button = nullptr;
- Button *copy_button = nullptr;
- Button *collapse_button = nullptr;
- bool collapse = false;
- Button *show_search_button = nullptr;
- LineEdit *search_box = nullptr;
-
- Button *tool_button = nullptr;
- bool is_loading_state = false;
- Timer *save_state_timer = nullptr;
- 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);
- ErrorHandlerList eh;
-
- void _meta_clicked(const String &p_meta);
- void _clear_request();
- void _copy_request();
- static void _undo_redo_cbk(void *p_self, const String &p_name);
- void _rebuild_log();
- void _add_log_line(LogMessage &p_message, bool p_replace_previous = false);
- bool _check_display_message(LogMessage &p_message);
- void _set_filter_active(bool p_active, MessageType p_message_type);
- void _set_search_visible(bool p_visible);
- void _search_changed(const String &p_text);
- void _process_message(const String &p_msg, MessageType p_type, bool p_clear);
- void _reset_message_counts();
- void _set_collapse(bool p_collapse);
- void _start_state_save_timer();
- void _save_state();
- void _load_state();
- void _update_theme();
- void _editor_settings_changed();
- protected:
- void _notification(int p_what);
- public:
- void add_message(const String &p_msg, MessageType p_type = MSG_TYPE_STD);
- void set_tool_button(Button *p_tool_button);
- void register_undo_redo(UndoRedo *p_undo_redo);
- void deinit();
- void clear();
- EditorLog();
- ~EditorLog();
- };
- VARIANT_ENUM_CAST(EditorLog::MessageType);
- #endif
|