[gitg] Bind available/enabled ui element properties



commit 10cd83fbbba46f1ddcf5900eb9922c8fdd0122cc
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date:   Sun Oct 28 18:25:08 2012 +0100

    Bind available/enabled ui element properties

 gitg/gitg-ui-elements.vala        |   16 ++++++++++++----
 plugins/diff/gitg-diff.vala       |    4 ++++
 plugins/files/gitg-files.vala     |    4 ++++
 plugins/history/gitg-history.vala |    4 ++++
 4 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/gitg/gitg-ui-elements.vala b/gitg/gitg-ui-elements.vala
index d33ac58..b814615 100644
--- a/gitg/gitg-ui-elements.vala
+++ b/gitg/gitg-ui-elements.vala
@@ -72,6 +72,8 @@ public class UIElements<T>
 			button = new Gtk.RadioToolButton(null);
 		}
 
+		e.bind_property("enabled", button, "sensitive", BindingFlags.DEFAULT | BindingFlags.SYNC_CREATE);
+
 		button.set_icon_widget(img);
 		button.set_label(e.display_name);
 
@@ -130,8 +132,6 @@ public class UIElements<T>
 				{
 					set_current_impl(wasavail.element);
 				}
-
-				wasavail.navigation_button.set_sensitive(wasavail.element.enabled);
 			}
 		});
 	}
@@ -223,8 +223,6 @@ public class UIElements<T>
 
 		if (button != null)
 		{
-			button.set_sensitive(e.enabled);
-
 			d_available_sorted.insert_sorted(ae, (a, b) => {
 				return a.element.negotiate_order(b.element);
 			});
@@ -243,6 +241,11 @@ public class UIElements<T>
 		d_available_elements.insert(e.id, ae);
 	}
 
+	private void available_changed(Object o, ParamSpec spec)
+	{
+		update();
+	}
+
 	private void add_ui_element(GitgExt.UIElement e)
 	{
 		d_elements.insert(e.id, e);
@@ -251,11 +254,16 @@ public class UIElements<T>
 		{
 			add_available(e);
 		}
+
+		e.notify["available"].connect(available_changed);
 	}
 
 	private void remove_ui_element(GitgExt.UIElement e)
 	{
 		remove_available(e);
+
+		e.notify["available"].disconnect(available_changed);
+
 		d_elements.remove(e.id);
 	}
 
diff --git a/plugins/diff/gitg-diff.vala b/plugins/diff/gitg-diff.vala
index 2fa6f07..a3bd2ff 100644
--- a/plugins/diff/gitg-diff.vala
+++ b/plugins/diff/gitg-diff.vala
@@ -38,6 +38,10 @@ namespace GitgDiff
 			d_diff.show();
 
 			d_sw.add(d_diff);
+
+			application.notify["current_view"].connect((a, v) => {
+				notify_property("available");
+			});
 		}
 
 		public string id
diff --git a/plugins/files/gitg-files.vala b/plugins/files/gitg-files.vala
index 07b8d7d..2e09137 100644
--- a/plugins/files/gitg-files.vala
+++ b/plugins/files/gitg-files.vala
@@ -41,6 +41,10 @@ namespace GitgFiles
 		construct
 		{
 			d_model = new TreeStore();
+
+			application.notify["current_view"].connect((a, v) => {
+				notify_property("available");
+			});
 		}
 
 		public string id
diff --git a/plugins/history/gitg-history.vala b/plugins/history/gitg-history.vala
index 0418a13..6a6b6bf 100644
--- a/plugins/history/gitg-history.vala
+++ b/plugins/history/gitg-history.vala
@@ -70,6 +70,10 @@ namespace GitgHistory
 			update_sort_mode();
 
 			application.bind_property("repository", d_model, "repository", BindingFlags.DEFAULT);
+
+			application.notify["repository"].connect((a, r) => {
+				notify_property("available");
+			});
 		}
 
 		private void update_sort_mode()



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