public static MenuItem add_MenuItem(this MenuItem menuItem , string name, bool returnNewMenuItem, Action onClick)
 {
     return (MenuItem)menuItem.parentForm()
                              .invokeOnThread(
                                  ()=>{
                                          var newMenuItem = new MenuItem();
                                          newMenuItem.Text = name;
                                          if(onClick.notNull())
                                              newMenuItem.Click+= (sender,e)=>{
                                                                                  O2Thread.mtaThread(()=> onClick());
                                              };
                                          menuItem.MenuItems.Add(newMenuItem);
                                          if (returnNewMenuItem)
                                              return newMenuItem;
                                          return menuItem;
                                  });
 }
		public static TreeView add_TreeView_For_CommandClasses_Visualization(this Control control, JavaMetadata_XRefs xRefs, Action<string> onClassSelected, Func<string,string,string> resolveGetterReturnType	)
		{
			var treeView = control.add_TreeView();   

			var showHttpName = false; 
			var configPanel = control.insert_Below(30);
			configPanel.add_CheckBox("Show Http Variable Name",0,0,(value)=> showHttpName = value)
					   .autoSize(); 
			
			Func<Java_Method,string> getMethodNodeText =
				(method) => {
								if (showHttpName)
									return method.Name
												 .subString(3)
												 .lowerCaseFirstLetter();
									
								return "{0}   {1}".format(method.Name, method.returnType());
								//.GenericSignature.isNull()
								//											? method.ParametersAndReturnType
								//											: method.GenericSignature.returnType());
							};
			Func<string,string,string> localResolveGetterReturnType =
				(methodName, returnType) => {
												if (resolveGetterReturnType.isNull())
													return returnType;
												return resolveGetterReturnType(methodName, returnType);									
											};
			
			Action<TreeNode, string> add_Getters =  
				(treeNode, className)=> {
											if (xRefs.Classes_by_Signature.hasKey(className))
											{									
												var _class = xRefs.Classes_by_Signature[className];  
												var getters = _class.java_Methods_Getters_Public().with_Primitive_ReturnType(false); 
												
												treeNode.add_Nodes( getters.Where((method)=>method.returnType()!="java.lang.String"),   
																	(method)=> getMethodNodeText(method),
																	//(method)=> method.str(),
								 									(method)=> localResolveGetterReturnType(method.Name,method.returnType()), 
																	(method)=> true, 
																	(method)=> Color.DarkBlue);
			
											}
											else											
												treeNode.add_Node("[Getters] ... class not found: {0}".format(className))
														.color(Color.DarkRed);
										}; 
			  
			Action<TreeNode, string> add_Setters =  
				(treeNode, className)=> { 
											if (xRefs.Classes_by_Signature.hasKey(className))
											{									 
												var _class = xRefs.Classes_by_Signature[className];     
												var setters = _class.java_Methods_Setters_Public().with_Primitive_Parameter(true);  
												
												treeNode.add_Nodes( setters, 
																	//(method)=> "{0}   {1}".format(method.Name, method.ParametersAndReturnType), 
																	(method)=> getMethodNodeText(method),
																	(method)=> method ,
																	(method)=> false,
																	(method)=> Color.DarkGreen);
			
											}
											else
												treeNode.add_Node("[Setters] ... class not found: {0}".format(className))
														.color(Color.DarkRed);
										};
										
			
			treeView.beforeExpand<string>(
				(treeNode, returnType)=>{	
											var className = (returnType.starts("L"))
																? returnType.removeFirstChar().removeLastChar()
																: returnType;
											add_Getters(treeNode, className);
											add_Setters(treeNode, className);								
											//if (xRefs.Classes_by_Signature.hasKey(className))
											//	treeNode.add_Node("FOUND Class!!!");
											//else
											//	treeNode.add_Node(returnType);					
							  			});
			
			treeView.afterSelect<string>(
				(@class)=>{
							if (onClassSelected.notNull())
								onClassSelected(@class);
						  });
						  
			return treeView;							  			
		}
    	public static TreeView add_TreeView_for_HtmlTags(this Control control, Action<string> applyFilter)
    	{
    		control.clear();
    		var htmlTags_TreeView = control.add_TreeView();
    		htmlTags_TreeView.beforeExpand<HtmlAgilityPack.HtmlNode>(
					(treeNode, htmlNode)=>{																
											  if (htmlNode.Attributes != null)
											  	  foreach(var attribute in htmlNode.Attributes)
											 	  	  treeNode.add_Node("a: {0}={1}".format(attribute.Name, attribute.Value)); 
											  treeNode.add_Node("v: {0}".format(htmlNode.InnerHtml));  	
											  if (htmlNode.ChildNodes != null)
											  	  foreach(var childNode in htmlNode.ChildNodes)
												  	  if (childNode.html().valid()) 
													  	  treeNode.add_Node("n: {0}".format(childNode.Name), childNode, true);  
										  });	
										  
			var treeView_ContextMenu = htmlTags_TreeView.add_ContextMenu();			
			treeView_ContextMenu.add_MenuItem("Sort Nodes", ()=> htmlTags_TreeView.sort());
			treeView_ContextMenu.add_MenuItem("Don't Sort Nodes", ()=> htmlTags_TreeView.sort(false));
			//treeView_ContextMenu.add_MenuItem("Show all nodes",()=> htmlNodeFilter.sendKeys("//*".line()));   
			
			if (applyFilter.notNull())
				htmlTags_TreeView.insert_Below_HtmlTagFilter(applyFilter);
			return htmlTags_TreeView;										  
    	}
		public Ctrl_ProcessFinder onProcessChange(Action<Process> callback)
		{
			if(callback.notNull())
				this.ActiveWindowChanged  += (sender, e)=> callback.invoke(this.TargetProcess);	
			return this;
		}
Example #5
0
 public Command(Action<object> execute, Predicate<object> canExecute)
 {
     this.execute = execute.notNull();
     this.canExecute = canExecute;
 }