From d33442c2576793420802bbd54127923079c487c4 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Sun, 2 Sep 2018 13:03:12 +0200 Subject: Add support for node renaming. --- src/vytree.ml | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/vytree.ml') diff --git a/src/vytree.ml b/src/vytree.ml index b200cc4..57c3612 100644 --- a/src/vytree.ml +++ b/src/vytree.ml @@ -43,6 +43,11 @@ let replace node child = let children' = Vylist.replace (fun x -> x.name = name) child children in { node with children = children' } +let replace_full node child name = + let children = node.children in + let children' = Vylist.replace (fun x -> x.name = name) child children in + { node with children = children' } + let find node name = Vylist.find (fun x -> x.name = name) node.children @@ -131,6 +136,13 @@ let rec insert_multi_level default_data node path_done path_remaining data = let delete node path = do_with_child delete_immediate node path +let rename node path newname = + let rename_immediate newname' node' name' = + let child = find_or_fail node' name' in + let child = { child with name=newname' } in + replace_full node' child name' + in do_with_child (rename_immediate newname) node path + let update node path data = let update_data data' node' name = let child = find_or_fail node' name in -- cgit v1.2.3