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));
55 * load from a javascript file.. rather than bjs..
60 _loadItems : function(cb)
63 if (this.items !== false) {
69 var tr = new TokenReader( {
74 collapseWhite : false,
76 ignoreBadGrammer: true
79 var str = File.read(this.path);
80 var toks = tr.tokenize(new TextStream(str));
81 var rf = new JsParser(toks);
85 this.modOrder = cfg.modOrder || '001';
86 this.name = cfg.name.replace(/\.bjs/, ''); // BC!
87 this.parent = cfg.parent;
88 this.permname = cfg.permname || '';
89 this.title = cfg.title || cfg.name;;
90 this.items = cfg.items || [];
92 //this.fixItems(_this, false);
100 * { success : , failure : , scope : }
106 getTree : function( o ) {
107 print("File.getTree tree called on base object?!?!");
109 toJsonArray : function()
113 ['id', 'name', 'parent', 'title', 'path', 'items' , 'permname', 'modOrder' ].forEach( function(k) {
114 ret[k] = typeof(_this[k]) == 'undefined' ? '' : _this[k];
118 getTitle : function()
123 return this.path.split('/').pop();
126 getTitleTip: function()
129 return '<b>' + this.title + '</b> ' + this.path;
135 this.cn.sort(function(a,b) {
136 return a.path > b.path;// ? 1 : -1;
139 // should be in palete provider really..
141 guessName : function(ar) // turns the object into full name.
143 // eg. xns: Roo, xtype: XXX -> Roo.xxx
144 if (typeof( ar['|xns'] ) == 'undefined' || typeof( ar['xtype'] ) == 'undefined') {
148 return ar['|xns'] +'.' + ar['xtype'];
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)
187 isListener = isListener || false;
189 // am I munging a object or array...
190 if (obj.constructor.toString() === Array.toString()) {
191 for (var i= 0; i < obj.length; i++) {
205 typeof(obj['|xns']) != 'undefined' &&
206 typeof(obj['xtype']) != 'undefined'
208 this.mungeXtype(obj['|xns'] + '.' + obj['xtype'], els);
209 //els.push('xtype: '+ obj['|xns'] + '.' + obj['xtype']);
210 skip.push('|xns','xtype');
214 if (!isArray && obj.items && obj.items.length) {
217 for (var ii =0; ii< obj.items.length; ii++) {
218 var pl = obj.items[ii];
221 if (typeof(pl['*prop']) == 'undefined') {
226 //print(JSON.stringify(pl,null,4));
228 var prop = pl['*prop'] + '';
230 if (!prop.match(/\[\]$/)) {
231 // it's a standard prop..
233 // munge property..??
240 prop = prop.substring(0, prop.length -2); //strip []
241 // it's an array type..
242 obj[prop] = obj[prop] || [];
244 // print("ADDNG PROP:" + prop + ' ' + keys.indexOf(prop) );
245 if (keys.indexOf(prop) < 0) {
253 obj.items = newitems;
254 if (!obj.items.length) {
262 //if (isArray) { print(JSON.stringify(keys, null,4)); }
263 // keys is just the real keys of the object.
268 for (var ii =0; ii< keys.length; ii++) {
272 if (typeof(obj[i]) == 'undefined') { // empty or removed.
276 if (!isArray && skip.indexOf(i) > -1) { // things we do not write..
280 // set the key to be quoted with singel quotes..
281 var leftv = i[0] == '|' ? i.substring(1) : i;
282 // skip builder stuff. prefixed with '.' .. just like unix fs..
283 if (leftv[0] == '.') {
286 if (Lang.isKeyword(leftv) || Lang.isBuiltin(leftv)) {
287 left = "'" + leftv + "'";
288 } else if (leftv.match(/[^A-Z_]+/i)) { // not plain a-z... - quoted.
289 var val = JSON.stringify(leftv);
290 left = "'" + val.substring(1, val.length-1).replace(/'/g, "\\'") + "'";
300 // change the lines...
301 var str= ('' + obj[i]).replace(/^\s+|\s+$/g,""); // remove bar.
302 var lines = str.split("\n");
303 if (lines.length > 1) {
304 str = lines.join("\n" + pad);
307 els.push(left + str);
313 //var left = isArray ? '' : (JSON.stringify(i) + " : " )
316 // does not hapepnd with arrays..
317 if (typeof(el) == 'string' && !obj[i].length) { //skip empty.
320 // this needs to go...
321 //if (typeof(el) == 'string' && obj[i].match(new RegExp("Gtk.main" + "_quit"))) { // we can not handle this very well..
325 var str= ('' + obj[i]).replace(/^\s+|\s+$/g,"");;
326 var lines = str.split("\n");
327 if (lines.length > 1) {
328 str = lines.join("\n" + pad);
331 els.push(left + str);
338 if (typeof(el) == 'object') {
340 // we can skip empty items lists and empty listeners..
341 //if (!isArray && i == 'items' && !el.length) {
345 var right = _this.mungeToString(el, i == 'listeners', pad + ' ');
347 //if (!left.length && isArray) print(right);
349 if ((typeof(right) != 'undefined') && right.length){
350 els.push(left + right);
356 if (typeof(obj[i]) != 'string') {
357 els.push(left + JSON.stringify(obj[i]));
361 if (!_this.doubleStringProps) {
362 els.push(left + JSON.stringify(obj[i]));
365 if (_this.doubleStringProps.indexOf(i) > -1) {
366 els.push(left + JSON.stringify(obj[i]));
370 els.push(left + "'" + obj[i].replace(/'/g, "\\'") + "'");
375 if (!isArray && !els.length) {
379 var spad = pad.substring(0, pad.length-4);
380 return (isArray ? '[' : '{') + "\n" +
381 pad + els.join(",\n" + pad ) +
382 "\n" + spad + (isArray ? ']' : '}');