[gitg] Only update panels when mapped



commit 2e4590d3964a492c3d5ad3d4ec4f6d83f06de7f4
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Fri Mar 1 16:11:06 2013 +0100

    Only update panels when mapped

 libgitg-gtk/Makefile.am               |    3 +-
 libgitg-gtk/gitg-gtk-when-mapped.vala |  108 +++++++++++++++++++++++++++++++++
 plugins/diff/gitg-diff.vala           |    8 ++-
 plugins/files/gitg-files.vala         |    9 +++-
 4 files changed, 125 insertions(+), 3 deletions(-)
---
diff --git a/libgitg-gtk/Makefile.am b/libgitg-gtk/Makefile.am
index 9f095d9..724b8f1 100644
--- a/libgitg-gtk/Makefile.am
+++ b/libgitg-gtk/Makefile.am
@@ -55,7 +55,8 @@ VALA_FILES =                                          \
        gitg-gtk-diff-view-request.vala                 \
        gitg-gtk-diff-view-request-resource.vala        \
        gitg-gtk-diff-view-request-diff.vala            \
-       gitg-gtk-dash-view.vala
+       gitg-gtk-dash-view.vala                         \
+       gitg-gtk-when-mapped.vala
 
 # Ignore all warnings for vala code...
 libgitg_gtk_1_0_la_CFLAGS =            \
diff --git a/libgitg-gtk/gitg-gtk-when-mapped.vala b/libgitg-gtk/gitg-gtk-when-mapped.vala
new file mode 100644
index 0000000..40a1397
--- /dev/null
+++ b/libgitg-gtk/gitg-gtk-when-mapped.vala
@@ -0,0 +1,108 @@
+namespace GitgGtk
+{
+       public class WhenMapped
+       {
+               public delegate void OnMapped();
+
+               private unowned Gtk.Widget? d_widget;
+               private unowned Object? d_lifetime;
+               private ulong d_sid;
+
+               public WhenMapped(Gtk.Widget widget)
+               {
+                       d_sid = 0;
+                       d_widget = widget;
+
+                       d_widget.weak_ref(weak_notify);
+               }
+
+               private void weak_notify(Object o)
+               {
+                       d_widget = null;
+
+                       if (d_lifetime != null)
+                       {
+                               d_lifetime.weak_unref(lifetime_weak_notify);
+                               d_lifetime = null;
+                       }
+               }
+
+               ~WhenMapped()
+               {
+                       if (d_widget != null)
+                       {
+                               if (d_sid != 0)
+                               {
+                                       d_widget.disconnect(d_sid);
+                               }
+
+                               d_widget.weak_unref(weak_notify);
+                               d_widget = null;
+                       }
+
+                       if (d_lifetime != null)
+                       {
+                               d_lifetime.weak_unref(lifetime_weak_notify);
+                               d_lifetime = null;
+                       }
+               }
+
+               private void lifetime_weak_notify(Object o)
+               {
+                       if (d_sid != 0 && d_widget != null)
+                       {
+                               d_widget.disconnect(d_sid);
+                               d_sid = 0;
+                       }
+
+                       d_lifetime = null;
+               }
+
+               public void update(owned OnMapped mapped, Object? lifetime = null)
+               {
+                       if (d_widget == null)
+                       {
+                               return;
+                       }
+
+                       if (d_sid != 0)
+                       {
+                               d_widget.disconnect(d_sid);
+                       }
+
+                       if (d_lifetime != null)
+                       {
+                               d_lifetime.weak_unref(lifetime_weak_notify);
+                               d_lifetime = null;
+                       }
+
+                       if (d_widget.get_mapped())
+                       {
+                               mapped();
+                       }
+                       else
+                       {
+                               d_sid = d_widget.map.connect(() => {
+                                       d_sid = 0;
+
+                                       if (d_lifetime != null)
+                                       {
+                                               d_lifetime.weak_unref(lifetime_weak_notify);
+                                               d_lifetime = null;
+                                       }
+
+                                       mapped();
+                               });
+
+                               d_lifetime = lifetime;
+
+                               if (d_lifetime != null)
+                               {
+                                       d_lifetime.weak_ref(lifetime_weak_notify);
+                               }
+                       }
+               }
+       }
+}
+
+// ex: ts=4 noet
diff --git a/plugins/diff/gitg-diff.vala b/plugins/diff/gitg-diff.vala
index 579da48..8ed0ef5 100644
--- a/plugins/diff/gitg-diff.vala
+++ b/plugins/diff/gitg-diff.vala
@@ -28,6 +28,7 @@ namespace GitgDiff
                private Gtk.ScrolledWindow d_sw;
                private GitgGtk.DiffView d_diff;
                private GitgExt.ObjectSelection? d_view;
+               private GitgGtk.WhenMapped d_whenMapped;
 
                construct
                {
@@ -38,6 +39,8 @@ namespace GitgDiff
                        d_diff.show();
                        d_sw.add(d_diff);
 
+                       d_whenMapped = new GitgGtk.WhenMapped(d_sw);
+
                        application.notify["current_view"].connect((a, v) => {
                                notify_property("available");
                        });
@@ -80,7 +83,10 @@ namespace GitgDiff
 
                                if (c != null)
                                {
-                                       d_diff.commit = c;
+                                       d_whenMapped.update(() => {
+                                               d_diff.commit = c;
+                                       }, this);
+
                                        return false;
                                }
 
diff --git a/plugins/files/gitg-files.vala b/plugins/files/gitg-files.vala
index 53d9e4c..0505891 100644
--- a/plugins/files/gitg-files.vala
+++ b/plugins/files/gitg-files.vala
@@ -40,6 +40,8 @@ namespace GitgFiles
                private Gtk.Viewport d_imagevp;
                private Gtk.Image d_image;
 
+               private GitgGtk.WhenMapped d_whenMapped;
+
                construct
                {
                        d_model = new TreeStore();
@@ -87,7 +89,10 @@ namespace GitgFiles
 
                                if (c != null)
                                {
-                                       d_model.tree = c.get_tree();
+                                       d_whenMapped.update(() => {
+                                               d_model.tree = c.get_tree();
+                                       }, this);
+
                                        return false;
                                }
 
@@ -186,6 +191,8 @@ namespace GitgFiles
 
                                update_packing();
                        }
+
+                       d_whenMapped = new GitgGtk.WhenMapped(d_paned);
                }
 
                public Gtk.Widget? widget


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