diff options
author | Eric M <itsjusteza@gmail.com> | 2021-05-05 11:05:09 +1000 |
---|---|---|
committer | Eric M <itsjusteza@gmail.com> | 2021-05-06 00:48:19 +1000 |
commit | 902d468f5233f97f56771ce60159aabf2a78a113 (patch) | |
tree | e654648f3d4a3e4c0e03d72d4b1f6bab46a568ae | |
parent | e189ff55a747a397e613e192ef0fd402e40e2b9f (diff) |
Made Editor Log buttons save their state, per project.
-rw-r--r-- | editor/editor_log.cpp | 61 | ||||
-rw-r--r-- | editor/editor_log.h | 18 | ||||
-rw-r--r-- | editor/editor_node.cpp | 2 |
3 files changed, 78 insertions, 3 deletions
diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index 9f188b53c4..07aa41bd67 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; @@ -231,7 +280,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(); } @@ -240,6 +290,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) { @@ -258,6 +309,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 8eeabf9cfd..7e7e6bbcfe 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"); |