1 //<Script type="text/javascript">
3 console = imports.console;
4 XObject = imports.XObject.XObject;
6 Lang = imports.Builder.Provider.File.Lang.Lang;
8 File = imports.File.File;
11 Base = XObject.define(
15 XObject.extend(this, cfg);
21 name : false, // is the JS name of the file.
22 path : '', // is the full path to the file.
23 parent : false, // JS parent.
25 title : false, // a title.. ?? nickname.. ??? -
26 project: false, // name...
27 Project : false, // link to container project!
29 items : false, // the tree of nodes.
31 cn : false, // array used by project tree.
38 var write = this.toJsonArray()
39 print("WRITE: " + this.path);// + "\n" + JSON.stringify(write));
40 File.write(this.path, JSON.stringify(write));
45 * { success : , failure : , scope : }
51 getTree : function( o ) {
52 console.log("File.getTree tree called on base object?!?!");
54 toJsonArray : function()
58 ['id', 'name', 'parent', 'title', 'path', 'items'].forEach( function(k) {
68 return this.path.split('/').pop();
71 getTitleTip: function()
74 return '<b>' + this.title + '</b> ' + this.path;
80 this.cn.sort(function(a,b) {
81 return a.path > b.path;// ? 1 : -1;
84 // should be in palete provider really..
86 guessName : function(ar) // turns the object into full name.
88 // eg. xns: Roo, xtype: XXX -> Roo.xxx
89 if (typeof( ar['|xns'] ) == 'undefined' || typeof( ar['xtype'] ) == 'undefined') {
93 return ar['|xns'] +'.' + ar['xtype'];
100 toSourceStdClass: function()
102 var cfg = this.items[0]
103 var fcfg = XObject.extend({ }, this.items[0]);
104 delete fcfg['*class'];
105 delete fcfg['*extends'];
106 delete fcfg['*static'];
107 delete fcfg['|constructor'];
109 var hasExtends = (typeof(cfg['*extends']) != 'undefined') && cfg['*extends'].length;
110 var hasConstructor = (typeof(cfg['|constructor']) != 'undefined');
111 var isStatic = (typeof(cfg['*static']) == '*static');
116 newline = hasConstructor ?
119 cfg['//constructor'] + "\n" +
120 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
121 "Roo.extend(" + cfg['*class'] + ":, " + cfg['*extends'] + ", " :
123 cfg['//*class'] + "\n" +
124 cfg['*class'] + " = new " + cfg['*extends'] + "(" ;
131 newline = hasConstructor ?
133 cfg['//constructor'] + "\n" +
134 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
135 'Roo.apply( ' + cfg['*class'] + ".prototype , " :
137 cfg['//*class'] + "\n" +
138 cfg['*class'] + " = ";
141 endline = hasConstructor ? ');' : ';';
144 return this.outputHeader() +
146 this.objectToJsString(fcfg,1) +
155 copyTo: function(path, cb)
158 this.loadItems(function() {
169 mungeToString: function(obj, isListener, pad)
174 isListener = isListener || false;
176 // am I munging a object or array...
177 if (obj.constructor.toString() === Array.toString()) {
178 for (var i= 0; i < obj.length; i++) {
192 typeof(obj['|xns']) != 'undefined' &&
193 typeof(obj['xtype']) != 'undefined'
195 els.push('xtype: '+ obj['|xns'] + '.' + obj['xtype']);
196 skip.push('|xns','xtype');
203 keys.forEach(function(i) {
205 if (!isArray && skip.indexOf(i) > -1) { // things we do not write..
210 if (!_this.withDebug) {
211 // do not write listeners unless we are debug mode.
214 //if (obj[i].match(new RegExp("Gtk.main" + "_quit"))) { // we can not handle this very well..
217 var str= ('' + obj[i]).replace(/^\s+|\s+$/g,"");
218 var lines = str.split("\n");
219 if (lines.length > 1) {
220 str = lines.join("\n" + pad);
222 els.push(JSON.stringify(i) + ":" + str);
228 var left = isArray ? '' : (JSON.stringify(i) + " : " )
231 // does not hapepnd with arrays..
232 if (typeof(el) == 'string' && !obj[i].length) { //skip empty.
235 // this needs to go...
236 //if (typeof(el) == 'string' && obj[i].match(new RegExp("Gtk.main" + "_quit"))) { // we can not handle this very well..
240 var str= ('' + obj[i]).replace(/^\s+|\s+$/g,"");;
241 var lines = str.split("\n");
242 if (lines.length > 1) {
243 str = lines.join("\n" + pad);
246 els.push(left + str);
253 if (typeof(el) == 'object') {
254 els.push(left + _this.mungeToString(el, i == 'listeners', pad + ' '));
259 els.push(left + JSON.stringify(obj[i]));
261 var spad = pad.substring(0, pad.length-4);
262 return (isArray ? '[' : '{') + "\n" +
263 pad + els.join(",\n" + pad ) +
264 "\n" + spad + (isArray ? ']' : '}');
273 objectToJsString : function (o, ind)
279 var ix = new Array(ind+1).join(" ");
280 var ix1 = new Array(ind).join(" ");
283 if (k[0] == '+') { // + means hide from renderer.. we do not save this.
286 if (k[0] == '/') { // means hide from renderer.. we prefix the col with it..
291 if (typeof(v) == 'object') {
293 if ((v.constructor != Array) && !this.objectKeys(v).length) {
296 if ((v.constructor == Array) && !v.length && k == 'items') {
300 ret += ret.length ? ",\n" : '';
302 var kk = k[0] == '|' ? k.substring(1) : k;
303 if (typeof(o['//' + kk]) != 'undefined') {
304 ret += ix + o['//' + kk].split("\n").join( "\n" + ix) + "\n";
309 if (v.constructor == Array) {
310 ret += ix + this.toJsProp(k) + ' : ' + this.arrayToJsString(v, ind+1);
315 ret += ix + this.toJsProp(k) + ' : ' + this.objectToJsString(v, ind+1);
319 ret += ix + this.toJsProp(k) + ' : ' + (v ? 'true' : 'false');
323 ret += ix + this.toJsProp(k) + ' : ' + v;
329 ret += ix + this.toJsProp(k) + ' : ' + v.split("\n").join( "\n" + ix);
335 // we should use special stuff here to determine if it's a singly or dobuley
337 ret += ix + this.toJsProp(k) + ' : ' + this.stringToJsString(v, k, o);
343 return "{\n" + ret + "\n" + ix1 + '}';
346 arrayToJsString : function (ar, ind)
349 ar.forEach( function(o) {
350 if (typeof(o) == 'object' && (o.constructor != Array)) {
359 ix = new Array(ind+1).join(" ");
360 ix1 = new Array(ind).join(" ");
368 ar.forEach( function(v, n) {
369 // skip blank last element in an array
370 if ((n == (ar.length -1)) && typeof(v) == 'undefined') {
374 // empty objects in array?
375 if (typeof(v) == 'object' && v.constructor != Array) {
376 if (!_this.objectKeys(v).length) {
382 ret += ret.length ? cr : '';
387 if (v.constructor == Array) {
389 ret += ix + _this.arrayToJsString(v, ind+1);
393 ret += ix + _this.objectToJsString(v, ind+1);
397 ret += ix + (v ? 'true' : 'false');
407 ret += ix + v.split("\n").join( "\n" + ix);
413 // we should use special stuff here to determine if it's a singly or dobuley
415 ret += ix + JSON.stringify(v);
422 return "[" + lb + ret + lb + ix1 + "]";
425 stringToJsString : function(v, k , o) {
426 // since most properties can use single quotes (non-translatable)
427 // we try to fix this here..
428 var val = JSON.stringify(v);
429 if (['xns', 'xtype' ].indexOf(k) > -1) {
430 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";
438 toJsProp: function(v) {
439 var vv = v[0] == '|' ? v.substring(1) : v;
440 if (Lang.isKeyword(vv) || Lang.isBuiltin(vv)) {
441 return "'" + vv + "'";
443 if (vv.match(/[^A-Z_]+/i)) {
444 var val = JSON.stringify(vv);
445 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";