[gitg] Scroll to row after selecting it



commit c2fd37bba4aa291094f9fb01067b72df1f87c7d2
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Wed Aug 5 19:36:42 2015 +0200

    Scroll to row after selecting it

 gitg/history/gitg-history-refs-list.vala |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/gitg/history/gitg-history-refs-list.vala b/gitg/history/gitg-history-refs-list.vala
index 1d71d9d..33fed66 100644
--- a/gitg/history/gitg-history-refs-list.vala
+++ b/gitg/history/gitg-history-refs-list.vala
@@ -823,6 +823,8 @@ public class RefsList : Gtk.ListBox
                if (d_all_commits != null)
                {
                        select_row(d_all_commits);
+                       scroll_to_row(d_all_commits);
+
                        return true;
                }
 
@@ -839,7 +841,10 @@ public class RefsList : Gtk.ListBox
                {
                        if (ourref.get_name() == refname)
                        {
-                               select_row(d_ref_map[ourref]);
+                               var row = d_ref_map[ourref];
+
+                               select_row(row);
+                               scroll_to_row(row);
                                return true;
                        }
                }
@@ -1114,6 +1119,26 @@ public class RefsList : Gtk.ListBox
 
                return ret;
        }
+
+       private void scroll_to_row(RefRow row)
+       {
+               var adj = get_adjustment();
+
+               Gtk.Allocation alloc;
+               row.get_allocation(out alloc);
+
+               var v = adj.get_value();
+               var s = adj.get_page_size();
+
+               if (alloc.y < v)
+               {
+                       adj.set_value(alloc.y);
+               }
+               else if (alloc.y + alloc.height > v + s)
+               {
+                       adj.set_value(alloc.y + alloc.height - s);
+               }
+       }
 }
 
 }


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