GUI2/Menu Button: changed callbacks to NOTIFY_MODIFIED ones

menu_button doesn't even actually inherit from clickable_item. The only reason
[dis]connect_click_handler was declared in this class is the original implementation
was copied extensively from the Button widget.

Using NOTIFY_MODIFIED also means callbacks can fire if set_value/set_selected is used
on a menu_button.

The [dis]connect_click_handler functions were also removed from multimenu_button. All
callbacks for this widget type already used NOTIFY_MODIFIED signals.
This commit is contained in:
Charles Dang 2018-06-16 13:17:23 +11:00
parent 2d9b7d82c6
commit 55f14ff22c
10 changed files with 38 additions and 42 deletions

View file

@ -336,7 +336,9 @@ void addon_manager::pre_show(window& window)
}
status_filter.set_values(status_filter_entries);
status_filter.connect_click_handler(std::bind(&addon_manager::apply_filters, this, std::ref(window)));
connect_signal_notify_modified(status_filter,
std::bind(&addon_manager::apply_filters, this, std::ref(window)));
multimenu_button& type_filter = find_widget<multimenu_button>(&window, "type_filter", false);
@ -347,7 +349,8 @@ void addon_manager::pre_show(window& window)
type_filter.set_values(type_filter_entries);
connect_signal_notify_modified(type_filter, std::bind(&addon_manager::apply_filters, this, std::ref(window)));
connect_signal_notify_modified(type_filter,
std::bind(&addon_manager::apply_filters, this, std::ref(window)));
menu_button& order_dropdown = find_widget<menu_button>(&window, "order_dropdown", false);
@ -366,7 +369,9 @@ void addon_manager::pre_show(window& window)
}
order_dropdown.set_values(order_dropdown_entries);
order_dropdown.connect_click_handler(std::bind(&addon_manager::order_addons, this, std::ref(window)));
connect_signal_notify_modified(order_dropdown,
std::bind(&addon_manager::order_addons, this, std::ref(window)));
button& url_go_button = find_widget<button>(&window, "url_go", false);
button& url_copy_button = find_widget<button>(&window, "url_copy", false);

View file

@ -72,7 +72,7 @@ void faction_select::pre_show(window& window)
//
// Set up leader menu button
//
find_widget<menu_button>(&window, "leader_menu", false).connect_click_handler(
connect_signal_notify_modified(find_widget<menu_button>(&window, "leader_menu", false),
std::bind(&faction_select::on_leader_select, this, std::ref(window)));
//

View file

@ -769,8 +769,8 @@ void mp_lobby::pre_show(window& window)
replay_options.set_selected(2);
}
replay_options.connect_click_handler(
std::bind(&mp_lobby::skip_replay_changed_callback, this, std::ref(window)));
connect_signal_notify_modified(replay_options,
std::bind(&mp_lobby::skip_replay_changed_callback, this, std::ref(window)));
filter_friends_ = find_widget<toggle_button>(&window, "filter_with_friends", false, true);
filter_ignored_ = find_widget<toggle_button>(&window, "filter_without_ignored", false, true);

View file

@ -205,7 +205,9 @@ void mp_create_game::pre_show(window& win)
};
game_menu_button.set_values(game_types, get_initial_type_index());
game_menu_button.connect_click_handler(std::bind(&mp_create_game::update_games_list, this, std::ref(win)));
connect_signal_notify_modified(game_menu_button,
std::bind(&mp_create_game::update_games_list, this, std::ref(win)));
//
// Set up mods list
@ -256,7 +258,9 @@ void mp_create_game::pre_show(window& win)
}
eras_menu_button_->set_values(era_names);
eras_menu_button_->connect_click_handler(std::bind(&mp_create_game::on_era_select, this, std::ref(win)));
connect_signal_notify_modified(*eras_menu_button_,
std::bind(&mp_create_game::on_era_select, this, std::ref(win)));
const int era_selection = create_engine_.find_extra_by_id(ng::create_engine::ERA, preferences::era());
if(era_selection >= 0) {
@ -289,7 +293,9 @@ void mp_create_game::pre_show(window& win)
menu_button& rfm_menu_button = find_widget<menu_button>(&win, "random_faction_mode", false);
rfm_menu_button.set_values(rfm_options, initial_index);
rfm_menu_button.connect_click_handler(std::bind(&mp_create_game::on_random_faction_mode_select, this, std::ref(win)));
connect_signal_notify_modified(rfm_menu_button,
std::bind(&mp_create_game::on_random_faction_mode_select, this, std::ref(win)));
on_random_faction_mode_select(win);

View file

@ -282,7 +282,7 @@ void mp_options_helper::display_custom_options(const std::string& type, int node
menu->set_selected(std::distance(combo_values.begin(), iter));
}
menu->connect_click_handler(
connect_signal_notify_modified(*menu,
std::bind(&mp_options_helper::update_options_data_map_menu_button, this, menu, visible_options_.back(), option_cfg));
} else if(opt.key == "slider") {

View file

@ -210,7 +210,9 @@ void mp_staging::add_side_node(window& window, ng::side_engine_ptr side)
menu_button& ai_selection = find_widget<menu_button>(&row_grid, "ai_controller", false);
ai_selection.set_values(ai_options, selection);
ai_selection.connect_click_handler(std::bind(&mp_staging::on_ai_select, this, side, std::ref(ai_selection)));
connect_signal_notify_modified(ai_selection,
std::bind(&mp_staging::on_ai_select, this, side, std::ref(ai_selection)));
on_ai_select(side, ai_selection);
@ -226,7 +228,9 @@ void mp_staging::add_side_node(window& window, ng::side_engine_ptr side)
controller_selection.set_values(controller_names, side->current_controller_index());
controller_selection.set_active(controller_names.size() > 1);
controller_selection.connect_click_handler(std::bind(&mp_staging::on_controller_select, this, side, std::ref(row_grid)));
connect_signal_notify_modified(controller_selection,
std::bind(&mp_staging::on_controller_select, this, side, std::ref(row_grid)));
on_controller_select(side, row_grid);
@ -275,7 +279,9 @@ void mp_staging::add_side_node(window& window, ng::side_engine_ptr side)
team_selection.set_values(team_names, initial_team_selection);
team_selection.set_active(!saved_game);
team_selection.connect_click_handler(std::bind(&mp_staging::on_team_select, this, std::ref(window), side, std::ref(team_selection), _3, _4));
connect_signal_notify_modified(team_selection,
std::bind(&mp_staging::on_team_select, this, std::ref(window), side, std::ref(team_selection), _3, _4));
//
// Colors
@ -293,7 +299,9 @@ void mp_staging::add_side_node(window& window, ng::side_engine_ptr side)
color_selection.set_values(color_options, side->color());
color_selection.set_active(!saved_game);
color_selection.set_use_markup(true);
color_selection.connect_click_handler(std::bind(&mp_staging::on_color_select, this, side, std::ref(row_grid)));
connect_signal_notify_modified(color_selection,
std::bind(&mp_staging::on_color_select, this, side, std::ref(row_grid)));
//
// Gold and Income

View file

@ -441,9 +441,8 @@ void preferences_dialog::post_build(window& window)
set_resolution_list(res_list, window.video());
res_list.connect_click_handler(
std::bind(&preferences_dialog::handle_res_select,
this, std::ref(window)));
connect_signal_notify_modified(res_list,
std::bind(&preferences_dialog::handle_res_select, this, std::ref(window)));
/* SHOW FLOATING LABELS */
register_bool("show_floating_labels", true,

View file

@ -73,7 +73,9 @@ void statistics_dialog::pre_show(window& window)
menu_button& scenario_menu = find_widget<menu_button>(&window, "scenario_menu", false);
scenario_menu.set_values(menu_items, selection_index_);
scenario_menu.connect_click_handler(std::bind(&statistics_dialog::on_scenario_select, this, std::ref(window)));
connect_signal_notify_modified(scenario_menu,
std::bind(&statistics_dialog::on_scenario_select, this, std::ref(window)));
//
// Set up primary stats list

View file

@ -54,18 +54,6 @@ public:
/** See @ref styled_widget::get_state. */
virtual unsigned get_state() const override;
/** Inherited from clickable_item. */
void connect_click_handler(const event::signal_function& signal)
{
connect_signal_mouse_left_click(*this, signal);
}
/** Inherited from clickable_item. */
void disconnect_click_handler(const event::signal_function& signal)
{
disconnect_signal_mouse_left_click(*this, signal);
}
/***** ***** ***** setters / getters for members ***** ****** *****/
void set_values(const std::vector<::config>& values, int selected = 0);

View file

@ -54,18 +54,6 @@ public:
/** See @ref styled_widget::get_state. */
virtual unsigned get_state() const override;
/** Inherited from clickable_item. */
void connect_click_handler(const event::signal_function& signal)
{
connect_signal_mouse_left_click(*this, signal);
}
/** Inherited from clickable_item. */
void disconnect_click_handler(const event::signal_function& signal)
{
disconnect_signal_mouse_left_click(*this, signal);
}
/***** ***** ***** setters / getters for members ***** ****** *****/
/**