protected void AddChildToIntermediate(BrowserTreeNode childNode, IntermediateNodeType intNodeType, int intIndex) { // Look for the intermediate node with the right type bool found = false; foreach (BrowserTreeNode intNode in Nodes) { if (intNode is IntermediateTreeNode && ((IntermediateTreeNode)intNode).NodeType == intNodeType) { intNode.AddLogicalNode(childNode, ++intIndex); found = true; break; } } // Add a new intermediate node if (!found) { IntermediateTreeNode intNode = new IntermediateTreeNode(intNodeType, this); intNode._useIntermediates = _useIntermediates; intNode.SetPresInfo(intNodeType.PresentationInfo); ((TreeListView)TreeView).Add(Nodes, intNode); intNode.AddLogicalNode(childNode, ++intIndex); _hasChildIntNodes = true; } }
// ISearchMaterializer interface // We find the lowest level BrowserTreeNode and assume that // under that are BasicInfos that are represented by // ComMemberTreeNodes. For example, a typical // case is a ComTypeLibTreeNode will be the first entry. Under // that is a ComClassInfo. We assume the tree node type // that can represent a ComClassInfo is a ComMemberTreeNode, // and look through all of the children of the // ComTypeLibTreeNode (as a BrowserTreeNode) to find the // matching ComClassInfo (as a BasicInfo), and then point // to the found node. // public virtual void PointToNode() { // The array of a stack is returned in the order // of the pops Object[] nodes = _searchStack.ToArray(); for (int i = nodes.Length - 1; i >= 0; i--) { // The lowest level BrowserTreeNode if (nodes[i] is BrowserTreeNode && (i == 0 || !(nodes[i - 1] is BrowserTreeNode))) { BrowserTreeNode node = (BrowserTreeNode)nodes[i]; // Make sure we add the typelib node to the // recently used section and deal with that node if (node is ComTypeLibTreeNode) { node = ComSupport.AddTypeLib (((ComTypeLibTreeNode)node).TypeLib); } // Assume what's beneath here are ComMemberTreeNodes if (i == 0) { ((BrowserTreeNode)node).PointToNode(); } else { Materialize((BrowserTreeNode)node, nodes, --i); } return; } } }
// Return true if this is being made a favorite, which // should cause the expansion of the original node to be cancelled protected bool MakeFavorite(bool doExpand) { if (_typeLib.Registered && !HasRemoveFavorite()) { // This may already be a favorite, since it got // moved there when it was translated (if it was just // translated) BrowserTreeNode foundNode = ComSupport.FindTypeLib(_typeLib.Key, ComSupport.FavoriteTypeLibNode); if (foundNode == null) { // Not in the favorites, put it there foundNode = new ComTypeLibTreeNode(_typeLib); ComSupport.FavoriteTypeLibNode.AddLogicalNode(foundNode); } _typeLib.RememberMe(); if (doExpand) { foundNode.Expand(); foundNode.PointToNode(); // Cancel expansion of original node return(true); } } return(false); }
// intIndex is the index into the intermediate node types // to consider user for adding this node protected void AddLogicalNode(IBrowserNode child, int intIndex) { BrowserTreeNode childNode = (BrowserTreeNode)child; // See if we have an intermediate node type if (childNode._intermediateNodeTypes != null && intIndex < childNode._intermediateNodeTypes.Count) { AddChildToIntermediate(childNode, (IntermediateNodeType)childNode. _intermediateNodeTypes[intIndex], intIndex); } else { ((TreeListView)TreeView).Add(Nodes, childNode); } // Update the logical tree only when the child is // added to the first level intermediate node if (intIndex == 0) { childNode._logicalParent = this; _logicalNodes.Add(childNode); childNode.AddedToTree(); } }
// Removes this node from the logical nodes public virtual void RemoveLogicalNode() { DetailPanel.Clear(); // The parent might no longer contain this node because it // might have been invalidated if (Parent == null) { if (TreeView != null && TreeView.Nodes.Contains(this)) { RemoveHack(); } _logicalParent = null; return; } if (_logicalParent == Parent && Parent.Nodes.Contains(this)) { _logicalParent._logicalNodes.Remove(this); _logicalParent = null; RemoveHack(); return; } if (_logicalParent != Parent) { throw new Exception("Removal in the case of intermediate nodes not yet supported"); } }
public void AddChildren() { if (_childrenAdded) { return; } _childrenAdded = true; ICollection children = GetChildren(); //Console.WriteLine("children count: " + children.Count); _useIntermediates = false; if (((BrowserTree)TreeView).UseIntermediateNodes) { if (children.Count > ((BrowserTree)TreeView).IntermediateNodeThreshold) { _useIntermediates = true; } } TreeView.BeginUpdate(); foreach (Object child in children) { BrowserTreeNode newNode = AllocateChildNode(child); AddLogicalNode(newNode); } TreeView.EndUpdate(); }
internal IntermediateTreeNode(IntermediateNodeType nodeType, BrowserTreeNode logicalParent) : base() { _nodeType = nodeType; _logicalParent = logicalParent; // These are always setup with their children added _childrenAdded = true; PostConstructor(); }
protected virtual int OrderCompareTo(BrowserTreeNode other) { if (_nodeOrder > other._nodeOrder) { return(1); } if (_nodeOrder < other._nodeOrder) { return(-1); } return(0); }
// Adds a dummy node to this node to indicate that children // are present. The actual nodes are added when the tree is // expanded. public void AddDummy() { // Dummy might already be there if (Nodes.Count > 0) { return; } if (HasChildren()) { BrowserTreeNode dummy = new BrowserTreeNode(); dummy._isDummy = true; Nodes.Add(dummy); } }
public override void Select() { // Go the non-intermediate parent and tell them an // intermediate child was selected, so it can update the // detail panel or something BrowserTreeNode parent = (BrowserTreeNode)Parent; while (parent is IntermediateTreeNode) { parent = (BrowserTreeNode)parent.Parent; } parent.IntermediateChildSelect(); base.Select(); }
public void RemoveDummy() { // Dummy might not be there in the case of a node // that does not use it if (Nodes.Count == 0) { return; } BrowserTreeNode dummy = (BrowserTreeNode)Nodes[0]; if (dummy._isDummy) { Nodes.RemoveAt(0); } }
// Points to the next node in the array when materializing // a node from a search. index points to the childNode. protected void Materialize(BrowserTreeNode node, Object[] nodes, int index) { node.ExpandNode(); foreach (ComMemberTreeNode childNode in node.LogicalNodes) { if (childNode.MemberInfo.Equals(nodes[index])) { if (index == 0) childNode.PointToNode(); else Materialize(childNode, nodes, --index); return; } } }
internal static void Init() { _comTree = new BrowserTree(); _comTree.Dock = DockStyle.Fill; _comTree.BorderStyle = BorderStyle.None; _comTree.UseIntermediateNodes = true; // Sucks, see comment in BrowserTreeNode.PostConstructor _comTree.Font = new Font(_comTree.Font, FontStyle.Bold); _comTabPage = new TabPage(); _comTabPage.Controls.Add(_comTree); _comTabPage.Text = "ActiveX/COM"; _comTabPage.BorderStyle = BorderStyle.None; // Favorite/recently accessed typelibs _favTypeLibNode = new BrowserTreeNode(); _favTypeLibNode.Text = StringParser.Parse("${res:ComponentInspector.ComTreeNode.Text}"); _favTypeLibNode.ChildrenAlreadyAdded = true; _favTypeLibNode.SetPresInfo(PresentationMap.COM_FOLDER_TYPELIB); _typeLibNode = new ComTypeLibRootTreeNode(); _typeLibNode.NodeOrder = 1; _progIdNode = new ComProgIdRootTreeNode(); _progIdNode.NodeOrder = 2; _classCatNode = new ComCatRootTreeNode(); _classCatNode.NodeOrder = 3; _classNode = new ComClassRootTreeNode(); _classNode.NodeOrder = 4; _interfaceNode = new ComInterfaceRootTreeNode(); _interfaceNode.NodeOrder = 5; _appIdNode = new ComAppIdRootTreeNode(); _appIdNode.NodeOrder = 6; _registeredNode = new BrowserTreeNode(); _registeredNode.Text = StringParser.Parse("${res:ComponentInspector.Registry.Text}"); _registeredNode.ChildrenAlreadyAdded = true; _registeredNode.SetPresInfo(PresentationMap.FOLDER_CLOSED); _comTree.AddNode(_favTypeLibNode); _comTree.AddNode(_registeredNode); _registeredNode.AddLogicalNode(_typeLibNode); _registeredNode.AddLogicalNode(_classNode); _registeredNode.AddLogicalNode(_classCatNode); _registeredNode.AddLogicalNode(_appIdNode); _registeredNode.AddLogicalNode(_interfaceNode); _registeredNode.AddLogicalNode(_progIdNode); _registeredNode.Expand(); _typelibs = ComponentInspectorProperties.PreviouslyOpenedTypeLibraries; }
public void PointToNode() { // This is the node to point to, might change, see comments // below. BrowserTreeNode node = this; TreeListView tree = (TreeListView)TreeView; if (!IsVisible) { // Ensure visible may cause a node above us to // be Invalidated() and therefore leaving this // node as an orphan. Should this happen, we need to // Find the correct node. String savePath = FullPath; EnsureVisible(); // We got invalidated, refind the right node by name if (TreeView == null) { node = (BrowserTreeNode)tree.FindNodeByFullPath(savePath); // Should not happen if (node == null) { ErrorDialog.Show("(bug) node " + savePath + " not found in PointToNode", "Error Finding Node", MessageBoxIcon.Error); return; } } } // If the node was previously selected, we need to // force the selection processing again because focus // may have gone elsewhere requiring the detail panel to // get reset. Need a better way to handle this. if (tree.SelectedNode == node) { DetailPanel.Clear(); node.Select(); } tree.SetSelectedNode(node); tree.Focus(); }
// Points to the next node in the array when materializing // a node from a search. index points to the childNode. protected void Materialize(BrowserTreeNode node, Object[] nodes, int index) { node.ExpandNode(); foreach (ComMemberTreeNode childNode in node.LogicalNodes) { if (childNode.MemberInfo.Equals(nodes[index])) { if (index == 0) { childNode.PointToNode(); } else { Materialize(childNode, nodes, --index); } return; } } }
internal BrowserFinder(String findWhat, int compareType, int maxLevel, bool useName, bool useValue, BrowserTreeNode startNode, SearchNodeDelegate nodeFound, SearchNodeDelegate nodeLooking, SearchStatusDelegate searchStatus, SearchInvalidateDelegate searchInvalidate) { _findWhat = findWhat; _compareType = compareType; _maxLevel = maxLevel; _useName = useName; _useValue = useValue; _startNode = startNode; _tree = startNode.TreeView; _nodeFound = nodeFound; _nodeLooking = nodeLooking; _searchStatus = searchStatus; _searchInvalidate = searchInvalidate; _searchStack = new Stack(); _browserFinder = this; }
// s/b protected, stupid compiler internal static BrowserTreeNode FindTypeLib(TypeLibKey libKey, BrowserTreeNode parent) { BrowserTreeNode typeLibNode = null; // Will happen if not COM product if (parent == null) return null; // Make sure we get all of the children added parent.ExpandNode(); foreach (BrowserTreeNode node in parent.LogicalNodes) { if (node is ComTypeLibTreeNode) { if (((ComTypeLibTreeNode)node).TypeLib.Key.Equals(libKey)) { typeLibNode = node; break; } } } return typeLibNode; }
internal static void Init() { _assyTree = new BrowserTree(); SetupTree(_assyTree); _assyRootNode = new BrowserTreeNode(); _assyRootNode.Text = StringParser.Parse("${res:ComponentInspector.AssemblyTreeNode.Text}"); _assyRootNode.ChildrenAlreadyAdded = true; _assyRootNode.SetPresInfo(PresentationMap.FOLDER_CLOSED); _assyTree.AddNode(_assyRootNode); _assyTabPage = new TabPage(); _assyTabPage.Controls.Add(_assyTree); _assyTabPage.Text = StringParser.Parse("${res:ComponentInspector.FindDialog.AssembliesRadioButton}"); _assyTabPage.BorderStyle = BorderStyle.None; _controlTree = new ControlTree(); SetupTree(_controlTree); _controlTabPage = new TabPage(); _controlTabPage.Controls.Add(_controlTree); _controlTabPage.Text = StringParser.Parse("${res:ComponentInspector.ControlsTab}"); _controlTabPage.BorderStyle = BorderStyle.None; _assemblies = ComponentInspectorProperties.PreviouslyOpenedAssemblies; }
// Adds a dummy node to this node to indicate that children // are present. The actual nodes are added when the tree is // expanded. public void AddDummy() { // Dummy might already be there if (Nodes.Count > 0) return; if (HasChildren()) { BrowserTreeNode dummy = new BrowserTreeNode(); dummy._isDummy = true; Nodes.Add(dummy); } }
// Removes this node from the logical nodes public virtual void RemoveLogicalNode() { DetailPanel.Clear(); // The parent might no longer contain this node because it // might have been invalidated if (Parent == null) { if (TreeView != null && TreeView.Nodes.Contains(this)) RemoveHack(); _logicalParent = null; return; } if (_logicalParent == Parent && Parent.Nodes.Contains(this)) { _logicalParent._logicalNodes.Remove(this); _logicalParent = null; RemoveHack(); return; } if (_logicalParent != Parent) { throw new Exception("Removal in the case of intermediate nodes not yet supported"); } }
protected virtual int OrderCompareTo(BrowserTreeNode other) { if (_nodeOrder > other._nodeOrder) return 1; if (_nodeOrder < other._nodeOrder) return -1; return 0; }
public static void AssemblyLoadHandler(object sender, AssemblyLoadEventArgs args) { try { lock (_assyTree) { TraceUtil.WriteLineInfo(null, "Assembly loaded: " + args.LoadedAssembly.FullName); try { String junk = args.LoadedAssembly.CodeBase; } catch (NotSupportedException) { // This will happen in the case of COM typelib // being converted (because a dynamic assembly // does not have a CodeBase), just ignore it since // we will get a later assembly load notification when // the saved assembly is used the first time. return; } // This is an in memory version the real one will // come along later Module[] mods = args.LoadedAssembly.GetModules(); if (mods[0].Name.Equals("<Unknown>")) return; if (FindAssemblyTreeNode(args.LoadedAssembly) == null) { AssemblyTreeNode node = AddAssy(args.LoadedAssembly, null); RememberAssembly(args.LoadedAssembly, null, null); // Already loaded _assyLoadedNode = node; ComSupport.AssemblyLoadHandler(args.LoadedAssembly, node); } } } catch (Exception ex) { TraceUtil.WriteLineIf(null, TraceLevel.Error, "Exception processing assy load event: " + args.LoadedAssembly.FullName + " " + ex); } }
protected BrowserTreeNode SearchNode(BrowserTreeNode startNode, String searchName) { startNode.ExpandNode(); foreach (ComMemberTreeNode node in startNode.LogicalNodes) { if (node.MemberInfo.Name.Equals(searchName)) return node; } return null; }
internal static void OpenFile(String fileName) { // Keep track if the assembly was actually loaded, if // not then it must already be loaded, so handle adding // it to the tree. _assyLoadedNode = null; LoadAssembly(fileName); if (_assyLoadedNode == null) { Assembly assy = Assembly.LoadFrom(fileName); if (assy.Equals(Assembly.GetExecutingAssembly())){ throw new Exception("You may not inspect the Component Inspector"); } // Already loaded _assyLoadedNode = FindAssemblyNode(assy); if (_assyLoadedNode == null) { AssemblyTreeNode node = AddAssy(assy, null); RememberAssembly(assy, null, null); _assyLoadedNode = node; } } // Make sure this node is presented and selected SelectAssyTab(); _assyLoadedNode.PointToNode(); }