Esempio n. 1
0
        void AddNode(TreeNavigator treeNavigator, SyntaxNode syntaxNode)
        {
            var leadingTrivia  = syntaxNode.GetLeadingTrivia();
            var trailingTrivia = syntaxNode.GetTrailingTrivia();

            AddLeadingTrivia(leadingTrivia);

            SetNodeText(treeNavigator, syntaxNode.GetType().Name, syntaxNode.Span, Colors.DarkBlue);

            foreach (var child in syntaxNode.ChildNodesAndTokens())
            {
                treeNavigator.AddChild();
                if (child.IsNode)
                {
                    AddNode(treeNavigator, child.AsNode());
                }
                else
                {
                    var token = child.AsToken();
                    if (token.LeadingTrivia != leadingTrivia)
                    {
                        AddLeadingTrivia(token.LeadingTrivia);
                    }
                    SetNodeText(treeNavigator, token.GetType().Name, token.Span, Colors.DarkGreen);
                    if (token.TrailingTrivia != trailingTrivia)
                    {
                        AddTrailingTrivia(token.TrailingTrivia);
                    }
                }
                treeNavigator.MoveToParent();
            }

            AddTrailingTrivia(trailingTrivia);

            void AddLeadingTrivia(SyntaxTriviaList triviaList)
            {
                foreach (var trivia in triviaList)
                {
                    AddTrivia(trivia);
                    treeNavigator.InsertAfter();
                }
            }

            void AddTrailingTrivia(SyntaxTriviaList triviaList)
            {
                foreach (var trivia in triviaList)
                {
                    treeNavigator.InsertAfter();
                    AddTrivia(trivia);
                }
            }

            void AddTrivia(SyntaxTrivia trivia) => SetNodeText(treeNavigator, trivia.GetType().Name, trivia.Span, Colors.DarkRed);
        }
Esempio n. 2
0
//		public VirtualGridRow GetSelectedGridRow()
//		{
//			TreePosition tp = Tree.SelectedRow;
//
//			foreach (VirtualGridRow row in Rows)
//			{
//				TreeNavigator tn = DataStore.GetNavigatorAt (tp);
//				//DataStore.
//				//VirtualGridRow rw = (VirtualGridRow)GetValue(tn,"");
//				//tn.GetValue(
//			}
//			return null;
//		}


        public void addData(TreeNavigator navigator, VirtualTreeRow row)
        {
            if (navigator == null)
            {
                throw new ArgumentNullException("navigator");
            }

            if (row == null)
            {
                throw new ArgumentNullException("row");
            }

            //add children
            if ((row.Children != null) && (row.Children.Count > 0))
            {
                TreeNavigator current = navigator;
                int           idx     = 0;
                foreach (KeyValuePair <String, VirtualTreeRow> kp in row.Children)
                {
                    if (idx > 0)
                    {
                        current.InsertAfter();
                    }

                    setData(current, kp.Value.Data);

                    if (kp.Value.Children.Count > 0)
                    {
                        addData(current.AddChild(), kp.Value);
                        current.MoveToParent();
                    }
                    else
                    {
                        if (kp.Value.Rows.Count > 0)
                        {
                            addData(current.AddChild(), kp.Value);
                            current.MoveToParent();
                        }
                    }

                    idx++;
                }
            }

            //if no children available add the assigned rows
            if ((row.Children == null) || (row.Children.Count < 1))
            {
                int idx = 0;
                foreach (VirtualGridRow rw in row.Rows)
                {
                    if (idx > 0)
                    {
                        navigator.InsertAfter();
                    }

                    setData(navigator, rw.Datas);

                    idx++;
                }
            }
        }
Esempio n. 3
0
        //        public VirtualGridRow GetSelectedGridRow()
        //        {
        //            TreePosition tp = Tree.SelectedRow;
        //
        //            foreach (VirtualGridRow row in Rows)
        //            {
        //                TreeNavigator tn = DataStore.GetNavigatorAt (tp);
        //                //DataStore.
        //                //VirtualGridRow rw = (VirtualGridRow)GetValue(tn,"");
        //                //tn.GetValue(
        //            }
        //            return null;
        //        }
        public void addData(TreeNavigator navigator, VirtualTreeRow row)
        {
            if (navigator == null)
            {
                throw new ArgumentNullException("navigator");
            }

            if (row == null)
            {
                throw new ArgumentNullException("row");
            }

            //add children
            if ((row.Children != null) && (row.Children.Count > 0))
            {
                TreeNavigator current = navigator;
                int idx = 0;
                foreach (KeyValuePair<String,VirtualTreeRow> kp in row.Children)
                {
                    if (idx > 0)
                    {
                        current.InsertAfter();
                    }

                    setData(current,kp.Value.Data);

                    if (kp.Value.Children.Count > 0)
                    {
                        addData(current.AddChild(),kp.Value);
                        current.MoveToParent();
                    } else
                    {
                        if (kp.Value.Rows.Count > 0)
                        {
                            addData(current.AddChild(),kp.Value);
                            current.MoveToParent();
                        }
                    }

                    idx++;
                }
            }

            //if no children available add the assigned rows
            if ((row.Children == null) || (row.Children.Count < 1))
            {
                int idx = 0;
                foreach (VirtualGridRow rw in row.Rows)
                {
                    if (idx > 0)
                    {
                        navigator.InsertAfter();
                    }

                    setData(navigator,rw.Datas);

                    idx++;
                }
            }
        }
        void AddNode(TreeNavigator treeNavigator, SyntaxNode syntaxNode, bool hideLeadingTrivia = false)
        {
            var leadingTrivia  = syntaxNode.GetLeadingTrivia();
            var trailingTrivia = syntaxNode.GetTrailingTrivia();

            if (!hideLeadingTrivia)
            {
                AddLeadingTrivia(leadingTrivia);
            }

            AddSyntaxNode(treeNavigator, syntaxNode);

            bool isFirst = true;

            foreach (var child in syntaxNode.ChildNodesAndTokens())
            {
                //leading trivia is duplicated between the compilation unit and its first child
                bool hideChildLeadingTrivia = isFirst && syntaxNode is ICompilationUnitSyntax;
                isFirst = false;

                treeNavigator.AddChild();

                if (child.IsNode)
                {
                    AddNode(treeNavigator, child.AsNode(), hideChildLeadingTrivia);
                }
                else
                {
                    var token = child.AsToken();
                    if (token.LeadingTrivia != leadingTrivia)
                    {
                        AddLeadingTrivia(token.LeadingTrivia);
                    }
                    AddSyntaxToken(treeNavigator, token);
                    if (token.TrailingTrivia != trailingTrivia)
                    {
                        AddTrailingTrivia(token.TrailingTrivia);
                    }
                }

                treeNavigator.MoveToParent();
            }

            AddTrailingTrivia(trailingTrivia);

            void AddLeadingTrivia(SyntaxTriviaList triviaList)
            {
                foreach (var trivia in triviaList)
                {
                    AddSyntaxTrivia(treeNavigator, trivia);
                    treeNavigator.InsertAfter();
                }
            }

            void AddTrailingTrivia(SyntaxTriviaList triviaList)
            {
                foreach (var trivia in triviaList)
                {
                    treeNavigator.InsertAfter();
                    AddSyntaxTrivia(treeNavigator, trivia);
                }
            }
        }