Example #1
0
        //-----------------------------------------------------------------------
        public void Add()
        {
            var def = Definition as CollectionDefinition;

            if (IsAtMax)
            {
                return;
            }

            var      cdef = Definition as CollectionDefinition;
            DataItem item = null;

            using (UndoRedo.DisableUndoScope())
            {
                item = SelectedDefinition.Item1.CreateData(UndoRedo);
            }

            UndoRedo.ApplyDoUndo(
                delegate
            {
                Children.Add(item);
                RaisePropertyChangedEvent("HasContent");
                RaisePropertyChangedEvent("Description");
            },
                delegate
            {
                Children.Remove(item);
                RaisePropertyChangedEvent("HasContent");
                RaisePropertyChangedEvent("Description");
            },
                "Adding item " + item.Name + " to collection " + Name);

            IsExpanded = true;
        }
        //-----------------------------------------------------------------------
        public override void Paste()
        {
            if (WrappedItem != null)
            {
                WrappedItem.Paste();
            }
            else
            {
                GraphNodeDefinition chosen = null;
                foreach (var def in ReferenceDef.Definitions.Values)
                {
                    if (Clipboard.ContainsData(def.CopyKey))
                    {
                        var flat = Clipboard.GetData(def.CopyKey) as string;
                        var root = XElement.Parse(flat);

                        if (root.Name == def.Name)
                        {
                            chosen = def;
                            break;
                        }
                    }
                }

                if (chosen == null)
                {
                    return;
                }

                GraphNodeItem item = null;
                using (UndoRedo.DisableUndoScope())
                {
                    item = chosen.CreateData(UndoRedo) as GraphNodeItem;
                    if (item is GraphStructItem && item.Children.Count == 0)
                    {
                        (item.Definition as GraphStructDefinition).CreateChildren(item as GraphStructItem, UndoRedo);
                    }

                    item.Paste();
                }

                UndoRedo.ApplyDoUndo(delegate
                {
                    ChosenDefinition = chosen;
                    WrappedItem      = item;
                },
                                     delegate
                {
                    ChosenDefinition = null;
                    WrappedItem      = null;
                },
                                     "Paste Item " + item.Name);
            }
        }
        //-----------------------------------------------------------------------
        public void Create(string chosenName = null)
        {
            var Node = GetParentNode();

            var chosen = chosenName != null ?
                         (Definition as GraphReferenceDefinition).Definitions[chosenName] :
                         (Definition as GraphReferenceDefinition).Definitions[SelectedDefinition.Item1];

            GraphNodeItem item = null;

            using (UndoRedo.DisableUndoScope())
            {
                item = chosen.CreateData(UndoRedo) as GraphNodeItem;

                if (Node != null)
                {
                    var x = Node.X + 100;

                    if (!double.IsNaN(Node.GraphNode.ActualWidth))
                    {
                        x += Node.GraphNode.ActualWidth;
                    }
                    else
                    {
                        x += 200;
                    }

                    item.X = x;
                    item.Y = Node.Y;
                }
            }

            UndoRedo.ApplyDoUndo(delegate
            {
                WrappedItem = item;
                if (!DataModel.GraphNodeItems.Contains(item))
                {
                    DataModel.GraphNodeItems.Add(item);
                }
            },
                                 delegate
            {
                WrappedItem = null;
                DataModel.GraphNodeItems.Remove(item);
            },
                                 "Create Item " + item.Name);

            IsExpanded = true;
        }
        //-----------------------------------------------------------------------
        public void Create()
        {
            if (IsMultiediting)
            {
                foreach (var item in MultieditItems)
                {
                    var si = item as KeyframeItem;
                    if (!si.HasContent)
                    {
                        si.Create();
                    }
                }

                MultiEdit(MultieditItems, MultieditCount.Value);
            }
            else
            {
                var sdef = Definition as KeyframeDefinition;

                using (UndoRedo.DisableUndoScope())
                {
                    sdef.CreateChildren(this, UndoRedo);
                }

                var newChildren = Children.ToList();
                Children.Clear();

                UndoRedo.ApplyDoUndo(
                    delegate
                {
                    foreach (var child in newChildren)
                    {
                        Children.Add(child);
                    }
                    RaisePropertyChangedEvent("HasContent");
                    RaisePropertyChangedEvent("Description");
                },
                    delegate
                {
                    Children.Clear();
                    RaisePropertyChangedEvent("HasContent");
                    RaisePropertyChangedEvent("Description");
                },
                    Name + " created");

                IsExpanded = true;
            }
        }
        //-----------------------------------------------------------------------
        public override void Paste()
        {
            if (Clipboard.ContainsData(CopyKey))
            {
                var asString = Clipboard.GetData(CopyKey) as string;

                PrimitiveDataItem <T> item = null;

                using (UndoRedo.DisableUndoScope())
                {
                    item = (Definition as PrimitiveDataDefinition).LoadFromString(asString, UndoRedo) as PrimitiveDataItem <T>;
                }

                Value = item.Value;
            }
        }
Example #6
0
        //-----------------------------------------------------------------------
        public void AddNew()
        {
            CollectionChildItem child = null;

            using (UndoRedo.DisableUndoScope())
            {
                var item = WrappedItem.Definition.CreateData(UndoRedo);
                child             = Definition.CreateData(UndoRedo) as CollectionChildItem;
                child.WrappedItem = item;
            }

            var collection = ParentCollection;
            var index      = collection.Children.IndexOf(this) + 1;

            (ParentCollection as ICollectionItem).Insert(index, child);
        }
Example #7
0
        //-----------------------------------------------------------------------
        public void Duplicate()
        {
            var el = new XElement("Root");

            WrappedItem.Definition.SaveData(el, WrappedItem);

            CollectionChildItem child = null;

            using (UndoRedo.DisableUndoScope())
            {
                var item = WrappedItem.Definition.LoadData(el.Elements().First(), UndoRedo);
                child             = Definition.CreateData(UndoRedo) as CollectionChildItem;
                child.WrappedItem = item;
            }

            var collection = ParentCollection;
            var index      = collection.Children.IndexOf(this) + 1;

            (ParentCollection as ICollectionItem).Insert(index, child);
        }
 //-----------------------------------------------------------------------
 public StructItem(DataDefinition definition, UndoRedoManager undoRedo) : base(definition, undoRedo)
 {
     PropertyChanged += (e, a) =>
     {
         if (a.PropertyName == "HasContent")
         {
             RaisePropertyChangedEvent("ShowClearButton");
         }
         else if (a.PropertyName == "Parent")
         {
             if (!HasContent && IsWrappedItem)
             {
                 using (UndoRedo.DisableUndoScope())
                 {
                     Create();
                 }
             }
         }
     };
 }
Example #9
0
 //-----------------------------------------------------------------------
 public GraphStructItem(DataDefinition definition, UndoRedoManager undoRedo) : base(definition, undoRedo)
 {
     PropertyChanged += (e, a) =>
     {
         if (a.PropertyName == "HasContent")
         {
             RaisePropertyChangedEvent("ShowClearButton");
         }
         else if (a.PropertyName == "Parent")
         {
             if (!HasContent && (Parent is CollectionChildItem || Parent is ReferenceItem))
             {
                 using (UndoRedo.DisableUndoScope())
                 {
                     Create();
                 }
             }
         }
     };
 }
        //-----------------------------------------------------------------------
        public void Create()
        {
            if (IsMultiediting)
            {
                foreach (var item in MultieditItems)
                {
                    var ri = item as ReferenceItem;
                    ri.SelectedDefinition = SelectedDefinition;
                    ri.Create();
                }
            }
            else
            {
                DataItem item   = null;
                var      chosen = (Definition as ReferenceDefinition).Definitions[SelectedDefinition.Item1];
                using (UndoRedo.DisableUndoScope())
                {
                    item = chosen.CreateData(UndoRedo);
                    if (item is StructItem && item.Children.Count == 0)
                    {
                        (item.Definition as StructDefinition).CreateChildren(item as StructItem, UndoRedo);
                    }
                }

                UndoRedo.ApplyDoUndo(delegate
                {
                    ChosenDefinition = chosen;
                    WrappedItem      = item;
                },
                                     delegate
                {
                    ChosenDefinition = null;
                    WrappedItem      = null;
                },
                                     "Create Item " + item.Name);

                IsExpanded = true;
            }
        }
Example #11
0
        //-----------------------------------------------------------------------
        public void PasteNew()
        {
            foreach (var childDef in CDef.ChildDefinitions)
            {
                if (Clipboard.ContainsData(childDef.WrappedDefinition.CopyKey))
                {
                    var flat = Clipboard.GetData(childDef.WrappedDefinition.CopyKey) as string;
                    var root = XElement.Parse(flat);

                    CollectionChildItem child = null;

                    using (UndoRedo.DisableUndoScope())
                    {
                        var item = childDef.WrappedDefinition.LoadData(root, UndoRedo);
                        child             = childDef.CreateData(UndoRedo) as CollectionChildItem;
                        child.WrappedItem = item;
                    }

                    UndoRedo.ApplyDoUndo(
                        delegate
                    {
                        Children.Add(child);
                        RaisePropertyChangedEvent("HasContent");
                        RaisePropertyChangedEvent("Description");
                    },
                        delegate
                    {
                        Children.Remove(child);
                        RaisePropertyChangedEvent("HasContent");
                        RaisePropertyChangedEvent("Description");
                    },
                        Name + " pasted new");

                    IsExpanded = true;
                }
            }
        }
Example #12
0
        //-----------------------------------------------------------------------
        public void Create()
        {
            var sdef = Definition as GraphNodeDefinition;

            if (sdef is GraphStructDefinition)
            {
                using (UndoRedo.DisableUndoScope())
                {
                    (sdef as GraphStructDefinition).CreateChildren(this, UndoRedo);
                }
            }

            var newChildren = Children.ToList();

            Children.Clear();

            UndoRedo.ApplyDoUndo(
                delegate
            {
                foreach (var child in newChildren)
                {
                    Children.Add(child);
                }
                RaisePropertyChangedEvent("HasContent");
                RaisePropertyChangedEvent("Description");
            },
                delegate
            {
                Children.Clear();
                RaisePropertyChangedEvent("HasContent");
                RaisePropertyChangedEvent("Description");
            },
                Name + " created");

            IsExpanded = true;
        }
        //-----------------------------------------------------------------------
        public override void Paste()
        {
            if (Clipboard.ContainsData(CopyKey))
            {
                var flat = Clipboard.GetData(CopyKey) as string;
                var root = XElement.Parse(flat);

                var sdef = Definition as ComplexDataDefinition;

                var             prevChildren = Children.ToList();
                List <DataItem> newChildren  = null;

                List <DataItem> oldAtts = null;
                List <DataItem> newAtts = null;

                using (UndoRedo.DisableUndoScope())
                {
                    var item = sdef.LoadData(root, UndoRedo);

                    if (item.Children.Count == 0 && item.Attributes.Count == 0)
                    {
                        item = sdef.CreateData(UndoRedo);
                    }

                    newChildren = item.Children.ToList();

                    if (item is ComplexDataItem)
                    {
                        oldAtts = (this as ComplexDataItem).Attributes.ToList();
                        newAtts = (item as ComplexDataItem).Attributes.ToList();
                    }
                }

                UndoRedo.ApplyDoUndo(
                    delegate
                {
                    Children.Clear();
                    foreach (var child in newChildren)
                    {
                        Children.Add(child);
                    }

                    if (this is ComplexDataItem)
                    {
                        var si = this as ComplexDataItem;
                        Attributes.Clear();
                        foreach (var att in newAtts)
                        {
                            Attributes.Add(att);
                        }
                    }

                    RaisePropertyChangedEvent("HasContent");
                    RaisePropertyChangedEvent("Description");
                },
                    delegate
                {
                    Children.Clear();
                    foreach (var child in prevChildren)
                    {
                        Children.Add(child);
                    }

                    if (this is ComplexDataItem)
                    {
                        var si = this as ComplexDataItem;
                        Attributes.Clear();
                        foreach (var att in oldAtts)
                        {
                            Attributes.Add(att);
                        }
                    }

                    RaisePropertyChangedEvent("HasContent");
                    RaisePropertyChangedEvent("Description");
                },
                    Name + " pasted");
            }
        }