mirror of
https://gitlab.gnome.org/GNOME/gitg
synced 2024-08-27 20:09:23 +00:00
Implemented order negotiation for ui elements
This commit is contained in:
parent
1ccd4c9fee
commit
f303cfa551
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -201,6 +201,11 @@ namespace GitgHistory
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public int negotiate_order(GitgExt.UIElement other)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue