[california/wip/730603-gsettings] Clean up some binding issues
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/730603-gsettings] Clean up some binding issues
- Date: Fri, 30 May 2014 00:31:54 +0000 (UTC)
commit d811787591fc08f9e1706574db02178b3a6f46dd
Author: Jim Nelson <jim yorba org>
Date: Thu May 29 17:31:43 2014 -0700
Clean up some binding issues
src/base/base-object.vala | 17 +++++++++++++++++
src/host/host-main-window.vala | 22 ++++++++++++++++++++--
2 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/src/base/base-object.vala b/src/base/base-object.vala
index 99025b4..97779dd 100644
--- a/src/base/base-object.vala
+++ b/src/base/base-object.vala
@@ -4,6 +4,10 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
+// It's either this or double-unref Binding objects; see
+// https://bugzilla.gnome.org/show_bug.cgi?id=730967
+extern void g_binding_unbind(Binding *binding);
+
namespace California {
/**
@@ -15,6 +19,19 @@ public abstract class BaseObject : Object {
}
/**
+ * Helper for unbinding properties until g_binding_unbind() is bound.
+ *
+ * See [[https://bugzilla.gnome.org/show_bug.cgi?id=730967]]
+ */
+ public static void unbind_property(ref Binding? binding) {
+ if (binding == null)
+ return;
+
+ g_binding_unbind(binding);
+ binding = null;
+ }
+
+ /**
* Returns a string representation of the object ''for debugging and logging only''.
*
* String conversion for other purposes (user labels, serialization, etc.) should be handled
diff --git a/src/host/host-main-window.vala b/src/host/host-main-window.vala
index a8d8657..ddb084a 100644
--- a/src/host/host-main-window.vala
+++ b/src/host/host-main-window.vala
@@ -51,6 +51,8 @@ public class MainWindow : Gtk.ApplicationWindow {
private Gtk.Stack view_stack = new Gtk.Stack();
private Gtk.HeaderBar headerbar = new Gtk.HeaderBar();
private Gtk.Button today = new Gtk.Button.with_label(_("_Today"));
+ private Binding view_stack_binding;
+ private Gee.HashSet<string> view_stack_ids = new Gee.HashSet<string>();
public MainWindow(Application app) {
Object (application: app);
@@ -164,8 +166,23 @@ public class MainWindow : Gtk.ApplicationWindow {
// bind stack's visible child property to the settings for it, both ways ... because we want
// to initialize with the settings, use it as the source w/ SYNC_CREATE
- Settings.instance.bind_property(Settings.PROP_CALENDAR_VIEW, view_stack, "visible-child-name",
- BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
+ view_stack_binding = Settings.instance.bind_property(Settings.PROP_CALENDAR_VIEW, view_stack,
+ "visible-child-name", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL,
+ transform_setting_to_calendar_view);
+
+ // to prevent storing the different children's names as the widget is destroyed (cleared,
+ // i.e. remove each one by one), unbind before that occurs
+ view_stack.destroy.connect(() => { BaseObject.unbind_property(ref view_stack_binding); });
+ }
+
+ // only allow known stack children ids through
+ private bool transform_setting_to_calendar_view(Binding binding, Value source, ref Value target) {
+ if (!view_stack_ids.contains(source.get_string()))
+ return false;
+
+ target = source;
+
+ return true;
}
public override void map() {
@@ -177,6 +194,7 @@ public class MainWindow : Gtk.ApplicationWindow {
}
private void add_controller(View.Controllable controller) {
+ view_stack_ids.add(controller.id);
view_stack.add_titled(controller.get_container(), controller.id, controller.title);
controller.get_container().show_all();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]