Exemplo n.º 1
0
        public void TestInheritance()
        {
            NamedObjectSave baseListNos = new NamedObjectSave();
            baseListNos.SourceType = SourceType.FlatRedBallType;
            baseListNos.SourceClassType = "PositionedObjectList";
            baseListNos.SourceClassGenericType = mEntitySave.Name;

            NamedObjectSave derivedNos = new NamedObjectSave();
            derivedNos.SourceType = SourceType.Entity;
            derivedNos.SourceClassType = mDerivedEntitySave.Name;

            if (derivedNos.CanBeInList(baseListNos) == false)
            {
                throw new Exception("CanBeInList doesn't properly follow inheritance");
            }
        }
        private static bool HandleDropOnList(TreeNode treeNodeMoving, TreeNode targetNode, NamedObjectSave targetNos, NamedObjectSave movingNos)
        {
            bool succeeded = true;

            #region Failure cases

            if (string.IsNullOrEmpty(targetNos.SourceClassGenericType))
            {
                MessageBox.Show("The target Object has not been given a list type yet");
            }
            else if (movingNos.CanBeInList(targetNos) == false)
            {
                MessageBox.Show("The Object you are moving is of type " + movingNos.SourceClassType +
                    " but the list is of type " + targetNos.SourceClassGenericType);

            }
            else if (treeNodeMoving.Parent.IsRootNamedObjectNode() == false)
            {
                MessageBox.Show("The Object you are moving is already part of a list, so it can't be moved");
            }

            #endregion

            else
            {
                succeeded = true;
                // Get the old parent of the moving NOS
                TreeNode parentTreeNode = treeNodeMoving.Parent;
                if (parentTreeNode.IsNamedObjectNode())
                {
                    NamedObjectSave parentNos = parentTreeNode.Tag as NamedObjectSave;

                    parentNos.ContainedObjects.Remove(movingNos);
                }
                else
                {
                    EditorLogic.CurrentElement.NamedObjects.Remove(movingNos);
                }
                parentTreeNode.Nodes.Remove(treeNodeMoving);
                targetNode.Nodes.Add(treeNodeMoving);
                // Add the NOS to the tree node moving on
                targetNos.ContainedObjects.Add(movingNos);

            }
            return succeeded;
        }