internal void RemoveObject(Object obj, bool skipRemoveNode) { IList list = (IList)Obj; list.Remove(obj); if (_typeHandler != null && _typeHandler.Enabled) { ObjectTreeNode otNode = null; for (int i = 0; i < LogicalNodes.Count; i++) { if (LogicalNodes[i] is ObjectTreeNode) { otNode = (ObjectTreeNode)LogicalNodes[i]; if (otNode.Obj == obj) { break; } } } if (skipRemoveNode) { return; } if (otNode != null) { otNode.RemoveLogicalNode(); } else { throw new Exception("Node does not exist where expected " + this + " " + obj); } } }
public override void RemoveLogicalNode() { // Is the parent is a list, remove this node from the list if (LogicalParent is ObjectTreeNode) { ObjectTreeNode parent = (ObjectTreeNode)LogicalParent; ObjectInfo parentObjInfo = parent.ObjectInfo; // Tell the parent not to remove this node, only the object // since we are removing ourself if (typeof(IList).IsAssignableFrom(parentObjInfo.ObjType)) { parent.RemoveObject(Obj, SKIP_REMOVE_NODE); } } // Is this is a control, remove it from the design // surface if (Obj != null && Obj is Control) { ObjectBrowser.ImagePanel.RemoveControl((Control)Obj); } // Turn off any event logging SetEventLogging(false, !SHOW_PROBLEMS); base.RemoveLogicalNode(); }
// Finds the node containing the specified object // returns true if it found the object internal static bool SelectObjectMember(IObjectMember om, bool createObj) { ObjectTreeNode node = FindObject(om.Obj, createObj); if (node != null) { node = node.FindMember(om.Member); if (node == null) { ErrorDialog.Show("You requested to show member " + om.Member + " but it cannot be shown because " + "it is not visible according to the " + "preferences you have selected " + "in the object tree. To show this " + "member, please modify those " + "preferences.", "Member not visible", MessageBoxIcon.Error); return(false); } node.PointToNode(); return(true); } return(false); }
// Find the specified object internal static ObjectTreeNode FindObject(Object obj, bool createObj) { ArrayList nodes = new ArrayList(); SearchFor(null, obj, ObjectBrowser.ObjTree.Nodes, nodes); if (nodes.Count > 0) { return((ObjectTreeNode)nodes[0]); } else { if (createObj) { if (TraceUtil.If(null, TraceLevel.Verbose)) { Trace.WriteLine("FindObj - not found - creating"); } ObjectTreeNode tlNode = ObjectBrowser.GetTopLevelObjectNode(); tlNode.AddObject(obj); ObjectTreeNode node = FindObject(obj, false); if (TraceUtil.If(null, TraceLevel.Verbose)) { Trace.WriteLine("FindObj - found created node: " + node); } return(node); } return(null); } }
// Called when menu requests the change of event logging state public override void EventLoggingClick(object sender, EventArgs e) { // Things with an object are handled by the parent (which does // all of the events for the object) if (Obj != null) { base.EventLoggingClick(sender, e); return; } ObjectTreeNode parentNode = (ObjectTreeNode)_logicalParent; Object parent = parentNode.Obj; if (parent == null) { ErrorDialog.Show("You cannot enable event logging " + ObjectInfo.NULL_PARENT_TEXT, "Cannot Enable Event Logging", MessageBoxIcon.Error); return; } bool newState = !EventLogging; try { // Tell the event logger ObjectBrowser.EventLog.ToggleLogging(this, newState); } catch (Exception ex) { ErrorDialog.Show(ex, "Unable to Change Event Logging", MessageBoxIcon.Error); } }
// Finds the node containing the specified object // returns true if it found the object internal static bool SelectObject(Object obj, bool createObj) { ObjectTreeNode node = FindObject(obj, createObj); if (node != null) { node.PointToNode(); return(true); } return(false); }
// Adds the newly created object to this node internal ObjectInfo AddNewObject(Object obj, IDragDropItem sourceNode) { // Returns null if it did not work ObjectInfo objInfo = AddObject(obj); if (objInfo == null) { return(null); } // Expand this and select the node that // contains the object we just created Expand(); foreach (TreeNode n in LogicalNodes) { if (n is ObjectTreeNode) { ObjectTreeNode objTreeNode = (ObjectTreeNode)n; if (objTreeNode.Obj == obj) { objTreeNode.PointToNode(); } } } // Point the control's site to this so that we can track // the selection of controls in the object tree // FIXME - this does not work since this node can be removed // from the tree, nothing should refer to these tree nodes if (obj is Control) { Control control = (Control)obj; if (control.Site != null) { ((DesignerSite)control.Site).TargetNode = (ObjectTreeNode)TreeView.SelectedNode; } } // If we are giving focus to a control not on the // design surface (see create object above), don't // give focus to the newly created tree node if (sourceNode == null || !(sourceNode is TypeTreeNode && obj is Control && !((TypeTreeNode)sourceNode).OnDesignSurface)) { TreeView.Focus(); } return(objInfo); }
// Search for either an object or a type protected static void SearchFor(Type type, Object lookObj, ICollection nodesToSearch, ArrayList outputNodes) { foreach (TreeNode treeNode in nodesToSearch) { if (treeNode is ObjectTreeNode) { ObjectTreeNode node = (ObjectTreeNode)treeNode; Object obj = node.Obj; if (type != null) { // We don't want to consider value types if (obj != null && !typeof(ValueType).IsAssignableFrom(obj.GetType()) && type.IsAssignableFrom(obj.GetType())) { outputNodes.Add(node); } } else { if (obj == lookObj) { if (TraceUtil.If(null, TraceLevel.Verbose)) { Trace.WriteLine("SearchFor obj found: " + node); } // There should only be one node that matches outputNodes.Add(node); break; } } SearchFor(type, lookObj, node.LogicalNodes, outputNodes); } // The ones that are not ObjectTreeNode are the dummy nodes } }
internal BaseTypeHandler GetTypeHandler(Type type, ObjectTreeNode node) { TypeHandlerInfo thInfo = null; if (type == null) return null; foreach (TypeHandlerInfo t in _typeHandlers) { if (t._typeHandled.IsAssignableFrom(type)) { thInfo = t; break; } } if (thInfo == null) return null; // We assume there is only one constructor, // which takes the type handler info and the node ConstructorInfo ci = thInfo._handlerType. GetConstructors(ReflectionHelper.ALL_BINDINGS)[0]; Object[] parameters = new Object[] { thInfo, node }; return (BaseTypeHandler)ci.Invoke(parameters); }
// Creates the object of the specified class, and wraps a tree node // around it ObjectInfo CreateObjectInternal(IDragDropItem sourceNode, ObjectTreeNode targetNode) { _sourceNode = sourceNode; _targetNode = targetNode; Object obj = null; ConstructorInfo constructor = null; ConstructorInfo[] constructors = null; try { if (sourceNode is ITargetType && !((ITargetType)sourceNode).IsMember) { ITargetType targetTypeNode = (ITargetType)sourceNode; Type t = targetTypeNode.Type; if (!CheckCreateType(t, sourceNode, !THROW)) return null; // String is a special case, we just do it with the // string parameter value if (t.Equals(typeof(String))) { ObjectBrowser.ParamPanel.GetParameterValues(!Constants.IGNORE_EXCEPTION, ParamPanel.SET_MEMBER, out obj); } else { constructors = t.GetConstructors(ReflectionHelper.ALL_BINDINGS); if (constructors.Length == 0) { obj = Activator.CreateInstance(t); } else { constructor = FindConstructor(constructors); if (constructor == null) return null; } } } else if (sourceNode is MemberTreeNode) { constructor = (ConstructorInfo)((MemberTreeNode)sourceNode).Member; } else if (sourceNode is AssemblyTreeNode) { CreateFromEntry(((AssemblyTreeNode)sourceNode).Assembly); // This gets finished when the event processing // is finished and we go to idle return null; } else { throw new Exception("Bug: invalid node being dragged: " + sourceNode.GetType()); } // Invoke the constructor with the parameters // defined in the param panel if (obj == null) { Object fieldPropValue; obj = constructor.Invoke(ObjectBrowser.ParamPanel.GetParameterValues(!Constants.IGNORE_EXCEPTION, ParamPanel.SET_MEMBER, out fieldPropValue)); } return FinishObjectCreation(obj); } catch (Exception ex) { Exception showException = ex; // Remove the useless wrapper exception if (showException is TargetInvocationException) showException = ex.InnerException; ErrorDialog.Show(showException, "Error creating object", MessageBoxIcon.Error); return null; } }
internal static ObjectInfo CreateObject(IDragDropItem sourceNode, ObjectTreeNode targetNode) { ObjectCreator objCreator = new ObjectCreator(); _objCreator = objCreator; return objCreator.CreateObjectInternal(sourceNode, targetNode); }
protected static void AddRunningObjs() { TraceUtil.WriteLineInfo(null, "AddRunningObjs"); ObjectTreeNode tlNode = null; // Running objects - added to object tree if (_runningObjInfo == null) { _runningObjInfo = ObjectInfoFactory.GetObjectInfo(false, new ArrayList()); _runningObjInfo.ObjectName = StringParser.Parse("${res:ComponentInspector.ComRunningObjectsTreeNode.Text}"); tlNode = new ObjectTreeNode(true, _runningObjInfo); // The children are explicitly added here tlNode.ChildrenAlreadyAdded = true; tlNode.NodeOrder = 20; tlNode.AllowDelete = false; tlNode.IsDropTarget = false; ObjectBrowser.ObjTree.CreateControl(); ObjectBrowser.ObjTree.Invoke(new BrowserTree.AddNodeInvoker(ObjectBrowser.ObjTree.AddNode), new Object[] { tlNode }); } else { tlNode = ObjectTreeNode.FindObject(_runningObjInfo.Obj, !ObjectTreeNode.CREATE_OBJ); ((ArrayList)_runningObjInfo.Obj).Clear(); tlNode.InvalidateNode(); } ProgressDialog progress = new ProgressDialog(); progress.Setup(StringParser.Parse("${res:ComponentInspector.ProgressDialog.AddingRunningComObjectsDialogTitle}"), StringParser.Parse("${res:ComponentInspector.ProgressDialog.AddingRunningComObjectsMessage}"), ComObjectInfo.GetRunningObjectCount(), ProgressDialog.HAS_PROGRESS_TEXT, ProgressDialog.FINAL); progress.ShowIfNotDone(); foreach (ComObjectInfo comObjInfo in ComObjectInfo.GetRunningObjects(progress)) { ObjectBrowser.ObjTree.Invoke(new ObjectTreeNode.AddObjectInvoker(tlNode.AddObject), new Object[] { comObjInfo }); } tlNode.Expand(); progress.Finished(); }
internal IListTypeHandler(TypeHandlerManager.TypeHandlerInfo info, ObjectTreeNode node) : base(info, node) { }
void InitializeComponent(bool showStatusPanel, bool tabbedLayout) { SuspendLayout(); CausesValidation = false; AutoScaleDimensions = new SizeF(6F, 13F); AutoScaleMode = AutoScaleMode.Font; Name = "ObjectBrowserControl"; Size = new Size(800, 700); // All of the dimensions are here int objTreeWidth = (int)(ClientSize.Width * 2/WIDTH_UNITS); int assyTreeWidth = (int)(ClientSize.Width * 3/WIDTH_UNITS); int paramsWidth = (int)(ClientSize.Width * 1/WIDTH_UNITS); int imageWidth = (int)(ClientSize.Width * 2/WIDTH_UNITS); int topHeight = (int)(ClientSize.Height * 2.5/HEIGHT_UNITS); int bottomHeight = (int)(ClientSize.Height * 2.5/HEIGHT_UNITS); int detailHeight = (int)(ClientSize.Height * 1/HEIGHT_UNITS); int objTreeHeight = ClientSize.Height - detailHeight; // Contents of treePanel, on the left _objTree = new BrowserTree(TOP_OBJ_NAME); // Hook up the routines that get called when preferences change ComponentInspectorProperties.ShowPropertyAccessorMethodsChanged += ObjectTreeInvalidated; ComponentInspectorProperties.ShowFieldsChanged += ObjectTreeInvalidated; ComponentInspectorProperties.ShowPropertiesChanged += ObjectTreeInvalidated; ComponentInspectorProperties.ShowMethodsChanged += ObjectTreeInvalidated; ComponentInspectorProperties.ShowEventsChanged += ObjectTreeInvalidated; ComponentInspectorProperties.ShowBaseClassesChanged += ObjectTreeInvalidated; ComponentInspectorProperties.ShowPublicMembersOnlyChanged += ObjectTreeInvalidated; ComponentInspectorProperties.ShowMemberCategoriesChanged += ObjectTreePreferencesChanged; ComponentInspectorProperties.ShowBaseCategoriesChanged += ObjectTreePreferencesChanged; ComponentInspectorProperties.CategoryThresholdChanged += ObjectTreePreferencesChanged; ComponentInspectorProperties.ShowBaseClassNamesChanged += ObjectTreeInvalidated; ComponentInspectorProperties.DisplayHexChanged += ObjectTreeInvalidated; ComponentInspectorProperties.ShowAssemblyPanelChanged += TabPanelChanged; ComponentInspectorProperties.ShowControlPanelChanged += TabPanelChanged; ComponentInspectorProperties.ShowGacPanelChanged += TabPanelChanged; ComponentInspectorProperties.TypeHandlerChanged += ObjectTreeInvalidated; ColumnHeader ch = new ColumnHeader(); ch.Text = StringParser.Parse("${res:ComponentInspector.ObjectBrowser.ValueColumnHeader}"); ch.TextAlign = HorizontalAlignment.Left; _objTree.Columns.Add(ch); _objTree.BorderStyle = BorderStyle.None; _objTree.AllowDrop = true; _objTree.IsObjectContainer = true; _objTree.IsDropTarget = true; _objTree.UseCompareTo = true; _objTree.GotFocus += new EventHandler(TreeFocused); UpdateObjectTreePreferences(); _objTree.SetupPanel(); _objTree.Panel.Dock = DockStyle.Fill; _objTree.Panel.Width = objTreeWidth; _objTree.Panel.Height = objTreeHeight; _objTree.Panel.BorderStyle = BorderStyle.None; _objTreePanel = new Panel(); _objTreePanel.Dock = DockStyle.Left; _objTreePanel.Width = _objTree.Panel.Width; // Note we add the parent, because the tree comes with a // panel that's the parent of the tree _objTreePanel.Controls.Add(_objTree.Panel); _objTreePanel.BorderStyle = BorderStyle.Fixed3D; new PanelLabel(_objTreePanel, StringParser.Parse("${res:ComponentInspector.ObjectBrowser.ObjectsTreePanel}")); // Image panel _imagePanel = NoGoop.ObjBrowser.ImagePanel.CreateImagePanel(objTreeWidth, !tabbedLayout); _imagePanel.WrapperPanel.Dock = DockStyle.Fill; // For text associated with each tree node _detailPanel = new DetailPanel(); _detailPanel.Dock = DockStyle.Bottom; _params = new ParamPanel(); _params.Dock = DockStyle.Fill; _params.Width = paramsWidth; _eventLog = new EventLogList(this); AssemblySupport.Init(); AssemblySupport.AssyTree.GotFocus += new EventHandler(TreeFocused); // Splitter between main tree and the rest, vertical Splitter mainSplitter = new Splitter(); mainSplitter.Dock = DockStyle.Left; mainSplitter.Width = Utils.SPLITTER_SIZE; Panel paramPanel = new Panel(); paramPanel.Dock = DockStyle.Left; paramPanel.Width = _params.Width; paramPanel.Controls.Add(_params); paramPanel.BorderStyle = BorderStyle.Fixed3D; new PanelLabel(paramPanel, StringParser.Parse("${res:ComponentInspector.ObjectBrowser.ParametersPanel}")); Splitter propImageSplitter = new Splitter(); propImageSplitter.Dock = DockStyle.Left; propImageSplitter.Width = Utils.SPLITTER_SIZE; // Contains the property panel and image panel Panel propImagePanel = new Panel(); propImagePanel.Dock = DockStyle.Top; propImagePanel.Height = topHeight; propImagePanel.Controls.Add(_imagePanel.WrapperPanel); propImagePanel.Controls.Add(propImageSplitter); propImagePanel.Controls.Add(paramPanel); // Splitter between node details and the rest _topTabSplitter = new Splitter(); _topTabSplitter.Dock = DockStyle.Top; _topTabSplitter.Height = Utils.SPLITTER_SIZE; GacList gacList = new GacList(); gacList.Width = assyTreeWidth; gacList.Dock = DockStyle.Fill; gacList.BorderStyle = BorderStyle.None; _gacTabPage = new TabPage(); _gacTabPage.Controls.Add(gacList); _gacTabPage.Text = "GAC"; _gacTabPage.BorderStyle = BorderStyle.None; // Object tab page. if (tabbedLayout) { _objTreeTabPage = new TabPage(); _objTreeTabPage.Controls.Add(_objTreePanel); _objTreeTabPage.Text = StringParser.Parse("${res:ComponentInspector.ObjectBrowser.ObjectsTreePanel}"); _objTreeTabPage.BorderStyle = BorderStyle.None; } // Not presently used _outputList = new OutputList(); _outputList.Width = assyTreeWidth; _outputList.Dock = DockStyle.Fill; _outputList.BorderStyle = BorderStyle.None; TabPage outputTabPage = new TabPage(); outputTabPage.Controls.Add(_outputList); outputTabPage.Text = StringParser.Parse("${res:ComponentInspector.ObjectBrowser.OutputTab}"); outputTabPage.BorderStyle = BorderStyle.None; _tabControl = new TabControl(); _tabControl.Dock = DockStyle.Fill; _tabControl.Width = assyTreeWidth; _tabControl.SelectedIndexChanged += new EventHandler(TabIndexChangedHandler); // Contains the property panel and image panel Panel tabPanel = new Panel(); tabPanel.Dock = DockStyle.Fill; if (tabbedLayout) { propImagePanel.Dock = DockStyle.Fill; } else { tabPanel.Controls.Add(_tabControl); tabPanel.Controls.Add(_topTabSplitter); } tabPanel.Controls.Add(propImagePanel); // All of the panels on the top _topPanel = new Panel(); _topPanel.Dock = DockStyle.Fill; _topPanel.Height = topHeight + bottomHeight; _topPanel.Controls.Add(tabPanel); _topPanel.Controls.Add(mainSplitter); if (tabbedLayout) { _tabControl.Dock = DockStyle.Left; _objTreePanel.Dock = DockStyle.Fill; _topPanel.Controls.Add(_tabControl); } else { _topPanel.Controls.Add(_objTreePanel); } if (!tabbedLayout) { _topBottomSplitter = new Splitter(); _topBottomSplitter.Dock = DockStyle.Bottom; _topBottomSplitter.Height = Utils.SPLITTER_SIZE; _topBottomSplitter.MinSize = detailHeight; } if (showStatusPanel) { _statusPanel = new StatusPanel(); _statusPanelLabel = new PanelLabel(_statusPanel); _statusPanelLabel.Dock = DockStyle.Top; } Controls.Add(_topPanel); if (showStatusPanel) { Controls.Add(_statusPanelLabel); } if (!tabbedLayout) { Controls.Add(_topBottomSplitter); Controls.Add(_detailPanel); } // To allow file dropping DragEnter += new DragEventHandler(DragEnterEvent); DragDrop += new DragEventHandler(DragDropEvent); DragOver += new DragEventHandler(DragOverEvent); AllowDrop = true; _objTree.BeginUpdate(); // Add top level nodes ArrayList tlList = new ArrayList(); ObjectInfo objInfo = ObjectInfoFactory.GetObjectInfo(false, tlList); objInfo.ObjectName = TOP_OBJ_NAME; BrowserTreeNode node = new ObjectTreeNode(false, objInfo); // Make sure this is the first node node.NodeOrder = 0; node.AllowDelete = false; _objTree.Nodes.Add(node); // Just for testing if (LocalPrefs.Get(LocalPrefs.DEV) != null) tlList.Add(this); _objTree.EndUpdate(); ComSupport.Init(); ComSupport.ComTree.GotFocus += new EventHandler(TreeFocused); SetTabPanels(); ResumeLayout(); }
internal IEnumeratorTypeHandler(TypeHandlerManager.TypeHandlerInfo info, ObjectTreeNode node) : base(info, node) { }
internal BaseTypeHandler(TypeHandlerManager.TypeHandlerInfo info, ObjectTreeNode node) { _info = info; _node = node; }