Add filter box to hotkey preferences
This commit is contained in:
parent
309b6e9eae
commit
18cc72e167
3 changed files with 65 additions and 0 deletions
|
@ -41,6 +41,36 @@
|
|||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[label]
|
||||
definition = "default"
|
||||
label = _ "Search:"
|
||||
[/label]
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_grow = true
|
||||
|
||||
[text_box]
|
||||
id = "filter"
|
||||
definition = "default"
|
||||
|
||||
tooltip = _ "Filters on addon description, version, type or author."
|
||||
{FITER_TEXT_BOX_HINT}
|
||||
[/text_box]
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
|
|
@ -141,6 +141,11 @@ preferences_dialog::preferences_dialog(const config& game_cfg, const PREFERENCE_
|
|||
}
|
||||
}
|
||||
|
||||
void preferences_dialog::on_filtertext_changed(text_box_base* textbox)
|
||||
{
|
||||
hotkey_name_filter_callback(*textbox->get_window());
|
||||
}
|
||||
|
||||
// Helper function to refresh resolution list
|
||||
void preferences_dialog::set_resolution_list(menu_button& res_list, CVideo& video)
|
||||
{
|
||||
|
@ -751,6 +756,9 @@ void preferences_dialog::post_build(window& window)
|
|||
|
||||
listbox& hotkey_list = setup_hotkey_list(window);
|
||||
|
||||
text_box& filter = find_widget<text_box>(&window, "filter", false);
|
||||
filter.set_text_changed_callback(std::bind(&preferences_dialog::on_filtertext_changed, this, _1));
|
||||
|
||||
// Action column
|
||||
hotkey_list.register_translatable_sorting_option(0, [this](const int i) { return visible_hotkeys_[i]->description.str(); });
|
||||
|
||||
|
@ -908,6 +916,30 @@ void preferences_dialog::remove_hotkey_callback(listbox& hotkeys)
|
|||
find_widget<label>(hotkeys.get_row_grid(row_number), "lbl_hotkey", false).set_label(hotkey::get_names(hotkey_item.command));
|
||||
}
|
||||
|
||||
void preferences_dialog::hotkey_name_filter_callback(window& window) const
|
||||
{
|
||||
const text_box& name_filter = find_widget<const text_box>(&window, "filter", false);
|
||||
std::string text = name_filter.get_value();
|
||||
boost::algorithm::to_lower(text);
|
||||
|
||||
boost::dynamic_bitset<> res(visible_hotkeys_.size());
|
||||
|
||||
for (std::size_t h = 0; h < visible_hotkeys_.size(); ++h)
|
||||
{
|
||||
const std::string description_lower = boost::algorithm::to_lower_copy(visible_hotkeys_[h]->description.str(), std::locale::classic());
|
||||
|
||||
if (description_lower.find(text) != std::string::npos) {
|
||||
res[h] = true;
|
||||
}
|
||||
else {
|
||||
res[h] = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
find_widget<listbox>(&window, "list_hotkeys", false).set_row_shown(res);
|
||||
}
|
||||
|
||||
void preferences_dialog::hotkey_type_filter_callback(window& window) const
|
||||
{
|
||||
const multimenu_button& hotkey_menu = find_widget<const multimenu_button>(&window, "hotkey_category_menu", false);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "config.hpp"
|
||||
#include "gui/dialogs/modal_dialog.hpp"
|
||||
#include "gui/widgets/group.hpp"
|
||||
#include "gui/widgets/text_box.hpp"
|
||||
#include "hotkey/hotkey_command.hpp"
|
||||
#include "preferences/game.hpp"
|
||||
#include "utils/make_enum.hpp"
|
||||
|
@ -111,6 +112,7 @@ private:
|
|||
void on_page_select(window& window);
|
||||
void on_tab_select(window& window);
|
||||
void on_advanced_prefs_list_select(listbox& tree);
|
||||
void on_filtertext_changed(text_box_base* textbox);
|
||||
|
||||
/** Special callback functions */
|
||||
void handle_res_select(window& window);
|
||||
|
@ -119,6 +121,7 @@ private:
|
|||
void remove_hotkey_callback(listbox& hotkeys);
|
||||
void default_hotkey_callback(window& window);
|
||||
void hotkey_type_filter_callback(window& window) const;
|
||||
void hotkey_name_filter_callback(window& window) const;
|
||||
|
||||
group<preferences::LOBBY_JOINS> lobby_joins_group;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue