X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=src%2FPalete%2FPalete.vala;h=d82e8b1fe3fb20d6cde6153f23d542e435c0afb4;hb=e8963dbac540c13be86e781c8c1c3a44d012b493;hp=ecfcba9b03633ca101f4ee8b8b8b9b2c7a3abb24;hpb=1bf6a47290ca909fa53b938d23f311d79e59d957;p=app.Builder.js diff --git a/src/Palete/Palete.vala b/src/Palete/Palete.vala index ecfcba9b0..d82e8b1fe 100644 --- a/src/Palete/Palete.vala +++ b/src/Palete/Palete.vala @@ -1,4 +1,5 @@ +using Gtk; namespace Palete { @@ -240,178 +241,201 @@ namespace Palete public JsRender.Node? loadTemplate(string path) { - var pa = new Json.Parser(); - pa.load_from_file(path); - var node = pa.get_root(); + var pa = new Json.Parser(); + pa.load_from_file(path); + var node = pa.get_root(); - if (node.get_node_type () != Json.NodeType.OBJECT) { - return null; - } - var obj = node.get_object (); + if (node.get_node_type () != Json.NodeType.OBJECT) { + return null; + } + var obj = node.get_object (); - var ret = new JsRender.Node(); + var ret = new JsRender.Node(); - ret.loadFromJson(obj, 1); - ret.ref(); // not sure if needed -- but we had a case where ret became uninitialized? + ret.loadFromJson(obj, 1); + ret.ref(); // not sure if needed -- but we had a case where ret became uninitialized? - return ret; - } + return ret; + } - public void loadUsageFile (string fname) { + public void loadUsageFile (string fname) { - print("Palete Load called\n"); - string raw; - if (!FileUtils.test (fname, FileTest.EXISTS)) { - throw new Error.MISSING_FILE(fname + " not found"); - } + print("Palete Load called\n"); + string raw; + if (!FileUtils.test (fname, FileTest.EXISTS)) { + throw new Error.MISSING_FILE(fname + " not found"); + } - FileUtils.get_contents(fname, out raw); - // print(data); - var data = raw.split("\n"); - var state = 0; - var cfg = new Gee.ArrayList(); - var left = new Gee.ArrayList(); - var right = new Gee.ArrayList(); + FileUtils.get_contents(fname, out raw); + // print(data); + var data = raw.split("\n"); + var state = 0; + var cfg = new Gee.ArrayList(); + var left = new Gee.ArrayList(); + var right = new Gee.ArrayList(); - for (var i = 0; i < data.length; i++) { - var d = data[i].strip(); - //print("READ " + d + "\n"); - if ( - d.length < 1 - || - Regex.match_simple ("^\\s+$", d) - || - Regex.match_simple ("^\\s*/", d) - ){ - continue; - } + for (var i = 0; i < data.length; i++) { + var d = data[i].strip(); + //print("READ " + d + "\n"); + if ( + d.length < 1 + || + Regex.match_simple ("^\\s+$", d) + || + Regex.match_simple ("^\\s*/", d) + ){ + continue; + } - if (Regex.match_simple ("^left:", d)) { - state = 1; - if (left.size > 0 ){ - cfg.add(new Usage( left, right)); - } - left = new Gee.ArrayList(); - right = new Gee.ArrayList(); - continue; - } - if (Regex.match_simple ("^right:", d)) { - state = 2; - continue; - } - if (state == 1) { - //print("add left: " + d + "\n"); - left.add(d); - continue; - } - //print("add Right: " + d + "\n"); - right.add(d); - //Seed.quit(); - - } - if (left.size > 0 ){ - cfg.add(new Usage( left, right)); - } - this.map = cfg; + if (Regex.match_simple ("^left:", d)) { + state = 1; + if (left.size > 0 ){ + cfg.add(new Usage( left, right)); + } + left = new Gee.ArrayList(); + right = new Gee.ArrayList(); + continue; + } + if (Regex.match_simple ("^right:", d)) { + state = 2; + continue; + } + if (state == 1) { + //print("add left: " + d + "\n"); + left.add(d); + continue; + } + //print("add Right: " + d + "\n"); + right.add(d); + //Seed.quit(); + + } + if (left.size > 0 ){ + cfg.add(new Usage( left, right)); + } + this.map = cfg; - } + } - ValaSource vs; - public void validateVala( - string code, + + public void validateVala( + WindowState state, + string code, string property, string ptype, JsRender.JsRender file, - JsRender.Node node, - ValaSourceResult result_cb - ) - { + JsRender.Node node + ) + { - this.result_callback = result_cb; - print("validate code (%s) %s\n", file.language, code); - + print("validate code (%s) %s\n", file.language, code); + - - if (file.language != "vala" ) { // not sure if we need to validate property - return; - } - // file.project , file.path, file.build_module, "" - - - this.vs = new ValaSource((Project.Gtk)file.project, file.path, file.build_module, ""); + + if (file.language != "vala" ) { // not sure if we need to validate property + return; + } + // file.project , file.path, file.build_module, "" + - //var cd = new JSCore.ClassDefinitionEmpty(); - this.vs.checkFileWithNodePropChange( - file, - node, - property, - ptype, - code, - validateValaResult - - - ); - + + //var cd = new JSCore.ClassDefinitionEmpty(); + state.valasource.checkFileWithNodePropChange( + file, + node, + property, + ptype, + code + ); + - } - void validateValaResult(Json.Object res) { - this.result_callback(res); - this.vs = null; - } + } + - ValaSourceResult result_callback; - public Gee.HashMap validateJavascript( - string code, - string property, - string ptype, - JsRender.JsRender file, - JsRender.Node node - ) - { - - print("validate code (%s) %s\n", file.language, code); - var ret = new Gee.HashMap(); + + public Gee.HashMap validateJavascript( + string code, + string property, + string ptype, + JsRender.JsRender file, + JsRender.Node? node + ) + { + + print("validate code (%s) ptype=%s property=%s\n", file.language, ptype, property); + var ret = new Gee.HashMap(); - if (file.language != "js") { - return ret; - } - if (ptype != "listener" && property[0] == '|') { + if (file.language != "js") { + return ret; + } + if (ptype != "listener" && property.length > 0 && property[0] == '|') { + return ret; + } + + //var cd = new JSCore.ClassDefinitionEmpty(); + //print("TESTING CODE %s\n", code); + string errmsg; + var testcode = ptype == "file" ? code : "var __aaa___ = " + code; + var line = Javascript.singleton().validate( + testcode, out errmsg); + + if (line < 0) { + if (ptype == "file") { + return this.validateJavascriptCompression(code); + } + print("no errors\n"); + return ret; + } + ret.set(line, errmsg); + print("got errors\n"); return ret; - } + + } + + public Gee.HashMap validateJavascriptCompression(string code) + { + // this uses the roojspacker code to try and compress the code. + // it should highlight errors before we actually push live the code. - //var cd = new JSCore.ClassDefinitionEmpty(); - //print("TESTING CODE %s\n", code); - string errmsg; - var line = Javascript.singleton().validate( - "var __aaa___ = " + code, out errmsg); - - if (line < 0) { - print("no errors\n"); + var p = new JSDOC.Packer(); + p.keepWhite = false; + p.skipScope = false; + p.dumpTokens = false; + p.cleanup = false; + try { + p.packFile(code, "ANONFILE",""); + } catch (Exception e) { + + } + + var ret = new Gee.HashMap(); return ret; + } - ret.set(line, errmsg); - print("got errors\n"); - return ret; - - - } - - - public abstract void fillPack(JsRender.Node node,JsRender.Node parent); - public abstract void load(); - public abstract Gee.HashMap getPropertiesFor(string ename, string type); - public abstract GirObject? getClass(string ename); - - public abstract bool typeOptions(string fqn, string key, string type, out string[] opts); + + + + public abstract void fillPack(JsRender.Node node,JsRender.Node parent); + public abstract void load(); + public abstract Gee.HashMap getPropertiesFor(string ename, string type); + public abstract GirObject? getClass(string ename); - } + public abstract bool typeOptions(string fqn, string key, string type, out string[] opts); + public abstract List suggestComplete( + JsRender.JsRender file, + JsRender.Node? node, + string proptype, + string key, + string complete_string + ); + } }