internal ToolboxItemInfo GetToolboxItem(string name, string asmName) { XmlDocument doc = ObjectsDocument; if (doc != null) { XmlElement elem = (XmlElement)doc.SelectSingleNode("/objects/object[@type='" + name + "']"); if (elem == null) { elem = (XmlElement)doc.SelectSingleNode("/objects/object[@type='" + name + "," + asmName + "']"); } if (elem != null) { ToolboxItemInfo info = new ToolboxItemInfo(elem.GetAttribute("base-type")); info.PaletteCategory = elem.GetAttribute("palette-category"); return(info); } } return(null); }
void AddObject(TypeDefinition tdef, Dictionary <TypeDefinition, ToolboxItemInfo> localObjects, AssemblyResolver resolver, string basePath, AssemblyDefinition adef) { if (tdef.IsAbstract || !tdef.IsClass) { return; } ToolboxItemInfo tbinfo = GetToolboxItemInfo(resolver, basePath, adef, tdef, true); if (tbinfo == null) { return; } localObjects [tdef] = tbinfo; foreach (var nestedType in tdef.NestedTypes) { AddObject(nestedType, localObjects, resolver, basePath, adef); } }
private static void RegisterToolboxItem(ToolboxSection section, string name, ToolboxItemInfo item) { if (!section.Tools.Contains(name)) { var toolboxItem = new ToolboxItem(section.Tools) { Name = name, Title = item.Title, Description = string.Empty, ControlType = typeof(MvcControllerProxy).FullName, ControllerType = item.ControllerType, CssClass = item.CssClass, Parameters = new NameValueCollection() { { "ControllerName", item.ControllerType } } }; section.Tools.Add(toolboxItem); } }
void AddObjects(XmlDocument doc, AssemblyResolver resolver, AssemblyDefinition adef) { foreach (TypeDefinition tdef in adef.MainModule.Types) { if (tdef.IsNotPublic || tdef.IsAbstract || !tdef.IsClass) { continue; } ToolboxItemInfo tbinfo = GetToolboxItemInfo(resolver, tdef); if (tbinfo == null) { continue; } XmlElement elem = doc.CreateElement("object"); elem.SetAttribute("type", tdef.FullName); elem.SetAttribute("allow-children", "false"); elem.SetAttribute("base-type", tbinfo.BaseType); elem.SetAttribute("palette-category", tbinfo.PaletteCategory); doc.DocumentElement.AppendChild(elem); } }
void AddObjects(XmlDocument doc, AssemblyResolver resolver, string basePath, AssemblyDefinition adef) { Dictionary <TypeDefinition, ToolboxItemInfo> localObjects = new Dictionary <TypeDefinition, ToolboxItemInfo> (); foreach (TypeDefinition tdef in adef.MainModule.Types) { AddObject(tdef, localObjects, resolver, basePath, adef); } foreach (KeyValuePair <TypeDefinition, ToolboxItemInfo> item in localObjects) { TypeDefinition tdef = item.Key; ToolboxItemInfo tbinfo = item.Value; XmlElement elem = doc.CreateElement("object"); elem.SetAttribute("type", tdef.FullName); elem.SetAttribute("allow-children", "false"); elem.SetAttribute("palette-category", tbinfo.PaletteCategory); if (tdef.IsNotPublic) { elem.SetAttribute("internal", "true"); } doc.DocumentElement.AppendChild(elem); TypeDefinition curDef = tdef; while (curDef != null && curDef.FullName != tbinfo.BaseType) { if (curDef != tdef && localObjects.ContainsKey(curDef)) { tbinfo.BaseType = curDef.FullName; break; } else if (curDef.Module.Assembly.Name.Name == "gtk-sharp") { tbinfo.BaseType = curDef.FullName; break; } else if (curDef != tdef && GetToolboxItemInfo(resolver, basePath, curDef.Module.Assembly, curDef, false) != null) { tbinfo.BaseType = curDef.FullName; break; } if (curDef.Module.Assembly != adef) { LibraryInfo li = Refresh(resolver, curDef.Module.FullyQualifiedName, basePath); if (li.HasWidgets && li.GetToolboxItem(curDef.FullName, curDef.Module.Assembly.Name.Name) != null) { tbinfo.BaseType = curDef.FullName; break; } } AddProperties(curDef, elem); AddEvents(curDef, elem); if (curDef.BaseType != null && curDef.BaseType.FullName != tbinfo.BaseType) { curDef = FindTypeDefinition(resolver, adef, basePath, curDef.BaseType.FullName); } else { curDef = null; } } elem.SetAttribute("base-type", tbinfo.BaseType); } }
ToolboxItemInfo GetToolboxItemInfo(AssemblyResolver resolver, string baseDirectory, AssemblyDefinition asm, TypeDefinition tdef, bool checkBaseType) { if (tdef == null) { return(null); } ToolboxItemInfo info = null; string category = "General"; foreach (CustomAttribute attr in tdef.CustomAttributes) { switch (attr.AttributeType.FullName) { case "System.ComponentModel.ToolboxItemAttribute": if (attr.ConstructorArguments.Count > 0) { object param = attr.ConstructorArguments [0].Value; if (param == null) { return(null); } else if (param.GetType() == typeof(bool)) { if ((bool)param) { info = new ToolboxItemInfo("Gtk.Widget"); } else { return(null); } } else if (param.GetType() == typeof(TypeReference)) { info = new ToolboxItemInfo("Gtk.Widget"); } else { return(null); } } break; case "System.ComponentModel.CategoryAttribute": if (attr.ConstructorArguments.Count > 0) { object param = attr.ConstructorArguments [0].Value; if (param.GetType() == typeof(string)) { category = (string)param; } } break; default: continue; } } if (info == null && checkBaseType && tdef.BaseType != null) { string baseName = tdef.BaseType.FullName; foreach (AssemblyNameReference aref in asm.MainModule.AssemblyReferences) { LibraryInfo libInfo = GetInfo(resolver, aref.FullName, baseDirectory); if (libInfo != null && libInfo.HasWidgets) { ToolboxItemInfo binfo = libInfo.GetToolboxItem(baseName, aref.Name); if (binfo != null) { info = new ToolboxItemInfo(baseName); category = binfo.PaletteCategory; break; } } } } if (info != null) { info.PaletteCategory = category; } return(info); }
ToolboxItemInfo GetToolboxItemInfo (AssemblyResolver resolver, string baseDirectory, AssemblyDefinition asm, TypeDefinition tdef, bool checkBaseType) { if (tdef == null) return null; ToolboxItemInfo info = null; string category = "General"; foreach (CustomAttribute attr in tdef.CustomAttributes) { switch (attr.AttributeType.FullName) { case "System.ComponentModel.ToolboxItemAttribute": if (attr.ConstructorArguments.Count > 0) { object param = attr.ConstructorArguments [0].Value; if (param == null) return null; else if (param.GetType () == typeof (bool)) { if ((bool) param) info = new ToolboxItemInfo ("Gtk.Widget"); else return null; } else if (param.GetType () == typeof (TypeReference)) info = new ToolboxItemInfo ("Gtk.Widget"); else return null; } break; case "System.ComponentModel.CategoryAttribute": if (attr.ConstructorArguments.Count > 0) { object param = attr.ConstructorArguments [0].Value; if (param.GetType () == typeof (string)) category = (string) param; } break; default: continue; } } if (info == null && checkBaseType && tdef.BaseType != null) { string baseName = tdef.BaseType.FullName; foreach (AssemblyNameReference aref in asm.MainModule.AssemblyReferences) { LibraryInfo libInfo = GetInfo (resolver, aref.FullName, baseDirectory); if (libInfo != null && libInfo.HasWidgets) { ToolboxItemInfo binfo = libInfo.GetToolboxItem (baseName, aref.Name); if (binfo != null) { info = new ToolboxItemInfo (baseName); category = binfo.PaletteCategory; break; } } } } if (info != null) info.PaletteCategory = category; return info; }
internal ToolboxItemInfo GetToolboxItem (string name, string asmName) { XmlDocument doc = ObjectsDocument; if (doc != null) { XmlElement elem = (XmlElement) doc.SelectSingleNode ("/objects/object[@type='" + name + "']"); if (elem == null) elem = (XmlElement) doc.SelectSingleNode ("/objects/object[@type='" + name + "," + asmName + "']"); if (elem != null) { ToolboxItemInfo info = new ToolboxItemInfo (elem.GetAttribute ("base-type")); info.PaletteCategory = elem.GetAttribute ("palette-category"); return info; } } return null; }
ToolboxItemInfo GetToolboxItemInfo(AssemblyResolver resolver, TypeDefinition tdef) { if (tdef == null) return null; ToolboxItemInfo info = null; string category = "General"; foreach (CustomAttribute attr in tdef.CustomAttributes) { switch (attr.Constructor.DeclaringType.FullName) { case "System.ComponentModel.ToolboxItemAttribute": attr.Resolve (); if (attr.ConstructorParameters.Count > 0) { object param = attr.ConstructorParameters [0]; if (param == null) return null; else if (param.GetType () == typeof (bool)) { if ((bool) param) info = new ToolboxItemInfo ("Gtk.Widget"); else return null; } else if (param.GetType () == typeof (System.Type)) info = new ToolboxItemInfo ("Gtk.Widget"); else return null; } break; case "System.ComponentModel.CategoryAttribute": attr.Resolve (); if (attr.ConstructorParameters.Count > 0) { object param = attr.ConstructorParameters [0]; if (param.GetType () == typeof (string)) category = (string) param; } break; default: continue; } } if (info == null && tdef.BaseType != null) info = GetToolboxItemInfo (resolver, resolver.Resolve (tdef.BaseType)); if (info != null) info.PaletteCategory = category; return info; }
ToolboxItemInfo GetToolboxItemInfo(AssemblyResolver resolver, TypeDefinition tdef) { if (tdef == null) { return(null); } ToolboxItemInfo info = null; string category = "General"; foreach (CustomAttribute attr in tdef.CustomAttributes) { switch (attr.Constructor.DeclaringType.FullName) { case "System.ComponentModel.ToolboxItemAttribute": attr.Resolve(); if (attr.ConstructorParameters.Count > 0) { object param = attr.ConstructorParameters [0]; if (param == null) { return(null); } else if (param.GetType() == typeof(bool)) { if ((bool)param) { info = new ToolboxItemInfo("Gtk.Widget"); } else { return(null); } } else if (param.GetType() == typeof(System.Type)) { info = new ToolboxItemInfo("Gtk.Widget"); } else { return(null); } } break; case "System.ComponentModel.CategoryAttribute": attr.Resolve(); if (attr.ConstructorParameters.Count > 0) { object param = attr.ConstructorParameters [0]; if (param.GetType() == typeof(string)) { category = (string)param; } } break; default: continue; } } if (info == null && tdef.BaseType != null) { info = GetToolboxItemInfo(resolver, resolver.Resolve(tdef.BaseType)); } if (info != null) { info.PaletteCategory = category; } return(info); }