Skip to content

Commit

Permalink
Add hotkey categories filter to preferences
Browse files Browse the repository at this point in the history
This allows the user to filter out certain types of hotkeys,
making it easier to locate a specific hotkey.
  • Loading branch information
CelticMinstrel committed Aug 29, 2016
1 parent d99bea9 commit 61aa9df
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 229 deletions.
5 changes: 5 additions & 0 deletions data/gui/window/preferences.cfg
Expand Up @@ -184,6 +184,11 @@
fixed_width = "true"
[/linked_group]

[linked_group]
id = "hotkeys_categories"
fixed_width = true
[/linked_group]

[tooltip]
id = "tooltip"
[/tooltip]
Expand Down
49 changes: 48 additions & 1 deletion data/gui/window/preferences/02_hotkeys.cfg
@@ -1,9 +1,56 @@
#textdomain wesnoth-lib
###
### Preferences dialog, Advanced page
### Preferences dialog, Hotkeys page
###

[layer]
[row]
grow_factor = 0

[column]
horizontal_grow = true
vertical_alignment = "top"
border = "all"
border_size = 5

[grid_listbox]
id = "list_categories"
definition = "default"
has_minimum = true
has_maximum = false
[list_definition]
[row]
[column]
[toggle_panel]
definition = "default"
linked_group = "hotkeys_categories"
[grid]
[row]
#{_GUI_INFO_TAB_PADDING}

[column]
grow_factor = 1
border = all
border_size = 5

[label]
id = "cat_label"
definition = "default_tiny"
wrap = true
[/label]

[/column]

#{_GUI_INFO_TAB_PADDING}
[/row]
[/grid]
[/toggle_panel]
[/column]
[/row]
[/list_definition]
[/grid_listbox]
[/column]
[/row]

[row]
grow_factor = 1
Expand Down
47 changes: 47 additions & 0 deletions src/gui/dialogs/preferences_dialog.cpp
Expand Up @@ -848,10 +848,57 @@ void tpreferences::initialize_members(twindow& window)

row_data.clear();

tlistbox& hotkey_categories = find_widget<tlistbox>(&window, "list_categories", false);

const std::string cat_names[] = {
// TODO: This list needs to be synchronized with the hotkey::HOTKEY_CATEGORY enum
// Find some way to do that automatically
_("General"),
_("Saved Games"),
_("Map Commands"),
_("Unit Commands"),
_("Player Chat"),
_("Replay Control"),
_("Planning Mode"),
_("Scenario Editor"),
_("Editor Palettes"),
_("Editor Tools"),
_("Editor Clipboard"),
_("Editor Selection"),
_("Debug Commands"),
_("Custom WML Commands"),
// HKCAT_PLACEHOLDER intentionally excluded (it shouldn't have any anyway)
};

for(int i = 0; i <= hotkey::HKCAT_PLACEHOLDER; i++) {
row_data["cat_label"]["label"] = cat_names[i];
hotkey_categories.add_row(row_data);
hotkey_categories.select_row(hotkey_categories.get_item_count() - 1);
}

setup_hotkey_list(window);

tlistbox& hotkey_list = find_widget<tlistbox>(&window, "list_hotkeys", false);

hotkey_categories.set_callback_item_change([&hotkey_list, &hotkey_categories](size_t i) {
if(i >= hotkey::HKCAT_PLACEHOLDER) {
return;
}
hotkey::HOTKEY_CATEGORY cat = hotkey::HOTKEY_CATEGORY(i);
// For listboxes that allow multiple selection, get_selected_row() returns the most
// recently selected row. Thus, if it returns i, this row was just selected.
// Otherwise, it must have been deselected.
bool show = hotkey_categories.get_selected_row() == int(i);
std::vector<bool> mask = hotkey_list.get_rows_shown();
auto hotkeys = hotkey::get_hotkey_commands();
for(size_t j = 0; j < hotkeys.size(); j++) {
if(hotkeys[j].category == cat) {
mask[j] = show;
}
}
hotkey_list.set_row_shown(mask);
});

// Action column
hotkey_list.register_sorting_option(0, [this](const int i) { return visible_hotkeys_[i]->description.str(); });

Expand Down
9 changes: 9 additions & 0 deletions src/gui/widgets/listbox.cpp
Expand Up @@ -214,6 +214,15 @@ void tlistbox::set_row_shown(const std::vector<bool>& shown)
}
}

std::vector<bool> tlistbox::get_rows_shown() const
{
std::vector<bool> shown;
for(size_t i = 0; i < get_item_count(); i++) {
shown.push_back(generator_->get_item_shown(i));
}
return shown;
}

const tgrid* tlistbox::get_row_grid(const unsigned row) const
{
assert(generator_);
Expand Down
7 changes: 7 additions & 0 deletions src/gui/widgets/listbox.hpp
Expand Up @@ -142,6 +142,13 @@ class tlistbox : public tscrollbar_container
*/
void set_row_shown(const std::vector<bool>& shown);

/**
* Returns a list of visible rows
*
* @returns A mask indicating which rows are visible
*/
std::vector<bool> get_rows_shown() const;

/**
* Returns the grid of the wanted row.
*
Expand Down

0 comments on commit 61aa9df

Please sign in to comment.