public ascx_HtmlTagViewer buildGui(bool addLoadUrlTextBox, bool addHtmlCodeViewer)
		{
			//return (ascx_HtmlTagViewer)this.invokeOnThread(
			//	()=>{
			var TopPanel = this.add_Panel();
			HtmlTags_TreeView =  TopPanel.add_TreeView_for_HtmlTags()
									 	 .showSelection();			
			
			if (addHtmlCodeViewer)
			{
				HtmlCodeViewer = HtmlTags_TreeView.insert_Left<Panel>(TopPanel.width()/2).add_SourceCodeViewer(); 
				
				HtmlTags_TreeView.after_TagSelect_showIn_SouceCodeViewer(HtmlCodeViewer);
				
				var optionsPanel = HtmlCodeViewer.insert_Below<Panel>(50);
				optionsPanel.add_CheckBox("View as Xml",0,5, 
					(value)=>{
								ViewAsXml = value;
								reloadPage();
							 })
							 .append_Label("Search html code:")
							 .top(5)
							 .append_TextBox("")
							 .onTextChange((text)=> HtmlCodeViewer.editor().invoke("searchForTextInTextEditor_findNext",text))
							 .onEnter((text)=> HtmlCodeViewer.editor().invoke("searchForTextInTextEditor_findNext",text))
							 .align_Right(optionsPanel);
				
				optionsPanel.add_Link("Refresh tags",30,0,()=> show(HtmlCodeViewer.get_Text()));
			}
			
			if (addLoadUrlTextBox)	
			{
				PageToOpen = TopPanel.insert_Above<Panel>(20).add_TextBox().fill();
				var propertyGrid = HtmlTags_TreeView.insert_Right<Panel>(150).add_PropertyGrid();
				
				
				HtmlTags_TreeView.afterSelect<HtmlAgilityPack.HtmlNode>(
				  (htmlNode)=> propertyGrid.show(htmlNode));
				
				PageToOpen.onEnter(
							(text)=>{
										if (text.fileExists())
											show(text.fileContents());
										else 
											show(text.uri());
									}); 
			}																						
			
			HtmlNodeFilter = HtmlTags_TreeView.insert_Below_HtmlTagFilter((filter) => show(HtmlCode, filter) );
			
			return this;
		//});
		}
        private void buildGui(string startUrl)
        {
        	// test values  make these links on top of the location bar
//            var startUrl = @"http://www.google.co.uk";
        	//var startUrl = @"http://www.owasp.org/index.php/o2";        	
			
        	groupBoxes = this.add_SplitContainer_1x2("Browser","Pages Loaded","WebPage Info", true, 100,100);        	        	        	
        	webBrowser = groupBoxes[0].add_WebBrowserWithLocationBar(startUrl);        	        	
        	((O2BrowserIE)webBrowser).silent(true);
        	htmlPages_TreeView = groupBoxes[1].add_TreeView();
        	htmlPages_TreeView.HideSelection = false;

        	webBrowser.onDocumentCompleted += pageLoaded;
        	        	
        	htmlPages_TreeView.afterSelect<IO2HtmlPage>(showPageDetails);
        	
        	        	
        	        	
     	}        	     	     
		public void loadFiles(string filesPath, List<string> filesToLoad)
		{						
			sourceCode.set_Text("Loading files from: {0}".format(filesPath));
			Path.set_Text(filesPath);
			var filesContent = new Dictionary<string,string>();
			var nonBinaryFiles = new List<string>();
			foreach(var file in filesToLoad) 
				if (file.isBinaryFormat().isFalse()) 
					nonBinaryFiles.add(file);
			
			foreach(var file in nonBinaryFiles) 
					filesContent.add(file.remove(filesPath),file.contents());	
					
			searchEngine = new SearchEngine();
			searchEngine.loadFiles(nonBinaryFiles); 			
			
			//searchEngine.fixH2FileLoadingIssue();
			
			leftPanel.clear();
			treeView = leftPanel.add_TreeViewWithFilter(filesContent); 
			treeView.afterSelect<string>(
				(fileContents)=>{					
									sourceCode.open(filesPath + treeView.selected().get_Text());
								});						
			sourceCode.colorCodeForExtension(treeView.selected().str());
			sourceCode.set_Text("");
			textSearch_TextBox = leftPanel.controls<TextBox>(true)[1];
			textSearch_TextBox.onEnter(
				(text)=>{
					var searchResults = searchEngine.searchFor(text);
					dataGridView.loadInDataGridView_textSearchResults(searchResults);  
				});
			
			
		}		
		public ascx_CodeStreams buildGui() 
		{
			//codeViewer = this.add_SourceCodeViewer();
			_codeEditor = this.add_SourceCodeEditor();
			codeStreams = _codeEditor.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<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<SourceCodeEditor, List<CodeStreamPath>> colorCodePaths = 
				(codeEditor, codeStreamPaths)=> {
													foreach(var codeStreamPath in codeStreamPaths)
														colorCodePath(codeEditor, codeStreamPath,false); 
											    };
				
			Action<TreeView,SourceCodeEditor> set_AfterSelect_SyncWithCodeEditor = 
				(treeView, codeEditor)=>{
								treeView.afterSelect<CodeStreamPath>(
										(codeStreamPath)=> colorCodePath(codeEditor, codeStreamPath,true ) );
			
							};
			
			
			set_AfterSelect_SyncWithCodeEditor(codeStreams, _codeEditor.editor()); 
			set_AfterSelect_SyncWithCodeEditor(codeStreamViewer, _codeEditor.editor());
			
			codeStreams.afterSelect<CodeStreamPath>(
				(codeStreamPath)=> showCodeStreamPath(codeStreamViewer, codeStreamPath));											
					
			
			codeStreams.beforeExpand<CodeStreamPath>(
				(treeNode, codeStreamPath)=>{
												treeNode.add_Nodes(codeStreamPath.CodeStreamPaths, (codeStream) => codeStream.CodeStreamPaths.size() > 0 );
											});
			
			
			_codeEditor.onClick(
				()=>{ 
						if (savedMethodStream.notNull())
						{	
							_codeEditor.editor().clearMarkers();  
							codeStreamViewer.clear();
							codeStreams.clear();
							var line = _codeEditor.caret().Line + 1; 				
							var column = _codeEditor.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(_codeEditor.editor(), codeStreamPaths);   
							}
							else
								refresh_AllCodeStreams_TreeView();
								
								
							
						}
					});
				return this;
		}
		public static void showInTreeView(this MethodMappings methodMappings, TreeView treeView, string filter, bool showSourceCodeSnippets, bool onlyShowSourceCodeLine)		
		{
			treeView.parent().backColor("LightPink");
			treeView.visible(false);
			treeView.clear();
			var indexedMappings = methodMappings.indexedByKey(filter);
			if (onlyShowSourceCodeLine)
			{			
				//do this so that we don't add more than one item per line
				var indexedByFileAndLine = new Dictionary<string, MethodMapping>();
				
				foreach(var item in indexedMappings)
					foreach(var methodMapping in item.Value)
						if (methodMapping.File.valid())
						{
							var key = "{0}_{1}".format(methodMapping.File, methodMapping.Start_Line);
							indexedByFileAndLine.add(key, methodMapping);														
						}
				// now group then by the same text in the SourceCodeLine		
				var indexedBySourceCodeLine =  new Dictionary<string, List<MethodMapping>>();				
				foreach(var methodMapping in indexedByFileAndLine.Values)								
					indexedBySourceCodeLine.add(methodMapping.sourceCodeLine(), methodMapping);				
				
				//Finally show then
				foreach(var item  in indexedBySourceCodeLine)
				{
					var uniqueTextNode = treeView.add_Node(item.Key, item.Value,true);
				}
			}
			else
			{
				foreach(var item in indexedMappings)
				{
					var keyNodeText = "{0}                       ({1})".format(item.Key, item.Value.size());
					var keyNode= treeView.add_Node(keyNodeText, item.Value,true); 																
				}
				treeView.afterSelect<List<MethodMapping>>(
					(mappings)=>{
									var keyNode = treeView.selected();
									keyNode.clear();
									foreach(var methodMapping in mappings)
									{					
										var nodeText = (showSourceCodeSnippets) 
															? methodMapping.sourceCodeLine()								
															: "{0} - {1}".format(methodMapping.INodeType,methodMapping.SourceCode);
										keyNode.add_Node(nodeText, methodMapping);
									}
								  });									
			}
			treeView.parent().backColor("Control");
			treeView.visible(true);
		}
		//bool putJavaScriptCodeViewerOnTheLeft,
		public ascx_Javascript_AST buildGui( bool addUrlLoadTextBox)
		{
			var mainGui = this.add_1x1("Files or ScriptBlocks","Javascript Source (you can edit this code and see the results in realtime)");
			var splitContainer = this.controls<SplitContainer>();
			if (addUrlLoadTextBox)			
			{
				showJavascriptsFromUrl = 
				splitContainer.insert_Above<Panel>(25)
							  .add_LabelAndComboBoxAndButton("Enter Url to load Javascripts","","Open",  loadJavascriptsFromUrl)
							  .controls<ComboBox>();								  
			}
			/*if (putJavaScriptCodeViewerOnTheLeft)
			{				
				splitContainer.splitterDistance(this.width()/3);
				javascriptCode = mainGui[1].add_TreeView().showSelection().sort();
				sourceCode = mainGui[0].add_SourceCodeViewer(); 				
			}
			else			
			{*/
				javascriptCode = mainGui[0].add_TreeView().showSelection().sort();
				sourceCode = mainGui[1].add_SourceCodeViewer(); 
			//}
			pagesVisited = javascriptCode.insert_Above<ComboBox>(25).dropDownList();
			
			codeSnippet = sourceCode.insert_Below<TextBox>(100).multiLine().scrollBars(); 
			tabControl  = javascriptCode.insert_Below<TabControl>();
			
			jsAST = tabControl.add_Tab("Javascript - View Ast Tree")
								  .add_TreeView()
								  .showSelection();
								  
			jsFunctions = tabControl.add_Tab("JScript: Functions")
								  		.add_TreeView()
								  		.showSelection()
								  		.sort();
			
			jsIdentifiers = tabControl.add_Tab("JScript: Identifiers")
								  		  .add_TreeView()
								  		  .showSelection()
								  		  .sort();

			jsValues = tabControl.add_Tab("JScript: Values")
								  	 .add_TreeView()
								  	 .showSelection()
								  	 .sort();
								  		
			
			allAST = tabControl.add_Tab("Javascript - View Ast Elements")					    
								   .add_TreeView()
								   .showSelection()
								   .sort();
			
			var searchTab = tabControl.add_Tab("Search in Code")
									  .add_LabelAndComboBoxAndButton("search for (case sensitive)","","show",
									  	(text)=> {
									  				sourceCode.editor().invoke("searchForTextInTextEditor_findNext", text);
									  			 });
									  					  
			//tabControl.select_Tab(searchTab);
			javaScriptLoadMessage = javascriptCode.insert_Below<Panel>(20);
													  
			allAST.insert_Below<Panel>(25)
				  .add_CheckBox("Render this view (some performace impact on large scripts)", 0,0, 
				  		(value)=>{
				  					RenderViewAstElementsTreeView = value;
				  					processJavascript();
				  				 })
				  .autoSize(); 
				  
				  
			allAST.jint_configure_showSelectionDetails(sourceCode, codeSnippet); 
			jsFunctions.jint_configure_showSelectionDetails(sourceCode, codeSnippet); 
			jsIdentifiers.jint_configure_showSelectionDetails(sourceCode, codeSnippet); 
			jsValues.jint_configure_showSelectionDetails(sourceCode, codeSnippet); 

			javascriptCode.afterSelect<string>(
				(jsCode) => {
								sourceCode.editor().clearBookmarksAndMarkers();
								sourceCode.set_Text(jsCode,"*.js");
								sourceCode.editor().refresh(); 
							});
			
			sourceCode.onTextChanged(processJavascript);
			
			pagesVisited.onSelection<IE_HtmlPage>(
				(htmlPage)=>{
								var allScriptsCompiledOk = javascriptCode.populateWithHtmlPageScripts(htmlPage);
								javascriptCode.add_Node("zzz [Original Html Code for: {0}]".format(htmlPage.PageUri.str()),htmlPage.PageSource);
								handleCompilationResult(allScriptsCompiledOk);								
							});
							
			pagesVisited.onSelection<Jint_Wrapper>(
				(jintWrapper)=>{									
									var allScriptsCompiledOk = javascriptCode.populateWithHtmlPageScripts(jintWrapper.JavaScripts);
									javascriptCode.add_Node("zzz_[Original Code for: {0}]".format(jintWrapper.Uri.str()),jintWrapper.Html);
									handleCompilationResult(allScriptsCompiledOk);
							   });
			
			javascriptCode.onDrop(
				(fileOrFolder)=>{
									if (fileOrFolder.fileExists()) 
										javascriptCode.add_Node(fileOrFolder.str(), fileOrFolder.fileContents());
									else if (fileOrFolder.dirExists()) 
									{
										javascriptCode.clear();
										foreach(var file in fileOrFolder.files("*.js",true))
											javascriptCode.add_Node(file.str(), file.fileContents()); 
									}
								});


			this.add_ContextMenu().add_MenuItem("Show log viewer",()=> this.insert_Below<Panel>(90).add_LogViewer());
			
			return this;

		}
		public void addEditMenuItemsToTreeView(TreeView treeView)
        {
        	var contextMenu = treeView.add_ContextMenu(); 
			contextMenu.add_MenuItem("delete selected page (you must be an admin)",
							()=>{
									var pageToDelete = treeView.selected().get_Text();
									if (pageToDelete.valid()) 
										if (WikiApi.deletePage(pageToDelete)) 
											treeView.remove_Node(treeView.selected());													
								});	
								
		/*	contextMenu.add_MenuItem("reload all pages",
							()=>{
									treeView.clear();
									treeView.add_Nodes(WikiApi.allPages());
								}); 
		*/						
			var renameMenuItem = contextMenu.add_MenuItem("rename (user will copy, admin will move)");
			var renameTextBox = renameMenuItem.add_TextBox("rename");		   					   
			
			renameMenuItem.add_MenuItem("rename page with new title (set above)",
					()=> {
							var currentTitle = treeView.selected().get_Text();
							var newTitle = renameTextBox.get_Text(); 
							if (WikiApi.movePage(currentTitle, newTitle))
							{
								treeView.selected().set_Text(newTitle);								
							}
							//"renaming page '{0}' to '{1}'".info(currentTitle, newTitle);
						});
			treeView.afterSelect<string>(
					(page)=> 
							{								
								renameTextBox.set_Text(page);
								renameTextBox.width(page.size() * 7);								
							});						
        }
Esempio n. 8
0
        public void buildGui()
        {
            try
            {
                var topPanel = this.add_Panel();
                //serializedString = topPanel.insert_Right(200).add_GroupBox("Serialized Object").add_SourceCodeViewer();
                //var serializedStringPanel = serializedString.splitContainer().panel2Collapsed(true);
                propertyGrid = topPanel.add_GroupBox("").add_PropertyGrid().helpVisible(false);
                treeView = propertyGrid.parent().insert_Left<Panel>().add_TreeView().sort();
                //treeView.splitterDistance(300);
                var toStringValue = propertyGrid.parent().insert_Below<Panel>(100).add_GroupBox("ToString Value (not editable):").add_TextArea();
                var optionsPanel = treeView.insert_Below<Panel>(70);
                var objectName = toStringValue.parent().insert_Above<Panel>(20).add_TextBox("name", "");
                //propertyGrid.onValueChange(updateSerializedString);

                //setSerializedStringSyncWithPropertyGrid();

                //serializedString.insert_Above(20).add_Link("Sync Serialized String With PropertyGrid", 0, 0, () => updateSerializedStringSyncWithPropertyGrid());

                LinkLabel invokeLink = null;
                invokeLink = optionsPanel.add_CheckBox("Show Methods", 0, 0,
                                (value) =>
                                {
                                    ShowMethods = value;
                                    invokeLink.enabled(value);
                                    refresh();
                                })
                                         .append_Link("invoke", invokeSelectedMethod)
                                            .leftAdd(-16).topAdd(5).bringToFront()
                                            .enabled(false);

                optionsPanel.add_CheckBox("Show Property and Field info", 22, 0,
                    (value) =>
                    {
                        ShowPropertyAndFieldInfo = value;
                        refresh();
                    })
                            .autoSize()
                            .append_Link("refresh", () => refresh())
                            .left(200);
                optionsPanel.add_CheckBox("Sort Values", 0, 135,
                    (value) =>
                    {
                        Sorted = value;
                        try
                        {
                            treeView.sort(Sorted);  // throwing "Unable to cast object of type 'System.Boolean' to type 'System.Windows.Forms.TreeView'"
                        }
                        catch//(Exception ex)
                        {
                            //ex.log();
                        }
                    }).@checked(true);

                simpleView_CheckBox = optionsPanel.add_CheckBox("Simple View", 0, 220,
                    (value) =>
                    {
                        SimpleView = value;
                        //propertyGrid.splitContainer().panel1Collapsed(value);
                        refresh();
                    })
                            .bringToFront();

                /*showSerializedString_CheckBox = optionsPanel.add_CheckBox("Show serialized string", 44, 0,
                    (value) =>
                    {
                        ShowSerializedString = value;
                        serializedStringPanel.panel2Collapsed(!value);
                        refresh();
                    })
                             .autoSize();*/

                createObjectWhenNull_CheckBox = optionsPanel.add_CheckBox("Create Object When Null", 44, 150,
                    (value) =>
                    {
                        CreateObjectWhenNull = value;
                    })
                            .bringToFront()
                            .autoSize();

                treeView.afterSelect<object>(
                    (selectedObject) =>
                    {
                        var treeNode = treeView.selected();
                        objectName.set_Text(treeNode.get_Text());
                        var tag = WinForms_ExtensionMethods_TreeView.get_Tag(treeNode);
                        if (tag.notNull())// && tag.str() != treeNode.get_Text())
                        {
                            propertyGrid.show(selectedObject);
                            var toString = selectedObject.str();
                            if (toString == "System.__ComObject")
                                toString += " : {0}".format(selectedObject.comObject_TypeName());
                            toStringValue.set_Text(toString);

                            propertyGrid.parent().set_Text(selectedObject.typeFullName());
                            if (treeNode.nodes().size() == 0)
                            {
                                addObjectPropertyAndFields(treeNode, selectedObject);
                            }
                        }
                        else if (treeNode.nodes().size() == 0)
                        {
                            propertyGrid.show(null as object);
                            propertyGrid.parent().set_Text("[null value]");
                            toStringValue.set_Text("[null value]");
                            objectName.set_Text("");
                            treeNode.color(Color.Red);
                        }

                    });
                treeView.add_ContextMenu().add_MenuItem("Invoke Method", () => invokeSelectedMethod());
            }
            catch (Exception ex)
            {
                ex.log("in buildGui", true);
            }
            guiReady = true;
        }