Author: mhutch
Date: 2006-07-21 09:47:57 -0400 (Fri, 21 Jul 2006)
New Revision: 62860

Added:
   trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/
   trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/ChangeLog
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/BaseEditor.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/BoolEditor.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/CollectionEditor.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/ColorEditor.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/DefaultEditor.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/EnumEditor.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/EventEditor.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/ExpandableObjectEditor.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/NumberEditor.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/StringEditor.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/DefaultPropertyTab.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/EditorManager.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/EventPropertyTab.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/GridRow.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/PropertyEditorTypeAttribute.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/PropertyGrid.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/PropertyValueChangedEventArgs.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/PropertyValueChangedEventHandler.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/SurrogateUITypeEditorAttribute.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/BaseToolboxNode.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/CategoryToolboxNode.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/ItemToolboxNode.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/TextToolboxNode.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/Toolbox.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/ToolboxItemToolboxNode.cs
   
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/ToolboxStore.cs
Log:
Import components from AspNetEdit.



Property changes on: trunk/monodevelop/Extras/MonoDevelop.DesignerSupport
___________________________________________________________________
Name: svn:ignore
   + Makefile
Makefile.in
MonoDevelop.DesignerSupport.pidb


Added: trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/ChangeLog
===================================================================
--- trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/ChangeLog      
2006-07-21 13:45:55 UTC (rev 62859)
+++ trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/ChangeLog      
2006-07-21 13:47:57 UTC (rev 62860)
@@ -0,0 +1,36 @@
+2006-04-27  Michael Hutchinson <[EMAIL PROTECTED]> 
+
+       * MonoDevelop.DesignerSupport.Toolbox/CategoryToolboxNode.cs: 
+       Make sure we cover all items in filtering loop.
+
+2006-04-27  Michael Hutchinson <[EMAIL PROTECTED]> 
+
+       * MonoDevelop.DesignerSupport.Toolbox/ToolboxItemToolboxNode.cs: 
+         Accessor for ToolboxItem.
+       * MonoDevelop.DesignerSupport.Toolbox/ToolboxStore.cs:
+         Don't rebuild after blank filter.
+       * MonoDevelop.DesignerSupport.Toolbox/CategoryToolboxNode.cs:
+         Add Clear () method to remove all children.
+       * MonoDevelop.DesignerSupport.Toolbox/Toolbox.cs:
+         Get categories from ToolboxService, and maintain expansion 
+         and selection state where possible.
+       
+2006-04-26  Michael Hutchinson <[EMAIL PROTECTED]> 
+
+       * MonoDevelop.DesignerSupport.Toolbox/BaseToolboxNode.cs:
+       * MonoDevelop.DesignerSupport.Toolbox/CategoryToolboxNode.cs:
+       * MonoDevelop.DesignerSupport.Toolbox/ItemToolboxNode.cs:
+       * MonoDevelop.DesignerSupport.Toolbox/TextToolboxNode.cs:
+       * MonoDevelop.DesignerSupport.Toolbox/Toolbox.cs:
+       * MonoDevelop.DesignerSupport.Toolbox/ToolboxItemToolboxNode.cs:
+       * MonoDevelop.DesignerSupport.Toolbox/ToolboxStore.cs: 
+         Add new NodeStore-based Toolbox.
+
+       * MonoDevelop.DesignerSupport.PropertyGrid/PropertyGrid.cs:     
+         Add Refresh method as interim workaround for not being
+         able to track externally changed values of properties.
+
+2006-01-16 Michael Hutchinson <[EMAIL PROTECTED]>
+
+       * MonoDevelop.DesignerSupport.PropertyGrid.Editors/StringEditor.cs: 
+         Write helpful trace message after swallowing PropertyConverter 
failure.

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/DefaultPropertyTab.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI/DefaultPropertyTab.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/EditorManager.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI/EditorManager.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/EventPropertyTab.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI/EventPropertyTab.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/GridRow.cs
 (from rev 62627, trunk/aspeditor/src/propertygrid/AspNetEdit.UI/GridRow.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/PropertyEditorTypeAttribute.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI/PropertyEditorTypeAttribute.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/PropertyGrid.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI/PropertyGrid.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/PropertyValueChangedEventArgs.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI/PropertyValueChangedEventArgs.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/PropertyValueChangedEventHandler.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI/PropertyValueChangedEventHandler.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid/SurrogateUITypeEditorAttribute.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI/SurrogateUITypeEditorAttribute.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/BaseEditor.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI.Editors/BaseEditor.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/BoolEditor.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI.Editors/BoolEditor.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/CollectionEditor.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI.Editors/CollectionEditor.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/ColorEditor.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI.Editors/ColorEditor.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/DefaultEditor.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI.Editors/DefaultEditor.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/EnumEditor.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI.Editors/EnumEditor.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/EventEditor.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI.Editors/EventEditor.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/ExpandableObjectEditor.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI.Editors/ExpandableObjectEditor.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/NumberEditor.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI.Editors/NumberEditor.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/StringEditor.cs
 (from rev 62627, 
trunk/aspeditor/src/propertygrid/AspNetEdit.UI.Editors/StringEditor.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/BaseToolboxNode.cs
 (from rev 62627, 
trunk/aspeditor/src/editor/AspNetEdit.Gui.Toolbox/BaseToolboxNode.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/CategoryToolboxNode.cs
 (from rev 62627, 
trunk/aspeditor/src/editor/AspNetEdit.Gui.Toolbox/CategoryToolboxNode.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/ItemToolboxNode.cs
 (from rev 62627, 
trunk/aspeditor/src/editor/AspNetEdit.Gui.Toolbox/ItemToolboxNode.cs)
===================================================================
--- trunk/aspeditor/src/editor/AspNetEdit.Gui.Toolbox/ItemToolboxNode.cs        
2006-07-15 00:15:29 UTC (rev 62627)
+++ 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/ItemToolboxNode.cs
 2006-07-21 13:47:57 UTC (rev 62860)
@@ -0,0 +1,186 @@
+ /* 
+ * ItemToolboxNode.cs - A base class for ToolboxNodes that represent a 
+ *                                             selectable/usable item
+ * 
+ * Authors: 
+ *  Michael Hutchinson <[EMAIL PROTECTED]>
+ *  
+ * Copyright (C) 2006 Michael Hutchinson
+ *
+ * This sourcecode is licenced under The MIT License:
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to permit
+ * persons to whom the Software is furnished to do so, subject to the
+ * following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+ * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+using System;
+using System.Collections;
+using System.ComponentModel;
+using System.ComponentModel.Design;
+using System.Drawing.Design;
+using Gtk;
+
+namespace AspNetEdit.Gui.Toolbox
+{
+       public abstract class ItemToolboxNode : BaseToolboxNode
+       {
+               //we expect to serialise/deserialise these
+               //TODO: getters, setters
+               //TODO: serialisation
+               protected Gdk.Pixbuf Icon;
+               public string Name = "";
+               public string Category = "";
+               public string Description = "";
+               protected ICollection ItemFilters; //ToolboxItemFilterAttribute
+               
+               //need to be able to create empty instances of derived classes
+               //for deserialisation
+               public ItemToolboxNode ()
+               {
+               }
+               
+               #region Behaviours
+               
+               public override bool Filter (string keyword)
+               {
+                       return ((Name==null)? false : (Name.ToLower ().IndexOf 
(keyword) >= 0))
+                                  || ((Description == null)? false : 
(Description.ToLower ().IndexOf (keyword) >= 0));
+               }
+               
+               //Runs when item is clicked.
+               public abstract void Activate (object host);
+               
+               public virtual bool IsSupportedBy (object rootDesigner)
+               {
+                       //if something has no filters it is more useful and 
efficient
+                       //to show it for everything than to show it for nothing
+                       if (ItemFilters == null || ItemFilters.Count == 0)
+                               return true;
+                       
+                       //get the designer's filter attributes
+                       //TODO: This may be worth caching at some point
+                       Type desType = rootDesigner.GetType ();
+                       ToolboxItemFilterAttribute[] hostFilters =
+                               (ToolboxItemFilterAttribute[]) 
desType.GetCustomAttributes (typeof (ToolboxItemFilterAttribute), true);
+                       
+                       //check all of host's filters
+                       foreach (ToolboxItemFilterAttribute desFa in 
hostFilters)
+                       {
+                               if (!FilterPermitted (desFa, ItemFilters, 
rootDesigner))
+                                       return false;
+                       }
+                       
+                       //check all of item's filters
+                       foreach (ToolboxItemFilterAttribute itemFa in 
ItemFilters)
+                       {
+                               if (!FilterPermitted (itemFa, hostFilters, 
rootDesigner))
+                                       return false;
+                       }
+                       
+                       //we assume permitted, so only return false when 
blocked by a filter
+                       return true;
+               }
+               
+               //evaluate a filter attribute against a list, and check whther 
permitted
+               private bool FilterPermitted (ToolboxItemFilterAttribute desFa, 
ICollection filterAgainst, object rootDesigner)
+               {
+                       switch (desFa.FilterType) {
+                               case ToolboxItemFilterType.Allow:
+                                       //this is really for matching some 
other filter string against
+                                       return true;
+                               
+                               case ToolboxItemFilterType.Custom:
+                                       IToolboxUser tbUser = rootDesigner as 
IToolboxUser;
+                                       if (tbUser == null)
+                                               throw new ArgumentException 
("Host's root designer does not support IToolboxUser interface.");
+                                       return EvaluateCustomFilter (tbUser);
+                                       
+                               case ToolboxItemFilterType.Prevent:
+                                       //if host and toolboxitem have same 
filterstring, then not permitted
+                                       foreach (ToolboxItemFilterAttribute 
itemFa in filterAgainst)
+                                               if (desFa.Match (itemFa))
+                                                       return false;
+                                       return true;
+                               
+                               case ToolboxItemFilterType.Require:
+                                       //if host and toolboxitem have same 
filterstring, then permitted, unless one is prevented
+                                       foreach (ToolboxItemFilterAttribute 
itemFa in filterAgainst)
+                                               if (desFa.Match (itemFa) && 
(desFa.FilterType != ToolboxItemFilterType.Prevent))
+                                                       return true;
+                                       return false;
+                       }
+                       throw new InvalidOperationException ("Unexpected 
ToolboxItemFilterType value.");
+               }
+               
+               //utility, gets a root designer from an IDesignerHost and calls 
IsSupportedBy (object) on it
+               public virtual bool IsSupportedBy (IDesignerHost host)
+               {
+                       if (host == null)
+                               throw new ArgumentException ("IDesignerHost 
must not be null.");
+                       IComponent comp = host.RootComponent;
+                       if (comp == null)
+                               throw new ArgumentException ("Host does not 
have a root component.");
+                       IDesigner des = host.GetDesigner (comp);
+                       if (des == null)
+                               throw new ArgumentException ("Host does not 
have a root designer.");
+                       
+                       return IsSupportedBy (des);
+               }
+               
+               //if derived class supports it, we have to load the real 
toolboxitem
+               protected virtual bool EvaluateCustomFilter (IToolboxUser user)
+               {
+                       throw new InvalidOperationException ("Custom filters 
are only supported with ToolboxItems.");
+               }
+               
+               //TODO: drag source
+               
+               #endregion Behaviours
+               
+               
+               #region Tree columns
+
+               public override Gdk.Pixbuf ViewIcon {
+                       get {
+                               if (Icon != null)
+                                       return Icon;
+                               else
+                                       return base.ViewIcon;
+                       }
+               }
+               
+               public override string Label {
+                       get { 
+                               return Name;
+                       }
+               }
+               
+               #endregion Tree columns
+               
+               
+               protected Gdk.Pixbuf ImageToPixbuf (System.Drawing.Image image)
+               {
+                       using (System.IO.MemoryStream stream = new 
System.IO.MemoryStream ()) {
+                               image.Save (stream, 
System.Drawing.Imaging.ImageFormat.Png);
+                               stream.Position = 0;
+                               return new Gdk.Pixbuf (stream);
+                       }
+               }
+       }       
+}

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/TextToolboxNode.cs
 (from rev 62627, 
trunk/aspeditor/src/editor/AspNetEdit.Gui.Toolbox/TextToolboxNode.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/Toolbox.cs
 (from rev 62627, trunk/aspeditor/src/editor/AspNetEdit.Gui.Toolbox/Toolbox.cs)

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/ToolboxItemToolboxNode.cs
 (from rev 62627, 
trunk/aspeditor/src/editor/AspNetEdit.Gui.Toolbox/ToolboxItemToolboxNode.cs)
===================================================================
--- trunk/aspeditor/src/editor/AspNetEdit.Gui.Toolbox/ToolboxItemToolboxNode.cs 
2006-07-15 00:15:29 UTC (rev 62627)
+++ 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/ToolboxItemToolboxNode.cs
  2006-07-21 13:47:57 UTC (rev 62860)
@@ -0,0 +1,124 @@
+ /* 
+ * ToolboxItemToolboxNode.cs - A ToolboxNode that wraps a 
System.Drawing.Design.ToolboxItem
+ * 
+ * Authors: 
+ *  Michael Hutchinson <[EMAIL PROTECTED]>
+ *  
+ * Copyright (C) 2006 Michael Hutchinson
+ *
+ * This sourcecode is licenced under The MIT License:
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to permit
+ * persons to whom the Software is furnished to do so, subject to the
+ * following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+ * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+using System;
+using System.Collections;
+using System.ComponentModel;
+using System.ComponentModel.Design;
+using System.Drawing.Design;
+
+namespace AspNetEdit.Gui.Toolbox
+{
+       public class ToolboxItemToolboxNode : ItemToolboxNode
+       {
+               private ToolboxItem item;
+               
+               public ToolboxItemToolboxNode (ToolboxItem item)
+               {
+                       this.item = item;
+                       base.Name = item.DisplayName;
+                       if (item.Bitmap != null)
+                               base.Icon = base.ImageToPixbuf (item.Bitmap);
+                       
+                       if (item.AssemblyName != null)
+                               foreach 
(System.ComponentModel.CategoryAttribute ca in
+                                       System.Reflection.Assembly.Load 
(item.AssemblyName)
+                                       .GetType (item.TypeName)
+                                       .GetCustomAttributes (typeof 
(System.ComponentModel.CategoryAttribute), true))
+                                       this.Category = ca.Category;
+               }
+               
+               public ToolboxItem ToolboxItem
+               {
+                       get {
+                               //TODO: load assembly and then item, if not 
already done
+                               return item;
+                       }
+               }
+               
+               #region Behaviours
+               
+               //Runs when item is clicked.
+               //We should be able to avoid loading actual ToolboxItem 
instances and their
+               //associated assemblies until they are activated.
+               public override void Activate (object host)
+               {
+                       IDesignerHost desHost = host as IDesignerHost;
+                       
+                       if (desHost == null)
+                               throw new Exception("This ToolboxItem should 
not have been shown for this host. System.Drawing.Design.ToolboxItem requires a 
host of type System.ComponentModel.Design.IDesignerHost");
+                       
+                       //web controls have sample HTML that need to be 
deserialised
+                       //TODO: Fix WebControlToolboxItem so we don't have to 
mess around with type lookups and attributes here
+                       if ((item is 
System.Web.UI.Design.WebControlToolboxItem) && host is 
AspNetEdit.Editor.ComponentModel.DesignerHost)
+                       {
+                               AspNetEdit.Editor.ComponentModel.DesignerHost 
aspDesHost = (AspNetEdit.Editor.ComponentModel.DesignerHost) desHost;
+                               
+                               if (item.AssemblyName != null && item.TypeName 
!= null) {
+                                       //look up and register the type
+                                       ITypeResolutionService typeRes = 
(ITypeResolutionService) aspDesHost.GetService(typeof(ITypeResolutionService)); 
                                       
+                                       typeRes.ReferenceAssembly 
(item.AssemblyName);
+                                       Type controlType = typeRes.GetType 
(item.TypeName, true);
+                                               
+                                       //read the WebControlToolboxItem data 
from the attribute
+                                       AttributeCollection atts = 
TypeDescriptor.GetAttributes (controlType);
+                                       System.Web.UI.ToolboxDataAttribute tda 
= (System.Web.UI.ToolboxDataAttribute) 
atts[typeof(System.Web.UI.ToolboxDataAttribute)];
+                                               
+                                       //if it's present
+                                       if (tda != null && tda.Data.Length > 0) 
{
+                                               //look up the tag's prefix and 
insert it into the data                                          
+                                               
System.Web.UI.Design.IWebFormReferenceManager webRef = aspDesHost.GetService 
(typeof (System.Web.UI.Design.IWebFormReferenceManager)) as 
System.Web.UI.Design.IWebFormReferenceManager;
+                                               if (webRef == null)
+                                                       throw new 
Exception("Host does not provide an IWebFormReferenceManager");
+                                               string aspText = String.Format 
(tda.Data, webRef.GetTagPrefix (controlType));
+                                               
System.Diagnostics.Trace.WriteLine ("Toolbox processing ASP.NET item data: " + 
aspText);
+                                                       
+                                               //and add it to the document
+                                               
aspDesHost.RootDocument.DeserializeAndAdd (aspText);
+                                               return;
+                                       }
+                               }
+                       }
+                               
+                       //No ToolboxDataAttribute? Get the ToolboxItem to 
create the components itself
+                       item.CreateComponents (desHost);
+               }
+               
+               protected override bool EvaluateCustomFilter (IToolboxUser user)
+               {
+                       return user.GetToolSupported (item);
+               }
+               
+               
+               //TODO: drag source
+               
+               #endregion Behaviours
+       }       
+}

Copied: 
trunk/monodevelop/Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Toolbox/ToolboxStore.cs
 (from rev 62627, 
trunk/aspeditor/src/editor/AspNetEdit.Gui.Toolbox/ToolboxStore.cs)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to