7 public errordomain Error {
14 public class Usage : Object
16 public Gee.ArrayList<string> left;
17 public Gee.ArrayList<string> right;
18 public Usage(Gee.ArrayList<string> ileft, Gee.ArrayList<string> iright)
23 public bool leftHas(string s)
25 for(var i = 0 ; i < this.left.size; i++) {
26 var m = this.left.get(i);
30 if (!m.contains(":")) {
33 var ar = m.split(":");
47 //static Gee.HashMap<string,Palete>? cache = null;
50 public static Palete factory(project)
53 cache = new Gee.HashMap<string,Palete>();
55 if (cache.get(xtype) != null) {
56 return cache.get(xtype);
60 cache.set(xtype, new Gtk());
63 cache.set(xtype, new Roo());
66 throw new Error.INVALID_TYPE("invalid argument to Palete factory");
68 return cache.get(xtype);
72 public abstract class Palete : Object
78 public Gee.ArrayList<Usage> map;
80 public Gee.HashMap<string,GirObject> classes; // used in roo..
82 public Project.Project project;
84 public Palete(Project.Project project)
87 this.project = project;
93 //map : false, // array of mappings left: [] , right : []
95 //items : false, // the tree of nodes.
100 string guessName(JsRender.Node ar) throws Error // turns the object into full name.
102 throw new Error.NEED_IMPLEMENTING("xxx. guessName needs implimenting");
110 public string[] getChildList(string in_rval)
113 if (this.map == null) {
118 var rval = in_rval == "" ? "*top" : in_rval;
120 // should be a bit more than this..
121 // -> it should look for all elements that inherit
123 var rt = new Gee.ArrayList<string>();
124 for (var i = 0; i < this.map.size; i++) {
125 var m = this.map.get(i);
127 if (!m.leftHas(rval)) {
130 print("found LEFT, adding right\n");
132 for(var ii =0; ii < m.right.size; ii++) {
133 var l = m.right.get(ii);
135 if (rt.index_of(l) > -1) {
138 //print("ADD " + string.joinv(", ", ret) + "\n");
145 print ("drop list for %s is:\n%s\n", rval, string.joinv("\n", ret));
146 //console.log("DROP LIST:");
153 public string[] getDropList(string rval)
156 if (this.map == null) {
161 // should be a bit more than this..
162 // -> it should look for all elements that inherit
164 var rt = new Gee.ArrayList<string>();
165 for (var i = 0; i < this.map.size; i++) {
166 var m = this.map.get(i);
168 if (m.right.index_of(rval) < 0) {
171 //print("found RIGHT, adding left\n");
173 for(var ii =0; ii < m.left.size; ii++) {
174 var l = m.left.get(ii);
176 if (rt.index_of(l) > -1) {
179 //print("ADD " + string.joinv(", ", ret) + "\n");
186 print ("drop list for %s is:\n%s\n", rval, string.joinv("\n", ret));
187 //console.log("DROP LIST:");
193 public void saveTemplate (string name, JsRender.Node data)
197 // store it in user's directory..
198 var appdir = GLib.Environment.get_home_dir() + "/.Builder";
201 if (!GLib.FileUtils.test(appdir+ "/" + gn, GLib.FileTest.IS_DIR)) {
202 GLib.File.new_for_path (appdir+ "/" + gn).make_directory ();
205 GLib.FileUtils.set_contents(appdir+ "/" + gn + "/" + name + ".json", data.toJsonString());
210 * list templates - in home directory (and app dir in future...)
211 * @param {String} name - eg. Gtk.Window..
212 * @return {Array} list of templates available..
215 public GLib.List<string> listTemplates (JsRender.Node node)
220 var ret = new GLib.List<string>();
221 var dir= GLib.Environment.get_home_dir() + "/.Builder/" + gn;
222 if (!GLib.FileUtils.test(dir, GLib.FileTest.IS_DIR)) {
229 var f = File.new_for_path(dir);
231 var file_enum = f.enumerate_children(GLib.FileAttribute.STANDARD_DISPLAY_NAME, GLib.FileQueryInfoFlags.NONE, null);
234 while ((next_file = file_enum.next_file(null)) != null) {
235 var n = next_file.get_display_name();
236 if (!Regex.match_simple ("\\.json$", n)) {
239 ret.append( dir + "/" + n);
245 public JsRender.Node? loadTemplate(string path)
248 var pa = new Json.Parser();
249 pa.load_from_file(path);
250 var node = pa.get_root();
252 if (node.get_node_type () != Json.NodeType.OBJECT) {
255 var obj = node.get_object ();
257 var ret = new JsRender.Node();
260 ret.loadFromJson(obj, 1);
261 ret.ref(); // not sure if needed -- but we had a case where ret became uninitialized?
268 public void loadUsageFile (string fname) {
273 print("Palete Load called\n");
275 if (!FileUtils.test (fname, FileTest.EXISTS)) {
276 throw new Error.MISSING_FILE(fname + " not found");
279 FileUtils.get_contents(fname, out raw);
281 var data = raw.split("\n");
283 var cfg = new Gee.ArrayList<Usage>();
284 var left = new Gee.ArrayList<string>();
285 var right = new Gee.ArrayList<string>();
287 for (var i = 0; i < data.length; i++) {
288 var d = data[i].strip();
289 //print("READ " + d + "\n");
293 Regex.match_simple ("^\\s+$", d)
295 Regex.match_simple ("^\\s*/", d)
300 if (Regex.match_simple ("^left:", d)) {
303 cfg.add(new Usage( left, right));
305 left = new Gee.ArrayList<string>();
306 right = new Gee.ArrayList<string>();
309 if (Regex.match_simple ("^right:", d)) {
314 //print("add left: " + d + "\n");
318 //print("add Right: " + d + "\n");
324 cfg.add(new Usage( left, right));
331 public void validateVala(
336 JsRender.JsRender file,
341 print("validate code (%s) %s\n", file.language, code);
345 if (file.language != "vala" ) { // not sure if we need to validate property
348 // file.project , file.path, file.build_module, ""
352 //var cd = new JSCore.ClassDefinitionEmpty();
353 state.valasource.checkFileWithNodePropChange(
367 public bool javascriptHasErrors(
372 JsRender.JsRender file,
373 out Gee.HashMap<int,string> errors
377 print("validate code (%s) ptype=%s property=%s\n", file.language, ptype, property);
378 errors = new Gee.HashMap<int,string>();
380 if (file.language != "js") {
383 if (ptype != "listener" && property.length > 0 && property[0] == '|') {
387 //var cd = new JSCore.ClassDefinitionEmpty();
388 //print("TESTING CODE %s\n", code);
390 var testcode = ptype == "file" ? code : "var __aaa___ = " + code;
391 var line = Javascript.singleton().validate(
392 testcode, out errmsg);
395 if (ptype == "file") {
396 var err = new Json.Object();
397 err.set_int_member("ERR-TOTAL", 1);
398 var files_obj = new Json.Object();
399 var lines_obj = new Json.Object();
400 var lines_ar = new Json.Array();
401 lines_ar.add_string_element(errmsg);
402 lines_obj.set_array_member(line.to_string(), lines_ar);
403 files_obj.set_object_member(file.path, lines_obj);
405 err.set_object_member("ERR", files_obj);
407 state.showCompileResult(err);
408 // do not set errors.. that's not done here..
411 errors.set(line, errmsg); // depricated - this is used by the editor currently -- but we are planning to switch from that..
412 print("got errors\n");
416 // now syntax is OK.. try the
420 if (ptype == "file") {
421 return this.javascriptHasCompressionErrors(file, state, code);
423 print("no errors\n");
428 public bool javascriptHasCompressionErrors(JsRender.JsRender file, WindowState state, string code)
430 // this uses the roojspacker code to try and compress the code.
431 // it should highlight errors before we actually push live the code.
433 // standard error format: file %s, line %s, Error
435 var cfg = new JSDOC.PackerRun();
436 cfg.opt_keep_whitespace = false;
437 cfg.opt_skip_scope = false;
438 cfg.opt_dump_tokens = false;
439 cfg.opt_clean_cache = false;
442 var p = new JSDOC.Packer(cfg);
446 p.packFile(code, file.path,"");
447 state.showCompileResult(p.result);
448 if (p.hasErrors("")) {
459 public abstract void fillPack(JsRender.Node node,JsRender.Node parent);
460 public abstract void load();
461 public abstract Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type);
462 public abstract GirObject? getClass(string ename);
464 public abstract bool typeOptions(string fqn, string key, string type, out string[] opts);
465 public abstract List<SourceCompletionItem> suggestComplete(
466 JsRender.JsRender file,
470 string complete_string