Пример #1
0
        /// -------------------------------------------------------------------------------------------
        /// <summary>
        /// This method adds each node,subnode,child in Treenode named as nodeTemp.
        /// </summary>
        /// <param name="n">Its gets the node element from the TreeTemp</param>
        /// <param name="t">Its gets the parent of the current tree</param>
        /// <param name="ctp">input CSSTreeParser</param>
        /// -------------------------------------------------------------------------------------------
        private static void AddSubTree(TreeNode n, CommonTree t, CssTreeParser ctp)
        {
            TreeNode nodeTemp = n.Nodes.Add(t.Text);

            foreach (CommonTree child in ctp.Children(t))
            {
                AddSubTree(nodeTemp, child, ctp);
            }
        }
Пример #2
0
        /// -------------------------------------------------------------------------------------------
        /// <summary>
        /// This function parsing the CSS file and creates a TreeNode nodeTemp.
        /// </summary>
        /// <param name="path">Its gets the file path of the CSS File</param>
        /// -------------------------------------------------------------------------------------------
        private void ParseCSS(string path)
        {
            var ctp = new CssTreeParser();

            try
            {
                ctp.Parse(path);
                ErrorText = ctp.ErrorText();
            }
            catch (Exception)
            {
                ErrorText = ctp.ErrorText();
                throw;
            }
            CommonTree r = ctp.Root;

            _nodeTemp.Nodes.Clear();

            if (r.Text != "nil" && r.Text != null)
            {
                _nodeTemp.Text = "nil";
                AddSubTree(_nodeTemp, r, ctp);
            }
            else
            {
                string rootNode = r.Text ?? "nil";
                _nodeTemp.Text = rootNode;
                foreach (CommonTree child in ctp.Children(r))
                {
                    AddSubTree(_nodeTemp, child, ctp);
                }
            }

            // To validate the nodes in nodeTemp has copied to nodeFine
            if (_isReCycle == false)
            {
                _nodeFinal.Nodes.Clear();
                MakeTreeNode(_nodeTemp, _nodeFinal, false);
                // To traverse the node second time.
                if (_isReCycle)
                {
                    MakeTreeNode(_nodeFinal, _nodeFinal, true);
                }
            }
        }
Пример #3
0
 private void btnBrowse_Click(object sender, EventArgs e)
 {
     TreeNode _nodeTemp = new TreeNode();
     OpenFileDialog dlg = new OpenFileDialog();
     dlg.DefaultExt = "CSS";
     dlg.Filter = "Cascading Style Sheet (*.css)|*.css";
     if (dlg.ShowDialog() == DialogResult.OK)
     {
         string path = dlg.FileName;
         var ctp = new CssTreeParser();
         try
         {
             ctp.Parse(path);
         }
         catch (Exception)
         {
             throw;
         }
         CommonTree r = ctp.Root;
         _nodeTemp.Nodes.Clear();
         if (r.Text != "nil" && r.Text != null)
         {
             _nodeTemp.Text = "nil";
             AddSubTree(_nodeTemp, r, ctp);
         }
         else
         {
             string rootNode = r.Text ?? "nil";
             _nodeTemp.Text = rootNode;
             foreach (CommonTree child in ctp.Children(r))
             {
                 AddSubTree(_nodeTemp, child, ctp);
             }
         }
     }
     treeView1.Nodes.Clear();
     treeView1.Nodes.Add((TreeNode)_nodeTemp.Clone());
     treeView1.ExpandAll();
 }
Пример #4
0
 /// -------------------------------------------------------------------------------------------
 /// <summary>
 /// This method adds each node,subnode,child in Treenode named as nodeTemp.
 /// </summary>
 /// <param name="n">Its gets the node element from the TreeTemp</param>
 /// <param name="t">Its gets the parent of the current tree</param>
 /// <param name="ctp">input CSSTreeParser</param>
 /// -------------------------------------------------------------------------------------------
 private static void AddSubTree(TreeNode n, CommonTree t, CssTreeParser ctp)
 {
     TreeNode nodeTemp = n.Nodes.Add(t.Text);
     foreach (CommonTree child in ctp.Children(t))
         AddSubTree(nodeTemp, child, ctp);
 }
Пример #5
0
        /// -------------------------------------------------------------------------------------------
        /// <summary>
        /// This function parsing the CSS file and creates a TreeNode nodeTemp.
        /// </summary>
        /// <param name="path">Its gets the file path of the CSS File</param>
        /// -------------------------------------------------------------------------------------------
        private void ParseCSS(string path)
        {
            var ctp = new CssTreeParser();
            try
            {
                ctp.Parse(path);
                ErrorText = ctp.ErrorText();
            }
            catch (Exception)
            {
                ErrorText = ctp.ErrorText();
                throw;
            }
            CommonTree r = ctp.Root;
            _nodeTemp.Nodes.Clear();

            if (r.Text != "nil" && r.Text != null)
            {
                _nodeTemp.Text = "nil";
                AddSubTree(_nodeTemp, r, ctp);
            }
            else
            {
                string rootNode = r.Text ?? "nil";
                _nodeTemp.Text = rootNode;
                foreach (CommonTree child in ctp.Children(r))
                {
                    AddSubTree(_nodeTemp, child, ctp);
                }
            }

            // To validate the nodes in nodeTemp has copied to nodeFine
            if (_isReCycle == false)
            {
                _nodeFinal.Nodes.Clear();
                MakeTreeNode(_nodeTemp, _nodeFinal, false);
                // To traverse the node second time.
                if (_isReCycle)
                {
                    MakeTreeNode(_nodeFinal, _nodeFinal, true);
                }
            }
        }