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);
16 this.doubleStringProps = false;
22 name : false, // is the JS name of the file.
23 path : '', // is the full path to the file.
24 parent : false, // JS parent.
26 title : false, // a title.. ?? nickname.. ??? -
27 project: false, // name...
28 //Project : false, // link to container project!
30 items : false, // the tree of nodes.
32 cn : false, // array used by project tree.
39 var write = this.toJsonArray()
40 print("WRITE: " + this.path);// + "\n" + JSON.stringify(write));
41 File.write(this.path, JSON.stringify(write, null, 4));
46 * { success : , failure : , scope : }
52 getTree : function( o ) {
53 console.log("File.getTree tree called on base object?!?!");
55 toJsonArray : function()
59 ['id', 'name', 'parent', 'title', 'path', 'items' ].forEach( function(k) {
69 return this.path.split('/').pop();
72 getTitleTip: function()
75 return '<b>' + this.title + '</b> ' + this.path;
81 this.cn.sort(function(a,b) {
82 return a.path > b.path;// ? 1 : -1;
85 // should be in palete provider really..
87 guessName : function(ar) // turns the object into full name.
89 // eg. xns: Roo, xtype: XXX -> Roo.xxx
90 if (typeof( ar['|xns'] ) == 'undefined' || typeof( ar['xtype'] ) == 'undefined') {
94 return ar['|xns'] +'.' + ar['xtype'];
101 toSourceStdClass: function()
103 var cfg = this.items[0]
104 var fcfg = XObject.extend({ }, this.items[0]);
105 delete fcfg['*class'];
106 delete fcfg['*extends'];
107 delete fcfg['*static'];
108 delete fcfg['|constructor'];
110 var hasExtends = (typeof(cfg['*extends']) != 'undefined') && cfg['*extends'].length;
111 var hasConstructor = (typeof(cfg['|constructor']) != 'undefined');
112 var isStatic = (typeof(cfg['*static']) == '*static');
117 newline = hasConstructor ?
120 cfg['//constructor'] + "\n" +
121 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
122 "Roo.extend(" + cfg['*class'] + ":, " + cfg['*extends'] + ", " :
124 cfg['//*class'] + "\n" +
125 cfg['*class'] + " = new " + cfg['*extends'] + "(" ;
132 newline = hasConstructor ?
134 cfg['//constructor'] + "\n" +
135 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
136 'Roo.apply( ' + cfg['*class'] + ".prototype , " :
138 cfg['//*class'] + "\n" +
139 cfg['*class'] + " = ";
142 endline = hasConstructor ? ');' : ';';
145 return this.outputHeader() +
147 this.objectToJsString(fcfg,1) +
156 copyTo: function(path, cb)
159 this.loadItems(function() {
169 * munge JSON tree into Javascript code.
171 * FIXME: + or / prefixes to properties hide it from renderer.
172 * FIXME: '*props' - not supported by this.. ?? - upto rendering code..
173 * FIXME: needs to understand what properties might be translatable (eg. double quotes)
175 * @arg {object} obj the object or array to munge..
176 * @arg {boolean} isListener - is the array being sent a listener..
177 * @arg {string} pad - the padding to indent with.
181 mungeToString: function(obj, isListener, pad)
186 isListener = isListener || false;
188 // am I munging a object or array...
189 if (obj.constructor.toString() === Array.toString()) {
190 for (var i= 0; i < obj.length; i++) {
204 typeof(obj['|xns']) != 'undefined' &&
205 typeof(obj['xtype']) != 'undefined'
207 this.mungeXtype(obj['|xns'] + '.' + obj['xtype'], els);
208 //els.push('xtype: '+ obj['|xns'] + '.' + obj['xtype']);
209 skip.push('|xns','xtype');
213 if (!isArray && obj.items && obj.items.length) {
216 obj.items.forEach(function(pl) {
217 if (typeof(pl['*prop']) == 'undefined') {
222 var prop = pl['*prop'] + '';
224 if (!prop.match(/\[\]$/)) {
225 // it's a standard prop..
230 prop = prop.substring(0, prop.length -2); //strip []
231 // it's an array type..
232 obj[prop] = obj[prop] || [];
234 print("ADDNG PROP:" + prop + ' ' + keys.indexOf(prop) );
235 if (keys.indexOf(prop) < 0) {
242 obj.items = newitems;
243 if (!obj.items.length) {
257 keys.forEach(function(i) {
259 if (typeof(obj[i]) == 'undefined') { // empty or removed.
263 if (!isArray && skip.indexOf(i) > -1) { // things we do not write..
267 // set the key to be quoted with singel quotes..
268 var leftv = i[0] == '|' ? i.substring(1) : i;
269 if (Lang.isKeyword(leftv) || Lang.isBuiltin(leftv)) {
270 left = "'" + leftv + "'";
271 } else if (leftv.match(/[^A-Z_]+/i)) { // not plain a-z... - quoted.
272 var val = JSON.stringify(leftv);
273 left = "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";
281 // change the lines...
282 var str= ('' + obj[i]).replace(/^\s+|\s+$/g,"");
283 var lines = str.split("\n");
284 if (lines.length > 1) {
285 str = lines.join("\n" + pad);
287 els.push(left + str);
293 //var left = isArray ? '' : (JSON.stringify(i) + " : " )
296 // does not hapepnd with arrays..
297 if (typeof(el) == 'string' && !obj[i].length) { //skip empty.
300 // this needs to go...
301 //if (typeof(el) == 'string' && obj[i].match(new RegExp("Gtk.main" + "_quit"))) { // we can not handle this very well..
305 var str= ('' + obj[i]).replace(/^\s+|\s+$/g,"");;
306 var lines = str.split("\n");
307 if (lines.length > 1) {
308 str = lines.join("\n" + pad);
311 els.push(left + str);
318 if (typeof(el) == 'object') {
320 // we can skip empty items lists and empty listeners..
321 //if (!isArray && i == 'items' && !el.length) {
325 var right = _this.mungeToString(el, i == 'listeners', pad + ' ');
326 if (typeof(right) != 'undefined') {
327 els.push(left + right);
333 if (typeof(obj[i]) != 'string') {
334 els.push(left + JSON.stringify(obj[i]));
338 if (!this.doubleStringProps) {
339 els.push(left + JSON.stringify(obj[i]));
341 if (this.doubleStringProps.indexOf(i)) {
342 els.push(left + JSON.stringify(obj[i]));
346 els.push(left + "'" + v.replace(/'/, "\\'") + "'");
351 if (!isArray && !els.length) {
355 var spad = pad.substring(0, pad.length-4);
356 return (isArray ? '[' : '{') + "\n" +
357 pad + els.join(",\n" + pad ) +
358 "\n" + spad + (isArray ? ']' : '}');