Пример #1
0
        /// <summary>
        /// Returns whether the context can insert the data object</summary>
        /// <param name="insertingObject">Data to insert; e.g., System.Windows.Forms.IDataObject</param>
        /// <returns>True iff the context can insert the data object</returns>
        public bool CanInsert(object insertingObject)
        {
            IDataObject dataObject = (IDataObject)insertingObject;

            object[] items = dataObject.GetData(typeof(object[])) as object[];
            if (items == null || items.Length == 0)
            {
                return(false);
            }

            IEnumerable <DomNode> childNodes = items.AsIEnumerable <DomNode>();
            DomNode parent = m_insertionParent.As <DomNode>();

            if (parent != null)
            {
                foreach (DomNode child in childNodes)
                {
                    // can't add child to parent if it will cause a cycle
                    foreach (DomNode ancestor in parent.Lineage)
                    {
                        if (ancestor == child)
                        {
                            return(false);
                        }
                    }

                    // don't add child to the same parent
                    if (parent == child.Parent)
                    {
                        return(false);
                    }

                    // make sure parent can hold child of this type
                    if (!CanParent(parent, child.Type))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            else
            {
                EmptyRef emptyRef = m_insertionParent as EmptyRef;
                if (emptyRef != null)
                {
                    foreach (DomNode child in childNodes)
                    {
                        if (!CanReference(emptyRef, child.Type))
                        {
                            return(false);
                        }
                    }

                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// Gets item's display information</summary>
        /// <param name="item">Item being displayed</param>
        /// <param name="info">Item info, to fill out</param>
        public void GetInfo(object item, ItemInfo info)
        {
            DomNode node = item as DomNode;

            if (node != null)
            {
                if (node.Type == UISchema.UIRefType.Type)
                {
                    info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.RefImage);
                    string   label    = string.Empty;
                    UIRef    uiRef    = node.As <UIRef>();
                    UIObject uiTarget = uiRef.UIObject;
                    if (uiTarget != null)
                    {
                        label = uiTarget.Name;
                    }

                    info.Label = "[" + label + "]";
                }
                else if (node.Is <Curve>())
                {
                    Curve cv = node.Cast <Curve>();
                    info.Label      = string.IsNullOrWhiteSpace(cv.DisplayName) ? cv.Name : cv.DisplayName;
                    info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.CurveImage);
                }
                else
                {
                    NodeTypePaletteItem paletteItem = node.Type.GetTag <NodeTypePaletteItem>();
                    if (paletteItem != null)
                    {
                        info.ImageIndex = info.GetImageList().Images.IndexOfKey(paletteItem.ImageName);
                    }

                    info.Label = node.GetId();
                }

                info.IsLeaf = !GetChildren(item).Any();
            }
            else
            {
                EmptyRef emptyRef = item as EmptyRef;
                if (emptyRef != null)
                {
                    info.Label      = "Ref";
                    info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.RefEmptyImage);
                    info.IsLeaf     = true;
                }
            }

            if (string.IsNullOrEmpty(info.Label))
            {
                throw new ArgumentException("info.lable");
            }
        }
Пример #3
0
        // check child type against empty ref to determine if reference is valid
        private bool CanReference(EmptyRef emptyRef, DomNodeType childType)
        {
            return
                // dropping shader on sprite?
                (((childType == UISchema.UIShaderType.Type) &&
                  emptyRef.ChildInfo.IsEquivalent(UISchema.UISpriteType.ShaderChild)) ||

                 // dropping font on text item?
                 ((childType == UISchema.UIFontType.Type) &&
                  emptyRef.ChildInfo.IsEquivalent(UISchema.UITextItemType.FontChild)));
        }
Пример #4
0
        /// <summary>
        /// Gets item's display information</summary>
        /// <param name="item">Item being displayed</param>
        /// <param name="info">Item info, to fill out</param>
        public void GetInfo(object item, ItemInfo info)
        {
            DomNode node = item as DomNode;

            if (node != null)
            {
                if (node.Type == UISchema.UIRefType.Type)
                {
                    info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.RefImage);
                    string   label    = string.Empty;
                    UIRef    uiRef    = node.As <UIRef>();
                    UIObject uiTarget = uiRef.UIObject;
                    if (uiTarget != null)
                    {
                        label = uiTarget.Name;
                    }

                    info.Label = "[" + label + "]";
                }
                else
                {
                    NodeTypePaletteItem paletteItem = node.Type.GetTag <NodeTypePaletteItem>();
                    if (paletteItem != null)
                    {
                        info.ImageIndex = info.GetImageList().Images.IndexOfKey(paletteItem.ImageName);
                        info.Label      = node.GetId();
                    }
                }

                info.IsLeaf = !Enumerable.Any(GetChildren(item));
                return;
            }
            else
            {
                EmptyRef emptyRef = item as EmptyRef;
                if (emptyRef != null)
                {
                    info.Label      = "Ref";
                    info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.RefEmptyImage);
                    info.IsLeaf     = true;
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Inserts a reference to an object of given type using a transaction. Called by automated scripts during testing.</summary>
        /// <typeparam name="T">Type of object to insert</typeparam>
        /// <param name="insertingObject">DomNode that contains inserted object</param>
        /// <param name="insertionParent">Parent where object is inserted</param>
        /// <returns>Inserted object</returns>
        public T InsertAsRef <T>(DomNode insertingObject, DomNode insertionParent) where T : class
        {
            ChildInfo childInfo = GetChildInfo(insertionParent, UISchema.UIRefType.Type);
            EmptyRef  emptyRef  = new EmptyRef(insertionParent, childInfo);

            SetInsertionParent(emptyRef);

            insertingObject.SetAttribute(UISchema.UIType.nameAttribute, typeof(T).Name);
            DataObject dataObject = new DataObject(new object[] { insertingObject });

            ITransactionContext transactionContext = this.As <ITransactionContext>();

            transactionContext.DoTransaction(
                delegate
            {
                Insert(dataObject);
            }, "Scripted Insert Object");

            UIRef   uiRef   = emptyRef.Parent.GetChild(childInfo).As <UIRef>();
            DomNode newNode = uiRef.DomNode.As <DomNode>();

            return(newNode.As <T>());
        }
Пример #6
0
        /// <summary>
        /// Inserts the data object into the context</summary>
        /// <param name="insertingObject">Data to insert</param>
        public void Insert(object insertingObject)
        {
            IDataObject dataObject = (IDataObject)insertingObject;

            object[] items = dataObject.GetData(typeof(object[])) as object[];
            if (items == null || items.Length == 0)
            {
                return;
            }

            IEnumerable <DomNode> childNodes = items.AsIEnumerable <DomNode>();
            // if no items are parented, then we should clone the items, which must be from the clipboard
            bool fromScrap = true;

            foreach (DomNode child in childNodes)
            {
                if (child.Parent != null)
                {
                    fromScrap = false;
                    break;
                }
            }
            if (fromScrap)
            {
                childNodes = DomNode.Copy(childNodes);
                // inited extensions for copied DomNodes
                foreach (DomNode child in childNodes)
                {
                    child.InitializeExtensions();
                }
            }

            DomNode parent = m_insertionParent.As <DomNode>();

            if (parent != null)
            {
                foreach (DomNode child in childNodes)
                {
                    ChildInfo childInfo = GetChildInfo(parent, child.Type);
                    if (childInfo != null)
                    {
                        if (childInfo.IsList)
                        {
                            IList <DomNode> list = parent.GetChildList(childInfo);
                            list.Add(child);
                        }
                        else
                        {
                            parent.SetChild(childInfo, child);
                        }
                    }
                }
            }
            else
            {
                EmptyRef emptyRef = m_insertionParent as EmptyRef;
                if (emptyRef != null)
                {
                    foreach (DomNode child in childNodes)
                    {
                        UIRef uiRef = UIRef.New(child.As <UIObject>());
                        emptyRef.Parent.SetChild(emptyRef.ChildInfo, uiRef.DomNode);
                    }
                }
            }
        }