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

Commit

Permalink
2005-09-19 Michael Hutchinson <m.j.hutchinson@gmail.com>
Browse files Browse the repository at this point in the history
	* Toolbox.cs: Oops, broke TextToolboxItem functionality. Fix not to look up types if ToolboxItem has null TypeName.


svn path=/trunk/aspeditor/; revision=50207
  • Loading branch information
mhutch committed Sep 18, 2005
1 parent 5715df9 commit 91f5cef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
4 changes: 4 additions & 0 deletions src/editor/AspNetEdit.Editor.UI/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2005-09-19 Michael Hutchinson <m.j.hutchinson@gmail.com>

* Toolbox.cs: Oops, broke TextToolboxItem functionality. Fix not to look up types if ToolboxItem has null TypeName.

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

* Toolbox.cs: Use System.Web.UI.ToolboxDataAttribute when inserting Web Controls, if present
53 changes: 28 additions & 25 deletions src/editor/AspNetEdit.Editor.UI/Toolbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,35 +199,38 @@ void itemBox_ButtonPressEvent (object o, ButtonPressEventArgs args)
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
//TODO: Fix WebControlToolboxItem so we don't have to mess around with type lookups and attributes here
if (item.AssemblyName != null && item.TypeName != null) {
//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");

//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);
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);
//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);
//and add it to the document
host.RootDocument.DeserializeAndAdd (aspText);
toolboxService.SelectedToolboxItemUsed ();
return;
}
}
//else get the toolboxitem to do the work for us
else
item.CreateComponents (host);

//No ToolboxDataAttribute? Get the ToolboxItem to create the components itself
item.CreateComponents (host);

toolboxService.SelectedToolboxItemUsed ();
return;
Expand Down

0 comments on commit 91f5cef

Please sign in to comment.