Advertisement
ilih

Untitled

Jan 29th, 2022
1,347
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Add
  2. public TreeViewLayer TreeView;
  3.  
  4. public void AddLayer(Layer layer)
  5. {
  6.     var node = new TreeNode<Layer>(layer);
  7.     TreeView.Nodes.Add(node);
  8. }
  9.  
  10. // Duplicate
  11. public void Duplicate(TreeNode<Layer> node)
  12. {
  13.     var layer = node.Item; // maybe it also should be copied
  14.     var duplicated_node = new TreeNode<Layer>(layer, CreateNodesCopy(node.Nodes)); // create the new node with duplicated nested nodes
  15.     duplicated_node.Parent = node.Parent; // add node to the same branch
  16. }
  17.  
  18. ObservableList<TreeNode<Layer>> DuplicateNodes(ObservableList<TreeNode<Layer>> nodes)
  19. {
  20.     var result = new ObservableList<TreeNode<Layer>>();
  21.     if (nodes == null)
  22.     {
  23.         return result;
  24.     }
  25.  
  26.     foreach (var node in nodes)
  27.     {
  28.         result.Add(Duplicate(node));
  29.     }
  30.  
  31.     return result;
  32. }
  33.  
  34. // Remove
  35. public void Remove(TreeNode<Layer> node)
  36. {
  37.     node.Parent = null;
  38. }
  39.  
  40. // Serialization
  41. public List<TreeNodeSerialized<Layer>> Serialize()
  42. {
  43.     return TreeNode<Layer>.Serialize(TreeView.Nodes); // convert nodes to simple list than can be easily serialized
  44. }
  45.  
  46. public void Deserialize(List<TreeNodeSerialized<Layer>> nodes)
  47. {
  48.     TreeView.Nodes = TreeNode<Layer>.Deserialize(nodes);
  49. }
Advertisement
RAW Paste Data Copied
Advertisement