Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
2005-09-18 Michael Hutchinson <m.j.hutchinson@gmail.com>
Browse files Browse the repository at this point in the history
	* Toolbox.cs: Use System.Web.UI.ToolboxDataAttribute when inserting Web Controls, if present

svn path=/trunk/aspeditor/; revision=50193
  • Loading branch information
mhutch committed Sep 18, 2005
1 parent c6b3352 commit 5715df9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/editor/AspNetEdit.Editor.UI/ChangeLog
Original file line number Diff line number Diff line change
@@ -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
37 changes: 34 additions & 3 deletions src/editor/AspNetEdit.Editor.UI/Toolbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,47 @@ void itemBox_ButtonPressEvent (object o, ButtonPressEventArgs args)
ToolboxItem item = ((ToolboxItemBox) o).ToolboxItem;

//get the services
IDesignerHost host = parentServices.GetService (typeof (IDesignerHost)) as IDesignerHost;
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) {
item.CreateComponents (host);
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;
}
Expand Down

0 comments on commit 5715df9

Please sign in to comment.