Palete/Gtk.vala
[app.Builder.js] / Palete / Gtk.vala
1 namespace Palete {
2
3         
4         
5         
6         
7         public class Introspect.El : Object
8         {
9                 public enum eltype { 
10                             NS,
11                             CLASS,
12                             METHOD,
13                             PROP
14                 }
15                 
16             
17                 public eltype type;
18         }
19
20
21         public class Gtk : Palete {
22                 
23                 
24                 public Gtk()
25                 {
26
27
28                     
29                     base();
30                     this.name = "Gtk";
31                                  
32                                 //this.load();
33                     // various loader methods..
34                       //this.map = [];
35                     //this.load();
36                     //this.proplist = {};
37                     //this.comments = { }; 
38                     // no parent...
39                 }
40               
41                 public override void  load () {
42
43                         this.loadUsageFile(Builder4.Application.configDirectory() + "/resources/GtkUsage.txt");
44          
45                      
46                 }
47                 
48                 public string doc(string what) {
49                         var ns = what.split(".")[0];
50                         var gir =  Gir.factory(ns);
51                         return   gir.doc(what);
52                         
53                     //return typeof(this.comments[ns][what]) == 'undefined' ?  '' : this.comments[ns][what];
54                 }
55
56                         // does not handle implements...
57                 public override GirObject? getClass(string ename)
58                 {
59
60                         var es = ename.split(".");
61                         var gir = Gir.factory(es[0]);
62                 
63                         return gir.classes.get(es[1]);
64                 
65                 }
66
67                 public override Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type)
68                 {
69                         //print("Loading for " + ename);
70                     
71
72
73                                 // if (typeof(this.proplist[ename]) != 'undefined') {
74                         //print("using cache");
75                         //   return this.proplist[ename][type];
76                         //}
77                         // use introspection to get lists..
78          
79                         var es = ename.split(".");
80                         var gir = Gir.factory(es[0]);
81                 
82                         var cls = gir.classes.get(es[1]);
83                         if (cls == null) {
84                                 var ret = new Gee.HashMap<string,GirObject>();
85                                 return ret;
86                                 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
87                         
88                         }
89
90                         //cls.parseProps();
91                         //cls.parseSignals(); // ?? needed for add handler..
92                         //cls.parseMethods(); // ?? needed for ??..
93                         //cls.parseConstructors(); // ?? needed for ??..
94
95                         cls.overlayParent();
96
97                         switch  (type) {
98                                 case "props":
99                                         return cls.props;
100                                 case "signals":
101                                         return cls.signals;
102                                 case "methods":
103                                         return cls.methods;
104                                 case "ctors":
105                                         return cls.ctors;
106                                 default:
107                                         throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + type);
108                                         //var ret = new Gee.HashMap<string,GirObject>();
109                                         //return ret;
110                                 
111                         }
112                                 
113                         
114                         //cls.overlayInterfaces(gir);
115                     
116                     
117                      
118                 }
119                 public string[] getInheritsFor(string ename)
120                 {
121                         string[] ret = {};
122                          
123                         var cls = Gir.factoryFqn(ename);
124                          
125                         if (cls == null || cls.nodetype != "Class") {
126                                 print("getInheritsFor:could not find cls: %s\n", ename);
127                                 return ret;
128                         }
129                         
130                         return cls.inheritsToStringArray();
131                         
132
133                 }
134          
135                 public override void fillPack(JsRender.Node node,JsRender.Node parent)
136                 {   
137                         
138                         string inherits =  string.joinv(" ", 
139                                       this.getInheritsFor (node.fqn())) + " ";
140                         inherits += node.fqn() + " ";
141                         //print ("fillPack:Inherits : %s\n", inherits);
142                         // parent.fqn() method ( node.fqn()
143                         var methods = this.getPropertiesFor (parent.fqn(), "methods");
144                         
145                         var res = new Gee.HashMap<string,string>();
146                         var map = methods.map_iterator();
147                         while (map.next()) {
148                                 
149                                 var n = map.get_key();
150                                 //print ("fillPack:checking method %s\n", n);
151                                 
152                                 var meth = map.get_value();
153                                 if (meth.paramset == null || meth.paramset.params.size < 1) {
154                                         print ("fillPack:c -- no params\n");
155                                 
156                                         continue;
157                                 }
158                                 var fp = meth.paramset.params.get(0);
159                                 
160                                 var type = Gir.fqtypeLookup(fp.type, meth.ns);
161                                 print ("fillPack:first param type is %s\n", type);
162
163                                 
164                                 if (!inherits.contains(" " + type + " ")) {
165                                         continue;
166                                 }
167                                 
168                                 
169                                 var pack = meth.name;
170                                 for(var i =1; i < meth.paramset.params.size; i++) {
171                                         var ty = Gir.fqtypeLookup(meth.paramset.params.get(i).type, meth.ns);
172                                         pack += "," + Gir.guessDefaultValueForType(ty);
173                                 }
174
175                                 print ("fillPack:add pack:  --          %s\n",pack );
176
177                                 res.set(meth.name, pack);
178                                 
179                                 
180
181                         }
182                         if (res.size < 1) {
183                                 return ;
184                         }
185                         if (res.has_key("pack_start")) {
186                                 node.props.set("* pack", res.get("pack_start"));
187                                 return;
188                         }
189                         if (res.has_key("add")) {
190                                 node.props.set("* pack", res.get("add"));
191                                 return;
192                         }
193                         var riter = res.map_iterator();
194                         while(riter.next()) {
195                                 node.props.set("* pack", riter.get_value());
196                                 return;
197                         }
198                         
199                         
200                 }
201  
202         
203     }
204 }
205