From c9747c0db5cd84b5fa5c9d100a5490b19efbec2d Mon Sep 17 00:00:00 2001 From: Iris Morelle Date: Mon, 6 Jul 2020 21:29:15 -0400 Subject: [PATCH] gui2/logging: Add filtering functionality To make it easier to find log domains among the giant list. --- data/gui/window/logging.cfg | 43 ++++++++++++++++++++++++----- src/gui/dialogs/log_settings.cpp | 46 ++++++++++++++++++++++++++++++++ src/gui/dialogs/log_settings.hpp | 6 +++++ 3 files changed, 88 insertions(+), 7 deletions(-) diff --git a/data/gui/window/logging.cfg b/data/gui/window/logging.cfg index 1c0b317f867a..6ca7c4a41bc7 100644 --- a/data/gui/window/logging.cfg +++ b/data/gui/window/logging.cfg @@ -127,13 +127,42 @@ _ "Disable logging"#enddef [grid] [row] [column] - border = "all" - border_size = 5 - horizontal_alignment = "left" - [label] - definition = "title" - label = _ "Logging Options" - [/label] + horizontal_grow = true + + [grid] + + [row] + + [column] + grow_factor = 1 + border = "all" + border_size = 5 + horizontal_alignment = "left" + vertical_alignment = "top" + + [label] + definition = "title" + label = _ "Logging Options" + [/label] + + [/column] + + [column] + border = "all" + border_size = 5 + horizontal_alignment = "right" + + [text_box] + id = "filter_box" + definition = "default" + {FILTER_TEXT_BOX_HINT} + [/text_box] + + [/column] + + [/row] + + [/grid] [/column] [/row] diff --git a/src/gui/dialogs/log_settings.cpp b/src/gui/dialogs/log_settings.cpp index c4614a218e68..19d7ede0ea99 100644 --- a/src/gui/dialogs/log_settings.cpp +++ b/src/gui/dialogs/log_settings.cpp @@ -15,10 +15,12 @@ #include "gui/dialogs/log_settings.hpp" +#include "gettext.hpp" #include "gui/auxiliary/find_widget.hpp" #include "gui/widgets/grid.hpp" #include "gui/widgets/listbox.hpp" #include "gui/widgets/settings.hpp" +#include "gui/widgets/text_box.hpp" #include "gui/widgets/toggle_button.hpp" #include "gui/widgets/window.hpp" @@ -32,6 +34,7 @@ namespace dialogs REGISTER_DIALOG(log_settings) log_settings::log_settings() + : last_words_() { //list of names must match those in logging.cfg widget_id_.push_back("none"); @@ -85,6 +88,49 @@ void log_settings::pre_show(window& window) } } } + + text_box* filter = find_widget(&window, "filter_box", false, true); + filter->set_text_changed_callback(std::bind(&log_settings::filter_text_changed, this, _1, _2)); + + window.keyboard_capture(filter); + window.add_to_keyboard_chain(&logger_box); +} + +void log_settings::filter_text_changed(text_box_base* textbox, const std::string& text) +{ + window& window = *textbox->get_window(); + listbox& list = find_widget(&window, "logger_listbox", false); + + const std::vector words = utils::split(text, ' '); + + if(words == last_words_) { + return; + } + + last_words_ = words; + + boost::dynamic_bitset<> show_items; + show_items.resize(list.get_item_count(), true); + + if(!text.empty()) { + for(unsigned int i = 0; i < list.get_item_count(); i++) { + assert(i < domain_list_.size()); + + bool found = false; + + for(const auto& word : words) + { + found = translation::ci_search(domain_list_[i], word); + if(!found) { + break; + } + } + + show_items[i] = found; + } + } + + list.set_row_shown(show_items); } void log_settings::post_show(window& /*window*/) diff --git a/src/gui/dialogs/log_settings.hpp b/src/gui/dialogs/log_settings.hpp index 41802dad5149..aadf42abb1d6 100644 --- a/src/gui/dialogs/log_settings.hpp +++ b/src/gui/dialogs/log_settings.hpp @@ -19,6 +19,8 @@ namespace gui2 { +class text_box_base; + namespace dialogs { @@ -50,6 +52,10 @@ class log_settings : public modal_dialog /** Inherited from modal_dialog. */ virtual void post_show(window& window) override; + void filter_text_changed(text_box_base* textbox, const std::string& text); + + std::vector last_words_; + }; } // namespace dialogs