[gitg] Bind wrap and tab_width properties



commit 99eca15797bbeaf2d062fe1dca99807b8a12f93a
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Wed Aug 26 20:12:40 2015 +0200

    Bind wrap and tab_width properties

 libgitg/gitg-diff-view-file.vala |   12 ++++++++++++
 libgitg/gitg-diff-view-hunk.vala |   28 ++++++++++++++++++++++++++++
 libgitg/gitg-diff-view.vala      |   37 +++++++------------------------------
 3 files changed, 47 insertions(+), 30 deletions(-)
---
diff --git a/libgitg/gitg-diff-view-file.vala b/libgitg/gitg-diff-view-file.vala
index d598691..f1a0b4c 100644
--- a/libgitg/gitg-diff-view-file.vala
+++ b/libgitg/gitg-diff-view-file.vala
@@ -65,6 +65,16 @@ class Gitg.DiffViewFile : Gtk.Grid
                }
        }
 
+       public bool wrap
+       {
+               get; set;
+       }
+
+       public int tab_width
+       {
+               get; set;
+       }
+
        public int maxlines
        {
                get; set;
@@ -118,6 +128,8 @@ class Gitg.DiffViewFile : Gtk.Grid
                d_grid_hunks.add(widget);
 
                this.bind_property("maxlines", widget, "maxlines", BindingFlags.DEFAULT | 
BindingFlags.SYNC_CREATE);
+               this.bind_property("wrap", widget, "wrap", BindingFlags.DEFAULT | BindingFlags.SYNC_CREATE);
+               this.bind_property("tab-width", widget, "tab-width", BindingFlags.DEFAULT | 
BindingFlags.SYNC_CREATE);
 
                sensitive = true;
        }
diff --git a/libgitg/gitg-diff-view-hunk.vala b/libgitg/gitg-diff-view-hunk.vala
index 2f10d07..3994a18 100644
--- a/libgitg/gitg-diff-view-hunk.vala
+++ b/libgitg/gitg-diff-view-hunk.vala
@@ -61,6 +61,34 @@ class Gitg.DiffViewHunk : Gtk.Grid
                get; set;
        }
 
+       public bool wrap
+       {
+               get { return d_sourceview_hunk.wrap_mode != Gtk.WrapMode.NONE; }
+               set
+               {
+                       if (value)
+                       {
+                               d_sourceview_hunk.wrap_mode = Gtk.WrapMode.WORD_CHAR;
+                       }
+                       else
+                       {
+                               d_sourceview_hunk.wrap_mode = Gtk.WrapMode.NONE;
+                       }
+               }
+       }
+
+       public int tab_width
+       {
+               get { return (int)d_sourceview_hunk.tab_width; }
+               set
+               {
+                       if (value > 0)
+                       {
+                               d_sourceview_hunk.tab_width = (uint)value;
+                       }
+               }
+       }
+
        private DiffViewLinesRenderer d_old_lines;
        private DiffViewLinesRenderer d_new_lines;
        private DiffViewLinesRenderer d_sym_lines;
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index 9974558..763fcc9 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -91,19 +91,10 @@ public class Gitg.DiffView : Gtk.Grid
                }
        }
 
-       private bool d_wrap;
-
        public bool wrap
        {
-               get { return d_wrap; }
-               construct set
-               {
-                       if (d_wrap != value)
-                       {
-                               d_wrap = value;
-                               update_wrap();
-                       }
-               }
+               get;
+               construct set;
                default = true;
        }
 
@@ -119,19 +110,10 @@ public class Gitg.DiffView : Gtk.Grid
                default = true;
        }
 
-       int d_tab_width;
-
        public int tab_width
        {
-               get { return d_tab_width; }
-               construct set
-               {
-                       if (d_tab_width != value)
-                       {
-                               d_tab_width = value;
-                               update_tab_width();
-                       }
-               }
+               get;
+               construct set;
                default = 4;
        }
 
@@ -218,14 +200,6 @@ public class Gitg.DiffView : Gtk.Grid
                }
        }
 
-       private void update_wrap()
-       {
-       }
-
-       private void update_tab_width()
-       {
-       }
-
        private void update()
        {
                // If both `d_diff` and `d_commit` are null, clear
@@ -389,6 +363,9 @@ public class Gitg.DiffView : Gtk.Grid
                        d_grid_files.add(file);
 
                        file.notify["expanded"].connect(auto_update_expanded);
+
+                       this.bind_property("wrap", file, "wrap", BindingFlags.DEFAULT | 
BindingFlags.SYNC_CREATE);
+                       this.bind_property("tab-width", file, "tab-width", BindingFlags.DEFAULT | 
BindingFlags.SYNC_CREATE);
                }
        }
 


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