Exemple #1
0
        public TreePath(T node, ITreePath <T> parent = null)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            Node   = node;
            Parent = parent;
        }
 public ElementEdit(
     AbstractDocument document,
     ITreePath <ITextNode> oldElementPath,
     ITreePath <ITextNode> newElementPath,
     int index,
     ITextNode[] addedNodes,
     ITextNode[] removedNodes) : base(false, "")
 {
     Index               = index;
     this.addedNodes     = addedNodes;
     this.removedNodes   = removedNodes;
     this.document       = document;
     this.oldElementPath = oldElementPath;
     this.newElementPath = newElementPath;
 }
Exemple #3
0
        public static ITreePath <ITextNode> ReplaceAll(ITreePath <ITextNode> oldPath, ITextNode newNode)
        {
            var oldNode = oldPath.Node;

            if (oldPath.Parent == null)
            {
                return(new TreePath <ITextNode>(newNode));
            }

            var parentPath  = oldPath.Parent;
            var parentNode  = parentPath.Node;
            var idx         = parentNode.IndexOf(oldNode);
            var changedNode = parentNode.Replace(idx, 1, new[] { newNode });
            var changedPath = ReplaceAll(parentPath, changedNode);

            return(changedPath.Append(newNode));
        }
Exemple #4
0
        public override ITreeNode Get(ITreePath path, ref int offset, bool getRef = false)
        {
            if (path.IsPathToCurrent)
            {
                return(this);
            }

            if (path.IsAbsolute)
            {
                offset = 0;
                return(Root.Get(path.StepDown(), ref offset, getRef));
            }
            if (path.IsPathIndexed)
            {
                var arrayChild = GetChildByName(path.ArrayName);
                return(arrayChild?.Get(path, ref offset, getRef));
            }
            var child = GetChildByName(path.Nodes.First());

            return(child?.Get(path.StepDown(), ref offset, getRef));
        }
Exemple #5
0
 public override void AddChild(ITreePath path, ITreeNode node)
 {
     if (path.IsPathToCurrent)
     {
         AddChild(node);
     }
     else if (path.IsAbsolute)
     {
         Root.AddChild(path.StepDown(), node);
     }
     else
     {
         var nextNode = path.Nodes.First();
         var child    = GetChildByName(nextNode);
         if (child == null)
         {
             AddChild(new PlcMetaDataTreeNode(nextNode));
             child = GetChildByName(nextNode);
         }
         child.AddChild(path.StepDown(), node);
     }
 }
Exemple #6
0
        public static PlcObject AddPlcObjectToTree(PlcObject obj, ITree tree, ITreePath path)
        {
            var node = PlcMetaDataTreePath.CreateNodePath(path, obj);

            if (!(tree.Get(node) is PlcObject metaDataNode))
            {
                lock (tree.Root)
                {
                    metaDataNode = tree.Get(node) as PlcObject;
                    if (metaDataNode == null)
                    {
                        tree.Root.AddChild(path, obj);
                    }
                    else
                    {
                        return(metaDataNode);
                    }
                }
                return(obj);
            }
            return(metaDataNode);
        }
Exemple #7
0
        public override ITreeNode Get(ITreePath path)
        {
            int dummy = 0;

            return(Get(path, ref dummy));
        }
Exemple #8
0
 public static PlcMetaDataTreePath CreateNodePath(ITreePath path, PlcObject plcObject) => path.Extend(plcObject.Name) as PlcMetaDataTreePath;
Exemple #9
0
 public bool TryGet(ITreePath path, ref int offset, out ITreeNode node, bool getRef = false)
 {
     node = Root.Get(path, ref offset, getRef);
     return(node != null);
 }
Exemple #10
0
 public bool TryGet(ITreePath path, out ITreeNode node)
 {
     node = Root.Get(path);
     return(node != null);
 }
Exemple #11
0
 public ITreeNode Get(ITreePath path, ref int offset, bool getRef = false)
 {
     return(Root.Get(path, ref offset, getRef));
 }
Exemple #12
0
 public ITreeNode Get(ITreePath path)
 {
     return(Root.Get(path));
 }