Implemented order negotiation for ui elements

This commit is contained in:
Jesse van den Kieboom 2012-07-17 22:52:27 +02:00
parent 1ccd4c9fee
commit f303cfa551
5 changed files with 56 additions and 1 deletions

View file

@ -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);
}
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}
}
}

View file

@ -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;
}
}
}
}

View file

@ -201,6 +201,11 @@ namespace GitgHistory
return true;
}
}
public int negotiate_order(GitgExt.UIElement other)
{
return -1;
}
}
}