From 7bedaa9ab6a6e8a73a243527ff22d0f16acb4148 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Mon, 6 Jun 2016 15:59:39 +0800 Subject: [PATCH] src/Builder4/Editor.bjs src/Builder4/Editor.vala src/Builder4/WindowRooView.bjs src/Builder4/WindowRooView.vala --- src/Builder4/Editor.bjs | 6 +- src/Builder4/WindowRooView.bjs | 20 ++- src/Builder4/WindowRooView.vala | 271 ++++++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+), 4 deletions(-) diff --git a/src/Builder4/Editor.bjs b/src/Builder4/Editor.bjs index 2479b280a..b60e5098e 100644 --- a/src/Builder4/Editor.bjs +++ b/src/Builder4/Editor.bjs @@ -9,8 +9,8 @@ "items" : [ { "# Xcls_MainWindow window" : "null", - "# string activeEditor" : "\"\"", "| bool saveContents" : " () {\n \n \n if (_this.file == null) {\n return true;\n }\n \n \n \n \n \n var str = _this.buffer.toString();\n \n _this.buffer.checkSyntax();\n \n \n \n // LeftPanel.model.changed( str , false);\n _this.dirty = false;\n _this.save_button.el.sensitive = false;\n \n // find the text for the node..\n if (_this.file.xtype != \"PlainFile\") {\n if (ptype == \"listener\") {\n this.node.listeners.set(key,str);\n \n } else {\n this.node.props.set(key,str);\n }\n } else {\n _this.file.setSource( str );\n }\n \n // call the signal..\n this.save();\n \n return true;\n\n} ", + "# string activeEditor" : "\"\"", "| void scroll_to_line" : "(int line) {\n\n\tGLib.Timeout.add(500, () => {\n \n\t\tvar buf = this.view.el.get_buffer();\n\n\t\tvar sbuf = (Gtk.SourceBuffer) buf;\n\n\n\t\tGtk.TextIter iter; \n\t\tsbuf.get_iter_at_line(out iter, line);\n\t\tthis.view.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);\n\t\treturn false;\n\t}); \n}\n", "# int pos_root_x" : "", "# int pos_root_y" : "", @@ -53,8 +53,8 @@ }, { "id" : "key_edit", - "xtype" : "Entry", "* pack" : "pack_end,true,true", + "xtype" : "Entry", "$ xns" : "Gtk" } ] @@ -90,8 +90,8 @@ "changed" : " () => {\n // check syntax??\n // ??needed..??\n _this.save_button.el.sensitive = true;\n print(\"EDITOR CHANGED\");\n this.checkSyntax();\n \n _this.dirty = true;\n\n // this.get('/LeftPanel.model').changed( str , false);\n return ;\n}\n\n \n" }, "bool check_queued" : false, - "id" : "buffer", "int error_line" : "-1", + "id" : "buffer", "| bool highlightErrors" : "( Gee.HashMap validate_res) {\n \n this.error_line = validate_res.size;\n\n if (this.error_line < 1) {\n return true;\n }\n var tlines = this.el.get_line_count ();\n Gtk.TextIter iter;\n var valiter = validate_res.map_iterator();\n while (valiter.next()) {\n \n // print(\"get inter\\n\");\n var eline = valiter.get_key();\n if (eline > tlines) {\n continue;\n }\n this.el.get_iter_at_line( out iter, eline);\n //print(\"mark line\\n\");\n this.el.create_source_mark(valiter.get_value(), \"ERR\", iter);\n } \n return false;\n }", "| string toString" : " () {\n \n Gtk.TextIter s;\n Gtk.TextIter e;\n this.el.get_start_iter(out s);\n this.el.get_end_iter(out e);\n var ret = this.el.get_text(s,e,true);\n //print(\"TO STRING? \" + ret);\n return ret;\n}\n ", "| bool checkSyntax" : " () {\n \n if (this.check_running) {\n print(\"Check is running\\n\");\n if (this.check_queued) { \n print(\"Check is already queued\");\n return true;\n }\n this.check_queued = true;\n print(\"Adding queued Check \");\n GLib.Timeout.add_seconds(1, () => {\n this.check_queued = false;\n \n this.checkSyntax();\n return false;\n });\n \n\n return true;\n }\n var str = this.toString();\n \n // needed???\n if (this.error_line > 0) {\n Gtk.TextIter start;\n Gtk.TextIter end; \n this.el.get_bounds (out start, out end);\n\n this.el.remove_source_marks (start, end, null);\n }\n if (str.length < 1) {\n print(\"checkSyntax - empty string?\\n\");\n return true;\n }\n \n if (_this.file.xtype == \"PlainFile\") {\n \n // assume it's gtk...\n this.check_running = true;\n \n if (!_this.window.windowstate.valasource.checkPlainFileSpawn(\n\t _this.file,\n\t str\n\t )) {\n this.check_running = false;\n }\n\t\n return true;\n \n }\n if (_this.file == null) {\n return true;\n }\n var p = Palete.factory(_this.file.xtype); \n \n\n \n this.check_running = true;\n \n \n if (_this.file.language == \"js\") {\n this.check_running = false;\n print(\"calling validate javascript\\n\"); \n return this.highlightErrors(p.validateJavascript(\n str, \n _this.key, \n _this.ptype,\n _this.file,\n _this.node\n )); \n \n }\n \n \n print(\"calling validate vala\\n\"); \n // clear the buttons.\n \n \n if (! _this.window.windowstate.valasource.checkFileWithNodePropChange(\n _this.file,\n _this.node,\n _this.key, \n _this.ptype,\n str\n )) {\n this.check_running = false;\n } \n \n \n \n //print(\"done mark line\\n\");\n \n return true; // at present allow saving - even if it's invalid..\n}\n", diff --git a/src/Builder4/WindowRooView.bjs b/src/Builder4/WindowRooView.bjs index a4c51acbc..60a496490 100644 --- a/src/Builder4/WindowRooView.bjs +++ b/src/Builder4/WindowRooView.bjs @@ -174,7 +174,25 @@ "$ xns" : "Gtk", "gboolean show_line_numbers" : true, "$ string propSelected" : "\"\"", - "gboolean editable" : false + "gboolean editable" : false, + "items" : [ + { + "listeners" : { + "changed" : " () => {\n // check syntax??\n // ??needed..??\n _this.save_button.el.sensitive = true;\n print(\"EDITOR CHANGED\");\n this.checkSyntax();\n \n _this.dirty = true;\n\n // this.get('/LeftPanel.model').changed( str , false);\n return ;\n}\n\n \n" + }, + "bool check_queued" : false, + "id" : "buffer", + "int error_line" : "-1", + "| bool highlightErrors" : "( Gee.HashMap validate_res) {\n \n this.error_line = validate_res.size;\n\n if (this.error_line < 1) {\n return true;\n }\n var tlines = this.el.get_line_count ();\n Gtk.TextIter iter;\n var valiter = validate_res.map_iterator();\n while (valiter.next()) {\n \n // print(\"get inter\\n\");\n var eline = valiter.get_key();\n if (eline > tlines) {\n continue;\n }\n this.el.get_iter_at_line( out iter, eline);\n //print(\"mark line\\n\");\n this.el.create_source_mark(valiter.get_value(), \"ERR\", iter);\n } \n return false;\n }", + "| string toString" : " () {\n \n Gtk.TextIter s;\n Gtk.TextIter e;\n this.el.get_start_iter(out s);\n this.el.get_end_iter(out e);\n var ret = this.el.get_text(s,e,true);\n //print(\"TO STRING? \" + ret);\n return ret;\n}\n ", + "| bool checkSyntax" : " () {\n \n if (this.check_running) {\n print(\"Check is running\\n\");\n if (this.check_queued) { \n print(\"Check is already queued\");\n return true;\n }\n this.check_queued = true;\n print(\"Adding queued Check \");\n GLib.Timeout.add_seconds(1, () => {\n this.check_queued = false;\n \n this.checkSyntax();\n return false;\n });\n \n\n return true;\n }\n var str = this.toString();\n \n // needed???\n if (this.error_line > 0) {\n Gtk.TextIter start;\n Gtk.TextIter end; \n this.el.get_bounds (out start, out end);\n\n this.el.remove_source_marks (start, end, null);\n }\n if (str.length < 1) {\n print(\"checkSyntax - empty string?\\n\");\n return true;\n }\n \n if (_this.file.xtype == \"PlainFile\") {\n \n // assume it's gtk...\n this.check_running = true;\n \n if (!_this.window.windowstate.valasource.checkPlainFileSpawn(\n\t _this.file,\n\t str\n\t )) {\n this.check_running = false;\n }\n\t\n return true;\n \n }\n if (_this.file == null) {\n return true;\n }\n var p = Palete.factory(_this.file.xtype); \n \n\n \n this.check_running = true;\n \n \n if (_this.file.language == \"js\") {\n this.check_running = false;\n print(\"calling validate javascript\\n\"); \n return this.highlightErrors(p.validateJavascript(\n str, \n _this.key, \n _this.ptype,\n _this.file,\n _this.node\n )); \n \n }\n \n \n print(\"calling validate vala\\n\"); \n // clear the buttons.\n \n \n if (! _this.window.windowstate.valasource.checkFileWithNodePropChange(\n _this.file,\n _this.node,\n _this.key, \n _this.ptype,\n str\n )) {\n this.check_running = false;\n } \n \n \n \n //print(\"done mark line\\n\");\n \n return true; // at present allow saving - even if it's invalid..\n}\n", + "* pack" : "set_buffer", + "xtype" : "SourceBuffer", + "bool check_running" : false, + "$ xns" : "Gtk", + "| bool highlightErrorsJson" : "(string type, Json.Object obj) {\n Gtk.TextIter start;\n Gtk.TextIter end; \n this.el.get_bounds (out start, out end);\n \n this.el.remove_source_marks (start, end, type);\n \n \n // we should highlight other types of errors..\n \n if (!obj.has_member(type)) {\n print(\"Return has no errors\\n\");\n return true;\n }\n \n if (_this.window.windowstate.state != WindowState.State.CODEONLY && \n _this.window.windowstate.state != WindowState.State.CODE\n ) {\n return true;\n } \n \n \n var err = obj.get_object_member(type);\n \n \n if (_this.file == null) {\n return true;\n \n }\n var valafn = _this.file.path;\n \n if (_this.file.xtype != \"PlainFile\") {\n\n\n \n \n valafn = \"\";\n try { \n var regex = new Regex(\"\\\\.bjs$\");\n // should not happen\n \n \n valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , \".vala\");\n } catch (GLib.RegexError e) {\n return true;\n } \n\n\n\n }\n if (!err.has_member(valafn)) {\n print(\"File path has no errors\\n\");\n return true;\n }\n\n var lines = err.get_object_member(valafn);\n \n var offset = 1;\n if (obj.has_member(\"line_offset\")) {\n offset = (int)obj.get_int_member(\"line_offset\") + 1;\n }\n \n\n \n \n var tlines = this.el.get_line_count () +1;\n \n lines.foreach_member((obj, line, node) => {\n \n Gtk.TextIter iter;\n // print(\"get inter\\n\");\n var eline = int.parse(line) - offset;\n print(\"GOT ERROR on line %s -- converted to %d\\n\", line,eline);\n \n \n if (eline > tlines || eline < 0) {\n return;\n }\n this.el.get_iter_at_line( out iter, eline);\n //print(\"mark line\\n\");\n var msg = \"Line: %d\".printf(eline+1);\n var ar = lines.get_array_member(line);\n for (var i = 0 ; i < ar.get_length(); i++) {\n\t\t msg += (msg.length > 0) ? \"\\n\" : \"\";\n\t\t msg += ar.get_string_element(i);\n\t }\n \n \n this.el.create_source_mark(msg, type, iter);\n } );\n return false;\n \n\n\n\n\n}\n" + } + ] } ] } diff --git a/src/Builder4/WindowRooView.vala b/src/Builder4/WindowRooView.vala index 027328b82..4fd258709 100644 --- a/src/Builder4/WindowRooView.vala +++ b/src/Builder4/WindowRooView.vala @@ -22,6 +22,7 @@ public class Xcls_WindowRooView : Object public Xcls_view view; public Xcls_inspectorcontainer inspectorcontainer; public Xcls_sourceview sourceview; + public Xcls_buffer buffer; // my vars (def) public Gtk.Widget lastObj; @@ -950,6 +951,9 @@ public class Xcls_WindowRooView : Object this.el.editable = false; this.el.show_line_marks = true; this.el.show_line_numbers = true; + var child_0 = new Xcls_buffer( _this ); + child_0.ref(); + this.el.set_buffer ( child_0.el ); // init method @@ -1333,6 +1337,273 @@ public class Xcls_WindowRooView : Object } } + public class Xcls_buffer : Object + { + public Gtk.SourceBuffer el; + private Xcls_WindowRooView _this; + + + // my vars (def) + public bool check_queued; + public int error_line; + public bool check_running; + + // ctor + public Xcls_buffer(Xcls_WindowRooView _owner ) + { + _this = _owner; + _this.buffer = this; + this.el = new Gtk.SourceBuffer( null ); + + // my vars (dec) + this.check_queued = false; + this.error_line = -1; + this.check_running = false; + + // set gobject values + + //listeners + this.el.changed.connect( () => { + // check syntax?? + // ??needed..?? + _this.save_button.el.sensitive = true; + print("EDITOR CHANGED"); + this.checkSyntax(); + + _this.dirty = true; + + // this.get('/LeftPanel.model').changed( str , false); + return ; + }); + } + + // user defined functions + public bool highlightErrors ( Gee.HashMap validate_res) { + + this.error_line = validate_res.size; + + if (this.error_line < 1) { + return true; + } + var tlines = this.el.get_line_count (); + Gtk.TextIter iter; + var valiter = validate_res.map_iterator(); + while (valiter.next()) { + + // print("get inter\n"); + var eline = valiter.get_key(); + if (eline > tlines) { + continue; + } + this.el.get_iter_at_line( out iter, eline); + //print("mark line\n"); + this.el.create_source_mark(valiter.get_value(), "ERR", iter); + } + return false; + } + public string toString () { + + Gtk.TextIter s; + Gtk.TextIter e; + this.el.get_start_iter(out s); + this.el.get_end_iter(out e); + var ret = this.el.get_text(s,e,true); + //print("TO STRING? " + ret); + return ret; + } + public bool checkSyntax () { + + if (this.check_running) { + print("Check is running\n"); + if (this.check_queued) { + print("Check is already queued"); + return true; + } + this.check_queued = true; + print("Adding queued Check "); + GLib.Timeout.add_seconds(1, () => { + this.check_queued = false; + + this.checkSyntax(); + return false; + }); + + + return true; + } + var str = this.toString(); + + // needed??? + if (this.error_line > 0) { + Gtk.TextIter start; + Gtk.TextIter end; + this.el.get_bounds (out start, out end); + + this.el.remove_source_marks (start, end, null); + } + if (str.length < 1) { + print("checkSyntax - empty string?\n"); + return true; + } + + if (_this.file.xtype == "PlainFile") { + + // assume it's gtk... + this.check_running = true; + + if (!_this.window.windowstate.valasource.checkPlainFileSpawn( + _this.file, + str + )) { + this.check_running = false; + } + + return true; + + } + if (_this.file == null) { + return true; + } + var p = Palete.factory(_this.file.xtype); + + + + this.check_running = true; + + + if (_this.file.language == "js") { + this.check_running = false; + print("calling validate javascript\n"); + return this.highlightErrors(p.validateJavascript( + str, + _this.key, + _this.ptype, + _this.file, + _this.node + )); + + } + + + print("calling validate vala\n"); + // clear the buttons. + + + if (! _this.window.windowstate.valasource.checkFileWithNodePropChange( + _this.file, + _this.node, + _this.key, + _this.ptype, + str + )) { + this.check_running = false; + } + + + + //print("done mark line\n"); + + return true; // at present allow saving - even if it's invalid.. + } + public bool highlightErrorsJson (string type, Json.Object obj) { + Gtk.TextIter start; + Gtk.TextIter end; + this.el.get_bounds (out start, out end); + + this.el.remove_source_marks (start, end, type); + + + // we should highlight other types of errors.. + + if (!obj.has_member(type)) { + print("Return has no errors\n"); + return true; + } + + if (_this.window.windowstate.state != WindowState.State.CODEONLY && + _this.window.windowstate.state != WindowState.State.CODE + ) { + return true; + } + + + var err = obj.get_object_member(type); + + + if (_this.file == null) { + return true; + + } + var valafn = _this.file.path; + + if (_this.file.xtype != "PlainFile") { + + + + + valafn = ""; + try { + var regex = new Regex("\\.bjs$"); + // should not happen + + + valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala"); + } catch (GLib.RegexError e) { + return true; + } + + + + } + if (!err.has_member(valafn)) { + print("File path has no errors\n"); + return true; + } + + var lines = err.get_object_member(valafn); + + var offset = 1; + if (obj.has_member("line_offset")) { + offset = (int)obj.get_int_member("line_offset") + 1; + } + + + + + var tlines = this.el.get_line_count () +1; + + lines.foreach_member((obj, line, node) => { + + Gtk.TextIter iter; + // print("get inter\n"); + var eline = int.parse(line) - offset; + print("GOT ERROR on line %s -- converted to %d\n", line,eline); + + + if (eline > tlines || eline < 0) { + return; + } + this.el.get_iter_at_line( out iter, eline); + //print("mark line\n"); + var msg = "Line: %d".printf(eline+1); + var ar = lines.get_array_member(line); + for (var i = 0 ; i < ar.get_length(); i++) { + msg += (msg.length > 0) ? "\n" : ""; + msg += ar.get_string_element(i); + } + + + this.el.create_source_mark(msg, type, iter); + } ); + return false; + + + + + + } + } + -- 2.39.2