GUI2/Tree View: use NOTIFY_MODIFIED events instead of manual callbacks

Unlike other widgets where `this` is the event target, the tree nodes fire the event
with the tree widget itself as the target.

I had added a fire-event call in f97dc8ae12, but with
the target as the node. I don't think there was any way that would have worked...
changed.
This commit is contained in:
Charles Dang 2018-07-14 12:02:44 +11:00
parent 996551e6f7
commit e62ec5f806
7 changed files with 10 additions and 19 deletions

View file

@ -201,7 +201,8 @@ void campaign_selection::pre_show(window& window)
/***** Setup campaign tree. *****/
tree_view& tree = find_widget<tree_view>(&window, "campaign_tree", false);
tree.set_selection_change_callback(std::bind(&campaign_selection::campaign_selected, this, std::ref(window)));
connect_signal_notify_modified(tree,
std::bind(&campaign_selection::campaign_selected, this, std::ref(window)));
toggle_button& sort_name = find_widget<toggle_button>(&window, "sort_name", false);
toggle_button& sort_time = find_widget<toggle_button>(&window, "sort_time", false);

View file

@ -396,7 +396,8 @@ public:
auto left_button = find_widget<button>(&window, "page_left", false, true);
auto right_button = find_widget<button>(&window, "page_right", false, true);
stuff_list->set_selection_change_callback(std::bind(&gamestate_inspector::controller::handle_stuff_list_item_clicked, this, _1));
connect_signal_notify_modified(*stuff_list,
std::bind(&gamestate_inspector::controller::handle_stuff_list_item_clicked, this, _1));
connect_signal_mouse_left_click(
*copy_button,

View file

@ -56,7 +56,8 @@ void help_browser::pre_show(window& window)
connect_signal_mouse_left_click(next_button,
std::bind(&help_browser::on_history_navigate, this, std::ref(window), false));
topic_tree.set_selection_change_callback(std::bind(&help_browser::on_topic_select, this, std::ref(window)));
connect_signal_notify_modified(topic_tree,
std::bind(&help_browser::on_topic_select, this, std::ref(window)));
window.keyboard_capture(&topic_tree);

View file

@ -40,7 +40,6 @@ tree_view::tree_view(const implementation::builder_tree_view& builder)
, need_layout_(false)
, root_node_(new tree_view_node("root", nullptr, *this, std::map<std::string, string_map>()))
, selected_item_(nullptr)
, selection_change_callback_()
{
connect_signal<event::LEFT_BUTTON_DOWN>(
std::bind(&tree_view::signal_handler_left_button_down, this, _2), event::dispatcher::back_pre_child);

View file

@ -97,11 +97,6 @@ public:
return selected_item_;
}
void set_selection_change_callback(std::function<void(widget&)> callback)
{
selection_change_callback_ = callback;
}
const std::vector<node_definition>& get_node_definitions() const
{
return node_definitions_;
@ -138,8 +133,6 @@ private:
tree_view_node* selected_item_;
std::function<void(widget&)> selection_change_callback_;
/**
* Resizes the content.
*

View file

@ -577,7 +577,7 @@ void tree_view_node::signal_handler_left_button_click(const event::ui_event even
unfolded_ = unfolded_new;
is_folded() ? fold_internal() : unfold_internal();
fire(event::NOTIFY_MODIFIED, *this, nullptr);
fire(event::NOTIFY_MODIFIED, get_tree_view(), nullptr);
}
void tree_view_node::signal_handler_label_left_button_click(const event::ui_event event, bool& handled, bool& halt)
@ -601,9 +601,7 @@ void tree_view_node::signal_handler_label_left_button_click(const event::ui_even
get_tree_view().selected_item_ = this;
if(get_tree_view().selection_change_callback_) {
get_tree_view().selection_change_callback_(get_tree_view());
}
fire(event::NOTIFY_MODIFIED, get_tree_view(), nullptr);
}
void tree_view_node::init_grid(grid* g, const std::map<std::string /* widget id */, string_map>& data)
@ -792,9 +790,7 @@ void tree_view_node::select_node(bool expand_parents)
get_tree_view().selected_item_ = this;
if(get_tree_view().selection_change_callback_) {
get_tree_view().selection_change_callback_(get_tree_view());
}
fire(event::NOTIFY_MODIFIED, get_tree_view(), nullptr);
label_->set_value_bool(true);
}

View file

@ -746,7 +746,7 @@ int intf_set_dialog_callback(lua_State* L)
static dialog_callback_wrapper wrapper;
connect_signal_notify_modified(*l, std::bind(&dialog_callback_wrapper::forward, wrapper, w));
} else if(gui2::tree_view* tv = dynamic_cast<gui2::tree_view*>(w)) {
tv->set_selection_change_callback(&dialog_callback);
connect_signal_notify_modified(*tv, std::bind(dialog_callback, _1));
} else {
return luaL_argerror(L, lua_gettop(L), "unsupported widget");
}