[gitg/vala] Made is_available and is_enabled properties



commit 1ccd4c9feea322ba800538be47cfc00b4109d843
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date:   Tue Jul 17 22:52:06 2012 +0200

    Made is_available and is_enabled properties

 gitg/gitg-ui-elements.vala           |   21 ++++++++-------------
 libgitg-ext/gitg-ext-ui-element.vala |   12 +++++++++---
 plugins/diff/gitg-diff.vala          |   25 +++++++++++++++----------
 plugins/files/gitg-files.vala        |   26 ++++++++++++++++----------
 plugins/history/gitg-history.vala    |   16 +++++++++++-----
 5 files changed, 59 insertions(+), 41 deletions(-)
---
diff --git a/gitg/gitg-ui-elements.vala b/gitg/gitg-ui-elements.vala
index 7236f62..31540cd 100644
--- a/gitg/gitg-ui-elements.vala
+++ b/gitg/gitg-ui-elements.vala
@@ -108,7 +108,7 @@ public class UIElements<T>
 			var elem = obj as GitgExt.UIElement;
 
 			var wasavail = d_available_elements.lookup(elem.id);
-			bool isavail = elem.is_available();
+			bool isavail = elem.available;
 
 			if (wasavail != null && !isavail)
 			{
@@ -121,16 +121,16 @@ public class UIElements<T>
 			}
 			else if (wasavail != null && wasavail.navigation_button != null)
 			{
-				if (!wasavail.element.is_enabled() && d_current == wasavail)
+				if (!wasavail.element.enabled && d_current == wasavail)
 				{
 					d_current = null;
 				}
-				else if (wasavail.element.is_enabled() && d_current == null)
+				else if (wasavail.element.enabled && d_current == null)
 				{
 					set_current_impl(wasavail.element);
 				}
 
-				wasavail.navigation_button.set_sensitive(wasavail.element.is_enabled());
+				wasavail.navigation_button.set_sensitive(wasavail.element.enabled);
 			}
 		});
 	}
@@ -142,8 +142,8 @@ public class UIElements<T>
 
 	private void set_current_impl(GitgExt.UIElement element)
 	{
-		if (!element.is_available() ||
-		    !element.is_enabled() ||
+		if (!element.available ||
+		    !element.enabled ||
 		    (d_current != null && d_current.element == element))
 		{
 			return;
@@ -221,7 +221,7 @@ public class UIElements<T>
 
 		if (button != null)
 		{
-			button.set_sensitive(e.is_enabled());
+			button.set_sensitive(e.enabled);
 
 			d_toolbar.add(button);
 		}
@@ -234,18 +234,13 @@ public class UIElements<T>
 		});
 
 		d_available_elements.insert(e.id, ae);
-
-		if (d_current == null && e.is_enabled())
-		{
-			set_current_impl(ae.element);
-		}
 	}
 
 	private void add_ui_element(GitgExt.UIElement e)
 	{
 		d_elements.insert(e.id, e);
 
-		if (e.is_available())
+		if (e.available)
 		{
 			add_available(e);
 		}
diff --git a/libgitg-ext/gitg-ext-ui-element.vala b/libgitg-ext/gitg-ext-ui-element.vala
index a7b5762..2043a7b 100644
--- a/libgitg-ext/gitg-ext-ui-element.vala
+++ b/libgitg-ext/gitg-ext-ui-element.vala
@@ -86,12 +86,18 @@ public interface UIElement : Object
 	 * This method is used by gitg to verify whether or not a particular ui
 	 * element is available given the current state of the application.
 	 *
-	 * @return ``true`` if the view is available, ``false`` otherwise.
+	 */
+	public abstract bool available { get; }
+
+	/**
+	 * Check whether the ui element is enabled in the current application state.
+	 *
+	 * This method is used by gitg to verify whether or not a particular ui
+	 * element is enabled (sensitive) given the current state of the application.
 	 *
 	 */
-	public abstract bool is_available();
+	public abstract bool enabled { get; }
 
-	public abstract bool is_enabled();
 }
 
 }
diff --git a/plugins/diff/gitg-diff.vala b/plugins/diff/gitg-diff.vala
index 832c04d..2b5dead 100644
--- a/plugins/diff/gitg-diff.vala
+++ b/plugins/diff/gitg-diff.vala
@@ -45,16 +45,19 @@ namespace GitgDiff
 			owned get { return "/org/gnome/gitg/Panels/Diff"; }
 		}
 
-		public bool is_available()
+		public bool available
 		{
-			var view = application.current_view;
-
-			if (view == null)
+			get
 			{
-				return false;
-			}
+				var view = application.current_view;
+
+				if (view == null)
+				{
+					return false;
+				}
 
-			return (view is GitgExt.ObjectSelection);
+				return (view is GitgExt.ObjectSelection);
+			}
 		}
 
 		public string display_name
@@ -105,10 +108,12 @@ namespace GitgDiff
 			}
 		}
 
-		public bool is_enabled()
+		public bool enabled
 		{
-			// TODO
-			return true;
+			get
+			{
+				return true;
+			}
 		}
 	}
 }
diff --git a/plugins/files/gitg-files.vala b/plugins/files/gitg-files.vala
index c159fcf..061be5a 100644
--- a/plugins/files/gitg-files.vala
+++ b/plugins/files/gitg-files.vala
@@ -48,16 +48,19 @@ namespace GitgFiles
 			owned get { return "/org/gnome/gitg/Panels/Files"; }
 		}
 
-		public bool is_available()
+		public bool available
 		{
-			var view = application.current_view;
-
-			if (view == null)
+			get
 			{
-				return false;
-			}
+				var view = application.current_view;
+
+				if (view == null)
+				{
+					return false;
+				}
 
-			return (view is GitgExt.ObjectSelection);
+				return (view is GitgExt.ObjectSelection);
+			}
 		}
 
 		public string display_name
@@ -278,10 +281,13 @@ namespace GitgFiles
 			set_viewer(wid);
 		}
 
-		public bool is_enabled()
+		public bool enabled
 		{
-			// TODO
-			return true;
+			get
+			{
+				// TODO
+				return true;
+			}
 		}
 	}
 }
diff --git a/plugins/history/gitg-history.vala b/plugins/history/gitg-history.vala
index 9acedc7..1e83941 100644
--- a/plugins/history/gitg-history.vala
+++ b/plugins/history/gitg-history.vala
@@ -58,10 +58,13 @@ namespace GitgHistory
 			application.bind_property("repository", d_model, "repository", BindingFlags.DEFAULT);
 		}
 
-		public bool is_available()
+		public bool available
 		{
-			// The history view is available only when there is a repository
-			return application.repository != null;
+			get
+			{
+				// The history view is available only when there is a repository
+				return application.repository != null;
+			}
 		}
 
 		public string display_name
@@ -191,9 +194,12 @@ namespace GitgHistory
 			return ret;
 		}
 
-		public bool is_enabled()
+		public bool enabled
 		{
-			return true;
+			get
+			{
+				return true;
+			}
 		}
 	}
 }



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