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
This commit is contained in:
Michael Hutchinson 2005-09-18 18:38:22 +00:00
Родитель c6b3352972
Коммит 5715df9d03
2 изменённых файлов: 37 добавлений и 3 удалений

Просмотреть файл

@ -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,7 +188,7 @@ namespace AspNetEdit.Editor.UI
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;
@ -196,8 +196,39 @@ namespace AspNetEdit.Editor.UI
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;
}