[gitg/wip/dashrow] dash view: use a template for the row



commit 777f04df978167d576daaf5082585d8ff24c4cc6
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Tue Jun 25 18:43:56 2013 +0200

    dash view: use a template for the row

 libgitg/gitg-dash-view.vala             |  161 ++++++++++++++++--------------
 libgitg/resources/gitg-dash-view-row.ui |  105 ++++++++++++++++++++
 libgitg/resources/resources.xml         |    3 +
 3 files changed, 194 insertions(+), 75 deletions(-)
---
diff --git a/libgitg/gitg-dash-view.vala b/libgitg/gitg-dash-view.vala
index 94f2260..73d0d56 100644
--- a/libgitg/gitg-dash-view.vala
+++ b/libgitg/gitg-dash-view.vala
@@ -24,16 +24,89 @@ namespace Gitg
                private static Gtk.IconSize d_icon_size;
                private string? d_filter_text;
 
+               [GtkTemplate (ui = "/org/gnome/gitg/gtk/dash-view")]
                private class DashRow : Gtk.ListBoxRow
                {
-                       public Repository? repository;
-                       public DateTime time;
-                       public ProgressBin bin;
-                       public Gtk.Image image;
-                       public Gtk.Label repository_label;
-                       public Gtk.Label branch_label;
-                       public Gtk.Arrow arrow;
-                       public Gtk.Spinner spinner;
+                       private Repository? d_repository;
+                       private DateTime d_time;
+                       [GtkChild]
+                       private ProgressBin d_progress_bin;
+                       [GtkChild]
+                       private Gtk.Image d_image;
+                       [GtkChild]
+                       private Gtk.Label d_repository_label;
+                       [GtkChild]
+                       private Gtk.Label d_branch_label;
+                       [GtkChild]
+                       private Gtk.Arrow d_arrow;
+                       [GtkChild]
+                       private Gtk.Spinner d_spinner;
+
+                       public Repository? repository
+                       {
+                               get { return d_repository; }
+                               set
+                               {
+                                       d_repository = value;
+
+                                       string branch_name = "";
+                                       if (d_repsitory != null)
+                                       {
+                                               try
+                                               {
+                                                       var head = d_repository.get_head();
+                                                       branch_name = head.parsed_name.shortname;
+                                               }
+                                               catch {}
+                                       }
+
+                                       d_branch_label.set_markup("<small>%s</small>".printf(branch_name));
+                               }
+                       }
+
+                       public DateTime time
+                       {
+                               get { return d_time; }
+                               set { d_time = value; }
+                       }
+
+                       public double fraction
+                       {
+                               set { d_progress_bin.fraction = value; }
+                       }
+
+                       public bool loading
+                       {
+                               set
+                               {
+                                       if (value)
+                                       {
+                                               d_arrow.hide();
+                                               d_spinner.show();
+                                               d_spinner.start();
+                                       }
+                                       else
+                                       {
+                                               d_spinner.stop();
+                                               d_spinner.hide();
+                                               d_arrow.show();
+                                               d_bin.fraction = 0;
+                                       }
+                               }
+                       }
+
+                       DashRow(string name, string branch_name, bool local)
+                       {
+                               d_time = new DateTime.now_local();
+
+                               // FIXME: Change folder image for a repository uses github remote.
+                               var folder_icon_name = local ? "folder" : "folder-remote";
+                               d_image.set_from_icon_name(folder_icon_name, d_icon_size);
+                               d_repository_label.set_markup("<b>%s</b>".printf(name));
+                               d_branch_label.set_markup("<small>%s</small>".printf(branch_name));
+
+                               add(row);
+                       }
                }
 
                public signal void repository_activated(Repository repository);
@@ -143,57 +216,6 @@ namespace Gitg
                        return row;
                }
 
-               private DashRow create_repository_row(string name, string branch_name, bool spin, bool local)
-               {
-                       var row = new DashRow();
-                       row.repository = null;
-                       row.time = new DateTime.now_local();
-                       row.bin = new ProgressBin();
-                       row.add(row.bin);
-                       var grid = new Gtk.Grid();
-                       grid.margin = 12;
-                       grid.column_spacing = 10;
-                       row.bin.add(grid);
-
-                       // FIXME: Change folder image for a repository uses github remote.
-                       var folder_icon_name = local ? "folder" : "folder-remote";
-                       row.image = new Gtk.Image.from_icon_name(folder_icon_name, d_icon_size);
-                       grid.attach(row.image, 0, 0, 1, 2);
-
-                       row.repository_label = new Gtk.Label(null);
-                       row.repository_label.set_markup("<b>%s</b>".printf(name));
-                       row.repository_label.ellipsize = Pango.EllipsizeMode.END;
-                       row.repository_label.halign = Gtk.Align.START;
-                       row.repository_label.valign = Gtk.Align.END;
-                       row.repository_label.hexpand = true;
-                       grid.attach(row.repository_label, 1, 0, 1, 1);
-
-                       row.branch_label = new Gtk.Label("");
-                       row.branch_label.set_markup("<small>%s</small>".printf(branch_name));
-                       row.branch_label.ellipsize = Pango.EllipsizeMode.END;
-                       row.branch_label.valign = Gtk.Align.START;
-                       row.branch_label.halign = Gtk.Align.START;
-                       row.branch_label.get_style_context().add_class("dim-label");
-                       grid.attach(row.branch_label, 1, 1, 1, 1);
-
-                       row.arrow = new Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE);
-                       grid.attach(row.arrow, 2, 0, 1, 2);
-
-                       row.show_all();
-                       add(row);
-
-                       if (spin)
-                       {
-                               row.arrow.hide();
-                               row.spinner = new Gtk.Spinner();
-                               grid.attach(row.spinner, 3, 0, 1, 2);
-                               row.spinner.show();
-                               row.spinner.start();
-                       }
-
-                       return row;
-               }
-
                private void add_repository_to_recent_manager(string uri)
                {
                        var recent_manager = Gtk.RecentManager.get_default();
@@ -226,7 +248,7 @@ namespace Gitg
                                }
                                catch {}
 
-                               row = create_repository_row(repository.name, head_name, false, local);
+                               row = new DashRow(repository.name, head_name, local);
                                row.repository = repository;
                        }
                        else
@@ -254,7 +276,7 @@ namespace Gitg
                                        var options = new Ggit.CloneOptions();
                                        options.set_is_bare(is_bare);
                                        options.set_fetch_progress_callback((stats) => {
-                                               row.bin.fraction = (stats.get_received_objects() + 
stats.get_indexed_objects()) / (double)(2 * stats.get_total_objects());
+                                               row.fraction = (stats.get_received_objects() + 
stats.get_indexed_objects()) / (double)(2 * stats.get_total_objects());
                                                return 0;
                                        });
 
@@ -309,11 +331,11 @@ namespace Gitg
                        }
 
                        // Clone
-                       DashRow? row = create_repository_row(subfolder_name, "Cloning...", true, false);
+                       DashRow row = new DashRow(subfolder_name, "Cloning...", false);
+                       row.loading = true;
 
                        clone.begin(row, url, subfolder, is_bare, (obj, res) => {
                                Gitg.Repository? repository = clone.end(res);
-                               string branch_name = "";
 
                                // FIXME: show an error
                                if (repository != null)
@@ -322,21 +344,10 @@ namespace Gitg
                                        File? repo_file = repository.get_location();
                                        var uri = (workdir != null) ? workdir.get_uri() : repo_file.get_uri();
                                        add_repository_to_recent_manager(uri);
-
-                                       try
-                                       {
-                                               var head = repository.get_head();
-                                               branch_name = head.parsed_name.shortname;
-                                       }
-                                       catch {}
                                }
 
                                row.repository = repository;
-                               row.branch_label.set_markup("<small>%s</small>".printf(branch_name));
-                               row.spinner.stop();
-                               row.spinner.hide();
-                               row.arrow.show();
-                               row.bin.fraction = 0;
+                               row.loading = false;
                        });
                }
 
diff --git a/libgitg/resources/gitg-dash-view-row.ui b/libgitg/resources/gitg-dash-view-row.ui
new file mode 100644
index 0000000..5ee2149
--- /dev/null
+++ b/libgitg/resources/gitg-dash-view-row.ui
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.8 -->
+  <template class="GitgDashRow" parent="GtkListBoxRow">
+    <child>
+      <object class="GitgProgressBin" id="d_progress_bin">
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkGrid" id="grid">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="has_focus">False</property>
+            <property name="is_focus">False</property>
+            <property name="margin_left">12</property>
+            <property name="margin_right">12</property>
+            <property name="margin_top">12</property>
+            <property name="margin_bottom">12</property>
+            <property name="column_spacing">10</property>
+            <child>
+              <object class="GtkImage" id="d_image">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="has_focus">False</property>
+                <property name="is_focus">False</property>
+                <property name="stock">gtk-missing-image</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="d_repository_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="has_focus">False</property>
+                <property name="is_focus">False</property>
+                <property name="halign">start</property>
+                <property name="valign">end</property>
+                <property name="hexpand">True</property>
+                <property name="ellipsize">end</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="d_branch_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="has_focus">False</property>
+                <property name="is_focus">False</property>
+                <property name="halign">start</property>
+                <property name="valign">start</property>
+                <property name="ellipsize">end</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkArrow" id="d_arrow">
+                <property name="can_focus">False</property>
+                <property name="has_focus">False</property>
+                <property name="is_focus">False</property>
+                <property name="shadow_type">none</property>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkSpinner" id="d_spinner">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="has_focus">False</property>
+                <property name="is_focus">False</property>
+              </object>
+              <packing>
+                <property name="left_attach">3</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">2</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/libgitg/resources/resources.xml b/libgitg/resources/resources.xml
index 6b1f114..a94611d 100644
--- a/libgitg/resources/resources.xml
+++ b/libgitg/resources/resources.xml
@@ -7,6 +7,9 @@
     <file compressed="true">diff-view.css</file>
     <file compressed="true">jquery-1.10.1.min.js</file>
   </gresource>
+  <gresource prefix="/org/gnome/gitg/gtk/dash-view">
+    <file compressed="true" preprocess="xml-stripblanks">gitg-dash-view-row.ui</file>
+  </gresource>
 </gresources>
 
 <!-- ex: et ts=2 -->


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