Commit 1cb2a772 authored by Julian Sparber's avatar Julian Sparber

Add longpress gesture for selecting contacts

parent 29fed9c5
......@@ -105,6 +105,9 @@ public class Contacts.ContactList : ListBox {
private bool sort_on_surname = false; // keep in sync with the setting
private GestureLongPress long_press;
private bool got_long_press = false;
public UiState state { get; set; }
public ContactList (Settings settings, Store store, Query query) {
......@@ -116,6 +119,16 @@ public class Contacts.ContactList : ListBox {
this.notify["state"].connect (on_ui_state_changed);
// Connect long press gesture
this.long_press = new GestureLongPress (this);
this.long_press.pressed.connect ((g, x, y) => {
this.got_long_press = true;
var row = (ContactDataRow) get_row_at_y ((int) Math.round (y));
if (row != null) {
row.selector_button.active = this.state != UiState.SELECTING || !row.selector_button.active;
}
});
this.sort_on_surname = settings.sort_on_surname;
settings.changed["sort-on-surname"].connect(() => {
this.sort_on_surname = settings.sort_on_surname;
......@@ -237,16 +250,29 @@ public class Contacts.ContactList : ListBox {
row.destroy ();
}
public override void row_activated (ListBoxRow row) {
if (!this.got_long_press) {
var data = (ContactDataRow?) row as ContactDataRow;
if (data != null && this.state == UiState.SELECTING)
data.selector_button.active = !data.selector_button.active;
} else {
this.got_long_press = false;
}
}
public override void row_selected (ListBoxRow? row) {
var data = (ContactDataRow?) row as ContactDataRow;
var individual = data != null ? data.individual : null;
selection_changed (individual);
if (this.state != UiState.SELECTING) {
var data = (ContactDataRow?) row as ContactDataRow;
var individual = data != null ? data.individual : null;
selection_changed (individual);
#if HAVE_TELEPATHY
if (individual != null)
Contact.fetch_contact_info (individual);
if (individual != null)
Contact.fetch_contact_info (individual);
#endif
}
}
private bool filter_row (ListBoxRow row) {
var individual = ((ContactDataRow) row).individual;
return this.filter_query.is_match (individual) > 0;
......@@ -308,7 +334,6 @@ public class Contacts.ContactList : ListBox {
if (event.button == Gdk.BUTTON_SECONDARY) {
var row = (ContactDataRow) get_row_at_y ((int) Math.round (event.y));
if (row != null) {
select_row (row);
row.selector_button.active = this.state != UiState.SELECTING || !row.selector_button.active;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment