[gitg/wip/remove-webkit] Use same gutter width for lines in all hunks



commit d17f06efadb87bf003ad94cb36f1cff147d96556
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Tue Aug 25 21:42:41 2015 +0200

    Use same gutter width for lines in all hunks

 libgitg/gitg-diff-view-file.vala           |    7 +++++++
 libgitg/gitg-diff-view-hunk.vala           |    8 ++++++++
 libgitg/gitg-diff-view-lines-renderer.vala |   24 +++++++++++++++++++++---
 libgitg/gitg-diff-view.vala                |   14 ++++++++++++++
 4 files changed, 50 insertions(+), 3 deletions(-)
---
diff --git a/libgitg/gitg-diff-view-file.vala b/libgitg/gitg-diff-view-file.vala
index dbc94ce..d598691 100644
--- a/libgitg/gitg-diff-view-file.vala
+++ b/libgitg/gitg-diff-view-file.vala
@@ -65,6 +65,11 @@ class Gitg.DiffViewFile : Gtk.Grid
                }
        }
 
+       public int maxlines
+       {
+               get; set;
+       }
+
        public Ggit.DiffDelta delta
        {
                get;
@@ -112,6 +117,8 @@ class Gitg.DiffViewFile : Gtk.Grid
 
                d_grid_hunks.add(widget);
 
+               this.bind_property("maxlines", widget, "maxlines", BindingFlags.DEFAULT | 
BindingFlags.SYNC_CREATE);
+
                sensitive = true;
        }
 }
diff --git a/libgitg/gitg-diff-view-hunk.vala b/libgitg/gitg-diff-view-hunk.vala
index c53465b..cf418ad 100644
--- a/libgitg/gitg-diff-view-hunk.vala
+++ b/libgitg/gitg-diff-view-hunk.vala
@@ -56,6 +56,11 @@ class Gitg.DiffViewHunk : Gtk.Grid
                get { return d_removed; }
        }
 
+       public int maxlines
+       {
+               get; set;
+       }
+
        private DiffViewLinesRenderer d_old_lines;
        private DiffViewLinesRenderer d_new_lines;
        private DiffViewLinesRenderer d_sym_lines;
@@ -68,6 +73,9 @@ class Gitg.DiffViewHunk : Gtk.Grid
                d_new_lines = new DiffViewLinesRenderer(hunk, lines, DiffViewLinesRenderer.Style.NEW);
                d_sym_lines = new DiffViewLinesRenderer(hunk, lines, DiffViewLinesRenderer.Style.SYMBOL);
 
+               this.bind_property("maxlines", d_old_lines, "maxlines", BindingFlags.DEFAULT | 
BindingFlags.SYNC_CREATE);
+               this.bind_property("maxlines", d_new_lines, "maxlines", BindingFlags.DEFAULT | 
BindingFlags.SYNC_CREATE);
+
                d_old_lines.xpad = 8;
                d_new_lines.xpad = 8;
                d_sym_lines.xpad = 6;
diff --git a/libgitg/gitg-diff-view-lines-renderer.vala b/libgitg/gitg-diff-view-lines-renderer.vala
index aa17c17..7b162bf 100644
--- a/libgitg/gitg-diff-view-lines-renderer.vala
+++ b/libgitg/gitg-diff-view-lines-renderer.vala
@@ -49,14 +49,32 @@ class Gitg.DiffViewLinesRenderer : Gtk.SourceGutterRendererText
                get; construct set;
        }
 
+       private int d_maxlines;
+
+       public int maxlines
+       {
+               get { return d_maxlines; }
+               set
+               {
+                       if (value > d_maxlines)
+                       {
+                               d_maxlines = value;
+
+                               calculate_num_digits();
+                               recalculate_size();
+                       }
+               }
+       }
+
        public DiffViewLinesRenderer(Ggit.DiffHunk hunk, Gee.ArrayList<Ggit.DiffLine> lines, Style style)
        {
                Object(hunk: hunk, lines: lines, style: style);
+               set_alignment(1.0f, 0.5f);
        }
 
        protected override void constructed()
        {
-               calulate_num_digits();
+               calculate_num_digits();
                precalculate_line_strings();
        }
 
@@ -160,7 +178,7 @@ class Gitg.DiffViewLinesRenderer : Gtk.SourceGutterRendererText
                set_size(size);
        }
 
-       private void calulate_num_digits()
+       private void calculate_num_digits()
        {
                var num_digits = 0;
 
@@ -169,7 +187,7 @@ class Gitg.DiffViewLinesRenderer : Gtk.SourceGutterRendererText
                        var oldn = hunk.get_old_start() + hunk.get_old_lines();
                        var newn = hunk.get_new_start() + hunk.get_new_lines();
 
-                       var num = int.max(oldn, newn);
+                       var num = int.max(int.max(oldn, newn), d_maxlines);
 
                        while (num > 0)
                        {
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index 61a59c1..95e76a9 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -264,10 +264,14 @@ public class Gitg.DiffView : Gtk.Grid
 
        private void update_diff(Ggit.Diff diff, Cancellable? cancellable)
        {
+               var files = new Gee.LinkedList<Gitg.DiffViewFile>();
+
                Gitg.DiffViewFile? current_file = null;
                Ggit.DiffHunk? current_hunk = null;
                Gee.ArrayList<Ggit.DiffLine>? current_lines = null;
 
+               var maxlines = 0;
+
                Anon add_hunk = () => {
                        if (current_hunk != null)
                        {
@@ -286,6 +290,8 @@ public class Gitg.DiffView : Gtk.Grid
                                current_file.show();
                                d_grid_files.add(current_file);
 
+                               files.add(current_file);
+
                                current_file = null;
                        }
                };
@@ -321,6 +327,9 @@ public class Gitg.DiffView : Gtk.Grid
                                                return 1;
                                        }
 
+                                       maxlines = int.max(maxlines, hunk.get_old_start() + 
hunk.get_old_lines());
+                                       maxlines = int.max(maxlines, hunk.get_new_start() + 
hunk.get_new_lines());
+
                                        add_hunk();
 
                                        current_hunk = hunk;
@@ -347,6 +356,11 @@ public class Gitg.DiffView : Gtk.Grid
 
                add_hunk();
                add_file();
+
+               foreach (var file in files)
+               {
+                       file.maxlines = maxlines;
+               }
        }
 
        public async PatchSet[] get_selection()


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