Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/editor_log.h
9821 views
1
/**************************************************************************/
2
/* editor_log.h */
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
31
#pragma once
32
33
#include "core/os/thread.h"
34
#include "scene/gui/box_container.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 UndoRedo;
40
41
class EditorLog : public HBoxContainer {
42
GDCLASS(EditorLog, HBoxContainer);
43
44
public:
45
enum MessageType {
46
MSG_TYPE_STD,
47
MSG_TYPE_ERROR,
48
MSG_TYPE_STD_RICH,
49
MSG_TYPE_WARNING,
50
MSG_TYPE_EDITOR,
51
};
52
53
private:
54
struct LogMessage {
55
String text;
56
MessageType type;
57
int count = 1;
58
bool clear = true;
59
60
LogMessage() {}
61
62
LogMessage(const String &p_text, MessageType p_type, bool p_clear) :
63
text(p_text),
64
type(p_type),
65
clear(p_clear) {
66
}
67
};
68
69
struct {
70
Color error_color;
71
Ref<Texture2D> error_icon;
72
73
Color warning_color;
74
Ref<Texture2D> warning_icon;
75
76
Color message_color;
77
} theme_cache;
78
79
// Encapsulates all data and functionality regarding filters.
80
struct LogFilter {
81
private:
82
// Force usage of set method since it has functionality built-in.
83
int message_count = 0;
84
bool active = true;
85
86
public:
87
MessageType type;
88
Button *toggle_button = nullptr;
89
90
void initialize_button(const String &p_name, const String &p_tooltip, Callable p_toggled_callback) {
91
toggle_button = memnew(Button);
92
toggle_button->set_toggle_mode(true);
93
toggle_button->set_pressed(true);
94
toggle_button->set_text(itos(message_count));
95
toggle_button->set_accessibility_name(TTRGET(p_name));
96
toggle_button->set_tooltip_text(TTRGET(p_tooltip));
97
toggle_button->set_focus_mode(FOCUS_ACCESSIBILITY);
98
// When toggled call the callback and pass the MessageType this button is for.
99
toggle_button->connect(SceneStringName(toggled), p_toggled_callback.bind(type));
100
}
101
102
int get_message_count() {
103
return message_count;
104
}
105
106
void set_message_count(int p_count) {
107
message_count = p_count;
108
toggle_button->set_text(itos(message_count));
109
}
110
111
bool is_active() {
112
return active;
113
}
114
115
void set_active(bool p_active) {
116
toggle_button->set_pressed(p_active);
117
active = p_active;
118
}
119
120
LogFilter(MessageType p_type) :
121
type(p_type) {
122
}
123
};
124
125
int line_limit = 10000;
126
127
Vector<LogMessage> messages;
128
// Maps MessageTypes to LogFilters for convenient access and storage (don't need 1 member per filter).
129
HashMap<MessageType, LogFilter *> type_filter_map;
130
131
RichTextLabel *log = nullptr;
132
133
Button *clear_button = nullptr;
134
Button *copy_button = nullptr;
135
136
Button *collapse_button = nullptr;
137
bool collapse = false;
138
139
Button *show_search_button = nullptr;
140
LineEdit *search_box = nullptr;
141
142
// Reference to the "Output" button on the toolbar so we can update its icon when warnings or errors are encountered.
143
Button *tool_button = nullptr;
144
145
bool is_loading_state = false; // Used to disable saving requests while loading (some signals from buttons will try to trigger a save, which happens during loading).
146
Timer *save_state_timer = nullptr;
147
148
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);
149
150
ErrorHandlerList eh;
151
152
//void _dragged(const Point2& p_ofs);
153
void _meta_clicked(const String &p_meta);
154
void _clear_request();
155
void _copy_request();
156
static void _undo_redo_cbk(void *p_self, const String &p_name);
157
158
void _rebuild_log();
159
void _add_log_line(LogMessage &p_message, bool p_replace_previous = false);
160
bool _check_display_message(LogMessage &p_message);
161
162
void _set_filter_active(bool p_active, MessageType p_message_type);
163
void _set_search_visible(bool p_visible);
164
void _search_changed(const String &p_text);
165
166
void _process_message(const String &p_msg, MessageType p_type, bool p_clear);
167
void _reset_message_counts();
168
169
void _set_collapse(bool p_collapse);
170
171
void _start_state_save_timer();
172
void _save_state();
173
void _load_state();
174
175
void _update_theme();
176
void _editor_settings_changed();
177
178
protected:
179
void _notification(int p_what);
180
181
public:
182
void add_message(const String &p_msg, MessageType p_type = MSG_TYPE_STD);
183
void set_tool_button(Button *p_tool_button);
184
void register_undo_redo(UndoRedo *p_undo_redo);
185
void deinit();
186
187
void clear();
188
189
EditorLog();
190
~EditorLog();
191
};
192
193
VARIANT_ENUM_CAST(EditorLog::MessageType);
194
195