Example #1
0
        public DiffNodeNamePair FindFirstMultiChildParent(DiffTree tree, PropertyName name, bool shortenName, bool allowReflection, DiffNode parentNode = null)
        {
            var oneNode = Nodes.Count == 1;

            var propertyNameString = Property.GetName(tree.Root, this, parentNode);

            // Collection elements should be referred to by their name or string representation
            var propName = IsCollectionElement
                ? new PropertyElementName(ObjectToString(allowReflection))
                : (Property.IsTab ? new PropertyTabName(propertyNameString) : new PropertyName(propertyNameString));

            // If the node can't be displayed and its name cant be ignored,
            // we can't go further down the tree. This can happen theoretically but hasn't occured anywhere yet
            if (propName.Name == null && !Property.IgnoreName)
            {
                return(new DiffNodeNamePair(parentNode?.ChangeExpanded(false), name, allowReflection));
            }

            var newName = name.SubProperty(propName);

            var elemName = Property.GetElementName();

            if (shortenName && Property.GetElementName() != null && !IsCollectionElement)
            {
                if (oneNode)
                {
                    // Remove everything from the path and replace it with the element name, e.g "Settings > DataSettings > GroupComparisons"
                    // becomes "GroupComparison:"
                    newName = PropertyName.ROOT.SubProperty(new PropertyElementName(elemName));
                }
                else
                {
                    // Multiple changes have been made to the collection
                    newName = propName;
                }
            }

            if (Property.IgnoreName && !IsCollectionElement)
            {
                newName = name;
            }

            var objects = Objects.Select(AuditLogObject.GetAuditLogObject)
                          .Where(o => o == null || o.IsName).ToArray();

            if (objects.Length == 2)
            {
                var type = Property.GetPropertyType(ObjectPair.Create(objects[1], objects[0]));
                if (((objects[0] != null) != (objects[1] != null) ||
                     (objects[0] != null && objects[1] != null && objects[0].AuditLogText != objects[1].AuditLogText && !typeof(DocNode).IsAssignableFrom(type))) &&
                    !Property.IsRoot)
                {
                    oneNode = false;     // Stop recursion, since in the undo-redo/summary log we don't want to go deeper for objects where the name changed
                }
            }

            return(oneNode && !IsFirstExpansionNode
                ? Nodes[0].FindFirstMultiChildParent(tree, newName, shortenName, allowReflection, this)
                : new DiffNodeNamePair(ChangeExpanded(false), newName, allowReflection));
        }
Example #2
0
        public List <DiffNodeNamePair> FindAllLeafNodes(DiffTree tree, PropertyName name, bool allowReflection, DiffNode parentNode = null)
        {
            var result = new List <DiffNodeNamePair>();

            var propertyNameString = Property.GetName(tree.Root, this, parentNode);

            var isName = false;
            // Collection elements should be referred to by their name or string representation
            var propName = IsCollectionElement
                ? new PropertyElementName(ObjectToString(allowReflection, Objects.FirstOrDefault(o => o != null), out isName))
                : (Property.IsTab ? new PropertyTabName(propertyNameString) : new PropertyName(propertyNameString));

            // The name can not be ignored if the node is a collection change (since then the child nodes of the collection change
            // have the same attribute as the collection change node)
            var canIgnoreName = (Property.IgnoreName && !IsCollectionElement);

            if (!canIgnoreName)
            {
                name = name != null?name.SubProperty(propName) : propName;
            }

            // We can't display sub changes of an element if it's unnamed, so we display its
            // string representation as a change
            if (IsCollectionElement && !isName && !canIgnoreName)
            {
                result.Add(new DiffNodeNamePair(this, name, allowReflection));
                return(result);
            }

            var obj           = Objects.FirstOrDefault();
            var isNamedChange = IsFirstExpansionNode || (obj != null && AuditLogObject.IsNameObject(obj)) &&
                                Expanded && !canIgnoreName;

            if (isNamedChange)
            {
                result.Add(new DiffNodeNamePair(this, name, allowReflection));
            }

            if (Nodes.Count == 0)
            {
                if (!isNamedChange)
                {
                    result.Add(new DiffNodeNamePair(this, name, allowReflection));
                }
            }
            else
            {
                var collectionPropDiffNode = this as CollectionPropertyDiffNode;
                if (collectionPropDiffNode != null && collectionPropDiffNode.RemovedAll)
                {
                    result.Add(new DiffNodeNamePair(this, name, allowReflection));
                }
                else
                {
                    foreach (var n in Nodes)
                    {
                        result.AddRange(n.FindAllLeafNodes(tree, name, allowReflection, this));
                    }
                }
            }

            return(result);
        }