[gnome-contacts] Scroll to contact when adding/updating contact



commit b7f432fc3ec236ab12c0fbed0ff3036005a5358f
Author: Krifa75 <yahiaoui fakhri gmail com>
Date:   Wed Jun 30 18:48:19 2021 +0200

    Scroll to contact when adding/updating contact

 src/contacts-contact-list.vala | 19 ++++++++++++++++++-
 src/contacts-list-pane.vala    |  4 ++++
 src/contacts-main-window.vala  |  1 +
 3 files changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/src/contacts-contact-list.vala b/src/contacts-contact-list.vala
index 63d90e45..3ac0c70a 100644
--- a/src/contacts-contact-list.vala
+++ b/src/contacts-contact-list.vala
@@ -287,7 +287,24 @@ public class Contacts.ContactList : Gtk.ListBox {
       return;
     }
 
-    select_row (find_row_for_contact (individual));
+    ContactDataRow? row = find_row_for_contact (individual);
+    select_row (row);
+    scroll_to_contact (row);
+  }
+
+  public void scroll_to_contact (Gtk.ListBoxRow? row = null) {
+    unowned ContactDataRow? selected_row = null;
+
+    if (row == null)
+      selected_row = get_selected_row () as ContactDataRow;
+    else
+      selected_row = row as ContactDataRow;
+
+    GLib.Timeout.add (100, () => {
+      if (selected_row != null)
+        selected_row.grab_focus ();
+      return GLib.Source.REMOVE;
+    });
   }
 
   public void hide_contact (Individual? individual) {
diff --git a/src/contacts-list-pane.vala b/src/contacts-list-pane.vala
index 1cf62d59..5439b365 100644
--- a/src/contacts-list-pane.vala
+++ b/src/contacts-list-pane.vala
@@ -94,6 +94,10 @@ public class Contacts.ListPane : Gtk.Frame {
     this.contacts_list.select_contact (individual);
   }
 
+  public void scroll_to_contact () {
+    this.contacts_list.scroll_to_contact ();
+  }
+
   public void hide_contact (Individual? individual) {
     this.contacts_list.hide_contact (individual);
   }
diff --git a/src/contacts-main-window.vala b/src/contacts-main-window.vala
index f8a46d6c..486c16aa 100644
--- a/src/contacts-main-window.vala
+++ b/src/contacts-main-window.vala
@@ -338,6 +338,7 @@ public class Contacts.MainWindow : Hdy.ApplicationWindow {
       this.state = UiState.SHOWING;
     }
     this.contact_pane.stop_editing (cancel);
+    this.list_pane.scroll_to_contact ();
 
     if (this.contact_pane.individual != null) {
       this.right_header.title = this.contact_pane.individual.display_name;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]