Skip to content

Commit

Permalink
Fix logic error in DragList.vala:bind_model
Browse files Browse the repository at this point in the history
  • Loading branch information
JMoerman committed Oct 30, 2017
1 parent f02cb79 commit fb70318
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/view/DragList.vala
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,19 @@ public class DragList : Gtk.Bin {
if (model == null) {
assert (create_widget_func == null);
}

remove_model ();
listbox.@foreach((widget) => {
remove(widget);
});

this.model = model;
this.create_widget_func = (owned) create_widget_func;

if (this.model == null) {
return;
}

for (uint i = 0; i < model.get_n_items (); i++) {
var row = this.create_widget_func(model.get_item (i));
_add_row (row);
Expand All @@ -181,6 +188,13 @@ public class DragList : Gtk.Bin {
model.item_moved.connect (on_model_item_moved);
}

private void remove_model () {
if (this.model != null) {
this.model.items_changed.disconnect (on_model_items_changed);
this.model.item_moved.disconnect (on_model_item_moved);
}
}

private void on_model_items_changed (uint index, uint removed, uint added) {
bool need_to_select_closest = false;
block_row_selected = true;
Expand Down

0 comments on commit fb70318

Please sign in to comment.