Пример #1
0
        //-----------------------------------------------------------------------
        public void Insert(int index, CollectionChildItem child)
        {
            var def = Definition as CollectionDefinition;

            if (IsAtMax)
            {
                return;
            }

            var cdef = Definition as CollectionDefinition;

            UndoRedo.ApplyDoUndo(
                delegate
            {
                Children.Insert(index, child);
                RaisePropertyChangedEvent("HasContent");
                RaisePropertyChangedEvent("Description");
            },
                delegate
            {
                Children.Remove(child);
                RaisePropertyChangedEvent("HasContent");
                RaisePropertyChangedEvent("Description");
            },
                "Inserting item " + child.Name + " to collection " + Name);
        }
        //-----------------------------------------------------------------------
        public void Clear()
        {
            if (IsMultiediting)
            {
                foreach (var item in MultieditItems)
                {
                    (item as ReferenceItem).Clear();
                }
            }
            else
            {
                var item   = WrappedItem;
                var oldDef = ChosenDefinition;

                UndoRedo.ApplyDoUndo(delegate
                {
                    ChosenDefinition = null;
                    WrappedItem      = null;
                },
                                     delegate
                {
                    ChosenDefinition = oldDef;
                    WrappedItem      = item;
                },
                                     "Clear Item " + Definition.Name);
            }
        }
Пример #3
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;
        }
Пример #4
0
        //-----------------------------------------------------------------------
        public void Remove(CollectionChildItem item)
        {
            var def = Definition as CollectionDefinition;

            if (IsAtMin)
            {
                return;
            }

            var index = Children.IndexOf(item);

            UndoRedo.ApplyDoUndo(
                delegate
            {
                Children.Remove(item);
                RaisePropertyChangedEvent("HasContent");
                RaisePropertyChangedEvent("Description");
            },
                delegate
            {
                Children.Insert(index, item);
                RaisePropertyChangedEvent("HasContent");
                RaisePropertyChangedEvent("Description");
            },
                "Removing item " + item.Name + " from collection " + Name);
        }
        //-----------------------------------------------------------------------
        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 Clear()
        {
            var item   = WrappedItem;
            var oldDef = ChosenDefinition;

            UndoRedo.ApplyDoUndo(delegate
            {
                WrappedItem = null;
            },
                                 delegate
            {
                WrappedItem = item;
            },
                                 "Clear Item " + Definition.Name);
        }
Пример #8
0
        //-----------------------------------------------------------------------
        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;
            }
        }
Пример #9
0
 //-----------------------------------------------------------------------
 protected override void AddContextMenuItems(ContextMenu menu)
 {
     menu.AddItem("Delete", () =>
     {
         var index = Parent.Children.IndexOf(this);
         UndoRedo.ApplyDoUndo(
             delegate
         {
             Parent.Children.Remove(this);
         },
             delegate
         {
             Parent.Children.Insert(index, this);
         }, "Delete Comment");
     });
 }
Пример #10
0
 //-----------------------------------------------------------------------
 public void MoveItem(int src, int dst)
 {
     UndoRedo.ApplyDoUndo(
         delegate
     {
         Children.Move(src, dst);
         RaisePropertyChangedEvent("HasContent");
         RaisePropertyChangedEvent("Description");
     },
         delegate
     {
         Children.Move(dst, src);
         RaisePropertyChangedEvent("HasContent");
         RaisePropertyChangedEvent("Description");
     },
         "Moving item " + src + " to " + dst + " in collection " + Name);
 }
        //-----------------------------------------------------------------------
        public void SetWrappedItem(GraphNodeItem item)
        {
            var oldItem = WrappedItem;

            UndoRedo.ApplyDoUndo(delegate
            {
                WrappedItem = item;
            },
                                 delegate
            {
                WrappedItem = oldItem;
            },
                                 "Set Item " + item.Name);

            if (IsCircular())
            {
                LinkType = LinkType.Reference;
            }
        }
Пример #12
0
        //-----------------------------------------------------------------------
        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;
            }
        }
Пример #13
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;
                }
            }
        }
        //-----------------------------------------------------------------------
        public virtual void Clear()
        {
            if (IsMultiediting)
            {
                foreach (var item in Children)
                {
                    item.ClearMultiEdit();
                }

                foreach (var item in MultieditItems)
                {
                    (item as ComplexDataItem).Clear();
                }
            }
            else
            {
                var prevChildren = Children.ToList();
                UndoRedo.ApplyDoUndo(
                    delegate
                {
                    Children.Clear();
                    RaisePropertyChangedEvent("HasContent");
                    RaisePropertyChangedEvent("Description");
                },
                    delegate
                {
                    foreach (var child in prevChildren)
                    {
                        Children.Add(child);
                    }
                    RaisePropertyChangedEvent("HasContent");
                    RaisePropertyChangedEvent("Description");
                },
                    Name + " cleared");
            }
        }
Пример #15
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;
        }
Пример #16
0
        //-----------------------------------------------------------------------
        public DataItem Add(KeyframeDefinition def, float time)
        {
            if (IsAtMax)
            {
                return(null);
            }

            KeyframeItem item = def.CreateData(UndoRedo) as KeyframeItem;

            item.SetKeyframeTime(time);

            Children.Sort((e) => (e as KeyframeItem).Time);

            if (Interpolate)
            {
                var index = Children.IndexOf(item);
                var prev  = Children.ElementAtOrDefault(index - 1) as KeyframeItem;
                var next  = Children.ElementAtOrDefault(index + 1) as KeyframeItem;

                if (prev == null && next == null)
                {
                }
                else if (prev == null)
                {
                    for (int i = 0; i < NumColourData(); i++)
                    {
                        item.SetColourData(i, next.GetColourData(i));
                    }
                    for (int i = 0; i < NumNumberData(); i++)
                    {
                        item.SetNumberData(i, next.GetNumberData(i));
                    }
                }
                else if (next == null)
                {
                    for (int i = 0; i < NumColourData(); i++)
                    {
                        item.SetColourData(i, prev.GetColourData(i));
                    }
                    for (int i = 0; i < NumNumberData(); i++)
                    {
                        item.SetNumberData(i, prev.GetNumberData(i));
                    }
                }
                else
                {
                    for (int i = 0; i < NumColourData(); i++)
                    {
                        var prevVal = prev.GetColourData(i);
                        var nextVal = next.GetColourData(i);

                        var prevTime = prev.GetKeyframeTime();
                        var nextTime = next.GetKeyframeTime();
                        var alpha    = (item.Time - prevTime) / (nextTime - prevTime);

                        var col = prevVal.Lerp(nextVal, alpha);

                        item.SetColourData(i, col);
                    }
                    for (int i = 0; i < NumNumberData(); i++)
                    {
                        var prevVal = prev.GetNumberData(i);
                        var nextVal = next.GetNumberData(i);

                        var prevTime = prev.GetKeyframeTime();
                        var nextTime = next.GetKeyframeTime();
                        var alpha    = (item.Time - prevTime) / (nextTime - prevTime);

                        var val = prevVal + (nextVal - prevVal) * alpha;

                        item.SetNumberData(i, val);
                    }
                }
            }

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

            IsExpanded = true;

            return(item);
        }
Пример #17
0
        //-----------------------------------------------------------------------
        public ContextMenu CreateContextMenu()
        {
            ContextMenu menu = new ContextMenu();

            AddContextMenuItems(menu);

            menu.AddSeperator();

            if (this is ComplexDataItem)
            {
                menu.AddItem("Add Comment", () =>
                {
                    var comment = new CommentItem(new CommentDefinition(), UndoRedo);

                    UndoRedo.ApplyDoUndo(delegate
                    {
                        Children.Add(comment);
                    }, delegate
                    {
                        Children.Remove(comment);
                    }, "Add Comment");
                });
            }

            menu.AddItem("Add Comment Above", () =>
            {
                var parent = FirstComplexParent(this);
                var index  = GetIndexInParent();

                var comment = new CommentItem(new CommentDefinition(), UndoRedo);

                UndoRedo.ApplyDoUndo(delegate
                {
                    parent.Children.Insert(index, comment);
                }, delegate
                {
                    parent.Children.Remove(comment);
                }, "Add Comment");
            });

            menu.AddItem("Add Comment Below", () =>
            {
                var parent = FirstComplexParent(this);
                var index  = GetIndexInParent();

                var comment = new CommentItem(new CommentDefinition(), UndoRedo);

                UndoRedo.ApplyDoUndo(delegate
                {
                    parent.Children.Insert(index + 1, comment);
                }, delegate
                {
                    parent.Children.Remove(comment);
                }, "Add Comment");
            });

            menu.AddSeperator();

            MenuItem focusItem = new MenuItem();

            focusItem.Header = "Focus";

            focusItem.Click += delegate
            {
                DataModel.FocusItem(this);
            };

            menu.Items.Add(focusItem);

            menu.Items.Add(new Separator());

            MenuItem resetItem = new MenuItem();

            resetItem.Header = "Reset To Default";

            resetItem.Click += delegate
            {
                ResetToDefault();
            };

            menu.Items.Add(resetItem);

            menu.Items.Add(new Separator());

            MenuItem collapseAllItem = new MenuItem();

            collapseAllItem.Header = "Collapse All";

            collapseAllItem.Click += delegate
            {
                foreach (var item in Root.Descendants)
                {
                    item.IsExpanded = false;
                }
            };

            menu.Items.Add(collapseAllItem);

            MenuItem expandAllItem = new MenuItem();

            expandAllItem.Header = "Expand All";

            expandAllItem.Click += delegate
            {
                foreach (var item in Root.Descendants)
                {
                    item.IsExpanded = true;
                }
            };

            menu.Items.Add(expandAllItem);

            MenuItem collapseLevelItem = new MenuItem();

            collapseLevelItem.Header = "Collapse Level";

            collapseLevelItem.Click += delegate
            {
                foreach (var item in Parent.Children)
                {
                    item.IsExpanded = false;
                }
            };

            menu.Items.Add(collapseLevelItem);

            MenuItem expandLevelItem = new MenuItem();

            expandLevelItem.Header = "Expand Level";

            expandLevelItem.Click += delegate
            {
                foreach (var item in Parent.Children)
                {
                    item.IsExpanded = true;
                }
            };

            menu.Items.Add(expandLevelItem);

            MenuItem collapseChildrenItem = new MenuItem();

            collapseChildrenItem.Header = "Collapse Children";

            collapseChildrenItem.Click += delegate
            {
                foreach (var item in Descendants)
                {
                    item.IsExpanded = false;
                }
            };

            menu.Items.Add(collapseChildrenItem);

            MenuItem expandChildrenItem = new MenuItem();

            expandChildrenItem.Header = "Expand Children";

            expandChildrenItem.Click += delegate
            {
                foreach (var item in Descendants)
                {
                    item.IsExpanded = true;
                }
            };

            menu.Items.Add(expandChildrenItem);

            return(menu);
        }
        //-----------------------------------------------------------------------
        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");
            }
        }