summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-05-07 00:47:41 +0200
committerGitHub <noreply@github.com>2021-05-07 00:47:41 +0200
commit04e995dd5d864f04a89ce02d957a425bd5109810 (patch)
treeff3dc2b9109c21d850a700007c277b7e8132812c
parent3a5310ccb990633bbba1d17dbeb503d46faa8615 (diff)
parent902d468f5233f97f56771ce60159aabf2a78a113 (diff)
Merge pull request #48466 from EricEzaM/output-log-save-state
Made Editor Log buttons save their state, per project.
-rw-r--r--editor/editor_log.cpp61
-rw-r--r--editor/editor_log.h18
-rw-r--r--editor/editor_node.cpp2
3 files changed, 78 insertions, 3 deletions
diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp
index 602035634a..7c485d53c5 100644
--- a/editor/editor_log.cpp
+++ b/editor/editor_log.cpp
@@ -75,6 +75,8 @@ void EditorLog::_notification(int p_what) {
collapse_button->set_icon(get_theme_icon("CombineLines", "EditorIcons"));
show_search_button->set_icon(get_theme_icon("Search", "EditorIcons"));
+ _load_state();
+
} else if (p_what == NOTIFICATION_THEME_CHANGED) {
Ref<Font> df_output_code = get_theme_font("output_source", "EditorFonts");
if (df_output_code.is_valid()) {
@@ -89,9 +91,56 @@ void EditorLog::_notification(int p_what) {
void EditorLog::_set_collapse(bool p_collapse) {
collapse = p_collapse;
+ _start_state_save_timer();
_rebuild_log();
}
+void EditorLog::_start_state_save_timer() {
+ if (!is_loading_state) {
+ save_state_timer->start();
+ }
+}
+
+void EditorLog::_save_state() {
+ Ref<ConfigFile> config;
+ config.instance();
+ // Load and amend existing config if it exists.
+ config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg"));
+
+ const String section = "editor_log";
+ for (Map<MessageType, LogFilter *>::Element *E = type_filter_map.front(); E; E = E->next()) {
+ config->set_value(section, "log_filter_" + itos(E->key()), E->get()->is_active());
+ }
+
+ config->set_value(section, "collapse", collapse);
+ config->set_value(section, "show_search", search_box->is_visible());
+
+ config->save(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg"));
+}
+
+void EditorLog::_load_state() {
+ is_loading_state = true;
+
+ Ref<ConfigFile> config;
+ config.instance();
+ Error err = config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg"));
+
+ if (err == OK) {
+ const String section = "editor_log";
+ for (Map<MessageType, LogFilter *>::Element *E = type_filter_map.front(); E; E = E->next()) {
+ E->get()->set_active(config->get_value(section, "log_filter_" + itos(E->key()), false));
+ }
+
+ collapse = config->get_value(section, "collapse", false);
+ collapse_button->set_pressed(collapse);
+ bool show_search = config->get_value(section, "show_search", true);
+ search_box->set_visible(show_search);
+ show_search_button->set_pressed(show_search);
+ }
+
+ is_loading_state = false;
+}
+
void EditorLog::_clear_request() {
log->clear();
messages.clear();
@@ -175,7 +224,7 @@ void EditorLog::_rebuild_log() {
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]->active;
+ bool filter_active = type_filter_map[p_message.type]->is_active();
String search_text = search_box->get_text();
bool search_match = search_text == String() || p_message.text.findn(search_text) > -1;
@@ -230,7 +279,8 @@ void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) {
}
void EditorLog::_set_filter_active(bool p_active, MessageType p_message_type) {
- type_filter_map[p_message_type]->active = p_active;
+ type_filter_map[p_message_type]->set_active(p_active);
+ _start_state_save_timer();
_rebuild_log();
}
@@ -239,6 +289,7 @@ void EditorLog::_set_search_visible(bool p_visible) {
if (p_visible) {
search_box->grab_focus();
}
+ _start_state_save_timer();
}
void EditorLog::_search_changed(const String &p_text) {
@@ -257,6 +308,12 @@ void EditorLog::_bind_methods() {
}
EditorLog::EditorLog() {
+ save_state_timer = memnew(Timer);
+ save_state_timer->set_wait_time(2);
+ save_state_timer->set_one_shot(true);
+ save_state_timer->connect("timeout", callable_mp(this, &EditorLog::_save_state));
+ add_child(save_state_timer);
+
HBoxContainer *hb = this;
VBoxContainer *vb_left = memnew(VBoxContainer);
diff --git a/editor/editor_log.h b/editor/editor_log.h
index 89d00d0fa0..3b6476634a 100644
--- a/editor/editor_log.h
+++ b/editor/editor_log.h
@@ -72,11 +72,11 @@ private:
private:
// Force usage of set method since it has functionality built-in.
int message_count = 0;
+ bool active = true;
public:
MessageType type;
Button *toggle_button = nullptr;
- bool active = true;
void initialize_button(const String &p_tooltip, Callable p_toggled_callback) {
toggle_button = memnew(Button);
@@ -100,6 +100,15 @@ private:
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) {
}
@@ -124,6 +133,9 @@ private:
// Warnings or Errors are encounetered.
Button *tool_button;
+ bool is_loading_state = false; // Used to disable saving requests while loading (some signals from buttons will try trigger a save, which happens during loading).
+ Timer *save_state_timer;
+
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, ErrorHandlerType p_type);
ErrorHandlerList eh;
@@ -147,6 +159,10 @@ private:
void _set_collapse(bool p_collapse);
+ void _start_state_save_timer();
+ void _save_state();
+ void _load_state();
+
protected:
static void _bind_methods();
void _notification(int p_what);
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 07e95e7b83..6390755656 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -4362,6 +4362,8 @@ void EditorNode::_save_docks() {
}
Ref<ConfigFile> config;
config.instance();
+ // Load and amend existing config if it exists.
+ config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg"));
_save_docks_to_config(config, "docks");
_save_open_scenes_to_config(config, "EditorNode");