Example #1
0
        /// <summary>
        /// Add a new child but the behaviour does not need to be saved.
        /// Used for collapsed referenced behaviours which show the behaviours they reference.
        /// </summary>
        /// <param name="connector">The connector the node will be added to. Use null for default connector.</param>
        /// <param name="node">The node you want to append.</param>
        /// <returns>Returns true if the child could be added.</returns>
        public virtual bool AddChildNotModified(Connector connector, Node node)
        {
            Debug.Check(connector != null && _children.HasConnector(connector));

            if (!connector.AcceptsChild(node.GetType()))
            {
                throw new Exception(Resources.ExceptionNodeHasTooManyChildren);
            }

            if (!connector.AddChild(node))
            {
                return(false);
            }

            node._parent = this;

            node.CopyWasModifiedFromParent(this);

            return(true);
        }
Example #2
0
        /// <summary>
        /// Add a new child node.
        /// </summary>
        /// <param name="connector">The connector the node will be added to. Use null for default connector.</param>
        /// <param name="node">The node you want to append.</param>
        /// <param name="index">The index of the new node.</param>
        /// <returns>Returns true if the child could be added.</returns>
        public virtual bool AddChild(Connector connector, Node node, int index)
        {
            Debug.Check(connector != null && _children.HasConnector(connector));

            if (!connector.AcceptsChild(node.GetType()))
            {
                throw new Exception(Resources.ExceptionNodeHasTooManyChildren);
            }

            if (!connector.AddChild(node, index))
            {
                return(false);
            }

            node._parent = this;

            BehaviorWasModified();

            return(true);
        }
Example #3
0
		/// <summary>
		/// Saves a node to the XML file.
		/// </summary>
		/// <param name="root">The XML node we want to attach the node to.</param>
		/// <param name="node">The node we want to save.</param>
		protected void SaveNode(XmlElement root, Node node)
		{
			// allow the node to process its attributes in preparation of the save
			node.PreSave(_node);

			// store the class we have to create when loading
			XmlElement elem= _xmlfile.CreateElement("Node");
			elem.SetAttribute("Class", node.GetType().FullName);

			// save attributes
			IList<DesignerPropertyInfo> properties= node.GetDesignerProperties();
			for(int p= 0; p <properties.Count; ++p)
			{
				if(!properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
					elem.SetAttribute(properties[p].Property.Name, properties[p].GetStringValue(node));
			}

			// append node to root
			root.AppendChild(elem);

			// save comment
			if(node.CommentObject !=null)
			{
				XmlElement comment= _xmlfile.CreateElement("Comment");

				properties= node.CommentObject.GetDesignerProperties();
				for(int p= 0; p <properties.Count; ++p)
				{
					if(!properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
						comment.SetAttribute(properties[p].Property.Name, properties[p].GetStringValue(node.CommentObject));
				}

				elem.AppendChild(comment);
			}

			// save events
			foreach(Nodes.Node.SubItem sub in node.SubItems)
			{
				if(sub is Nodes.Node.SubItemEvent)
				{
					Events.Event ne= ((Nodes.Node.SubItemEvent)sub).Event;

					XmlElement evnt= _xmlfile.CreateElement("Event");
					evnt.SetAttribute("Class", ne.GetType().FullName);

					// save attributes
					properties= ne.GetDesignerProperties();
					for(int p= 0; p <properties.Count; ++p)
					{
						if(!properties[p].Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
							elem.SetAttribute(properties[p].Property.Name, properties[p].GetStringValue(ne));
					}

					elem.AppendChild(evnt);
				}
			}

			// save children if allowed. Disallowed for referenced behaviours.
			if(node.SaveChildren)
			{
				// save connectors
				foreach(Nodes.Node.Connector connector in node.Connectors)
				{
					// if we have no children to store we can skip the connector
					if(connector.ChildCount <1)
						continue;

					XmlElement conn= _xmlfile.CreateElement("Connector");
					conn.SetAttribute("Identifier", connector.Identifier);
					elem.AppendChild(conn);

					// save their children
					for(int i= 0; i <connector.ChildCount; ++i)
						SaveNode(conn, connector.GetChild(i));
				}
			}
		}