9 public class Introspect.El : Object
23 public class Roo : Palete {
25 Gee.ArrayList<string> top_classes;
26 public static Gee.HashMap<string,GirObject>? classes_cache = null;
27 public static Gee.ArrayList<string>? top_classes_cache = null;
29 public Roo(Project.Project project)
36 this.top_classes = new Gee.ArrayList<string>();
39 this.load(); // ? initialize the roodata?
43 Gee.HashMap<string,GirObject> propsFromJSONArray(string type, Json.Array ar, GirObject cls)
46 var ret = new Gee.HashMap<string,GirObject>();
48 for (var i =0 ; i < ar.get_length(); i++) {
49 var o = ar.get_object_element(i);
50 var name = o.get_string_member("name");
51 var prop = new GirObject(type, name );
53 prop.type = o.get_string_member("type");
54 prop.doctxt = o.get_string_member("desc");
55 prop.propertyof = o.has_member("memberOf") ? o.get_string_member("memberOf") : "";
56 if (prop.propertyof.length < 1) {
57 prop.propertyof = cls.name;
60 // this is the function default.
61 prop.sig = o.has_member("sig") ? o.get_string_member("sig") : "";
63 if (o.has_member("optvals") ) {
64 var oar = o.get_array_member("optvals");
66 for (var oi = 0; oi < oar.get_length(); oi++) {
67 prop.optvalues.add(oar.get_string_element(oi));
72 //print(type + ":" + name +"\n");
79 public override void load () {
81 if (this.classes != null) {
84 if (Roo.classes_cache != null) {
85 this.classes = Roo.classes_cache;
86 this.top_classes = Roo.top_classes_cache ;
91 // this.loadUsageFile(BuilderApplication.configDirectory() + "/resources/RooUsage.txt");
92 this.classes = new Gee.HashMap<string,GirObject>();
93 var add_to = new Gee.HashMap<string,Gee.ArrayList<string>>();
95 var pa = new Json.Parser();
97 pa.load_from_file(BuilderApplication.configDirectory() + "/resources/roodata.json");
98 } catch(GLib.Error e) {
99 GLib.error("Could not load %s",BuilderApplication.configDirectory() + "/resources/roodata.json");
101 var node = pa.get_root();
103 var clist = node.get_object(); /// was in data... .get_object_member("data");
104 clist.foreach_member((o , key, value) => {
105 //print("cls:" + key+"\n");
107 var cls = new GirObject("class", key);
108 cls.props = this.propsFromJSONArray("prop", value.get_object().get_array_member("props"),cls);
109 cls.signals = this.propsFromJSONArray("signal", value.get_object().get_array_member("events"),cls);
112 if (value.get_object().has_member("methods")) {
113 cls.methods = this.propsFromJSONArray("method", value.get_object().get_array_member("methods"),cls);
115 if (value.get_object().has_member("implementations")) {
116 var vcn = value.get_object().get_array_member("implementations");
117 for (var i =0 ; i < vcn.get_length(); i++) {
118 cls.implementations.add(vcn.get_string_element(i));
124 if (value.get_object().has_member("tree_children")) {
125 var vcn = value.get_object().get_array_member("tree_children");
126 for (var i =0 ; i < vcn.get_length(); i++) {
127 var ad_c = vcn.get_string_element(i);
128 if (!cls.valid_cn.contains(ad_c)) {
129 cls.valid_cn.add( ad_c );
131 if (!add_to.has_key(ad_c)) {
132 add_to.set(ad_c, new Gee.ArrayList<string>());
134 if (!add_to.get(ad_c).contains(cls.name)) {
135 add_to.get(ad_c).add(cls.name);
145 if (value.get_object().has_member("tree_parent")) {
146 var vcn = value.get_object().get_array_member("tree_parent");
147 for (var i =0 ; i < vcn.get_length(); i++) {
148 if ("builder" == vcn.get_string_element(i)) {
149 // this class can be added to the top level.
150 GLib.debug("Add %s to *top", cls.name);
152 this.top_classes.add(cls.name);
159 this.classes.set(key, cls);
162 // look for properties of classes, that are atually clasess
163 // eg. Roo.data.Store has proxy and reader..
166 foreach(var cls in this.classes.values) {
167 foreach(var gir_obj in cls.props.values) {
168 var types = gir_obj.type.split("|");
169 for(var i =0; i < types.length; i++) {
172 if (/^Roo\./.match(type) && classes.has_key(type)) {
175 cls.valid_cn.add(type + ":" + gir_obj.name );
176 // Roo.bootstrap.panel.Content:east
177 // also means that Roo.bootstrap.panel.Grid:east works
178 var prop_type = classes.get(type);
179 foreach(var imp_str in prop_type.implementations) {
180 //GLib.debug("addChild for %s - child= %s:%s", cls.name, imp_str, gir_obj.name);
181 cls.valid_cn.add(imp_str + ":" + gir_obj.name);
182 if (!add_to.has_key(imp_str)) {
183 add_to.set( imp_str, new Gee.ArrayList<string>());
185 if (!add_to.get( imp_str).contains(cls.name)) {
186 add_to.get( imp_str ).add(cls.name );
192 if (!add_to.has_key( type)) {
193 add_to.set( type, new Gee.ArrayList<string>());
195 if (!add_to.get(type).contains(cls.name)) {
196 add_to.get( type ).add(cls.name );
203 foreach(var cls in this.classes.values) {
204 if (add_to.has_key(cls.name)) {
205 cls.can_drop_onto = add_to.get(cls.name);
208 Roo.classes_cache = this.classes;
209 Roo.top_classes_cache = this.top_classes;
213 public string doc(string what) {
215 /*var ns = what.split(".")[0];
220 var gir = Gir.factory(ns);
221 return gir.doc(what);
224 //return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
227 // does not handle implements...
228 public override GirObject? getClass(string ename)
231 return this.classes.get(ename);
237 public override Gee.HashMap<string,GirObject> getPropertiesFor(string ename, JsRender.NodePropType ptype)
239 //print("Loading for " + ename);
243 // if (typeof(this.proplist[ename]) != 'undefined') {
244 //print("using cache");
245 // return this.proplist[ename][type];
247 // use introspection to get lists..
250 var cls = this.classes.get(ename);
251 var ret = new Gee.HashMap<string,GirObject>();
253 print("could not find class: %s\n", ename);
255 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
260 //cls.parseSignals(); // ?? needed for add handler..
261 //cls.parseMethods(); // ?? needed for ??..
262 //cls.parseConstructors(); // ?? needed for ??..
264 //cls.overlayParent();
269 case JsRender.NodePropType.PROP:
270 return this.filterProps(cls.props);
271 case JsRender.NodePropType.LISTENER:
273 case JsRender.NodePropType.METHOD:
275 case JsRender.NodePropType.CTOR:
278 GLib.error( "getPropertiesFor called with: " + ptype.to_string());
279 //var ret = new Gee.HashMap<string,GirObject>();
285 //cls.overlayInterfaces(gir);
291 // removes all the properties where the type contains '.' ?? << disabled now..
293 public Gee.HashMap<string,GirObject> filterProps(Gee.HashMap<string,GirObject> props)
295 // we shold probably cache this??
297 var outprops = new Gee.HashMap<string,GirObject>();
299 foreach(var k in props.keys) {
300 var val = props.get(k);
311 //if (!val.type.contains(".")) {
318 // do nothing? - classes not allowed?
329 public string[] getInheritsFor(string ename)
332 var es = ename.split(".");
333 var gir = Gir.factory(null, es[0]);
335 var cls = gir.classes.get(es[1]);
339 return cls.inheritsToStringArray();
346 * Pulldown options for type
348 public override bool typeOptions(string fqn, string key, string type, out string[] opts)
351 print("get typeOptions %s (%s)%s", fqn, type, key);
352 if (type.up() == "BOOL" || type.up() == "BOOLEAN") {
353 opts = { "true", "false" };
357 var props = this.getPropertiesFor(fqn, JsRender.NodePropType.PROP);
358 if (!props.has_key(key)) {
359 print("prop %s does not have key %s\n", fqn, key);
362 var pr = props.get(key);
363 if (pr.optvalues.size < 1) {
364 print("prop %s no optvalues for %s\n", fqn, key);
368 for(var i = 0; i < pr.optvalues.size; i++) {
369 ret += pr.optvalues.get(i);
372 print("prop %s returning optvalues for %s\n", fqn, key);
379 public override Gee.ArrayList<string> getChildList(string in_rval, bool with_prop)
381 if (this.top_classes.size < 1) {
387 var ar = this.top_classes;
388 if (in_rval != "*top") {
389 if (this.classes.has_key(in_rval)) {
390 // some of these children will be eg: Roo.bootstrap.layout.Region:center
391 ar = this.classes.get(in_rval).valid_cn;
393 ar = new Gee.ArrayList<string>();
398 var ret = new Gee.ArrayList<string>();
399 foreach(var v in ar) {
400 if (v.contains(":")) {
408 GLib.debug("getChildList for %s returns %d items", in_rval, ar.size);
411 //return this.original_getChildList( in_rval);
416 public override Gee.ArrayList<string> getDropList(string rval)
419 if (this.dropCache.has_key(rval)) {
420 return this.dropCache.get(rval);
422 // we might be dragging Roo.bootstrap.layout.Region:center
423 // in which case we need to lookup Roo.bootstrap.layout.Region
424 // and see if it's has can_drop_onto
425 var ret = new Gee.ArrayList<string>();
426 var cls = this.classes.get(rval);
428 if (cls == null && rval.contains(":")) {
429 var rr = rval.substring(0,rval.index_of(":"));
430 GLib.debug("Converted classname to %s", rr);
431 cls = this.classes.get(rr);
434 return ret; //nothing..
437 foreach(var str in cls.can_drop_onto) {
441 //GLib.debug("getDropList for %s return[] %s", rval, string.joinv(", ", ret));
442 this.dropCache.set(rval,ret);
447 //return this.default_getDropList(rval);
449 public override JsRender.Node fqnToNode(string fqn)
451 var ret = new JsRender.Node();
453 // any default requred proerties?