1 //<Script type="text/javascript">
4 var XObject = imports.XObject.XObject;
7 var Lang = imports.JsRender.Lang.Lang;
10 var JsParser = imports.JsParser.JsParser;
11 var TokenReader = imports.JSDOC.TokenReader.TokenReader;
12 var TextStream = imports.JSDOC.TextStream.TextStream;
14 var File = imports.File.File;
17 Base = XObject.define(
21 XObject.extend(this, cfg);
27 * @cfg {Array} doubleStringProps list of properties that can be double quoted.
29 doubleStringProps : false,
32 name : false, // is the JS name of the file.
33 path : '', // is the full path to the file.
34 parent : false, // JS parent.
36 title : false, // a title.. ?? nickname.. ??? -
37 project: false, // name...
38 //Project : false, // link to container project!
40 items : false, // the tree of nodes.
42 cn : false, // array used by project tree.
49 var write = this.toJsonArray()
50 print("WRITE: " + this.path);// + "\n" + JSON.stringify(write));
51 File.write(this.path, JSON.stringify(write, null, 4));
61 * load from a javascript file.. rather than bjs..
66 _loadItems : function(cb)
69 if (this.items !== false) {
75 var tr = new TokenReader( {
80 collapseWhite : false,
82 ignoreBadGrammer: true
85 var str = File.read(this.path);
86 var toks = tr.tokenize(new TextStream(str));
87 var rf = new JsParser(toks);
91 this.modOrder = cfg.modOrder || '001';
92 this.name = cfg.name.replace(/\.bjs/, ''); // BC!
93 this.parent = cfg.parent;
94 this.permname = cfg.permname || '';
95 this.title = cfg.title || cfg.name;;
96 this.items = cfg.items || [];
98 //this.fixItems(_this, false);
106 * { success : , failure : , scope : }
112 getTree : function( o ) {
113 print("File.getTree tree called on base object?!?!");
115 toJsonArray : function()
119 ['id', 'name', 'parent', 'title', 'path', 'items' , 'permname', 'modOrder' ].forEach( function(k) {
120 ret[k] = typeof(_this[k]) == 'undefined' ? '' : _this[k];
124 getTitle : function()
129 return this.path.split('/').pop();
132 getTitleTip: function()
135 return '<b>' + this.title + '</b> ' + this.path;
141 this.cn.sort(function(a,b) {
142 return a.path > b.path;// ? 1 : -1;
145 // should be in palete provider really..
147 guessName : function(ar) // turns the object into full name.
149 // eg. xns: Roo, xtype: XXX -> Roo.xxx
150 if (typeof( ar['|xns'] ) == 'undefined' || typeof( ar['xtype'] ) == 'undefined') {
154 return ar['|xns'] +'.' + ar['xtype'];
161 copyTo: function(path, cb)
164 this.loadItems(function() {
174 * munge JSON tree into Javascript code.
176 * FIXME: + or / prefixes to properties hide it from renderer.
177 * FIXME: '*props' - not supported by this.. ?? - upto rendering code..
178 * FIXME: needs to understand what properties might be translatable (eg. double quotes)
180 * @arg {object} obj the object or array to munge..
181 * @arg {boolean} isListener - is the array being sent a listener..
182 * @arg {string} pad - the padding to indent with.
186 mungeToString: function(obj, isListener, pad)
193 isListener = isListener || false;
196 print("missing obj?");
200 // am I munging a object or array...
201 if (obj.constructor && obj.constructor.toString() === Array.toString()) {
202 for (var i= 0; i < obj.length; i++) {
216 typeof(obj['|xns']) != 'undefined' &&
217 typeof(obj['xtype']) != 'undefined'
219 this.mungeXtype(obj['|xns'] + '.' + obj['xtype'], els);
220 //els.push('xtype: '+ obj['|xns'] + '.' + obj['xtype']);
222 skip.push('|xns','xtype');
227 if (!isArray && obj.items && obj.items.length) {
230 for (var ii =0; ii< obj.items.length; ii++) {
231 var pl = obj.items[ii];
234 if (typeof(pl['*prop']) == 'undefined') {
239 //print(JSON.stringify(pl,null,4));
241 var prop = pl['*prop'] + '';
243 if (!prop.match(/\[\]$/)) {
244 // it's a standard prop..
246 // munge property..??
253 prop = prop.substring(0, prop.length -2); //strip []
254 // it's an array type..
255 obj[prop] = obj[prop] || [];
257 // print("ADDNG PROP:" + prop + ' ' + keys.indexOf(prop) );
258 if (keys.indexOf(prop) < 0) {
266 obj.items = newitems;
267 if (!obj.items.length) {
275 //if (isArray) { print(JSON.stringify(keys, null,4)); }
276 // keys is just the real keys of the object.
281 for (var ii =0; ii< keys.length; ii++) {
285 if (typeof(obj[i]) == 'undefined') { // empty or removed.
289 if (!isArray && skip.indexOf(i) > -1) { // things we do not write..
293 // set the key to be quoted with singel quotes..
294 var leftv = i[0] == '|' ? i.substring(1) : i;
295 // skip builder stuff. prefixed with '.' .. just like unix fs..
296 if (leftv[0] == '.') {
299 if (Lang.isKeyword(leftv) || Lang.isBuiltin(leftv)) {
300 left = "'" + leftv + "'";
301 } else if (leftv.match(/[^A-Z_]+/i)) { // not plain a-z... - quoted.
302 var val = JSON.stringify(leftv);
303 left = "'" + val.substring(1, val.length-1).replace(/'/g, "\\'") + "'";
313 // change the lines...
314 var str= ('' + obj[i]).replace(/^\s+|\s+$/g,""); // remove bar.
315 var lines = str.split("\n");
316 if (lines.length > 1) {
317 str = lines.join("\n" + pad);
320 els.push(left + str);
326 //var left = isArray ? '' : (JSON.stringify(i) + " : " )
329 // does not hapepnd with arrays..
330 if (typeof(el) == 'string' && !obj[i].length) { //skip empty.
333 // this needs to go...
334 //if (typeof(el) == 'string' && obj[i].match(new RegExp("Gtk.main" + "_quit"))) { // we can not handle this very well..
338 var str= ('' + obj[i]).replace(/^\s+|\s+$/g,"");;
339 var lines = str.split("\n");
340 if (lines.length > 1) {
341 str = lines.join("\n" + pad);
344 els.push(left + str);
351 if (typeof(el) == 'object') {
353 // we can skip empty items lists and empty listeners..
354 //if (!isArray && i == 'items' && !el.length) {
358 var right = _this.mungeToString(el, i == 'listeners', pad + ' ');
360 //if (!left.length && isArray) print(right);
362 if ((typeof(right) != 'undefined') && right.length){
363 els.push(left + right);
369 if (typeof(obj[i]) != 'string') {
370 els.push(left + JSON.stringify(obj[i]));
374 if (!_this.doubleStringProps) {
375 els.push(left + JSON.stringify(obj[i]));
378 if (_this.doubleStringProps.indexOf(i) > -1) {
379 els.push(left + JSON.stringify(obj[i]));
383 els.push(left + "'" + obj[i].replace(/'/g, "\\'") + "'");
388 if (!isArray && !els.length) {
392 var spad = pad.substring(0, pad.length-4);
393 return (isArray ? '[' : '{') + "\n" +
394 pad + els.join(",\n" + pad ) +
395 "\n" + spad + (isArray ? ']' : '}');