Пример #1
0
        public static Saved_MethodStream map_CodeStreams(this Saved_MethodStream savedMethodStream, O2MappedAstData astData, String file, INode iNode)
        {
            var o2CodeStream = astData.createO2CodeStream(file, iNode);

            //var uniqueStreamPaths = o2CodeStream.getUniqueStreamPaths(100);

            Func <O2CodeStreamNode, CodeStreamPath> map_O2CodeStreamNode = null;

            map_O2CodeStreamNode = (o2CodeStreamNode) =>
            {
                var codeStreamPath = new CodeStreamPath();
                codeStreamPath.Text       = o2CodeStreamNode.Text;
                codeStreamPath.Line       = o2CodeStreamNode.INode.StartLocation.Line;
                codeStreamPath.Column     = o2CodeStreamNode.INode.StartLocation.Column;
                codeStreamPath.Line_End   = o2CodeStreamNode.INode.EndLocation.Line;
                codeStreamPath.Column_End = o2CodeStreamNode.INode.EndLocation.Column;
                foreach (var childNode in o2CodeStreamNode.ChildNodes)
                {
                    codeStreamPath.CodeStreamPaths.add(map_O2CodeStreamNode(childNode));
                }
                return(codeStreamPath);
            };
            foreach (var streamNode in o2CodeStream.StreamNode_First)
            {
                savedMethodStream.CodeStreams.add(map_O2CodeStreamNode(streamNode));
            }
            return(savedMethodStream);
        }
        public ascx_CodeStreams buildGui()
        {
            codeViewer       = this.add_SourceCodeViewer();
            codeStreams      = codeViewer.insert_Right().add_GroupBox("All Code Streams").add_TreeView();
            codeStreamViewer = codeStreams.parent().insert_Below().add_GroupBox("Selected Code Stream").add_TreeView();
            //var codeStreamViewer = topPanel.insert_Right().add_TreeView();

            Action <TreeNode, CodeStreamPath> add_CodeStreamPath = null;

            add_CodeStreamPath =
                (treeNode, codeStreamPath) => {
                var newNode = treeNode.add_Node(codeStreamPath);
                foreach (var childPath in codeStreamPath.CodeStreamPaths)
                {
                    add_CodeStreamPath(newNode, childPath);
                }
            };

            Action <TreeView, CodeStreamPath> showCodeStreamPath =
                (treeView, codeStreamPath) => {
                treeView.clear();
                add_CodeStreamPath(treeView.rootNode(), codeStreamPath);
                treeView.expandAll();
                treeView.selectFirst();
            };

            Action <ascx_SourceCodeEditor, CodeStreamPath, bool> colorCodePath =
                (codeEditor, codeStreamPath, clearMarkers) =>
            {
                if (codeEditor.getSourceCode().inValid() || codeStreamPath.Line == 0 && codeStreamPath.Column == 0)
                {
                    return;
                }
                try
                {
                    if (clearMarkers)
                    {
                        codeEditor.clearMarkers();
                        codeEditor.caret(codeStreamPath.Line, codeStreamPath.Column);
                    }
                    codeEditor.selectTextWithColor(codeStreamPath.Line,
                                                   codeStreamPath.Column,
                                                   codeStreamPath.Line_End,
                                                   codeStreamPath.Column_End);
                    codeEditor.refresh();
                }
                catch (Exception ex)
                {
                    ex.log();
                }
            };

            Action <ascx_SourceCodeEditor, List <CodeStreamPath> > colorCodePaths =
                (codeEditor, codeStreamPaths) => {
                foreach (var codeStreamPath in codeStreamPaths)
                {
                    colorCodePath(codeEditor, codeStreamPath, false);
                }
            };

            Action <TreeView, ascx_SourceCodeEditor> set_AfterSelect_SyncWithCodeEditor =
                (treeView, codeEditor) => {
                treeView.afterSelect <CodeStreamPath>(
                    (codeStreamPath) => colorCodePath(codeEditor, codeStreamPath, true));
            };


            set_AfterSelect_SyncWithCodeEditor(codeStreams, codeViewer.editor());
            set_AfterSelect_SyncWithCodeEditor(codeStreamViewer, codeViewer.editor());

            codeStreams.afterSelect <CodeStreamPath>(
                (codeStreamPath) => showCodeStreamPath(codeStreamViewer, codeStreamPath));


            codeStreams.beforeExpand <CodeStreamPath>(
                (treeNode, codeStreamPath) => {
                treeNode.add_Nodes(codeStreamPath.CodeStreamPaths, (codeStream) => codeStream.CodeStreamPaths.size() > 0);
            });


            codeViewer.onClick(
                () => {
                if (savedMethodStream.notNull())
                {
                    codeViewer.editor().clearMarkers();
                    codeStreamViewer.clear();
                    codeStreams.clear();
                    var line   = codeViewer.caret().Line + 1;
                    var column = codeViewer.caret().Column + 1;
                    CodeStreamPath lastMatch = null;
                    foreach (var codeStreamPath in savedMethodStream.CodeStreams)
                    {
                        if (codeStreamPath.Line <= line && codeStreamPath.Line_End >= line &&
                            codeStreamPath.Column <= column && codeStreamPath.Column_End >= column)
                        {
                            codeStreams.add_Node(codeStreamPath);
                            lastMatch = codeStreamPath;
                        }
                    }
                    if (lastMatch.notNull())
                    {
                        showCodeStreamPath(codeStreamViewer, lastMatch);
                        var codeStreamPaths = (from node in codeStreamViewer.allNodes()
                                               select(CodeStreamPath) node.get_Tag()).toList();
                        colorCodePaths(codeViewer.editor(), codeStreamPaths);
                    }
                    else
                    {
                        refresh_AllCodeStreams_TreeView();
                    }
                }
            });
            return(this);
        }
		public static Saved_MethodStream map_CodeStreams(this Saved_MethodStream savedMethodStream, O2MappedAstData astData , String file, INode iNode)
		{									
		
			var o2CodeStream = astData.createO2CodeStream( file,iNode); 			
									
			//var uniqueStreamPaths = o2CodeStream.getUniqueStreamPaths(100);
			
			Func<O2CodeStreamNode, CodeStreamPath> map_O2CodeStreamNode = null; 
			map_O2CodeStreamNode = (o2CodeStreamNode) =>
				{
					var codeStreamPath = new CodeStreamPath(); 
					codeStreamPath.Text = o2CodeStreamNode.Text;
					codeStreamPath.Line = o2CodeStreamNode.INode.StartLocation.Line;
					codeStreamPath.Column = o2CodeStreamNode.INode.StartLocation.Column;
					codeStreamPath.Line_End = o2CodeStreamNode.INode.EndLocation.Line;
					codeStreamPath.Column_End = o2CodeStreamNode.INode.EndLocation.Column; 										
					foreach(var childNode in o2CodeStreamNode.ChildNodes)
						codeStreamPath.CodeStreamPaths.add(map_O2CodeStreamNode(childNode)); 
					return codeStreamPath;
				};
			foreach(var streamNode in o2CodeStream.StreamNode_First)
				savedMethodStream.CodeStreams.add(map_O2CodeStreamNode(streamNode));
			return savedMethodStream;	
		}