diff options
Diffstat (limited to 'src/sidebar/Branch.vala')
-rw-r--r-- | src/sidebar/Branch.vala | 64 |
1 files changed, 24 insertions, 40 deletions
diff --git a/src/sidebar/Branch.vala b/src/sidebar/Branch.vala index 23badda..a6c3ee8 100644 --- a/src/sidebar/Branch.vala +++ b/src/sidebar/Branch.vala @@ -1,4 +1,4 @@ -/* Copyright 2011-2014 Yorba Foundation +/* Copyright 2011-2015 Yorba Foundation * * This software is licensed under the GNU Lesser General Public License * (version 2.1 or later). See the COPYING file in this distribution. @@ -39,23 +39,22 @@ public class Sidebar.Branch : Object { public Sidebar.Entry entry; public weak Node? parent; - public CompareDataFunc<Sidebar.Entry> comparator; + public CompareFunc<Sidebar.Entry> comparator; public Gee.SortedSet<Node>? children = null; - public Node(Sidebar.Entry entry, Node? parent, - owned CompareDataFunc<Sidebar.Entry> comparator) { + public Node(Sidebar.Entry entry, Node? parent, CompareFunc<Sidebar.Entry> comparator) { this.entry = entry; this.parent = parent; - this.comparator = (owned) comparator; + this.comparator = comparator; } - private static int comparator_wrapper(Node? a, Node? b) { - if (a == b) + private static int comparator_wrapper(Node anode, Node bnode) { + if (anode == bnode) return 0; - assert(a.parent == b.parent); + assert(anode.parent == bnode.parent); - return a.parent.comparator(a.entry, b.entry); + return anode.parent.comparator(anode.entry, bnode.entry); } public bool has_children() { @@ -172,16 +171,16 @@ public class Sidebar.Branch : Object { cb(this); } - public void change_comparator(owned CompareDataFunc<Sidebar.Entry> comparator, bool recursive, + public void change_comparator(CompareFunc<Sidebar.Entry> comparator, bool recursive, ChildrenReorderedCallback cb) { - this.comparator = (owned) comparator; + this.comparator = comparator; // reorder children, but need to do manual recursion to set comparator reorder_children(false, cb); if (recursive) { foreach (Node child in children) - child.change_comparator((owned) comparator, true, cb); + child.change_comparator(comparator, true, cb); } } } @@ -189,7 +188,7 @@ public class Sidebar.Branch : Object { private Node root; private Options options; private bool shown = true; - private CompareDataFunc<Sidebar.Entry> default_comparator; + private CompareFunc<Sidebar.Entry> default_comparator; private Gee.HashMap<Sidebar.Entry, Node> map = new Gee.HashMap<Sidebar.Entry, Node>(); public signal void entry_added(Sidebar.Entry entry); @@ -204,19 +203,11 @@ public class Sidebar.Branch : Object { public signal void show_branch(bool show); - public Branch(Sidebar.Entry root, Options options, - owned CompareDataFunc<Sidebar.Entry> default_comparator, - owned CompareDataFunc<Sidebar.Entry>? root_comparator = null) { - this.default_comparator = (owned) default_comparator; - - CompareDataFunc<Sidebar.Entry>? broken_ternary_workaround; - - if (root_comparator != null) - broken_ternary_workaround = (owned) root_comparator; - else - broken_ternary_workaround = (owned) default_comparator; - - this.root = new Node(root, null, (owned) broken_ternary_workaround); + public Branch(Sidebar.Entry root, Options options, CompareFunc<Sidebar.Entry> default_comparator, + CompareFunc<Sidebar.Entry>? root_comparator = null) { + this.default_comparator = default_comparator; + this.root = new Node(root, null, + (root_comparator != null) ? root_comparator : default_comparator); this.options = options; map.set(root, this.root); @@ -254,7 +245,7 @@ public class Sidebar.Branch : Object { } public void graft(Sidebar.Entry parent, Sidebar.Entry entry, - owned CompareDataFunc<Sidebar.Entry>? comparator = null) { + CompareFunc<Sidebar.Entry>? comparator = null) { assert(map.has_key(parent)); assert(!map.has_key(entry)); @@ -262,15 +253,8 @@ public class Sidebar.Branch : Object { set_show_branch(true); Node parent_node = map.get(parent); - - CompareDataFunc<Sidebar.Entry>? broken_ternary_workaround; - - if (comparator != null) - broken_ternary_workaround = (owned) comparator; - else - broken_ternary_workaround = (owned) default_comparator; - - Node entry_node = new Node(entry, parent_node, (owned) broken_ternary_workaround); + Node entry_node = new Node(entry, parent_node, + (comparator != null) ? comparator : default_comparator); parent_node.add_child(entry_node); map.set(entry, entry_node); @@ -347,16 +331,16 @@ public class Sidebar.Branch : Object { entry_node.reorder_children(recursive, children_reordered_callback); } - public void change_all_comparators(owned CompareDataFunc<Sidebar.Entry>? comparator) { - root.change_comparator((owned) comparator, true, children_reordered_callback); + public void change_all_comparators(CompareFunc<Sidebar.Entry>? comparator) { + root.change_comparator(comparator, true, children_reordered_callback); } public void change_comparator(Sidebar.Entry entry, bool recursive, - owned CompareDataFunc<Sidebar.Entry>? comparator) { + CompareFunc<Sidebar.Entry>? comparator) { Node? entry_node = map.get(entry); assert(entry_node != null); - entry_node.change_comparator((owned) comparator, recursive, children_reordered_callback); + entry_node.change_comparator(comparator, recursive, children_reordered_callback); } public int get_child_count(Sidebar.Entry parent) { |