[gitg] Add setting to wrap lines in the diff view



commit 30aa7efb6ad09317b3974de4769b4e0cb97f6e25
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Sun Aug 9 20:11:47 2015 +0200

    Add setting to wrap lines in the diff view
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742031

 data/org.gnome.gitg.gschema.xml.in.in              |    7 ++++
 libgitg/gitg-diff-view-options.vala                |   16 ++++++++
 libgitg/gitg-diff-view.vala                        |   34 +++++++++++++++++-
 .../resources/ui/diff-view/diff-view-options.ui    |   39 ++++++++++++++++----
 libgitg/resources/ui/diff-view/diff-view.js        |   21 ++++++++++-
 plugins/diff/gitg-diff.vala                        |    6 +++
 6 files changed, 113 insertions(+), 10 deletions(-)
---
diff --git a/data/org.gnome.gitg.gschema.xml.in.in b/data/org.gnome.gitg.gschema.xml.in.in
index cf4bfeb..5dd3002 100644
--- a/data/org.gnome.gitg.gschema.xml.in.in
+++ b/data/org.gnome.gitg.gschema.xml.in.in
@@ -208,6 +208,13 @@
          inline.
       </_description>
     </key>
+    <key name="wrap" type="b">
+      <default>false</default>
+      <_summary>Wrap</_summary>
+      <_description>
+         Wrap lines.
+      </_description>
+    </key>
     <key name="context-lines" type="i">
       <default>3</default>
       <_summary>Number of Before/After Context Lines</_summary>
diff --git a/libgitg/gitg-diff-view-options.vala b/libgitg/gitg-diff-view-options.vala
index 8fae978..a00bebb 100644
--- a/libgitg/gitg-diff-view-options.vala
+++ b/libgitg/gitg-diff-view-options.vala
@@ -35,6 +35,9 @@ public class DiffViewOptions : Gtk.Grid
        [GtkChild (name = "label_ignore_whitespace")]
        private Gtk.Label d_label_ignore_whitespace;
 
+       [GtkChild (name = "wrap")]
+       private Gtk.Switch d_switch_wrap;
+
        [GtkChild (name = "adjustment_context")]
        private Gtk.Adjustment d_adjustment_context;
 
@@ -52,6 +55,7 @@ public class DiffViewOptions : Gtk.Grid
 
        public bool changes_inline { get; set; }
        public bool ignore_whitespace { get; set; }
+       public bool wrap { get; set; }
        public int context_lines { get; set; }
        public int tab_width { get; set; }
 
@@ -92,6 +96,12 @@ public class DiffViewOptions : Gtk.Grid
                                   BindingFlags.BIDIRECTIONAL |
                                   BindingFlags.SYNC_CREATE);
 
+               view.bind_property("wrap",
+                                  this,
+                                  "wrap",
+                                  BindingFlags.BIDIRECTIONAL |
+                                  BindingFlags.SYNC_CREATE);
+
                view.bind_property("context-lines",
                                   this,
                                   "context-lines",
@@ -116,6 +126,12 @@ public class DiffViewOptions : Gtk.Grid
                              BindingFlags.BIDIRECTIONAL |
                              BindingFlags.SYNC_CREATE);
 
+               bind_property("wrap",
+                             d_switch_wrap,
+                             "active",
+                             BindingFlags.BIDIRECTIONAL |
+                             BindingFlags.SYNC_CREATE);
+
                bind_property("context-lines",
                              d_adjustment_context,
                              "value",
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index 1bd82c0..c438228 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -131,7 +131,22 @@ namespace Gitg
                        }
                }
 
-               public bool wrap { get; set; default = true; }
+               private bool d_wrap;
+
+               public bool wrap
+               {
+                       get { return d_wrap; }
+                       construct set
+                       {
+                               if (d_wrap != value)
+                               {
+                                       d_wrap = value;
+                                       update_wrap();
+                               }
+                       }
+                       default = true;
+               }
+
                public bool staged { get; set; default = false; }
                public bool unstaged { get; set; default = false; }
                public bool show_parents { get; set; default = false; }
@@ -503,6 +518,23 @@ namespace Gitg
                        update();
                }
 
+               private void update_wrap()
+               {
+                       if (!d_loaded)
+                       {
+                               return;
+                       }
+
+                       var v = d_wrap ? "true" : "false";
+
+                       run_javascript.begin("update_wrap(" + v + ");", null, (obj, res) => {
+                               try
+                               {
+                                       run_javascript.end(res);
+                               } catch {}
+                       });
+               }
+
                private void update_tab_width()
                {
                        if (!d_loaded)
diff --git a/libgitg/resources/ui/diff-view/diff-view-options.ui 
b/libgitg/resources/ui/diff-view/diff-view-options.ui
index 62f36ee..6f3ac33 100644
--- a/libgitg/resources/ui/diff-view/diff-view-options.ui
+++ b/libgitg/resources/ui/diff-view/diff-view-options.ui
@@ -71,13 +71,38 @@
       </packing>
     </child>
     <child>
-      <object class="GtkSeparator" id="separator_first_options">
+      <object class="GtkSwitch" id="wrap">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="halign">center</property>
+        <property name="hexpand">False</property>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">2</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="label_wrap">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
+        <property name="halign">start</property>
+        <property name="hexpand">True</property>
+        <property name="label" translatable="yes">Wrap lines</property>
       </object>
       <packing>
         <property name="left_attach">0</property>
         <property name="top_attach">2</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkSeparator" id="separator_first_options">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">3</property>
         <property name="width">2</property>
       </packing>
     </child>
@@ -91,7 +116,7 @@
       </object>
       <packing>
         <property name="left_attach">0</property>
-        <property name="top_attach">6</property>
+        <property name="top_attach">7</property>
         <property name="width">2</property>
       </packing>
     </child>
@@ -102,7 +127,7 @@
       </object>
       <packing>
         <property name="left_attach">0</property>
-        <property name="top_attach">5</property>
+        <property name="top_attach">6</property>
         <property name="width">2</property>
       </packing>
     </child>
@@ -115,7 +140,7 @@
       </object>
       <packing>
         <property name="left_attach">0</property>
-        <property name="top_attach">4</property>
+        <property name="top_attach">5</property>
       </packing>
     </child>
     <child>
@@ -129,7 +154,7 @@
       </object>
       <packing>
         <property name="left_attach">1</property>
-        <property name="top_attach">4</property>
+        <property name="top_attach">5</property>
       </packing>
     </child>
     <child>
@@ -142,7 +167,7 @@
       </object>
       <packing>
         <property name="left_attach">0</property>
-        <property name="top_attach">3</property>
+        <property name="top_attach">4</property>
       </packing>
     </child>
     <child>
@@ -157,7 +182,7 @@
       </object>
       <packing>
         <property name="left_attach">1</property>
-        <property name="top_attach">3</property>
+        <property name="top_attach">4</property>
       </packing>
     </child>
   </template>
diff --git a/libgitg/resources/ui/diff-view/diff-view.js b/libgitg/resources/ui/diff-view/diff-view.js
index b14c449..13c68c2 100644
--- a/libgitg/resources/ui/diff-view/diff-view.js
+++ b/libgitg/resources/ui/diff-view/diff-view.js
@@ -583,13 +583,29 @@ function update_tab_width(width)
        if (tab_width_rule == null)
        {
                var sheet = document.getElementById('dynamic_styles').sheet;
-               sheet.addRule('#diff td.code', 'tab-size: ' + width, 0);
-               tab_width_rule = sheet.rules[0];
+               sheet.addRule('div#diff div.file table td.code', 'tab-size: ' + width, 0);
+               tab_width_rule = sheet.rules[sheet.rules.length - 1];
        }
 
        tab_width_rule.style.tabSize = width;
 }
 
+var wrap_rule = null;
+
+function update_wrap(wrap)
+{
+       settings.wrap = wrap;
+
+       if (wrap_rule == null)
+       {
+               var sheet = document.getElementById('dynamic_styles').sheet;
+               sheet.addRule('div#diff div.file table td.code', 'white-space: ' + (wrap ? 'pre-wrap' : 
'pre'), 0);
+               wrap_rule = sheet.rules[sheet.rules.length - 1];
+       }
+
+       wrap_rule.style.whiteSpace = wrap ? 'pre-wrap' : 'pre';
+}
+
 function expand_collapse_all()
 {
        var collapse = ($(this).text() === settings.strings.collapse_all);
@@ -656,6 +672,7 @@ function update_diff(id, lsettings)
        }
 
        update_tab_width(settings.tab_width);
+       update_wrap(settings.wrap);
 
        html_builder_worker = new Worker(workeruri);
        html_builder_tick = 0;
diff --git a/plugins/diff/gitg-diff.vala b/plugins/diff/gitg-diff.vala
index e5ee789..0e5e126 100644
--- a/plugins/diff/gitg-diff.vala
+++ b/plugins/diff/gitg-diff.vala
@@ -65,6 +65,12 @@ namespace GitgDiff
                                      SettingsBindFlags.GET |
                                      SettingsBindFlags.SET);
 
+                       settings.bind("wrap",
+                                     d_diff,
+                                     "wrap",
+                                     SettingsBindFlags.GET |
+                                     SettingsBindFlags.SET);
+
                        settings = new Settings("org.gnome.gitg.preferences.interface");
 
                        settings.bind("use-gravatar",


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