[gitg/vala] Implemented order negotiation for ui elements



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

    Implemented order negotiation for ui elements

 gitg/gitg-ui-elements.vala           |   14 +++++++++++++-
 libgitg-ext/gitg-ext-ui-element.vala |   12 ++++++++++++
 plugins/diff/gitg-diff.vala          |   13 +++++++++++++
 plugins/files/gitg-files.vala        |   13 +++++++++++++
 plugins/history/gitg-history.vala    |    5 +++++
 5 files changed, 56 insertions(+), 1 deletions(-)
---
diff --git a/gitg/gitg-ui-elements.vala b/gitg/gitg-ui-elements.vala
index 31540cd..d33ac58 100644
--- a/gitg/gitg-ui-elements.vala
+++ b/gitg/gitg-ui-elements.vala
@@ -36,6 +36,7 @@ public class UIElements<T>
 	private Peas.ExtensionSet d_extensions;
 	private HashTable<string, ActiveUIElement> d_available_elements;
 	private HashTable<string, GitgExt.UIElement> d_elements;
+	private List<ActiveUIElement> d_available_sorted;
 	private Gtk.Toolbar? d_toolbar;
 	private ActiveUIElement? d_current;
 	private Gtk.Bin d_container;
@@ -200,6 +201,7 @@ public class UIElements<T>
 		{
 			if (ae.navigation_button != null)
 			{
+				d_available_sorted.remove(ae);
 				ae.navigation_button.destroy();
 			}
 
@@ -223,7 +225,12 @@ public class UIElements<T>
 		{
 			button.set_sensitive(e.enabled);
 
-			d_toolbar.add(button);
+			d_available_sorted.insert_sorted(ae, (a, b) => {
+				return a.element.negotiate_order(b.element);
+			});
+
+			d_toolbar.insert(button, d_available_sorted.index(ae));
+			update_visibility();
 		}
 
 		button.toggled.connect((b) => {
@@ -315,6 +322,11 @@ public class UIElements<T>
 		d_extensions.foreach(extension_added);
 		d_extensions.extension_added.connect(extension_added);
 		d_extensions.extension_removed.connect(extension_removed);
+
+		if (d_current == null && d_available_sorted != null)
+		{
+			set_current_impl(d_available_sorted.data.element);
+		}
 	}
 }
 
diff --git a/libgitg-ext/gitg-ext-ui-element.vala b/libgitg-ext/gitg-ext-ui-element.vala
index 2043a7b..e815d14 100644
--- a/libgitg-ext/gitg-ext-ui-element.vala
+++ b/libgitg-ext/gitg-ext-ui-element.vala
@@ -98,6 +98,18 @@ public interface UIElement : Object
 	 */
 	public abstract bool enabled { get; }
 
+	/**
+	 * Negotiate the order with another UIElement.
+	 *
+	 * This method is used to determine the order in which elements need to
+	 * appear in the UI.
+	 *
+	 * @returns -1 if the element should appear before @other, 1 if the
+	 *          element should appear after @other and 0 if the order is
+	 *          unimportant.
+	 *
+	 */
+	public abstract int negotiate_order(UIElement other);
 }
 
 }
diff --git a/plugins/diff/gitg-diff.vala b/plugins/diff/gitg-diff.vala
index 2b5dead..5cef08e 100644
--- a/plugins/diff/gitg-diff.vala
+++ b/plugins/diff/gitg-diff.vala
@@ -115,6 +115,19 @@ namespace GitgDiff
 				return true;
 			}
 		}
+
+		public int negotiate_order(GitgExt.UIElement other)
+		{
+			// Should appear before the files
+			if (other.id == "/org/gnome/gitg/plugins/Files")
+			{
+				return -1;
+			}
+			else
+			{
+				return 0;
+			}
+		}
 	}
 }
 
diff --git a/plugins/files/gitg-files.vala b/plugins/files/gitg-files.vala
index 061be5a..922a141 100644
--- a/plugins/files/gitg-files.vala
+++ b/plugins/files/gitg-files.vala
@@ -289,6 +289,19 @@ namespace GitgFiles
 				return true;
 			}
 		}
+
+		public int negotiate_order(GitgExt.UIElement other)
+		{
+			// Should appear after the diff
+			if (other.id == "/org/gnome/gitg/plugins/Diff")
+			{
+				return 1;
+			}
+			else
+			{
+				return 0;
+			}
+		}
 	}
 }
 
diff --git a/plugins/history/gitg-history.vala b/plugins/history/gitg-history.vala
index 1e83941..5bb34b9 100644
--- a/plugins/history/gitg-history.vala
+++ b/plugins/history/gitg-history.vala
@@ -201,6 +201,11 @@ namespace GitgHistory
 				return true;
 			}
 		}
+
+		public int negotiate_order(GitgExt.UIElement other)
+		{
+			return -1;
+		}
 	}
 }
 



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