Skip to content
Browse files

2008-07-01 Mike Kestner <mkestner@novell.com>

	* libsteticui/AssemblyResolver.cs: make type resolver public.
	* libsteticui/LibraryCache.cs: [ToolboxItem] and [Category] scanner
	for identification of exported widgets from libraries.

svn path=/trunk/stetic/; revision=107002
  • Loading branch information...
1 parent 0ece1dc commit b5e343a3ad5ff6ee57fa719f3161af120ad5390d @mkestner mkestner committed Jul 1, 2008
Showing with 126 additions and 2 deletions.
  1. +6 −0 ChangeLog
  2. +1 −1 libsteticui/AssemblyResolver.cs
  3. +119 −1 libsteticui/LibraryCache.cs
View
6 ChangeLog
@@ -1,3 +1,9 @@
+2008-07-01 Mike Kestner <mkestner@novell.com>
+
+ * libsteticui/AssemblyResolver.cs: make type resolver public.
+ * libsteticui/LibraryCache.cs: [ToolboxItem] and [Category] scanner
+ for identification of exported widgets from libraries.
+
2008-06-25 Mike Kestner <mkestner@novell.com>
* libsteticui/Application.cs: use resolver.
View
2 libsteticui/AssemblyResolver.cs
@@ -67,7 +67,7 @@ public override AssemblyDefinition Resolve (AssemblyNameReference name)
return asm;
}
- TypeDefinition Resolve (TypeReference type)
+ public TypeDefinition Resolve (TypeReference type)
{
if (type is TypeDefinition)
return (TypeDefinition) type;
View
120 libsteticui/LibraryCache.cs
@@ -267,6 +267,106 @@ XmlDocument GetGuiDoc (AssemblyDefinition adef)
return doc;
}
+ bool ReferenceChainContainsGtk (AssemblyResolver resolver, AssemblyNameReference aref, Hashtable visited)
+ {
+ if (aref.Name == "gtk-sharp")
+ return true;
+ else if (visited.Contains (aref.Name))
+ return false;
+
+ visited [aref.Name] = aref;
+
+ AssemblyDefinition adef = resolver.Resolve (aref);
+ if (adef == null)
+ return false;
+
+ foreach (AssemblyNameReference child in adef.MainModule.AssemblyReferences)
+ if (ReferenceChainContainsGtk (resolver, child, visited))
+ return true;
+
+ return false;
+ }
+
+ class ToolboxItemInfo {
+
+ public ToolboxItemInfo (string base_type)
+ {
+ BaseType = base_type;
+ }
+
+ public string BaseType;
+ public string PaletteCategory;
+ }
+
+ 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;
+ }
+
+ 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);
+ }
+ }
+
XmlDocument GetObjectsDoc (AssemblyResolver resolver, AssemblyDefinition adef, string path)
{
XmlDocument doc = null;
@@ -278,12 +378,30 @@ XmlDocument GetObjectsDoc (AssemblyResolver resolver, AssemblyDefinition adef, s
using (stream)
doc.Load (stream);
}
+
+ if (resolver == null)
+ resolver = new AssemblyResolver (null);
+
+ Hashtable visited = new Hashtable ();
+ foreach (AssemblyNameReference aref in adef.MainModule.AssemblyReferences) {
+ if (!ReferenceChainContainsGtk (resolver, aref, visited))
+ continue;
+
+ if (doc == null) {
+ doc = new XmlDocument ();
+ doc.AppendChild (doc.CreateElement ("objects"));
+ }
+ AddObjects (doc, resolver, adef);
+ break;
+ }
+
if (doc != null) {
XmlElement elem = doc.CreateElement ("dependencies");
doc.DocumentElement.AppendChild (elem);
AddDependencies (elem, resolver, path, adef);
}
- } catch {
+ } catch (Exception e) {
+ Console.WriteLine ("Got exception loading objects: " + e);
doc = null;
}

0 comments on commit b5e343a

Please sign in to comment.
Something went wrong with that request. Please try again.