[gitg] Add preference to sort references by last activity



commit 2b9597144e382a47a98b066f97f9b1fa379846cc
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Sun Aug 9 09:30:16 2015 +0200

    Add preference to sort references by last activity
    
    https://bugzilla.gnome.org/show_bug.cgi?id=702594

 data/org.gnome.gitg.gschema.xml.in.in          |   12 ++
 gitg/history/gitg-history-refs-list.vala       |   85 +++++++++++-
 gitg/preferences/gitg-preferences-history.vala |   19 +++
 gitg/resources/ui/gitg-preferences-history.ui  |  187 ++++++++++++++----------
 4 files changed, 224 insertions(+), 79 deletions(-)
---
diff --git a/data/org.gnome.gitg.gschema.xml.in.in b/data/org.gnome.gitg.gschema.xml.in.in
index 4ec1439..5398928 100644
--- a/data/org.gnome.gitg.gschema.xml.in.in
+++ b/data/org.gnome.gitg.gschema.xml.in.in
@@ -10,6 +10,11 @@
     <value nick="all-commits" value="2"/>
   </enum>
 
+  <enum id="org.gnome.gitg.history.RefSortOrder">
+    <value nick="last-activity" value="0"/>
+    <value nick="name" value="1"/>
+  </enum>
+
   <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gitg.preferences" 
path="/org/gnome/gitg/preferences/">
     <child name="main" schema="org.gnome.gitg.preferences.main" />
     <child name="history" schema="org.gnome.gitg.preferences.history" />
@@ -113,6 +118,13 @@
         Setting that determines the default selection on startup of the history activity.
       </_description>
     </key>
+    <key name="reference-sort-order" enum="org.gnome.gitg.history.RefSortOrder">
+      <default>'last-activity'</default>
+      <_summary>Reference Sort Order</_summary>
+      <_description>
+        The order by which references in the history sidebar should be sorted.
+      </_description>
+    </key>
   </schema>
   <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gitg.preferences.commit" 
path="/org/gnome/gitg/preferences/commit/">
     <child name="message" schema="org.gnome.gitg.preferences.commit.message" />
diff --git a/gitg/history/gitg-history-refs-list.vala b/gitg/history/gitg-history-refs-list.vala
index b0b8053..af944f1 100644
--- a/gitg/history/gitg-history-refs-list.vala
+++ b/gitg/history/gitg-history-refs-list.vala
@@ -53,6 +53,12 @@ private class RefRow : RefTyped, Gtk.ListBoxRow
 {
        private const string version = Gitg.Config.VERSION;
 
+       public enum SortOrder
+       {
+               LAST_ACTIVITY = 0,
+               NAME = 1
+       }
+
        [GtkChild]
        private Gtk.Image d_icon;
 
@@ -67,6 +73,8 @@ private class RefRow : RefTyped, Gtk.ListBoxRow
 
        public Gitg.Ref? reference { get; set; }
 
+       private Ggit.Signature? d_updated;
+
        private Gtk.Entry? d_editing_entry;
        private uint d_idle_finish;
 
@@ -81,6 +89,27 @@ private class RefRow : RefTyped, Gtk.ListBoxRow
        {
                this.reference = reference;
 
+               if (reference != null)
+               {
+                       try
+                       {
+                               var obj = reference.resolve().lookup();
+
+                               if (obj is Ggit.Tag)
+                               {
+                                       d_updated = ((Ggit.Tag)obj).get_tagger();
+                               }
+                               else if (obj is Ggit.Commit)
+                               {
+                                       d_updated = ((Ggit.Commit)obj).get_committer();
+                               }
+                       }
+                       catch (Error e)
+                       {
+                               stderr.printf("%s\n", e.message);
+                       }
+               }
+
                if (animation == RefAnimation.ANIMATE)
                {
                        d_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN;
@@ -111,6 +140,11 @@ private class RefRow : RefTyped, Gtk.ListBoxRow
                d_revealer.notify["child-revealed"].connect(on_child_revealed);
        }
 
+       public Ggit.Signature? updated
+       {
+               get { return d_updated; }
+       }
+
        private void on_child_revealed(Object obj, ParamSpec spec)
        {
                if (!d_revealer.child_revealed)
@@ -190,7 +224,7 @@ private class RefRow : RefTyped, Gtk.ListBoxRow
                return 0;
        }
 
-       public int compare_to(RefRow other)
+       public int compare_to(RefRow other, SortOrder order)
        {
                if (reference == null)
                {
@@ -209,6 +243,17 @@ private class RefRow : RefTyped, Gtk.ListBoxRow
                        return ct;
                }
 
+               if (order == SortOrder.LAST_ACTIVITY)
+               {
+                       if (d_updated != null && other.updated != null)
+                       {
+                               var c1 = d_updated;
+                               var c2 = other.updated;
+
+                               return c2.get_time().compare(c1.get_time());
+                       }
+               }
+
                var t1 = label_text();
                var t2 = other.label_text();
 
@@ -442,6 +487,7 @@ public class RefsList : Gtk.ListBox
        private RefHeader? d_all_branches;
        private RefHeader? d_all_remotes;
        private RefHeader? d_all_tags;
+       private RefRow.SortOrder d_ref_sort_order;
 
        public signal void changed();
 
@@ -495,6 +541,41 @@ public class RefsList : Gtk.ListBox
 
                set_sort_func(sort_rows);
                set_filter_func(filter_func);
+
+               var settings = new Settings("org.gnome.gitg.preferences.history");
+
+               settings.bind("reference-sort-order",
+                             this,
+                             "reference-sort-order",
+                             SettingsBindFlags.GET | SettingsBindFlags.SET);
+       }
+
+       public string reference_sort_order
+       {
+               get
+               {
+                       if (d_ref_sort_order == RefRow.SortOrder.LAST_ACTIVITY)
+                       {
+                               return "last-activity";
+                       }
+                       else
+                       {
+                               return "name";
+                       }
+               }
+               set
+               {
+                       if (value == "last-activity")
+                       {
+                               d_ref_sort_order = RefRow.SortOrder.LAST_ACTIVITY;
+                       }
+                       else
+                       {
+                               d_ref_sort_order = RefRow.SortOrder.NAME;
+                       }
+
+                       invalidate_sort();
+               }
        }
 
        private RefHeader? find_header(Gtk.ListBoxRow row)
@@ -613,7 +694,7 @@ public class RefsList : Gtk.ListBox
                }
                else
                {
-                       return ref1.compare_to(ref2);
+                       return ref1.compare_to(ref2, d_ref_sort_order);
                }
        }
 
diff --git a/gitg/preferences/gitg-preferences-history.vala b/gitg/preferences/gitg-preferences-history.vala
index e32b73a..60ffe7f 100644
--- a/gitg/preferences/gitg-preferences-history.vala
+++ b/gitg/preferences/gitg-preferences-history.vala
@@ -50,6 +50,9 @@ public class PreferencesHistory : Gtk.Grid, GitgExt.Preferences
        [GtkChild (name = "select_all_commits" )]
        private Gtk.RadioButton d_select_all_commits;
 
+       [GtkChild (name = "sort_references_by_activity")]
+       private Gtk.CheckButton d_sort_references_by_activity;
+
        private Gtk.RadioButton[] d_select_buttons;
        private string[] d_select_names;
 
@@ -132,6 +135,22 @@ public class PreferencesHistory : Gtk.Grid, GitgExt.Preferences
                                notify_property("default-selection");
                        });
                }
+
+               settings.bind_with_mapping("reference-sort-order",
+                                          d_sort_references_by_activity,
+                                          "active",
+                                          SettingsBindFlags.GET | SettingsBindFlags.SET,
+                       (value, variant) => {
+                               value.set_boolean(variant.get_string() == "last-activity");
+                               return true;
+                       },
+
+                   (value, expected_type) => {
+                       return new Variant.string(value.get_boolean() ? "last-activity" : "name");
+                   },
+
+                   null, null
+               );
        }
 
        public string default_selection
diff --git a/gitg/resources/ui/gitg-preferences-history.ui b/gitg/resources/ui/gitg-preferences-history.ui
index e2d4391..202025e 100644
--- a/gitg/resources/ui/gitg-preferences-history.ui
+++ b/gitg/resources/ui/gitg-preferences-history.ui
@@ -24,18 +24,126 @@
         <property name="hexpand">True</property>
         <property name="row_spacing">6</property>
         <child>
+          <object class="GtkLabel" id="label2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">start</property>
+            <property name="label" translatable="yes">Default selection</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_start">12</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <child>
+              <object class="GtkRadioButton" id="select_current_branch">
+                <property name="label" translatable="yes">Current branch</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="halign">start</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkRadioButton" id="select_all_branches">
+                <property name="label" translatable="yes">All branches</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="halign">start</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">True</property>
+                <property name="group">select_current_branch</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkRadioButton" id="select_all_commits">
+                <property name="label" translatable="yes">All commits</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="halign">start</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">True</property>
+                <property name="group">select_current_branch</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label3">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">start</property>
+            <property name="label" translatable="yes">References</property>
+            <property name="margin_top">12</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="sort_references_by_activity">
+            <property name="label" translatable="yes">Sort references in the sidebar by latest 
activity</property>
+            <property name="use_action_appearance">False</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="halign">start</property>
+            <property name="draw_indicator">True</property>
+            <property name="margin_start">12</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">3</property>
+          </packing>
+        </child>
+        <child>
           <object class="GtkLabel" id="label1">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="halign">start</property>
             <property name="label" translatable="yes">Commits</property>
+            <property name="margin_top">12</property>
             <attributes>
               <attribute name="weight" value="bold"/>
             </attributes>
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">2</property>
+            <property name="top_attach">4</property>
           </packing>
         </child>
         <child>
@@ -146,82 +254,7 @@
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">3</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label2">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="halign">start</property>
-            <property name="label" translatable="yes">Default selection</property>
-            <attributes>
-              <attribute name="weight" value="bold"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkGrid" id="grid1">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="margin_start">12</property>
-            <property name="hexpand">True</property>
-            <property name="vexpand">True</property>
-            <child>
-              <object class="GtkRadioButton" id="select_current_branch">
-                <property name="label" translatable="yes">Current branch</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="halign">start</property>
-                <property name="active">True</property>
-                <property name="draw_indicator">True</property>
-              </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkRadioButton" id="select_all_branches">
-                <property name="label" translatable="yes">All branches</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="halign">start</property>
-                <property name="active">True</property>
-                <property name="draw_indicator">True</property>
-                <property name="group">select_current_branch</property>
-              </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkRadioButton" id="select_all_commits">
-                <property name="label" translatable="yes">All commits</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="halign">start</property>
-                <property name="active">True</property>
-                <property name="draw_indicator">True</property>
-                <property name="group">select_current_branch</property>
-              </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">2</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">1</property>
+            <property name="top_attach">5</property>
           </packing>
         </child>
       </object>


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