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 * @cfg {Array} doubleStringProps list of properties that can be double quoted.
23 doubleStringProps : false,
26 name : false, // is the JS name of the file.
27 path : '', // is the full path to the file.
28 parent : false, // JS parent.
30 title : false, // a title.. ?? nickname.. ??? -
31 project: false, // name...
32 //Project : false, // link to container project!
34 items : false, // the tree of nodes.
36 cn : false, // array used by project tree.
43 var write = this.toJsonArray()
44 print("WRITE: " + this.path);// + "\n" + JSON.stringify(write));
45 File.write(this.path, JSON.stringify(write, null, 4));
50 * { success : , failure : , scope : }
56 getTree : function( o ) {
57 console.log("File.getTree tree called on base object?!?!");
59 toJsonArray : function()
63 ['id', 'name', 'parent', 'title', 'path', 'items' , 'permname', 'modOrder' ].forEach( function(k) {
64 ret[k] = typeof(_this[k]) == 'undefined' ? '' : _this[k];
73 return this.path.split('/').pop();
76 getTitleTip: function()
79 return '<b>' + this.title + '</b> ' + this.path;
85 this.cn.sort(function(a,b) {
86 return a.path > b.path;// ? 1 : -1;
89 // should be in palete provider really..
91 guessName : function(ar) // turns the object into full name.
93 // eg. xns: Roo, xtype: XXX -> Roo.xxx
94 if (typeof( ar['|xns'] ) == 'undefined' || typeof( ar['xtype'] ) == 'undefined') {
98 return ar['|xns'] +'.' + ar['xtype'];
105 toSourceStdClass: function()
107 var cfg = this.items[0]
108 var fcfg = XObject.extend({ }, this.items[0]);
109 delete fcfg['*class'];
110 delete fcfg['*extends'];
111 delete fcfg['*static'];
112 delete fcfg['|constructor'];
114 var hasExtends = (typeof(cfg['*extends']) != 'undefined') && cfg['*extends'].length;
115 var hasConstructor = (typeof(cfg['|constructor']) != 'undefined');
116 var isStatic = (typeof(cfg['*static']) == '*static');
121 newline = hasConstructor ?
124 cfg['//constructor'] + "\n" +
125 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
126 "Roo.extend(" + cfg['*class'] + ":, " + cfg['*extends'] + ", " :
128 cfg['//*class'] + "\n" +
129 cfg['*class'] + " = new " + cfg['*extends'] + "(" ;
136 newline = hasConstructor ?
138 cfg['//constructor'] + "\n" +
139 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
140 'Roo.apply( ' + cfg['*class'] + ".prototype , " :
142 cfg['//*class'] + "\n" +
143 cfg['*class'] + " = ";
146 endline = hasConstructor ? ');' : ';';
149 return this.outputHeader() +
151 this.objectToJsString(fcfg,1) +
160 copyTo: function(path, cb)
163 this.loadItems(function() {
173 * munge JSON tree into Javascript code.
175 * FIXME: + or / prefixes to properties hide it from renderer.
176 * FIXME: '*props' - not supported by this.. ?? - upto rendering code..
177 * FIXME: needs to understand what properties might be translatable (eg. double quotes)
179 * @arg {object} obj the object or array to munge..
180 * @arg {boolean} isListener - is the array being sent a listener..
181 * @arg {string} pad - the padding to indent with.
185 mungeToString: function(obj, isListener, pad)
190 isListener = isListener || false;
192 // am I munging a object or array...
193 if (obj.constructor.toString() === Array.toString()) {
194 for (var i= 0; i < obj.length; i++) {
208 typeof(obj['|xns']) != 'undefined' &&
209 typeof(obj['xtype']) != 'undefined'
211 this.mungeXtype(obj['|xns'] + '.' + obj['xtype'], els);
212 //els.push('xtype: '+ obj['|xns'] + '.' + obj['xtype']);
213 skip.push('|xns','xtype');
217 if (!isArray && obj.items && obj.items.length) {
220 obj.items.forEach(function(pl) {
221 if (typeof(pl['*prop']) == 'undefined') {
226 var prop = pl['*prop'] + '';
228 if (!prop.match(/\[\]$/)) {
229 // it's a standard prop..
234 prop = prop.substring(0, prop.length -2); //strip []
235 // it's an array type..
236 obj[prop] = obj[prop] || [];
238 print("ADDNG PROP:" + prop + ' ' + keys.indexOf(prop) );
239 if (keys.indexOf(prop) < 0) {
246 obj.items = newitems;
247 if (!obj.items.length) {
261 keys.forEach(function(i) {
263 if (typeof(obj[i]) == 'undefined') { // empty or removed.
267 if (!isArray && skip.indexOf(i) > -1) { // things we do not write..
271 // set the key to be quoted with singel quotes..
272 var leftv = i[0] == '|' ? i.substring(1) : i;
273 if (Lang.isKeyword(leftv) || Lang.isBuiltin(leftv)) {
274 left = "'" + leftv + "'";
275 } else if (leftv.match(/[^A-Z_]+/i)) { // not plain a-z... - quoted.
276 var val = JSON.stringify(leftv);
277 left = "'" + val.substring(1, val.length-1).replace(/'/g, "\\'") + "'";
285 // change the lines...
286 var str= ('' + obj[i]).replace(/^\s+|\s+$/g,"");
287 var lines = str.split("\n");
288 if (lines.length > 1) {
289 str = lines.join("\n" + pad);
291 els.push(left + str);
297 //var left = isArray ? '' : (JSON.stringify(i) + " : " )
300 // does not hapepnd with arrays..
301 if (typeof(el) == 'string' && !obj[i].length) { //skip empty.
304 // this needs to go...
305 //if (typeof(el) == 'string' && obj[i].match(new RegExp("Gtk.main" + "_quit"))) { // we can not handle this very well..
309 var str= ('' + obj[i]).replace(/^\s+|\s+$/g,"");;
310 var lines = str.split("\n");
311 if (lines.length > 1) {
312 str = lines.join("\n" + pad);
315 els.push(left + str);
322 if (typeof(el) == 'object') {
324 // we can skip empty items lists and empty listeners..
325 //if (!isArray && i == 'items' && !el.length) {
329 var right = _this.mungeToString(el, i == 'listeners', pad + ' ');
330 if (typeof(right) != 'undefined') {
331 els.push(left + right);
337 if (typeof(obj[i]) != 'string') {
338 els.push(left + JSON.stringify(obj[i]));
342 if (!_this.doubleStringProps) {
343 els.push(left + JSON.stringify(obj[i]));
346 if (_this.doubleStringProps.indexOf(i) > -1) {
347 els.push(left + JSON.stringify(obj[i]));
351 els.push(left + "'" + obj[i].replace(/'/g, "\\'") + "'");
356 if (!isArray && !els.length) {
360 var spad = pad.substring(0, pad.length-4);
361 return (isArray ? '[' : '{') + "\n" +
362 pad + els.join(",\n" + pad ) +
363 "\n" + spad + (isArray ? ']' : '}');