mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-14 09:20:56 +00:00
help browser: add search functionality
This commit is contained in:
parent
24d3ba375a
commit
feb9bdac45
|
@ -13,6 +13,7 @@
|
|||
* Updated translations: Bengali, British English, Finnish, Italian
|
||||
### Units
|
||||
### User interface
|
||||
* It is now possible to search help topics by name/id in the Help Browser.
|
||||
### WML Engine
|
||||
* `[unit]dismissable` and `[unit]block_dismiss_message` keys added that allow marking an unit as dismissable, and what message to show if user clicks `Dismiss` button in Unit Recall dialog.
|
||||
### Miscellaneous and Bug Fixes
|
||||
|
|
|
@ -156,6 +156,19 @@
|
|||
[/toggle_button]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[text_box]
|
||||
id = "filter_box"
|
||||
definition = "default"
|
||||
{FILTER_TEXT_BOX_HINT}
|
||||
tooltip = _ "Search help topic names"
|
||||
[/text_box]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
border = "all"
|
||||
|
|
|
@ -22,14 +22,16 @@
|
|||
#include "gui/widgets/rich_label.hpp"
|
||||
#include "gui/widgets/scroll_label.hpp"
|
||||
#include "gui/widgets/scrollbar_panel.hpp"
|
||||
#include "gui/widgets/text_box.hpp"
|
||||
#include "gui/widgets/toggle_button.hpp"
|
||||
#include "gui/widgets/tree_view.hpp"
|
||||
#include "gui/widgets/tree_view_node.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "serialization/string_utils.hpp"
|
||||
#include "utils/ci_searcher.hpp"
|
||||
#include "video.hpp"
|
||||
|
||||
#include "help/help.hpp"
|
||||
#include "help/help_impl.hpp"
|
||||
|
||||
namespace gui2::dialogs
|
||||
{
|
||||
|
@ -81,6 +83,10 @@ void help_browser::pre_show()
|
|||
contents.set_visible(widget::visibility::invisible);
|
||||
}
|
||||
|
||||
text_box& filter = find_widget<text_box>("filter_box");
|
||||
add_to_keyboard_chain(&filter);
|
||||
filter.on_modified([this](const auto& box) { update_list(box.text()); });
|
||||
|
||||
topic_text.register_link_callback(std::bind(&help_browser::show_topic, this, std::placeholders::_1, true));
|
||||
|
||||
connect_signal_notify_modified(topic_tree, std::bind(&help_browser::on_topic_select, this));
|
||||
|
@ -95,19 +101,39 @@ void help_browser::pre_show()
|
|||
on_topic_select();
|
||||
}
|
||||
|
||||
void help_browser::add_topics_for_section(const help::section& parent_section, tree_view_node& parent_node)
|
||||
void help_browser::update_list(const std::string& filter_text) {
|
||||
tree_view& topic_tree = find_widget<tree_view>("topic_tree");
|
||||
topic_tree.clear();
|
||||
add_topics_for_section(toplevel_, topic_tree.get_root_node(), filter_text);
|
||||
}
|
||||
|
||||
bool help_browser::add_topics_for_section(const help::section& parent_section, tree_view_node& parent_node, const std::string& filter_text)
|
||||
{
|
||||
bool topics_added = false;
|
||||
const auto match = translation::make_ci_matcher(filter_text);
|
||||
|
||||
for(const help::section& section : parent_section.sections) {
|
||||
tree_view_node& section_node = add_topic(section.id, section.title, true, parent_node);
|
||||
bool subtopics_added = add_topics_for_section(section, section_node, filter_text);
|
||||
|
||||
add_topics_for_section(section, section_node);
|
||||
if (subtopics_added || match(section.id)) {
|
||||
if (!filter_text.empty()) {
|
||||
section_node.unfold();
|
||||
}
|
||||
topics_added = true;
|
||||
} else {
|
||||
find_widget<tree_view>("topic_tree").remove_node(§ion_node);
|
||||
}
|
||||
}
|
||||
|
||||
for(const help::topic& topic : parent_section.topics) {
|
||||
if(topic.id.compare(0, 2, "..") != 0) {
|
||||
if ((match(topic.id) || match(topic.title)) && (topic.id.compare(0, 2, "..") != 0)) {
|
||||
add_topic(topic.id, topic.title, false, parent_node);
|
||||
topics_added = true;
|
||||
}
|
||||
}
|
||||
|
||||
return topics_added;
|
||||
}
|
||||
|
||||
tree_view_node& help_browser::add_topic(const std::string& topic_id, const std::string& topic_title,
|
||||
|
|
|
@ -58,7 +58,8 @@ private:
|
|||
void on_topic_select();
|
||||
void on_history_navigate(bool backwards);
|
||||
|
||||
void add_topics_for_section(const help::section& parent_section, tree_view_node& parent_node);
|
||||
void update_list(const std::string&);
|
||||
bool add_topics_for_section(const help::section& parent_section, tree_view_node& parent_node, const std::string& filter_text = "");
|
||||
tree_view_node& add_topic(const std::string& topic_id, const std::string& topic_title,
|
||||
bool expands, tree_view_node& parent);
|
||||
void show_topic(std::string topic_id, bool add_to_history = true);
|
||||
|
|
Loading…
Reference in New Issue
Block a user