Attribute changed old-javascript
[app.Builder.js] / old-javascript / 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                 public Gee.ArrayList<string> package_cache;
24                 
25                 public Gtk()
26                 {
27
28
29                     
30                     base();
31                     this.name = "Gtk";
32                     this.loadPackages();         
33                                 //this.load();
34                     // various loader methods..
35                       //this.map = [];
36                     //this.load();
37                     //this.proplist = {};
38                     //this.comments = { }; 
39                     // no parent...
40                 }
41               
42                 public override void  load () {
43
44                         this.loadUsageFile(Builder4.Application.configDirectory() + "/resources/GtkUsage.txt");
45          
46                      
47                 }
48                 
49                 public string doc(string what) {
50                         var ns = what.split(".")[0];
51                         var gir =  Gir.factory(ns);
52                         return   gir.doc(what);
53                         
54                     //return typeof(this.comments[ns][what]) == 'undefined' ?  '' : this.comments[ns][what];
55                 }
56
57                         // does not handle implements...
58                 public override GirObject? getClass(string ename)
59                 {
60
61                         var es = ename.split(".");
62                         var gir = Gir.factory(es[0]);
63                 
64                         return gir.classes.get(es[1]);
65                 
66                 }
67
68                 public override Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type)
69                 {
70                         //print("Loading for " + ename);
71                     
72
73
74                                 // if (typeof(this.proplist[ename]) != 'undefined') {
75                         //print("using cache");
76                         //   return this.proplist[ename][type];
77                         //}
78                         // use introspection to get lists..
79          
80                         var es = ename.split(".");
81                         var gir = Gir.factory(es[0]);
82                 
83                         var cls = gir.classes.get(es[1]);
84                         if (cls == null) {
85                                 var ret = new Gee.HashMap<string,GirObject>();
86                                 return ret;
87                                 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
88                         
89                         }
90
91                         //cls.parseProps();
92                         //cls.parseSignals(); // ?? needed for add handler..
93                         //cls.parseMethods(); // ?? needed for ??..
94                         //cls.parseConstructors(); // ?? needed for ??..
95
96                         cls.overlayParent();
97
98                         switch  (type) {
99                                 case "props":
100                                         return cls.props;
101                                 case "signals":
102                                         return cls.signals;
103                                 case "methods":
104                                         return cls.methods;
105                                 case "ctors":
106                                         return cls.ctors;
107                                 default:
108                                         throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + type);
109                                         //var ret = new Gee.HashMap<string,GirObject>();
110                                         //return ret;
111                                 
112                         }
113                                 
114                         
115                         //cls.overlayInterfaces(gir);
116                     
117                     
118                      
119                 }
120                 public string[] getInheritsFor(string ename)
121                 {
122                         string[] ret = {};
123                          
124                         var cls = Gir.factoryFqn(ename);
125                          
126                         if (cls == null || cls.nodetype != "Class") {
127                                 print("getInheritsFor:could not find cls: %s\n", ename);
128                                 return ret;
129                         }
130                         
131                         return cls.inheritsToStringArray();
132                         
133
134                 }
135          
136                 public override void fillPack(JsRender.Node node,JsRender.Node parent)
137                 {   
138                         
139                         string inherits =  string.joinv(" ", 
140                                       this.getInheritsFor (node.fqn())) + " ";
141                         inherits += node.fqn() + " ";
142                         //print ("fillPack:Inherits : %s\n", inherits);
143                         // parent.fqn() method ( node.fqn()
144                         var methods = this.getPropertiesFor (parent.fqn(), "methods");
145                         
146                         var res = new Gee.HashMap<string,string>();
147                         var map = methods.map_iterator();
148                         while (map.next()) {
149                                 
150                                 var n = map.get_key();
151                                 //print ("fillPack:checking method %s\n", n);
152                                 
153                                 var meth = map.get_value();
154                                 if (meth.paramset == null || meth.paramset.params.size < 1) {
155                                         print ("fillPack:c -- no params\n");
156                                 
157                                         continue;
158                                 }
159                                 var fp = meth.paramset.params.get(0);
160                                 
161                                 var type = Gir.fqtypeLookup(fp.type, meth.ns);
162                                 print ("fillPack:first param type is %s\n", type);
163
164                                 
165                                 if (!inherits.contains(" " + type + " ")) {
166                                         continue;
167                                 }
168                                 
169                                 
170                                 var pack = meth.name;
171                                 for(var i =1; i < meth.paramset.params.size; i++) {
172                                         var ty = Gir.fqtypeLookup(meth.paramset.params.get(i).type, meth.ns);
173                                         pack += "," + Gir.guessDefaultValueForType(ty);
174                                 }
175
176                                 print ("fillPack:add pack:  --          %s\n",pack );
177
178                                 res.set(meth.name, pack);
179                                 
180                                 
181
182                         }
183                         if (res.size < 1) {
184                                 return ;
185                         }
186                         if (res.has_key("pack_start")) {
187                                 node.props.set("* pack", res.get("pack_start"));
188                                 return;
189                         }
190                         if (res.has_key("add")) {
191                                 node.props.set("* pack", res.get("add"));
192                                 return;
193                         }
194                         var riter = res.map_iterator();
195                         while(riter.next()) {
196                                 node.props.set("* pack", riter.get_value());
197                                 return;
198                         }
199                         
200                         
201                 }
202                 public Gee.ArrayList<string> packages()
203                 {
204                         return this.package_cache;
205                 }
206                 
207                 public void  loadPackages()
208                 {
209
210                          
211                         this.package_cache = new Gee.ArrayList<string>();
212                         var context = new Vala.CodeContext ();
213                         var dirname =  Path.get_dirname (context.get_vapi_path("glib-2.0"));
214                          
215                         var dir = File.new_for_path(dirname);
216                         try {
217                                 var file_enum = dir.enumerate_children(
218                                         GLib.FileAttribute.STANDARD_DISPLAY_NAME, 
219                                         GLib.FileQueryInfoFlags.NONE, 
220                                         null
221                                 );
222                         
223                          
224                                 FileInfo next_file; 
225                                 while ((next_file = file_enum.next_file(null)) != null) {
226                                         var fn = next_file.get_display_name();
227                                         if (!Regex.match_simple("\\.vapi$", fn)) {
228                                                 continue;
229                                         }
230                                         this.package_cache.add(Path.get_basename(fn).replace(".vapi", ""));
231                                 }       
232                         } catch(Error e) {
233                                 print("oops - something went wrong scanning the packages\n");
234                         }
235                          
236                         
237                          
238                 }
239  
240         
241     }
242 }
243