tools/build_gtk_tree.js
[app.Builder.js] / tools / build_gtk_tree.js
index a23c5c1..8d9adc8 100644 (file)
@@ -133,9 +133,13 @@ function BuildLists () {
                 if (m.memberOf == 'Gtk.Buildable') {
                     return;
                 }
-                if (m.name =='add_mnemonic_label') {
+                               //"Gtk.Widget:add_accelerator",
+                               //"Gtk.Widget:add_device_events"
+
+                if (m.name.match(/^(add_mnemonic_label|add_accelerator|add_device_events)$/)) {
                     return;
                 }
+        
                 // in theory you can not add a window to anything.. ???
                 //if ('Gtk.Window' == addable_type || methods[addable_type].extendsClasses.indexOf('Gtk.Window') > -1) {
                 //    return;
@@ -263,9 +267,68 @@ function BuildLists () {
     this.methods = methods;
     this.allmethods = methods;
     this.implementations = implementations;
-    //print(JSON.stringify(methods,null,4));
+    //print(JSON.stringify(methods,null,4)); Seed.exit();
     // dump out a usage file..
     
+    function verifyUsageMethod(parent,child,method)
+    {
+        // currently only verifies add on container.
+        if (method !='Gtk.Container:add') {
+            return true;
+        }
+        
+        var cls = parent.split('.').pop();
+         
+        
+        if (parent == 'Gtk.Bin' || methods['Gtk.Bin'].extendsClasses.indexOf(parent) > -1) {
+            return false;
+        }
+        if (['GtkSource.CompletionInfo',
+             'Gtk.MenuShell',
+             'GtkSource.View', // ??? nothing can be added to it?
+             'GtkClutter.Embed'
+             ].indexOf(parent) > -1) {
+             return false;
+        }
+        
+        print("TRY ctor:  " + parent );
+
+        var x = new imports.gi.Gtk[cls]();
+        print("TRY child type:  " + parent);
+        
+        print(parent + " : says children are of type : " + x.child_type());
+        return true;
+        
+    }
+    
+    function is_a(cls, instance_of) {
+        return methods[cls].extendsClasses.indexOf(instance_of) > -1; 
+    }
+    
+    function verifyUsage(parent,child)
+    {
+        // find all the methods that child can be added to parent.
+        var mts = methods[parent].can_contain_using;
+        for(var i =0;i<mts.length;i++) {
+            var m = mts[i].split(':');
+            if (!is_a(child,m[0])) {
+                continue;
+                
+            }
+            if (verifyUsageMethod(parent,child,mts[i])) {
+                return true;
+            }
+        }
+        return false;
+        
+        
+    }
+    
+    
+    
+    
+    
+    
     // basically anything that is a Gtk.Container, should be available at the top.
     /*
 left:
@@ -300,6 +363,11 @@ right:
             if (typeof(usage[par]) == 'undefined') {
                 usage[par] = [];
             }
+            
+            if (!verifyUsage(par,cls)) {
+                continue;
+            }
+            
             usage[par].pushUnique(cls);
             if (typeof(tops[cls]) == 'undefined') {
                 tops[cls] = [];
@@ -409,6 +477,7 @@ right:
     //print(JSON.stringify(implementations,null,4));
     
 }
+imports.gi.Gtk.init(Seed.argv);
 BuildLists();
 
 // we now have a list of classes / methods that can be used..