/// <summary>
        /// Inserts a new comment node either before or after the
        /// currently selected node.
        /// </summary>
        void InsertComment(XmlComment comment, InsertionMode insertionMode)
        {
            ExtTreeNode selectedNode = (ExtTreeNode)SelectedNode;

            if (selectedNode != null)
            {
                ExtTreeNode        parentNode = (ExtTreeNode)selectedNode.Parent;
                XmlCommentTreeNode newNode    = new XmlCommentTreeNode(comment);
                int index = 0;
                if (parentNode != null)
                {
                    index = parentNode.Nodes.IndexOf(selectedNode);
                }
                else
                {
                    index = Nodes.IndexOf(selectedNode);
                }
                if (insertionMode == InsertionMode.After)
                {
                    index++;
                }
                if (parentNode != null)
                {
                    newNode.Insert(index, parentNode);
                }
                else
                {
                    newNode.Insert(index, this);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Adds child elements to this tree node.
 /// </summary>
 protected override void Initialize()
 {
     Nodes.Clear();
     foreach (XmlNode childNode in element.ChildNodes)
     {
         XmlElement childElement = childNode as XmlElement;
         XmlText    text         = childNode as XmlText;
         XmlComment comment      = childNode as XmlComment;
         if (childElement != null)
         {
             XmlElementTreeNode treeNode = new XmlElementTreeNode(childElement);
             treeNode.AddTo(this);
         }
         else if (text != null)
         {
             XmlTextTreeNode treeNode = new XmlTextTreeNode(text);
             treeNode.AddTo(this);
         }
         else if (comment != null)
         {
             XmlCommentTreeNode treeNode = new XmlCommentTreeNode(comment);
             treeNode.AddTo(this);
         }
     }
 }
		public void Init()
		{
			treeViewContainer = new XmlTreeViewContainerControl();
							
			XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema();
			XmlSchemaCompletionData xhtmlSchema = new XmlSchemaCompletionData(reader);
			XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection();
			XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xhtmlSchema, String.Empty);
			
			treeViewContainer.LoadXml("<!-- comment --><html><body class='a'><p>Text</p></body></html>", provider);
			doc = treeViewContainer.Document;
			treeView = treeViewContainer.TreeView;
			
			commentTreeNode = (XmlCommentTreeNode)treeView.Nodes[0];
			htmlTreeNode = (XmlElementTreeNode)treeView.Nodes[1];
			htmlTreeNode.Expanding();
			
			bodyTreeNode = (XmlElementTreeNode)htmlTreeNode.Nodes[0];
			bodyTreeNode.Expanding();
			
			paraTreeNode = (XmlElementTreeNode)bodyTreeNode.Nodes[0];
			paraTreeNode.Expanding();
			
			textTreeNode = (XmlTextTreeNode)paraTreeNode.Nodes[0];
		}
		public void SetUp()
		{
			XmlCompletionDataProvider completionDataProvider = new XmlCompletionDataProvider(new XmlSchemaCompletionDataCollection(), null, String.Empty);
			treeViewContainerControl = new XmlTreeViewContainerControl();
			treeView = treeViewContainerControl.TreeView;
			treeViewContainerControl.LoadXml(GetXml(), completionDataProvider);
			doc = treeViewContainerControl.Document;
			
			clipboardHandler = treeViewContainerControl as IClipboardHandler;
			
			htmlElement = doc.DocumentElement;
			bodyElement = htmlElement.FirstChild as XmlElement;
			paragraphElement = bodyElement.SelectSingleNode("p") as XmlElement;
			paragraphText = paragraphElement.SelectSingleNode("text()") as XmlText;
			bodyComment = bodyElement.SelectSingleNode("comment()") as XmlComment;
			
			htmlTreeNode = treeView.Nodes[0] as XmlElementTreeNode;
			htmlTreeNode.PerformInitialization();
			bodyTreeNode = htmlTreeNode.FirstNode as XmlElementTreeNode;
			bodyTreeNode.PerformInitialization();
			bodyCommentTreeNode = bodyTreeNode.FirstNode as XmlCommentTreeNode;
			paragraphTreeNode = bodyTreeNode.LastNode as XmlElementTreeNode;
			paragraphTreeNode.PerformInitialization();
			paragraphTextTreeNode = paragraphTreeNode.FirstNode as XmlTextTreeNode;
		}
		public void SetUp()
		{
			SD.InitializeForUnitTests();
			treeViewContainer = new DerivedXmlTreeViewContainerControl();
			string xml = "<!-- Root comment --><root><!-- Child comment --><child></child></root>";
			treeViewContainer.LoadXml(xml);
			
			doc = treeViewContainer.Document;
			treeView = treeViewContainer.TreeView;
			
			// Get the root comment node in the tree.
			rootCommentNode = (XmlComment)doc.FirstChild;
			rootCommentTreeNode = treeView.Nodes[0] as XmlCommentTreeNode;
			
			// Get the child comment node in the tree.
			rootElementTreeNode = (XmlElementTreeNode)treeView.Nodes[1];
			rootElementTreeNode.Expanding();
			rootElement = rootElementTreeNode.XmlElement;
			
			childCommentTreeNode = rootElementTreeNode.Nodes[0] as XmlCommentTreeNode;
			childCommentNode = (XmlComment)rootElementTreeNode.XmlElement.FirstChild;
			
			childElementTreeNode = rootElementTreeNode.Nodes[1] as XmlElementTreeNode;
			childElement = childElementTreeNode.XmlElement;
		}
        /// <summary>
        /// Updates the corresponding tree node's text based on
        /// the comment's value.
        /// </summary>
        public void UpdateComment(XmlComment comment)
        {
            XmlCommentTreeNode node = FindComment(comment);

            if (node != null)
            {
                node.Update();
            }
        }
        /// <summary>
        /// Removes the specified comment from the tree.
        /// </summary>
        public void RemoveComment(XmlComment comment)
        {
            XmlCommentTreeNode node = FindComment(comment);

            if (node != null)
            {
                node.Remove();
            }
        }
        /// <summary>
        /// Appends a new child comment node to the currently selected element.
        /// </summary>
        public void AppendChildComment(XmlComment comment)
        {
            XmlElementTreeNode selectedNode = SelectedElementNode;

            if (selectedNode != null)
            {
                XmlCommentTreeNode newNode = new XmlCommentTreeNode(comment);
                newNode.AddTo(selectedNode);
                selectedNode.Expand();
            }
        }
        /// <summary>
        /// Locates the specified comment in the tree.
        /// </summary>
        XmlCommentTreeNode FindComment(XmlComment comment)
        {
            XmlCommentTreeNode selectedCommentTreeNode = SelectedNode as XmlCommentTreeNode;

            if (selectedCommentTreeNode != null && selectedCommentTreeNode.XmlComment == comment)
            {
                return(selectedCommentTreeNode);
            }
            else
            {
                return(FindComment(comment, Nodes));
            }
        }
		public void GhostImage()
		{
			XmlComment comment = doc.CreateComment(String.Empty);
			XmlCommentTreeNode node = new XmlCommentTreeNode(comment);

			Assert.IsFalse(node.ShowGhostImage);
			
			node.ShowGhostImage = false;
			Assert.AreEqual(XmlCommentTreeNode.XmlCommentTreeNodeImageKey, node.ImageKey);
		
			node.ShowGhostImage = true;
			Assert.IsTrue(node.ShowGhostImage);
			Assert.AreEqual(XmlCommentTreeNode.XmlCommentTreeNodeGhostImageKey, node.ImageKey);
		}
예제 #11
0
		public void Init()
		{
			treeViewContainer = new DerivedXmlTreeViewContainerControl();
			treeViewContainer.LoadXml("<!-- comment --><html><body class='a'><p>Text</p></body></html>");
			doc = treeViewContainer.Document;
			treeView = treeViewContainer.TreeView;
			
			commentTreeNode = (XmlCommentTreeNode)treeView.Nodes[0];
			htmlTreeNode = (XmlElementTreeNode)treeView.Nodes[1];
			htmlTreeNode.Expanding();
			
			bodyTreeNode = (XmlElementTreeNode)htmlTreeNode.Nodes[0];
			bodyTreeNode.Expanding();
			
			paraTreeNode = (XmlElementTreeNode)bodyTreeNode.Nodes[0];
			paraTreeNode.Expanding();
			
			textTreeNode = (XmlTextTreeNode)paraTreeNode.Nodes[0];
		}
		/// <summary>
		/// Adds child elements to this tree node.
		/// </summary>
		protected override void Initialize()
		{
			Nodes.Clear();
			foreach (XmlNode childNode in element.ChildNodes) {
				XmlElement childElement = childNode as XmlElement;
				XmlText text = childNode as XmlText;
				XmlComment comment = childNode as XmlComment;
				if (childElement != null) {
					XmlElementTreeNode treeNode = new XmlElementTreeNode(childElement);
					treeNode.AddTo(this);
				} else if (text != null) {
					XmlTextTreeNode treeNode = new XmlTextTreeNode(text);
					treeNode.AddTo(this);
				} else if (comment != null) {
					XmlCommentTreeNode treeNode = new XmlCommentTreeNode(comment);
					treeNode.AddTo(this);
				}
			}
		}
        /// <summary>
        /// Displays the document in the xml tree.
        /// </summary>
        void ShowDocument()
        {
            Nodes.Clear();
            if (document != null)
            {
                foreach (XmlNode node in document.ChildNodes)
                {
                    switch (node.NodeType)
                    {
                    case XmlNodeType.Element:
                        XmlElementTreeNode elementNode = new XmlElementTreeNode((XmlElement)node);
                        elementNode.AddTo(this);
                        break;

                    case XmlNodeType.Comment:
                        XmlCommentTreeNode commentNode = new XmlCommentTreeNode((XmlComment)node);
                        commentNode.AddTo(this);
                        break;
                    }
                }
            }
        }
		public void Init()
		{
			treeViewContainer = new XmlTreeViewContainerControl();
							
			XmlSchemaCompletion xhtmlSchema = new XmlSchemaCompletion(ResourceManager.ReadXhtmlStrictSchema());
			XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection();
			
			treeViewContainer.LoadXml("<!-- comment --><html><body class='a'><p>Text</p></body></html>", schemas, null);
			doc = treeViewContainer.Document;
			treeView = treeViewContainer.TreeView;
			
			commentTreeNode = (XmlCommentTreeNode)treeView.Nodes[0];
			htmlTreeNode = (XmlElementTreeNode)treeView.Nodes[1];
			htmlTreeNode.Expanding();
			
			bodyTreeNode = (XmlElementTreeNode)htmlTreeNode.Nodes[0];
			bodyTreeNode.Expanding();
			
			paraTreeNode = (XmlElementTreeNode)bodyTreeNode.Nodes[0];
			paraTreeNode.Expanding();
			
			textTreeNode = (XmlTextTreeNode)paraTreeNode.Nodes[0];
		}
 /// <summary>
 /// Looks at all the nodes in the tree view and returns the
 /// tree node that represents the specified comment node.
 /// </summary>
 XmlCommentTreeNode FindComment(XmlComment comment, TreeNodeCollection nodes)
 {
     foreach (ExtTreeNode node in nodes)
     {
         XmlCommentTreeNode commentTreeNode = node as XmlCommentTreeNode;
         if (commentTreeNode != null)
         {
             if (commentTreeNode.XmlComment == comment)
             {
                 return(commentTreeNode);
             }
         }
         else
         {
             // Look for a match in the node's child nodes.
             XmlCommentTreeNode childCommentTreeNode = FindComment(comment, node.Nodes);
             if (childCommentTreeNode != null)
             {
                 return(childCommentTreeNode);
             }
         }
     }
     return(null);
 }
		public void SetUp()
		{
			treeViewContainerControl = new DerivedXmlTreeViewContainerControl();
			treeView = treeViewContainerControl.TreeView;
			treeViewContainerControl.LoadXml(GetXml());
			doc = treeViewContainerControl.Document;
			
			clipboardHandler = treeViewContainerControl as IClipboardHandler;
			
			htmlElement = doc.DocumentElement;
			bodyElement = htmlElement.FirstChild as XmlElement;
			paragraphElement = bodyElement.SelectSingleNode("p") as XmlElement;
			paragraphText = paragraphElement.SelectSingleNode("text()") as XmlText;
			bodyComment = bodyElement.SelectSingleNode("comment()") as XmlComment;
			
			htmlTreeNode = treeView.Nodes[0] as XmlElementTreeNode;
			htmlTreeNode.PerformInitialization();
			bodyTreeNode = htmlTreeNode.FirstNode as XmlElementTreeNode;
			bodyTreeNode.PerformInitialization();
			bodyCommentTreeNode = bodyTreeNode.FirstNode as XmlCommentTreeNode;
			paragraphTreeNode = bodyTreeNode.LastNode as XmlElementTreeNode;
			paragraphTreeNode.PerformInitialization();
			paragraphTextTreeNode = paragraphTreeNode.FirstNode as XmlTextTreeNode;
		}
		public void SetUp()
		{
			XmlCompletionDataProvider completionDataProvider = new XmlCompletionDataProvider(new XmlSchemaCompletionDataCollection(), null, String.Empty);
			treeViewContainer = new DerivedXmlTreeViewContainerControl();
			treeViewContainer.LoadXml("<!-- Root comment --><root><!-- Child comment --><child></child></root>", completionDataProvider);
			
			doc = treeViewContainer.Document;
			treeView = treeViewContainer.TreeView;
			
			// Get the root comment node in the tree.
			rootCommentNode = (XmlComment)doc.FirstChild;
			rootCommentTreeNode = treeView.Nodes[0] as XmlCommentTreeNode;
			
			// Get the child comment node in the tree.
			rootElementTreeNode = (XmlElementTreeNode)treeView.Nodes[1];
			rootElementTreeNode.Expanding();
			rootElement = rootElementTreeNode.XmlElement;
			
			childCommentTreeNode = rootElementTreeNode.Nodes[0] as XmlCommentTreeNode;
			childCommentNode = (XmlComment)rootElementTreeNode.XmlElement.FirstChild;
			
			childElementTreeNode = rootElementTreeNode.Nodes[1] as XmlElementTreeNode;
			childElement = childElementTreeNode.XmlElement;
		}
		/// <summary>
		/// Inserts a new comment node either before or after the 
		/// currently selected node.
		/// </summary>
		void InsertComment(XmlComment comment, InsertionMode insertionMode)
		{
			ExtTreeNode selectedNode = (ExtTreeNode)SelectedNode;
			if (selectedNode != null) {
				ExtTreeNode parentNode = (ExtTreeNode)selectedNode.Parent;
				XmlCommentTreeNode newNode = new XmlCommentTreeNode(comment);
				int index = 0;
				if (parentNode != null) {
					index = parentNode.Nodes.IndexOf(selectedNode);
				} else {
					index = Nodes.IndexOf(selectedNode);
				}
				if (insertionMode == InsertionMode.After) {
					index++;
				}
				if (parentNode != null) {
					newNode.Insert(index, parentNode);
				} else {
					newNode.Insert(index, this);
				}
			}
		}
		/// <summary>
		/// Displays the document in the xml tree.
		/// </summary>
		void ShowDocument()
		{
			Nodes.Clear();
			if (document != null) {
				foreach (XmlNode node in document.ChildNodes) {
					switch (node.NodeType) {
						case XmlNodeType.Element:
							XmlElementTreeNode elementNode = new XmlElementTreeNode((XmlElement)node);
							elementNode.AddTo(this);
							break;
						case XmlNodeType.Comment:
							XmlCommentTreeNode commentNode = new XmlCommentTreeNode((XmlComment)node);
							commentNode.AddTo(this);
							break;
					}
				}
			}
		}
		/// <summary>
		/// Appends a new child comment node to the currently selected element.
		/// </summary>
		public void AppendChildComment(XmlComment comment)
		{
			XmlElementTreeNode selectedNode = SelectedElementNode;
			if (selectedNode != null) {
				XmlCommentTreeNode newNode = new XmlCommentTreeNode(comment);
				newNode.AddTo(selectedNode);
				selectedNode.Expand();
			}
		}
        /// <summary>
        /// Shows the corresponding tree node with the ghosted image
        /// that indicates it is being cut.
        /// </summary>
        void ShowCutComment(XmlComment comment, bool showGhostImage)
        {
            XmlCommentTreeNode node = FindComment(comment);

            node.ShowGhostImage = showGhostImage;
        }
		public void SelectedImageKey()
		{
			XmlComment comment = doc.CreateComment(String.Empty);
			XmlCommentTreeNode node = new XmlCommentTreeNode(comment);
			Assert.AreEqual(XmlCommentTreeNode.XmlCommentTreeNodeImageKey, node.SelectedImageKey);
		}
		public void XmlCommentIsSame()
		{
			XmlComment comment = doc.CreateComment(String.Empty);
			XmlCommentTreeNode node = new XmlCommentTreeNode(comment);
			Assert.AreSame(comment, node.XmlComment);
		}
		public void WhiteSpaceRemoved()
		{
			XmlComment comment = doc.CreateComment("  \t\tTest\t\t   ");
			XmlCommentTreeNode node = new XmlCommentTreeNode(comment);
			Assert.AreEqual("Test", node.Text);
		}