aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/add_conversation/select_jid_fragment.vala
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/ui/add_conversation/select_jid_fragment.vala')
-rw-r--r--main/src/ui/add_conversation/select_jid_fragment.vala74
1 files changed, 43 insertions, 31 deletions
diff --git a/main/src/ui/add_conversation/select_jid_fragment.vala b/main/src/ui/add_conversation/select_jid_fragment.vala
index bc349b6c..58f019c1 100644
--- a/main/src/ui/add_conversation/select_jid_fragment.vala
+++ b/main/src/ui/add_conversation/select_jid_fragment.vala
@@ -12,7 +12,7 @@ public class SelectJidFragment : Gtk.Box {
public signal void add_jid();
public signal void remove_jid(ListRow row);
public bool done {
- get { return filterable_list.get_selected_row() != null; }
+ get { return list.get_selected_row() != null; }
private set {}
}
@@ -22,43 +22,45 @@ public class SelectJidFragment : Gtk.Box {
[GtkChild] private unowned Button remove_button;
private StreamInteractor stream_interactor;
- private FilterableList filterable_list;
private Gee.List<Account> accounts;
-
private ArrayList<AddListRow> added_rows = new ArrayList<AddListRow>();
- public SelectJidFragment(StreamInteractor stream_interactor, FilterableList filterable_list, Gee.List<Account> accounts) {
+ private ListBox list;
+ private string[]? filter_values;
+
+ public SelectJidFragment(StreamInteractor stream_interactor, ListBox list, Gee.List<Account> accounts) {
this.stream_interactor = stream_interactor;
- this.filterable_list = filterable_list;
+ this.list = list;
this.accounts = accounts;
- filterable_list.visible = true;
- filterable_list.activate_on_single_click = false;
- filterable_list.vexpand = true;
- box.add(filterable_list);
+ list.activate_on_single_click = false;
+ list.vexpand = true;
+ box.append(list);
- filterable_list.set_sort_func(sort);
- filterable_list.row_selected.connect(check_buttons_active);
- filterable_list.row_selected.connect(() => { done = true; }); // just for notifying
+ list.set_sort_func(sort);
+ list.set_filter_func(filter);
+ list.row_selected.connect(check_buttons_active);
+ list.row_selected.connect(() => { done = true; }); // just for notifying
entry.changed.connect(() => { set_filter(entry.text); });
add_button.clicked.connect(() => { add_jid(); });
- remove_button.clicked.connect(() => { remove_jid(filterable_list.get_selected_row() as ListRow); });
+ remove_button.clicked.connect(() => { remove_jid(list.get_selected_row() as ListRow); });
}
public void set_filter(string str) {
if (entry.text != str) entry.text = str;
- foreach (AddListRow row in added_rows) filterable_list.remove(row);
+ foreach (AddListRow row in added_rows) list.remove(row);
added_rows.clear();
- string[] ? values = str == "" ? null : str.split(" ");
- filterable_list.set_filter_values(values);
+ filter_values = str == "" ? null : str.split(" ");
+ list.invalidate_filter();
+
try {
Jid parsed_jid = new Jid(str);
if (parsed_jid != null && parsed_jid.localpart != null) {
foreach (Account account in accounts) {
AddListRow row = new AddListRow(stream_interactor, parsed_jid, account);
- filterable_list.add(row);
+ list.append(row);
added_rows.add(row);
}
}
@@ -68,7 +70,7 @@ public class SelectJidFragment : Gtk.Box {
}
private void check_buttons_active() {
- ListBoxRow? row = filterable_list.get_selected_row();
+ ListBoxRow? row = list.get_selected_row();
bool active = row != null && !row.get_type().is_a(typeof(AddListRow));
remove_button.sensitive = active;
}
@@ -81,7 +83,29 @@ public class SelectJidFragment : Gtk.Box {
} else if (al2 != null && al1 == null) {
return 1;
}
- return filterable_list.sort(row1, row2);
+
+ ListRow? c1 = (row1.child as ListRow);
+ ListRow? c2 = (row2.child as ListRow);
+ if (c1 != null && c2 != null) {
+ return c1.name_label.label.collate(c2.name_label.label);
+ }
+
+ return 0;
+ }
+
+ private bool filter(ListBoxRow r) {
+ ListRow? row = (r.child as ListRow);
+ if (row == null) return true;
+
+ if (filter_values != null) {
+ foreach (string filter in filter_values) {
+ if (!(row.name_label.label.down().contains(filter.down()) ||
+ row.jid.to_string().down().contains(filter.down()))) {
+ return false;
+ }
+ }
+ }
+ return true;
}
private class AddListRow : ListRow {
@@ -101,16 +125,4 @@ public class SelectJidFragment : Gtk.Box {
}
}
-public abstract class FilterableList : Gtk.ListBox {
- public string[]? filter_values;
-
- public void set_filter_values(string[] values) {
- if (filter_values == values) return;
- filter_values = values;
- invalidate_filter();
- }
-
- public abstract int sort(ListBoxRow row1, ListBoxRow row2);
-}
-
}