1 //<Script type="text/javascript">
6 public errordomain Error {
10 public abstract 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.
21 public string region; // RooJS - insert region.
23 public string title; // a title.. ?? nickname.. ??? -
25 public string permname;
26 public string modOrder;
30 public Project.Project project;
31 //Project : false, // link to container project!
33 public Node tree; // the tree of nodes.
35 public GLib.List<JsRender> cn; // child files.. (used by project ... should move code here..)
37 public bool hasParent;
39 public JsRender(Project.Project project, string path) {
41 this.cn = new GLib.List<JsRender>();
43 this.project = project;
44 this.hasParent = false;
48 var ar = this.path.split("/");
49 // name is in theory filename without .bjs (or .js eventually...)
51 Regex regex = new Regex ("\\.(bjs|js)$");
53 this.name = regex.replace(ar[ar.length-1],ar[ar.length-1].length, 0 , "");
57 this.fullname = (this.parent.length > 0 ? (this.parent + ".") : "" ) + this.name;
62 public static JsRender factory(string xt, Project.Project project, string path)
67 return new Gtk(project, path);
69 return new Roo(project, path);
71 throw new Error.INVALID_FORMAT("JsRender Factory called with xtype=%s", xt);
75 public string toJsonString()
77 var generator = new Json.Generator ();
79 generator.pretty = true;
80 var node = new Json.Node(Json.NodeType.OBJECT);
81 node.set_object(this.toJsonObject());
82 generator.set_root(node);
83 return generator.to_data(null);
86 public abstract void save();
90 var generator = new Json.Generator ();
92 generator.pretty = true;
93 var node = new Json.Node(Json.NodeType.OBJECT);
94 node.set_object(this.toJsonObject());
95 generator.set_root(node);
97 print("WRITE: " + this.path);// + "\n" + JSON.stringify(write));
99 generator.to_file(this.path);
101 print("Save failed");
105 public void saveHTML ()
110 public abstract void loadItems() throws Error;
114 * load from a javascript file.. rather than bjs..
119 _loadItems : function(cb)
122 if (this.items !== false) {
128 var tr = new TokenReader( {
133 collapseWhite : false,
135 ignoreBadGrammer: true
138 var str = File.read(this.path);
139 var toks = tr.tokenize(new TextStream(str));
140 var rf = new JsParser(toks);
144 this.modOrder = cfg.modOrder || '001';
145 this.name = cfg.name.replace(/\.bjs/, ''); // BC!
146 this.parent = cfg.parent;
147 this.permname = cfg.permname || '';
148 this.title = cfg.title || cfg.name;;
149 this.items = cfg.items || [];
151 //this.fixItems(_this, false);
159 * { success : , failure : , scope : }
166 print("File.getTree tree called on base object?!?!");
169 public Json.Object toJsonObject ()
173 var ret = new Json.Object();
174 //ret.set_string_member("id", this.id); // not relivant..
175 ret.set_string_member("name", this.name);
176 ret.set_string_member("parent", this.parent == null ? "" : this.parent);
177 ret.set_string_member("title", this.title == null ? "" : this.title);
178 ret.set_string_member("path", this.path);
179 //ret.set_string_member("items", this.items);
180 ret.set_string_member("permname", this.permname == null ? "" : this.permname);
181 ret.set_string_member("modOrder", this.modOrder == null ? "" : this.modOrder);
182 var ar = new Json.Array();
183 ar.add_object_element(this.tree.toJsonObject());
184 ret.set_array_member("items", ar);
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 abstract string toSource() ;
264 public abstract string toValaSource(bool testcompile) ;