From c43dfb815a4951b8248f4f0e98babe4f80204f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Fri, 3 Apr 2015 13:14:53 +0200 Subject: Imported Upstream version 0.22.0 --- src/sidebar/Branch.vala | 64 +++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 40 deletions(-) (limited to 'src/sidebar/Branch.vala') 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 comparator; + public CompareFunc comparator; public Gee.SortedSet? children = null; - public Node(Sidebar.Entry entry, Node? parent, - owned CompareDataFunc comparator) { + public Node(Sidebar.Entry entry, Node? parent, CompareFunc 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 comparator, bool recursive, + public void change_comparator(CompareFunc 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 default_comparator; + private CompareFunc default_comparator; private Gee.HashMap map = new Gee.HashMap(); 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 default_comparator, - owned CompareDataFunc? root_comparator = null) { - this.default_comparator = (owned) default_comparator; - - CompareDataFunc? 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 default_comparator, + CompareFunc? 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? comparator = null) { + CompareFunc? 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? 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? comparator) { - root.change_comparator((owned) comparator, true, children_reordered_callback); + public void change_all_comparators(CompareFunc? comparator) { + root.change_comparator(comparator, true, children_reordered_callback); } public void change_comparator(Sidebar.Entry entry, bool recursive, - owned CompareDataFunc? comparator) { + CompareFunc? 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) { -- cgit v1.2.3