1 //<Script type="text/javascript">
6 public errordomain Error {
10 public class JsRender : Object {
12 * @cfg {Array} doubleStringProps list of properties that can be double quoted.
14 public GLib.List<string> doubleStringProps;
17 public string name; // is the JS name of the file.
18 public string fullname;
19 public string path; // is the full path to the file.
20 public string parent; // JS parent.
22 public string title; // a title.. ?? nickname.. ??? -
24 public string permname;
25 public string modOrder;
29 public Project.Project project;
30 //Project : false, // link to container project!
32 public Node tree; // the tree of nodes.
34 public GLib.List<JsRender> cn; // child files.. (used by project ... should move code here..)
36 public bool hasParent;
38 public JsRender(Project.Project project, string path) {
40 this.cn = new GLib.List<JsRender>();
42 this.project = project;
43 this.hasParent = false;
47 var ar = this.path.split("/");
48 // name is in theory filename without .bjs (or .js eventually...)
50 Regex regex = new Regex ("\\.(bjs|js)$");
52 this.name = regex.replace(ar[ar.length-1],ar[ar.length-1].length, 0 , "");
56 this.fullname = (this.parent.length > 0 ? (this.parent + ".") : "" ) + this.name;
61 public static JsRender factory(string xt, Project.Project project, string path)
66 return new Gtk(project, path);
68 return new Roo(project, path);
70 throw new Error.INVALID_FORMAT("JsRender Factory called with xtype=%s", xt);
74 public string toJsonString()
76 var generator = new Json.Generator ();
78 generator.pretty = true;
79 var node = new Json.Node(Json.NodeType.OBJECT);
80 node.set_object(this.toJsonArray());
81 generator.set_root(node);
82 return generator.to_data(null);
88 var generator = new Json.Generator ();
90 generator.pretty = true;
91 var node = new Json.Node(Json.NodeType.OBJECT);
92 node.set_object(this.toJsonArray());
93 generator.set_root(node);
95 print("WRITE: " + this.path);// + "\n" + JSON.stringify(write));
97 generator.to_file(this.path);
103 public void saveHTML ()
108 public void loadItems()
110 print("load items not handled..");
117 * load from a javascript file.. rather than bjs..
122 _loadItems : function(cb)
125 if (this.items !== false) {
131 var tr = new TokenReader( {
136 collapseWhite : false,
138 ignoreBadGrammer: true
141 var str = File.read(this.path);
142 var toks = tr.tokenize(new TextStream(str));
143 var rf = new JsParser(toks);
147 this.modOrder = cfg.modOrder || '001';
148 this.name = cfg.name.replace(/\.bjs/, ''); // BC!
149 this.parent = cfg.parent;
150 this.permname = cfg.permname || '';
151 this.title = cfg.title || cfg.name;;
152 this.items = cfg.items || [];
154 //this.fixItems(_this, false);
162 * { success : , failure : , scope : }
169 print("File.getTree tree called on base object?!?!");
172 public Json.Object toJsonArray ()
176 var ret = new Json.Object();
177 ret.set_string_member("id", this.id);
178 ret.set_string_member("name", this.name);
179 ret.set_string_member("parent", this.parent);
180 ret.set_string_member("title", this.title);
181 ret.set_string_member("path", this.path);
182 //ret.set_string_member("items", this.items);
183 ret.set_string_member("permname", this.permname);
184 ret.set_string_member("modOrder", this.modOrder);
191 public string getTitle ()
193 if (this.title.length > 0) {
196 var a = this.path.split("/");
197 return a[a.length-1];
199 public string getTitleTip()
201 if (this.title.length > 0) {
202 return "<b>" + this.title + "</b> " + this.path;
209 this.cn.sort(function(a,b) {
210 return a.path > b.path;// ? 1 : -1;
214 // should be in palete provider really..
216 public string guessName(Node ar) // turns the object into full name.
218 // eg. xns: Roo, xtype: XXX -> Roo.xxx
219 if (!ar.hasXnsType()) {
223 return ar.get("|xns") + "." + ar.get("|xtype");
230 copyTo: function(path, cb)
233 this.loadItems(function() {
244 * munge JSON tree into Javascript code.
246 * NOTE - needs a deep copy of original tree, before starting..
247 * - so that it does not modify current..
249 * FIXME: + or / prefixes to properties hide it from renderer.
250 * FIXME: '*props' - not supported by this.. ?? - upto rendering code..
251 * FIXME: needs to understand what properties might be translatable (eg. double quotes)
253 * @arg {object} obj the object or array to munge..
254 * @arg {boolean} isListener - is the array being sent a listener..
255 * @arg {string} pad - the padding to indent with.
258 public string mungeToString(string pad)
260 return this.tree.mungeToString(false, pad, this.doubleStringProps);
263 public string toSource() {