5 public static JSCore.Object class_constructor(JSCore.Context ctx, JSCore.Object constructor, JSCore.Value[] arguments, out JSCore.Value exception)
7 var c = new JSCore.Class (class_definition);
8 var o = new JSCore.Object (ctx, c, null);
11 Do something with object
16 static const JSCore.StaticFunction[] class_functions = {
19 static const JSCore.ClassDefinition class_definition = {
21 JSCore.ClassAttribute.None,
44 public errordomain Error {
51 public class Usage : Object
53 public Gee.ArrayList<string> left;
54 public Gee.ArrayList<string> right;
55 public Usage(Gee.ArrayList<string> ileft, Gee.ArrayList<string> iright)
60 public bool leftHas(string s)
62 for(var i = 0 ; i < this.left.size; i++) {
63 var m = this.left.get(i);
67 if (!m.contains(":")) {
70 var ar = m.split(":");
84 static Gee.HashMap<string,Palete>? cache = null;
86 public static Palete factory(string xtype)
89 cache = new Gee.HashMap<string,Palete>();
91 if (cache.get(xtype) != null) {
92 return cache.get(xtype);
96 cache.set(xtype, new Gtk());
99 cache.set(xtype, new Roo());
102 throw new Error.INVALID_TYPE("invalid argument to Palete factory");
104 return cache.get(xtype);
108 public abstract class Palete : Object
114 public Gee.ArrayList<Usage> map;
123 //map : false, // array of mappings left: [] , right : []
125 //items : false, // the tree of nodes.
130 string guessName(JsRender.Node ar) throws Error // turns the object into full name.
132 throw new Error.NEED_IMPLEMENTING("xxx. guessName needs implimenting");
138 * gather a list of potentional objects that can be added..
142 listChildren: function (existing) {
143 existing = existing || [];
144 // existing.push('*top'); // always have top
146 console.log("GATHER LIST? " + this.map.length);
149 function addRight(right) {
150 right.forEach(function(r) {
151 if (ret.indexOf(r) > -1) {
158 this.map.forEach(function(m) {
160 m.left.forEach( function(left) {
163 var l = left.replace(/:.*$/, '');
164 // print("chk:" + l + " in " + existing.join(','));
165 if (existing.indexOf(l) > -1) {
168 //return true; // no more needed..
175 // console.dump(ret);
185 public string[] getChildList(string in_rval)
188 if (this.map == null) {
193 var rval = in_rval == "" ? "*top" : in_rval;
195 // should be a bit more than this..
196 // -> it should look for all elements that inherit
198 var rt = new Gee.ArrayList<string>();
199 for (var i = 0; i < this.map.size; i++) {
200 var m = this.map.get(i);
202 if (!m.leftHas(rval)) {
205 print("found LEFT, adding right\n");
207 for(var ii =0; ii < m.right.size; ii++) {
208 var l = m.right.get(ii);
210 if (rt.index_of(l) > -1) {
213 //print("ADD " + string.joinv(", ", ret) + "\n");
220 print ("drop list for %s is:\n%s\n", rval, string.joinv("\n", ret));
221 //console.log("DROP LIST:");
228 public string[] getDropList(string rval)
231 if (this.map == null) {
236 // should be a bit more than this..
237 // -> it should look for all elements that inherit
239 var rt = new Gee.ArrayList<string>();
240 for (var i = 0; i < this.map.size; i++) {
241 var m = this.map.get(i);
243 if (m.right.index_of(rval) < 0) {
246 //print("found RIGHT, adding left\n");
248 for(var ii =0; ii < m.left.size; ii++) {
249 var l = m.left.get(ii);
251 if (rt.index_of(l) > -1) {
254 //print("ADD " + string.joinv(", ", ret) + "\n");
261 print ("drop list for %s is:\n%s\n", rval, string.joinv("\n", ret));
262 //console.log("DROP LIST:");
271 findType : function (data, prop, value)
273 if (prop[0] == '|') {
276 return typeof(value);
280 findOptions : function(ename)
282 switch(ename.toLowerCase()) {
284 return [ 'true', 'false' ];
285 // everything else does not have options.
293 console.log("OOPS: = unknown type: " + ename);
297 confirmCanAdd: function(parent, child) {
298 // confirms that one obj can be added to another.
299 // returns true, for items, or list of properties that can hold it..
303 getDefaultPack: function(pname, cname) {
307 public void saveTemplate (string name, JsRender.Node data)
311 // store it in user's directory..
312 var appdir = GLib.Environment.get_home_dir() + "/.Builder";
315 if (!GLib.FileUtils.test(appdir+ "/" + gn, GLib.FileTest.IS_DIR)) {
316 GLib.File.new_for_path (appdir+ "/" + gn).make_directory ();
319 GLib.FileUtils.set_contents(appdir+ "/" + gn + "/" + name + ".json", data.toJsonString());
324 * list templates - in home directory (and app dir in future...)
325 * @param {String} name - eg. Gtk.Window..
326 * @return {Array} list of templates available..
329 public GLib.List<string> listTemplates (JsRender.Node node)
334 var ret = new GLib.List<string>();
335 var dir= GLib.Environment.get_home_dir() + "/.Builder/" + gn;
336 if (!GLib.FileUtils.test(dir, GLib.FileTest.IS_DIR)) {
343 var f = File.new_for_path(dir);
345 var file_enum = f.enumerate_children(GLib.FileAttribute.STANDARD_DISPLAY_NAME, GLib.FileQueryInfoFlags.NONE, null);
348 while ((next_file = file_enum.next_file(null)) != null) {
349 var n = next_file.get_display_name();
350 if (!Regex.match_simple ("\\.json$", n)) {
353 ret.append( dir + "/" + n);
359 public JsRender.Node? loadTemplate(string path)
362 var pa = new Json.Parser();
363 pa.load_from_file(path);
364 var node = pa.get_root();
366 if (node.get_node_type () != Json.NodeType.OBJECT) {
369 var obj = node.get_object ();
371 var ret = new JsRender.Node();
374 ret.loadFromJson(obj, 1);
375 ret.ref(); // not sure if needed -- but we had a case where ret became uninitialized?
379 public void loadUsageFile (string fname) {
384 print("Palete Load called\n");
386 if (!FileUtils.test (fname, FileTest.EXISTS)) {
387 throw new Error.MISSING_FILE(fname + " not found");
390 FileUtils.get_contents(fname, out raw);
392 var data = raw.split("\n");
394 var cfg = new Gee.ArrayList<Usage>();
395 var left = new Gee.ArrayList<string>();
396 var right = new Gee.ArrayList<string>();
398 for (var i = 0; i < data.length; i++) {
399 var d = data[i].strip();
400 //print("READ " + d + "\n");
404 Regex.match_simple ("^\\s+$", d)
406 Regex.match_simple ("^\\s*/", d)
411 if (Regex.match_simple ("^left:", d)) {
414 cfg.add(new Usage( left, right));
416 left = new Gee.ArrayList<string>();
417 right = new Gee.ArrayList<string>();
420 if (Regex.match_simple ("^right:", d)) {
425 //print("add left: " + d + "\n");
429 //print("add Right: " + d + "\n");
435 cfg.add(new Usage( left, right));
440 public string validateCode(string code, string language)
442 if (language == "javascript") {
443 //var cd = new JSCore.ClassDefinitionEmpty();
444 var goc = new JSCore.Class( class_definition );
445 var cs = new JSCore.GlobalContext(goc);
448 var ret = cs.check_script_syntax(
449 new JSCore.String.with_utf8_c_string(code),
462 public abstract void fillPack(JsRender.Node node,JsRender.Node parent);
463 public abstract void load();
464 public abstract Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type);
465 public abstract GirObject? getClass(string ename);