[gitg/wip/simplify-arch: 2/7] Add support for builtin ui elements
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/wip/simplify-arch: 2/7] Add support for builtin ui elements
- Date: Mon, 1 Jul 2013 07:32:19 +0000 (UTC)
commit 1b3526d898c20811d71c1fc30a7d7a9c07537165
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Mon Jul 1 09:26:17 2013 +0200
Add support for builtin ui elements
gitg/gitg-ui-elements.vala | 68 +++++++++++++++++++++++++++++++++----------
gitg/gitg-window.vala | 7 ++--
2 files changed, 56 insertions(+), 19 deletions(-)
---
diff --git a/gitg/gitg-ui-elements.vala b/gitg/gitg-ui-elements.vala
index d6edc89..16a1d2a 100644
--- a/gitg/gitg-ui-elements.vala
+++ b/gitg/gitg-ui-elements.vala
@@ -20,16 +20,16 @@
namespace Gitg
{
-public class UIElements<T>
+public class UIElements<T> : Object
{
private Peas.ExtensionSet d_extensions;
- private HashTable<string, GitgExt.UIElement> d_elements;
+ private Gee.HashMap<string, GitgExt.UIElement> d_elements;
+ private Gee.HashSet<string> d_builtin_elements;
private List<GitgExt.UIElement> d_available_elements;
private GitgExt.UIElement? d_current;
private Gtk.Stack d_stack;
- public signal void activated(GitgExt.UIElement element);
-
+ [Notify]
public T? current
{
get
@@ -55,9 +55,8 @@ public class UIElements<T>
public void update()
{
// Update active elements based on availability
- d_extensions.foreach((extset, info, obj) => {
- var elem = obj as GitgExt.UIElement;
-
+ foreach (var elem in d_elements.values)
+ {
bool wasavail = is_available(elem);
bool isavail = elem.available;
@@ -76,7 +75,7 @@ public class UIElements<T>
d_current = null;
}
}
- });
+ }
set_first_enabled_current();
}
@@ -100,7 +99,7 @@ public class UIElements<T>
public T? lookup(string id)
{
- return (T)d_elements.lookup(id);
+ return (T)d_elements[id];
}
private bool is_available(GitgExt.UIElement element)
@@ -125,7 +124,8 @@ public class UIElements<T>
d_stack.set_visible_child(element.widget);
}
- activated(element);
+ notify_property("current");
+ element.activate();
}
private void remove_available(GitgExt.UIElement e)
@@ -144,6 +144,19 @@ public class UIElements<T>
d_available_elements.remove(e);
}
+ private bool order_after(GitgExt.UIElement a, GitgExt.UIElement b)
+ {
+ var ab = a.id in d_builtin_elements;
+ var bb = b.id in d_builtin_elements;
+
+ if (ab != bb)
+ {
+ return ab ? false : true;
+ }
+
+ return a.negotiate_order(b) > 0;
+ }
+
private void add_available(GitgExt.UIElement e)
{
d_stack.add_with_properties(e.widget,
@@ -154,7 +167,7 @@ public class UIElements<T>
int insert_position = 0;
unowned List<GitgExt.UIElement> item = d_available_elements;
- while (item != null && item.data.negotiate_order(e) <= 0)
+ while (item != null && order_after(e, item.data))
{
item = item.next;
insert_position++;
@@ -169,9 +182,14 @@ public class UIElements<T>
update();
}
+ private void on_element_activate(GitgExt.UIElement e)
+ {
+ set_current_impl(e);
+ }
+
private void add_ui_element(GitgExt.UIElement e)
{
- d_elements.insert(e.id, e);
+ d_elements[e.id] = e;
if (e.available)
{
@@ -179,6 +197,7 @@ public class UIElements<T>
}
e.notify["available"].connect(available_changed);
+ e.activate.connect(on_element_activate);
}
private void remove_ui_element(GitgExt.UIElement e)
@@ -186,8 +205,9 @@ public class UIElements<T>
remove_available(e);
e.notify["available"].disconnect(available_changed);
+ e.activate.disconnect(on_element_activate);
- d_elements.remove(e.id);
+ d_elements.unset(e.id);
}
private void extension_initial(Peas.ExtensionSet s,
@@ -227,13 +247,23 @@ public class UIElements<T>
}
}
- public UIElements(Peas.ExtensionSet extensions,
- Gtk.Stack? stack = null)
+ public UIElements.with_builtin(T[] builtin,
+ Peas.ExtensionSet extensions,
+ Gtk.Stack? stack = null)
{
d_extensions = extensions;
d_stack = stack;
+ d_builtin_elements = new Gee.HashSet<string>();
+
+ d_elements = new Gee.HashMap<string, GitgExt.UIElement>();
+
+ foreach (var b in builtin)
+ {
+ GitgExt.UIElement elem = (GitgExt.UIElement)b;
- d_elements = new HashTable<string, GitgExt.UIElement>(str_hash, str_equal);
+ d_builtin_elements.add(elem.id);
+ add_ui_element(elem);
+ }
// Add all the extensions
d_extensions.foreach(extension_initial);
@@ -242,6 +272,12 @@ public class UIElements<T>
d_extensions.extension_added.connect(extension_added);
d_extensions.extension_removed.connect(extension_removed);
}
+
+ public UIElements(Peas.ExtensionSet extensions,
+ Gtk.Stack? stack = null)
+ {
+ this.with_builtin(new T[] {}, extensions, stack);
+ }
}
}
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index 7b7c51e..7a7a933 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -599,13 +599,14 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
// Initialize peas extensions set for views
var engine = PluginsEngine.get_default();
- d_views = new UIElements<GitgExt.View>(new Peas.ExtensionSet(engine,
+ d_views = new UIElements<GitgExt.View>.with_builtin(new GitgExt.View[] {},
+ new Peas.ExtensionSet(engine,
typeof(GitgExt.View),
"application",
this),
- d_stack_view);
+ d_stack_view);
- d_views.activated.connect(on_view_activated);
+ d_views.notify["current"].connect(on_current_view_changed);
// Setup window geometry saving
Gdk.WindowState window_state = (Gdk.WindowState)d_state_settings.get_int("state");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]