[gitg] Automatically resize diff stat listbox



commit a1c0cacfbc80a9a0c007f90d2f3a93acacab36cb
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Mon Jul 8 18:37:23 2013 +0200

    Automatically resize diff stat listbox
    
    This patch will shrink the list box for the diff stat items up to a
    number of specified items. If more items are added to the list, then
    scrollbars will be shown.

 gitg/commit/gitg-commit-dialog.vala     |   34 +++++++++++++++++++++++++++++++
 gitg/resources/ui/gitg-commit-dialog.ui |    2 +-
 2 files changed, 35 insertions(+), 1 deletions(-)
---
diff --git a/gitg/commit/gitg-commit-dialog.vala b/gitg/commit/gitg-commit-dialog.vala
index 20469c0..82da9b6 100644
--- a/gitg/commit/gitg-commit-dialog.vala
+++ b/gitg/commit/gitg-commit-dialog.vala
@@ -65,6 +65,9 @@ class Dialog : Gtk.Dialog
        [GtkChild (name = "list_box_stats")]
        private Gtk.ListBox d_list_box_stats;
 
+       [GtkChild (name = "scrolled_window_stats")]
+       private Gtk.ScrolledWindow d_scrolled_window_stats;
+
        private bool d_show_markup;
        private bool d_show_right_margin;
        private bool d_show_subject_margin;
@@ -87,6 +90,13 @@ class Dialog : Gtk.Dialog
                construct set { d_diff_list = value; }
        }
 
+       public int max_visible_stat_items
+       {
+               get;
+               construct set;
+               default = 3;
+       }
+
        public GtkSource.View source_view_message
        {
                get { return d_source_view_message; }
@@ -418,6 +428,7 @@ class Dialog : Gtk.Dialog
        private void iterate_diff_list()
        {
                var n = diff_list.get_num_deltas();
+               int num = 0;
 
                for (var i = 0; i < n; ++i)
                {
@@ -456,7 +467,30 @@ class Dialog : Gtk.Dialog
                        row.show_all();
 
                        d_list_box_stats.add(row);
+                       ++num;
                }
+
+               d_list_box_stats.size_allocate.connect(() => {
+                       update_min_stat_size(num);
+               });
+       }
+
+       private void update_min_stat_size(int num)
+       {
+               int n = int.min(num, max_visible_stat_items);
+
+               var lastrow = d_list_box_stats.get_row_at_index(n - 1);
+
+               Gtk.Allocation allocation;
+               lastrow.get_allocation(out allocation);
+
+               if (n == num)
+               {
+                       d_scrolled_window_stats.set_policy(Gtk.PolicyType.NEVER,
+                                                          Gtk.PolicyType.NEVER);
+               }
+
+               d_scrolled_window_stats.set_min_content_height(allocation.y + allocation.height);
        }
 
        private void update_too_long_tag()
diff --git a/gitg/resources/ui/gitg-commit-dialog.ui b/gitg/resources/ui/gitg-commit-dialog.ui
index b3f0cb7..c445d9d 100644
--- a/gitg/resources/ui/gitg-commit-dialog.ui
+++ b/gitg/resources/ui/gitg-commit-dialog.ui
@@ -240,7 +240,7 @@
             <child>
               <object class="GtkScrolledWindow" id="scrolled_window_stats">
                 <property name="visible">True</property>
-                <property name="vexpand">True</property>
+                <property name="vexpand">False</property>
                 <property name="shadow_type">in</property>
                 <style>
                   <class name="view"/>


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