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 e8fb922516
commit 2adac53461
7 changed files with 10 additions and 19 deletions

View file

@ -249,7 +249,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

@ -398,7 +398,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

@ -55,7 +55,8 @@ void help_browser::pre_show(window& window)
tree_view& topic_tree = find_widget<tree_view>(&window, "topic_tree", false);
multi_page& topic_pages = find_widget<multi_page>(&window, "topic_text_pages", 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

@ -41,7 +41,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

@ -102,11 +102,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_;
@ -143,8 +138,6 @@ private:
tree_view_node* selected_item_;
std::function<void(widget&)> selection_change_callback_;
/**
* Resizes the content.
*

View file

@ -594,7 +594,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)
@ -618,9 +618,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)
@ -809,9 +807,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

@ -768,7 +768,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, _3, _4));
} 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");
}