mirror of
https://gitlab.gnome.org/GNOME/gitg
synced 2024-08-27 20:09:23 +00:00
Only update panels when mapped
This commit is contained in:
parent
9146df639f
commit
2e4590d396
|
@ -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 = \
|
||||
|
|
108
libgitg-gtk/gitg-gtk-when-mapped.vala
Normal file
108
libgitg-gtk/gitg-gtk-when-mapped.vala
Normal file
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue