Пример #1
0
        internal static bool CheckCreateType(Type t, IDragDropItem sourceNode, bool doThrow)
        {
            if (t == null)
            {
                String msg = "(This is a bug, please report this) "
                             + "Unable to determine .NET type for "
                             + sourceNode + new StackTrace(true);
                if (doThrow)
                {
                    throw new Exception(msg);
                }
                ErrorDialog.Show(msg,
                                 "Unable to Determine Type",
                                 MessageBoxIcon.Error);
                return(false);
            }

            if (!t.IsClass || t.IsAbstract)
            {
                String msg = "Cannot create an object of type " + t
                             + " because it is not a class, "
                             + "or is an abstract class";
                if (doThrow)
                {
                    throw new Exception(msg);
                }
                ErrorDialog.Show(msg,
                                 "Type is not Class",
                                 MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
Пример #2
0
        internal static ObjectInfo CreateObject(IDragDropItem sourceNode, ObjectTreeNode targetNode)
        {
            ObjectCreator objCreator = new ObjectCreator();

            _objCreator = objCreator;
            return(objCreator.CreateObjectInternal(sourceNode, targetNode));
        }
Пример #3
0
        internal IDragDropItem DragEventCommon(object sender, DragEventArgs e, ref IDragDropItem targetNode)
        {
            Object dragControl = ((IDragDropSourceTarget)_control).GetItemAt(_control.PointToClient(new Point(e.X, e.Y)));

            if (dragControl is IDragDropItem)
            {
                IDragDropItem node = (IDragDropItem)dragControl;
                if (node.IsDropTarget)
                {
                    foreach (Type t in _control.DragSourceTypes)
                    {
                        targetNode = (IDragDropItem)e.Data.GetData(t);
                        if (targetNode != null)
                        {
                            break;
                        }
                    }

                    if (targetNode != null)
                    {
                        e.Effect = DragDropEffects.Copy;
                        return(node);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            e.Effect = DragDropEffects.None;
            return(null);
        }
Пример #4
0
        protected void DragDropEvent(object sender, DragEventArgs e)
        {
            try {
                IDragDropItem targetNode = null;
                IDragDropItem node       =
                    DragEventCommon(sender, e, ref targetNode);

                if (node != null)
                {
                    Cursor save = Cursor.Current;
                    Cursor.Current = Cursors.WaitCursor;
                    node.DoDrop(targetNode);
                    Cursor.Current = save;
                }
                else
                {
                    // If we are not handling this, see of there is an
                    // ancestor control that's interested
                    IDropTarget con = FindAncestorDropControl(e);
                    if (con != null)
                    {
                        con.DragDropEvent(sender, e);
                    }
                }
            } catch (Exception ex) {
                TraceUtil.WriteLineWarning(this, "Exception in event handler: " + ex);
            }
        }
Пример #5
0
 // Here the tree is functioning like a tree node
 // for drag/drop.  This is used from a DragDropPanel
 // where something is dropped on the design surface,
 // but this tree is delegated to handling it.
 // We give it to the top-level node.
 public virtual void DoDrop(IDragDropItem node)
 {
     if (_isObjectContainer)
     {
         IDragDropItem targetNode = ObjectBrowser.GetTopLevelObjectNode();
         targetNode.DoDrop(node);
     }
 }
 // Create an object and drop it into the list
 public override void DoDrop(IDragDropItem node)
 {
     try {
         if (_isObjectContainer)
         {
             ObjectCreator.CreateObject(node, this);
         }
     } catch (Exception ex) {
         ErrorDialog.Show(ex,
                          "Exception on Drop",
                          MessageBoxIcon.Error);
     }
 }
        // 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);
        }
        // We don't really deserialize a tool box item, we fabricate
        // it is the drag source is a node that has a type.  Otherwise
        // we just return null indicating this is not from the toolbox
        public ToolboxItem DeserializeToolboxItem(Object obj, IDesignerHost host)
        {
            //Console.WriteLine("TBS:DeserializeToolBoxItem " + obj);
            if (!(obj is IDataObject))
            {
                return(null);
            }
            IDataObject   data       = (IDataObject)obj;
            bool          found      = false;
            IDragDropItem sourceNode = null;

            // Look for a node that represents a type, this is either
            // a constructor or a type node
            foreach (Type t in BrowserTree.DragSourceTypes)
            {
                sourceNode = (IDragDropItem)data.GetData(t);
                if (sourceNode != null && sourceNode is ITargetType)
                {
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                return(null);
            }
            Type type = ((ITargetType)sourceNode).Type;

            if (!(typeof(Control).IsAssignableFrom(type)))
            {
                return(null);
            }
            IDesignSurfaceNode dNode = (IDesignSurfaceNode)sourceNode;

            if (!dNode.OnDesignSurface)
            {
                return(null);
            }
            ToolboxItem ti = new ToolboxItem(type);

            ti.ComponentsCreated += new ToolboxComponentsCreatedEventHandler(ComponentsCreated);
            return(ti);
        }
Пример #9
0
        protected void DragEnterEvent(object sender, DragEventArgs e)
        {
            try {
                IDragDropItem targetNode = null;
                IDragDropItem node       = DragEventCommon(sender, e, ref targetNode);

                // If we are not handling this, see of there is an
                // ancestor control that's interested
                if (e.Effect == DragDropEffects.None)
                {
                    IDropTarget con = FindAncestorDropControl(e);
                    if (con != null)
                    {
                        con.DragEnterEvent(sender, e);
                    }
                }
            } catch (Exception ex) {
                TraceUtil.WriteLineWarning(this, "Exception in event handler: " + ex);
            }
        }
Пример #10
0
        // Used to start a drag
        protected void ItemDragEvent(object sender, ItemDragEventArgs e)
        {
            try {
                if (e.Item is IDragDropItem)
                {
                    IDragDropItem node = (IDragDropItem)e.Item;
                    node.SelectThisItem();

                    if (node.IsDragSource)
                    {
                        // Not too elegant, but we might be dragging
                        // controls to the design surface
                        DesignerHost.Host.AddingControls = true;
                        ((Control)_control).DoDragDrop(node, DragDropEffects.Copy);
                        DesignerHost.Host.AddingControls = false;
                    }
                }
            } catch (Exception ex) {
                TraceUtil.WriteLineWarning(this, "ItemDragEvent exception: " + ex);
            }
        }
Пример #11
0
		internal IDragDropItem DragEventCommon(object sender, DragEventArgs e, ref IDragDropItem targetNode)
		{
			Object dragControl = ((IDragDropSourceTarget)_control).GetItemAt(_control.PointToClient(new Point(e.X, e.Y)));
			if (dragControl is IDragDropItem) {
				IDragDropItem node = (IDragDropItem)dragControl;
				if (node.IsDropTarget) {
					foreach (Type t in _control.DragSourceTypes) {
						targetNode = (IDragDropItem)e.Data.GetData(t);
						if (targetNode != null) {
							break;
						}
					}

					if (targetNode != null) {
						e.Effect = DragDropEffects.Copy;
						return node;
					} else {
						return null;
					}
			   }
			}
			e.Effect = DragDropEffects.None;
			return null;
		}
Пример #12
0
		// Create an object and drop it into the list
		public override void DoDrop(IDragDropItem node)
		{
			try {
				if (_isObjectContainer) {
					ObjectCreator.CreateObject(node, this);
				}
			} catch (Exception ex) {
				ErrorDialog.Show(ex, 
								"Exception on Drop",
								MessageBoxIcon.Error);
			}
		}
Пример #13
0
		public virtual void DoDrop(IDragDropItem node)
		{
			throw new Exception("Requires subclass implementation");
		}
Пример #14
0
		// Here the tree is functioning like a tree node
		// for drag/drop.  This is used from a DragDropPanel
		// where something is dropped on the design surface, 
		// but this tree is delegated to handling it.
		// We give it to the top-level node.
		public virtual void DoDrop(IDragDropItem node)
		{
			if (_isObjectContainer) {
				IDragDropItem targetNode = ObjectBrowser.GetTopLevelObjectNode();
				targetNode.DoDrop(node);
			}
		}
Пример #15
0
		// 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;
			}
		}
Пример #16
0
		internal static bool CheckCreateType(Type t, IDragDropItem sourceNode, bool doThrow)
		{
			if (t == null) {
				String msg = "(This is a bug, please report this) "
					+ "Unable to determine .NET type for " 
					+ sourceNode + new StackTrace(true);
				if (doThrow)
					throw new Exception(msg);
				ErrorDialog.Show(msg,
								"Unable to Determine Type",
								 MessageBoxIcon.Error);
				return false;
			}

			if (!t.IsClass || t.IsAbstract) {
				String msg = "Cannot create an object of type " + t
					+ " because it is not a class, "
					+ "or is an abstract class";
				if (doThrow)
					throw new Exception(msg);
				ErrorDialog.Show(msg,
								"Type is not Class",
								 MessageBoxIcon.Error);
				return false;
			}
			return true;
		}
Пример #17
0
		internal static ObjectInfo CreateObject(IDragDropItem sourceNode, ObjectTreeNode targetNode)
		{
			ObjectCreator objCreator = new ObjectCreator();
			_objCreator = objCreator;
			return objCreator.CreateObjectInternal(sourceNode, targetNode);
		}
Пример #18
0
 public virtual void DoDrop(IDragDropItem node)
 {
     throw new Exception("Requires subclass implementation");
 }
Пример #19
0
        // 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);
            }
        }
Пример #20
0
		// 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;
		}