Documentation and code cleanup of set_button_state.

This commit is contained in:
fendrin 2013-03-31 15:56:16 +02:00
parent f6f50ec02f
commit eea59abd86
2 changed files with 23 additions and 20 deletions

View file

@ -1188,34 +1188,33 @@ void execute_command(display& disp, HOTKEY_COMMAND command, command_executor* ex
}
}
void command_executor::set_button_state(display& disp, HOTKEY_COMMAND command, int index) { //, command_executor* executor, int index) {
void command_executor::set_button_state(display& disp, HOTKEY_COMMAND command, int index) {
BOOST_FOREACH(const theme::menu& menu, disp.get_theme().menus()) {
if (menu.items().size() == 1) {
hotkey::HOTKEY_COMMAND hk = hotkey::get_id(menu.items().front());
if (menu.items().size() == 1) {
hotkey::HOTKEY_COMMAND hk = hotkey::get_id(menu.items().front());
if (hk == command) {
if (hk == command) {
//TODO 1?
ACTION_STATE state = get_action_state(command, index);
gui::button* button = disp.find_button(menu.get_id());
button->enable(can_execute_command(command, index));
switch (state) {
case ACTION_ON:
button->set_check(true);
break;
case ACTION_OFF:
button->set_check(false);
break;
case ACTION_STATELESS:
break;
default:
break;
}
ACTION_STATE state = get_action_state(command, index);
gui::button* button = disp.find_button(menu.get_id());
button->enable(can_execute_command(command, index));
switch (state) {
case ACTION_ON:
button->set_check(true);
break;
case ACTION_OFF:
button->set_check(false);
break;
case ACTION_STATELESS:
break;
default:
break;
}
}
}
}
}
void command_executor::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& gui)

View file

@ -387,6 +387,10 @@ public:
std::vector<std::string> get_menu_images(display &, const std::vector<std::string>& items_arg);
void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& gui);
/**
* Adjusts the state of those theme menu buttons which trigger hotkey events.
* \param command The command whose linked buttons are adjusted */
void set_button_state(display& disp, HOTKEY_COMMAND command, int index = -1);
virtual bool can_execute_command(HOTKEY_COMMAND command, int index=-1) const = 0;