Exemplo n.º 1
0
        /// <summary>
        /// 创建子节点
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="domnode"></param>
        /// <returns></returns>
        private DomTreeNode NewDomNode(IHTMLDOMNode domnode)
        {
            string text = "";

            if (Commentnode == domnode.nodeName)
            {
                if (domnode.nodeValue != null)
                {
                    text = "<!" + domnode.nodeValue + ">";
                }
            }
            else
            {
                text = string.Format("<{0}{1}>", domnode.nodeName.ToLower(), ToAttributeString(domnode));
            }
            DomTreeNode treeNode = new DomTreeNode();

            treeNode.Text = text;
            treeNode.Tag  = domnode;

            if (!nodeHash.Contains(domnode))
            {
                nodeHash.Add(domnode, treeNode);
            }
            return(treeNode);
        }
Exemplo n.º 2
0
        private System.Windows.Forms.ContextMenuStrip CreateContextMenu(DomTreeNode node)
        {
            IHTMLElement element = node.Tag as IHTMLElement;

            ContextMenuStrip strip = new ContextMenuStrip();


            ToolStripMenuItem item = new ToolStripMenuItem("复制HTML");

            item.Name = "copyHTML";
            item.Tag  = element;
            strip.Items.Add(item);

            item      = new ToolStripMenuItem("复制innerHTML");
            item.Name = "copyInnerHTML";
            item.Tag  = element;
            strip.Items.Add(item);

            item      = new ToolStripMenuItem("复制XPATH");
            item.Name = "copyXPATH";
            item.Tag  = element;
            strip.Items.Add(item);

            item      = new ToolStripMenuItem("删除");
            item.Name = "delete";
            item.Tag  = element;
            strip.Items.Add(item);


            strip.ItemClicked += new ToolStripItemClickedEventHandler(strip_ItemClicked);
            return(strip);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 加载单个树节点
        /// </summary>
        /// <param name="el"></param>
        /// <param name="dataDict"></param>
        private void PopulateNode(IHTMLElement el, List <IHTMLElement> dataDict)
        {
            if (el == null)
            {
                return;
            }
            DomTreeNode node = null;

            if (nodeHash.Contains(el))
            {
                node = nodeHash[el] as DomTreeNode;

                dataDict.Reverse();
                foreach (var o in dataDict)
                {
                    if (node == null)
                    {
                        continue;
                    }
                    //logger.Info("add treenode:" + XPathFinder.GetXPath(o, true));

                    IHTMLDOMNode parent = ((IHTMLDOMNode)o).parentNode;
                    if (parent == null)
                    {
                        parent = (IHTMLDOMNode)BrowserExtensions.GetFrame((IHTMLElement)o);
                    }
                    ParseNodes(parent, node, 1);
                    node.IsLoadData = true;
                    node            = nodeHash[o] as DomTreeNode;
                }
            }
            else
            {
                dataDict.Add(el);
                IHTMLDOMNode cnode    = el as IHTMLDOMNode;
                IHTMLElement parentEl = cnode.parentNode as IHTMLElement;
                if (parentEl == null)
                {
                    IHTMLElement frame = BrowserExtensions.GetFrame((IHTMLElement)el);
                    PopulateNode(frame, dataDict);
                }
                else
                {
                    PopulateNode(parentEl, dataDict);
                }
            }
        }
Exemplo n.º 4
0
        void DomTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            DomTreeNode node = e.Node as DomTreeNode;

            if (!node.IsExpanded && !node.IsLoadData)
            {
                node.IsLoadData = true;
                ParseNodes((IHTMLDOMNode)node.Tag, node, expandDeep);
            }

            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                TreeViewHitTestInfo info = this.HitTest(e.X, e.Y);
                this.ContextMenuStrip = CreateContextMenu(node);
                this.ContextMenuStrip.Show();
            }
        }
Exemplo n.º 5
0
        public void SelectNodes(IHTMLElement[] elements)
        {
            List <TreeNode> treeNodes = new List <TreeNode>();

            foreach (var el in elements)
            {
                PopulateNode((IHTMLDOMNode)el);
                DomTreeNode node = nodeHash[el] as DomTreeNode;
                if (node != null)
                {
                    treeNodes.Add(node);
                }
            }
            foreach (var node in treeNodes)
            {
                //node.BeginEdit();
                node.EnsureVisible();
                //node.EndEdit(false);
            }

            SelectedNodes = treeNodes;
        }