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, null, 4));
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', 'project'].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() {
168 * munge JSON tree into Javascript code.
170 * FIXME: + or / prefixes to properties hide it from renderer.
171 * FIXME: '*props' - not supported by this.. ?? - upto rendering code..
172 * FIXME: needs to understand what properties might be translatable (eg. double quotes)
174 * @arg {object} obj the object or array to munge..
175 * @arg {boolean} isListener - is the array being sent a listener..
176 * @arg {string} pad - the padding to indent with.
180 mungeToString: function(obj, isListener, pad)
185 isListener = isListener || false;
187 // am I munging a object or array...
188 if (obj.constructor.toString() === Array.toString()) {
189 for (var i= 0; i < obj.length; i++) {
203 typeof(obj['|xns']) != 'undefined' &&
204 typeof(obj['xtype']) != 'undefined'
206 this.mungeXtype(obj['|xns'] + '.' + obj['xtype'], els);
207 //els.push('xtype: '+ obj['|xns'] + '.' + obj['xtype']);
208 skip.push('|xns','xtype');
212 if (!isArray && obj.items && obj.items.length) {
215 obj.items.forEach(function(pl) {
216 if (typeof(pl['*prop']) == 'undefined') {
221 var prop = pl['*prop'] + '';
223 if (!prop.match(/\[\]$/)) {
224 // it's a standard prop..
229 prop = prop.substring(0, prop.length -2); //strip []
230 // it's an array type..
231 obj[prop] = obj[prop] || [];
233 print("ADDNG PROP:" + prop + ' ' + keys.indexOf(prop) );
234 if (keys.indexOf(prop) < 0) {
241 obj.items = newitems;
242 if (!obj.items.length) {
256 keys.forEach(function(i) {
258 if (typeof(obj) == 'undefined') { // empty or removed.
262 if (!isArray && skip.indexOf(i) > -1) { // things we do not write..
266 // set the key to be quoted with singel quotes..
267 var leftv = i[0] == '|' ? i.substring(1) : i;
268 if (Lang.isKeyword(leftv) || Lang.isBuiltin(leftv)) {
269 left = "'" + leftv + "'";
270 } else if (leftv.match(/[^A-Z_]+/i)) { // not plain a-z... - quoted.
271 var val = JSON.stringify(leftv);
272 left = "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";
280 // change the lines...
281 var str= ('' + obj[i]).replace(/^\s+|\s+$/g,"");
282 var lines = str.split("\n");
283 if (lines.length > 1) {
284 str = lines.join("\n" + pad);
286 els.push(left + str);
292 //var left = isArray ? '' : (JSON.stringify(i) + " : " )
295 // does not hapepnd with arrays..
296 if (typeof(el) == 'string' && !obj[i].length) { //skip empty.
299 // this needs to go...
300 //if (typeof(el) == 'string' && obj[i].match(new RegExp("Gtk.main" + "_quit"))) { // we can not handle this very well..
304 var str= ('' + obj[i]).replace(/^\s+|\s+$/g,"");;
305 var lines = str.split("\n");
306 if (lines.length > 1) {
307 str = lines.join("\n" + pad);
310 els.push(left + str);
317 if (typeof(el) == 'object') {
319 // we can skip empty items lists and empty listeners..
320 //if (!isArray && i == 'items' && !el.length) {
324 var right = _this.mungeToString(el, i == 'listeners', pad + ' ');
325 if (typeof(right) != 'undefined') {
326 els.push(left + right);
333 els.push(left + JSON.stringify(obj[i]));
336 if (!isArray && !els.length) {
340 var spad = pad.substring(0, pad.length-4);
341 return (isArray ? '[' : '{') + "\n" +
342 pad + els.join(",\n" + pad ) +
343 "\n" + spad + (isArray ? ']' : '}');