示例#1
0
        public virtual void Insert(IEnumerable <IOutlineNode> nodes, IOutlineNode after, bool copy)
        {
            using (var moveTransaction =
                       DesignItem.Context.OpenGroup("Item moved in outline view", nodes.Select(n => n.DesignItem).ToList()))
            {
                if (copy)
                {
                    nodes = nodes.Select(n => OutlineNode.Create(n.DesignItem.Clone())).ToList();
                }
                else
                {
                    foreach (var node in nodes)
                    {
                        node.DesignItem.Remove();
                    }
                }

                var index = after == null ? 0 : Children.IndexOf(after) + 1;

                var content = DesignItem.ContentProperty;
                if (content.IsCollection)
                {
                    foreach (var node in nodes)
                    {
                        content.CollectionElements.Insert(index++, node.DesignItem);
                    }
                }
                else
                {
                    content.SetValue(nodes.First().DesignItem);
                }
                moveTransaction.Commit();
            }
        }
示例#2
0
 void UpdateChildrenCore(IEnumerable <DesignItem> items, int index = -1)
 {
     foreach (var item in items)
     {
         if (ModelTools.CanSelectComponent(item))
         {
             if (Children.All(x => x.DesignItem != item))
             {
                 var node = OutlineNode.Create(item);
                 if (index > -1)
                 {
                     Children.Insert(index++, node);
                 }
                 else
                 {
                     Children.Add(node);
                 }
             }
         }
         else
         {
             var content = item.ContentProperty;
             if (content != null)
             {
                 if (content.IsCollection)
                 {
                     UpdateChildrenCore(content.CollectionElements);
                 }
                 else
                 {
                     if (content.Value != null)
                     {
                         UpdateChildrenCore(new[] { content.Value });
                     }
                 }
             }
         }
     }
 }