Permalink
Browse files

2005-09-18 Michael Hutchinson <m.j.hutchinson@gmail.com>

	* Toolbox.cs: Use System.Web.UI.ToolboxDataAttribute when inserting Web Controls, if present

svn path=/trunk/aspeditor/; revision=50193
  • Loading branch information...
1 parent c6b3352 commit 5715df9d0341a47a60209366e30bcbb3dabdf4e4 @mhutch mhutch committed Sep 18, 2005
Showing with 37 additions and 3 deletions.
  1. +3 −0 src/editor/AspNetEdit.Editor.UI/ChangeLog
  2. +34 −3 src/editor/AspNetEdit.Editor.UI/Toolbox.cs
@@ -0,0 +1,3 @@
+2005-09-18 Michael Hutchinson <m.j.hutchinson@gmail.com>
+
+ * Toolbox.cs: Use System.Web.UI.ToolboxDataAttribute when inserting Web Controls, if present
@@ -188,16 +188,47 @@ void itemBox_ButtonPressEvent (object o, ButtonPressEventArgs args)
ToolboxItem item = ((ToolboxItemBox) o).ToolboxItem;
- //get the services
+ //get the services
DesignerHost host = parentServices.GetService (typeof (IDesignerHost)) as DesignerHost;
IToolboxService toolboxService = parentServices.GetService (typeof (IToolboxService)) as IToolboxService;
if (toolboxService == null || host == null)
return;
if (selectedBox == (ToolboxItemBox) o) {
//check for doubleclick and create an item
- if (toolboxService.GetSelectedToolboxItem (host) == item) {
- if (args.Event.Time - lastClickTime <= Settings.DoubleClickTime) {
+ if (toolboxService.GetSelectedToolboxItem (host) == item) {
+ if (args.Event.Time - lastClickTime <= Settings.DoubleClickTime) {
+
+ //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
+
+ //look up and register the type
+ ITypeResolutionService typeRes = host.GetService(typeof(ITypeResolutionService)) as ITypeResolutionService;
+ if (typeRes == null)
+ throw new Exception("Host does not provide an ITypeResolutionService");
+ System.Reflection.Assembly assembly = typeRes.GetAssembly(item.AssemblyName, true);
+ 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 = host.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
+ host.RootDocument.DeserializeAndAdd (aspText);
+ }
+ //else get the toolboxitem to do the work for us
+ else
+ item.CreateComponents (host);
toolboxService.SelectedToolboxItemUsed ();
return;

0 comments on commit 5715df9

Please sign in to comment.