1 //<script type="text/javscript">
3 XObject = imports.XObject.XObject;
4 console = imports.console.console;
5 Collapse = imports.Collapse.Collapse;
8 * this takes our collased file, and turns it into the config array..
10 * @see rconv.js (our tester file)
14 * - Pman.Tab.* appears to work.
15 * .. next up ..Dialog...
19 RooFile = XObject.define(
22 RooFile.superclass.constructor.call(this, ar);
23 // console.log("STARTING OUTPUT");
35 // standard pman dialog
36 if (this.tokens[0].data == 'Pman.on') {
37 this.parsePmanLayout();
42 // Standard Pman Dialog -
43 if (this.tokens[2].props && typeof(this.tokens[2].props.create) != 'undefined') {
44 this.parsePmanDialog();
49 // Seed Gtk XObject application.
50 if (this.tokens.length > 2 && this.tokens[2].data.match(/^imports\./)) {
55 Seed.print("Unknown format");
56 Seed.print(JSON.stringify(this.tokens,null,4));
61 // perfect for dialogs...
64 var pos = this.lookFor( 'function');
69 if (pos > -1 && (this.tokens[pos-1].data == '=') && (this.tokens[pos-2].type == 'NAME')) {
72 '*class' : this.tokens[pos-2].data,
74 '//constructor' : this.tokens[pos-2].prefix,
75 '|constructor' : 'function ' + this.tokens[pos+1].toRaw() +
76 this.tokens[pos+2].toRaw()
84 // no function - we have a static one...
85 pos = this.lookFor( '=');
87 (this.tokens[pos-1].type == 'NAME') &&
88 (this.tokens[pos+1].data == '{')
91 '*class' : this.tokens[pos-1].data,
92 '//*class' : this.tokens[pos-1].prefix
96 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].props));
107 var pos = this.lookFor( 'Roo.apply');
108 //console.dump(this.tokens);
113 (this.tokens[pos+1].items[0][0].data == this.cfg['*class'] + '.prototype')
115 // XXXXXx.prototype = {
119 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[1][0].props));
125 var pos = this.lookFor('new');
128 (this.tokens[pos-2].type == 'NAME') &&
129 (this.tokens[pos-1].data == '=') &&
130 (this.tokens[pos+1].type == 'NAME') &&
131 (this.tokens[pos+2].data == '(')
135 '//*class' : this.tokens[pos-2].prefix,
136 '*class' : this.tokens[pos-2].data,
137 '*extends' : this.tokens[pos+1].data
140 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+2].items[0][0].props));
146 ///Builder.Provider.ProjectManager = new Roo.Observable({
150 var pos = this.lookFor( 'Roo.extend');
153 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
154 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
162 var pos = this.lookFor( 'Roo.extend');
165 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
166 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
179 // other type of layout
180 // console.dump(this.tokens);
182 // this type of file..
183 // xxxx.xxx = function
184 // -> into |constructor..
185 // -> extend + prototype
192 parsePmanLayout : function()
194 // then it's a layout style..
199 //console.dump(this.tokens);
200 // the list of statements inside of function..?
203 var stmts = this.tokens[1].items[1][2].items;
205 // look for register..
207 stmts.map( function(s, i) {
208 if (s[0].data == 'Pman.register') {
209 topp = brace = s[1].items[0][0].props;
213 console.dump(this.tokens);
214 throw "could not find top props...";
218 this.cfg = this.parseProps(topp);
219 this.cfg.name = this.tokens[3].data;
222 // ( { add { this.panel ( {
223 var cfg = this.tokens[7].items[0][0].props.add.val[2].items[2][3].items[0][0].props;
224 this.cfg.items = [ this.parseProps(cfg) ];
225 //console.dump(this.cfg);
227 parsePmanDialog : function() {
229 //console.dump(this.tokens);
230 this.cfg.name = this.tokens[0].data;
234 var cfg = this.tokens[2].props.create.val[2].items[1][3].items[0][0].props;
235 //console.dump(this.tokens);
236 //print(JSON.stringify(cfg,null,4)); Seed.quit();
238 // print("Trying standard dialog");Seed.quit();;
240 this.cfg.items = [ this.parseProps(cfg) ];
245 parseProps: function(o)
247 //print(JSON.stringify(o,null,4));
253 //print( "parsing prop: " + k);
254 if (o[k].key.data == '}') {
255 // typo trailing comma in object def.
260 if (o[k].key.type == 'STRN') {
261 kv = o[k].key.toJS();
263 if (!o[k].val.length) {
267 //console.dump(o[k]);
268 if (o[k].val[0].data == "function") {
270 // console.dump(o[k].key.prefix);
271 var pr = typeof(o[k].key.prefix) == 'undefined' ? '' : o[k].key.prefix ;
272 pr = this.clean_prefix( pr) ;
276 //print("running expand");
277 ret['|' +kv ] = this.clean_body( this.expand(o[k].val));
282 if (o[k].val[0].data == "[") {
284 if (o[k].val[0].items[0][0].data == '{') {
285 // array of objects..
287 // this works for items..
289 // used elsewhere for buttons: -> in which case we have a fake xtype
293 // if K is not ITEMS - we need to add '*prop' -> and add it to the items array..
294 var add = this.parseArray(o[k].val[0].items);
300 xtype : 'Array.' + kv,
304 fakeItems.push(fake_array);
310 ret['|' +kv ] = this.clean_body(this.expand(o[k].val)); // remove ','...
313 if (o[k].val[0].data == "(") {
314 ret['|' +kv ] = this.expand(o[k].val);
317 // value is an object..
319 if (o[k].val[0].data == "{") {
321 // things that can be property of object type:
323 var add = this.parseProps(o[k].val[0].props);
327 if (kv == 'set' || kv =='listeners') {
331 if ((typeof(add.xtype) != 'undefined') || ['sortInfo', 'center', 'east', 'west', 'north', 'south'].indexOf(kv) > -1) {
338 ret[ '|' + kv ] = this.expand(o[k].val);
341 // this hsould be added to 'items', with a *prop element..
344 //console.dump(o[k].val);
346 if (o[k].val[1].data == ',' || o[k].val[1].data == '}') {
347 // single item piece of data...
349 switch(o[k].val[0].type) {
353 ret[ kv ] = t1.toJS();
356 ret[ '|' + kv ] = t1.data;
362 ret[ '|' + kv ] = this.expand(o[k].val);
365 if (!ret.items && fakeItems.length) {
368 fakeItems.forEach( function(e) {
376 parseArray: function(ar) {
380 ar.map(function (e) {
382 if (typeof(e[0].props) == 'undefined') {
387 ret.push( this.parseProps(e[0].props));
399 //print(JSON.stringify(ar,null,4));
401 for(var i =0 ; i < ar.length -1; i++) {
402 ret += ar[i].toRaw();
409 clean_body : function(str)
411 var lns = str.split("\n");
413 lns.map( function(l, i) {
414 if (!i || !l.length || l.match(/^\s+$/)) {
418 var spc = l.match(/\s+/);
419 if (!spc || !spc[0].length) {
422 mindent = mindent < 0 ? spc[0].length : Math.min(spc[0].length, mindent);
425 //console.log(mindent + ":" + lns[0]);
430 lns.map( function(l,i) {
432 ar.push(l.replace(/^\s+/, ''));
435 ar.push(l.substring(mindent));
437 return ar.join("\n");
439 clean_prefix: function(str) {
446 var ret = str.replace(/^\s+/gm, "\n").replace(/\n+/gm, "\n");
447 return ret == "\n" ? '' : ret;