X-Git-Url: http://git.roojs.org/?p=app.Builder.js;a=blobdiff_plain;f=src%2FBuilder4%2FWindowRooView.vala;h=4582600330ef9e82d0d71fc10544b9f18c57b1f5;hp=811ec5f6ed66b4c83e3bd5758c1fab0aed8a9b74;hb=26980b815cd4686adba075775bc47ae9eabede08;hpb=3137e58d7ad41933aa9d74c7bc9d27c30b970a53 diff --git a/src/Builder4/WindowRooView.vala b/src/Builder4/WindowRooView.vala index 811ec5f6e..458260033 100644 --- a/src/Builder4/WindowRooView.vala +++ b/src/Builder4/WindowRooView.vala @@ -1031,6 +1031,10 @@ public class Xcls_WindowRooView : Object return false; }); + this.el.key_press_event.connect( () => { + this.onCursorChanged(); + return false; + }); } // user defined functions @@ -1087,7 +1091,7 @@ public class Xcls_WindowRooView : Object this.prop_selected = prop; } else if (kv[0] == "l") { - this.propSelected = prop; + this.prop_selected = prop; } } @@ -1103,6 +1107,18 @@ public class Xcls_WindowRooView : Object } // highlight the node.. + } + public void clearGreySelection () { + // clear all the marks.. + var sbuf = (Gtk.SourceBuffer)this.el.buffer; + + Gtk.TextIter start; + Gtk.TextIter end; + + sbuf.get_bounds (out start, out end); + sbuf.remove_source_marks (start, end, "grey"); + + } public void nodeSelected (JsRender.Node? sel, bool scroll ) { @@ -1116,21 +1132,97 @@ public class Xcls_WindowRooView : Object Gtk.main_iteration(); } - this.nodeSelected = sel; - - print("node selected\n"); + this.node_selected = sel; + + this.updateGreySelection(scroll); + + + + } + public string toString () { + Gtk.TextIter s; + Gtk.TextIter e; + this.el.get_buffer().get_start_iter(out s); + this.el.get_buffer().get_end_iter(out e); + var ret = this.el.get_buffer().get_text(s,e,true); + //print("TO STRING? " + ret); + return ret; + } + public void loadFile ( ) { + this.loading = true; + + + // get the cursor and scroll position.... var buf = this.el.get_buffer(); + var cpos = buf.cursor_position; + + print("BEFORE LOAD cursor = %d\n", cpos); + + var vadj_pos = this.el.get_vadjustment().get_value(); + + + + buf.set_text("",0); var sbuf = (Gtk.SourceBuffer) buf; - - // clear all the marks.. + + + if (_this.file == null || _this.file.xtype != "Roo") { + print("xtype != Roo"); + this.loading = false; + return; + } + + // get the string from the rendered tree... + + var str = _this.file.toSource(); + + // print("setting str %d\n", str.length); + buf.set_text(str, str.length); + var lm = Gtk.SourceLanguageManager.get_default(); + + //?? is javascript going to work as js? + + ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language)); + + Gtk.TextIter start; Gtk.TextIter end; sbuf.get_bounds (out start, out end); - sbuf.remove_source_marks (start, end, "grey"); - + sbuf.remove_source_marks (start, end, null); // remove all marks.. + GLib.Timeout.add(500, () => { + + print("RESORTING cursor to = %d\n", cpos); + Gtk.TextIter cpos_iter; + buf.get_iter_at_offset(out cpos_iter, cpos); + buf.place_cursor(cpos_iter); + + this.el.get_vadjustment().set_value(vadj_pos);; + + + this.onCursorChanged(); + + + _this.buffer.checkSyntax(); + return false; + }); + + this.loading = false; + _this.buffer.dirty = false; + } + public void updateGreySelection (bool scroll) { + var sel = this.node_selected; + print("node selected\n"); + var buf = this.el.get_buffer(); + var sbuf = (Gtk.SourceBuffer) buf; + + + this.clearGreySelection(); + + + if (sel == null) { print("no selected node\n"); // no highlighting.. @@ -1166,10 +1258,10 @@ public class Xcls_WindowRooView : Object var colon_pos = 0; // now if we have selected a property... - if (this.propSelected.length> 0 ) { + if (this.prop_selected.length> 0 ) { int nstart, nend; - if (sel.getPropertyRange(this.propSelected, out nstart, out nend) && nend > nstart) { + if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) { start_line = nstart; end_line = nend; this.el.editable = true; @@ -1188,7 +1280,7 @@ public class Xcls_WindowRooView : Object var first_line = this.el.buffer.get_text(start_line_iter, end_line_iter, false); print("first line = %s\n", first_line); if (first_line.contains(":")) { - colon_pos = start_line_iter.get_offset() + first_line.index_of(":"); + colon_pos = start_line_iter.get_offset() + first_line.index_of(":") + 1; } print("colon_pos = %d\n", colon_pos); } @@ -1205,7 +1297,7 @@ public class Xcls_WindowRooView : Object } - print("propSelected = %s range %d -> %d\n", this.propSelected, start_line, end_line); + print("propSelected = %s range %d -> %d\n", this.prop_selected, start_line, end_line); } @@ -1246,77 +1338,13 @@ public class Xcls_WindowRooView : Object } } - - - } - public string toString () { - Gtk.TextIter s; - Gtk.TextIter e; - this.el.get_buffer().get_start_iter(out s); - this.el.get_buffer().get_end_iter(out e); - var ret = this.el.get_buffer().get_text(s,e,true); - //print("TO STRING? " + ret); - return ret; - } - public void loadFile ( ) { - this.loading = true; - - - // get the cursor and scroll position.... - var buf = this.el.get_buffer(); - var cpos = buf.cursor_position; - - print("BEFORE LOAD cursor = %d\n", cpos); - - var vadj_pos = this.el.get_vadjustment().get_value(); - - - - buf.set_text("",0); - var sbuf = (Gtk.SourceBuffer) buf; + if (scroll) { + Gtk.TextIter cpos_iter; + buf.get_iter_at_line(out cpos_iter, start_line); + buf.place_cursor(cpos_iter); + } - - if (_this.file == null || _this.file.xtype != "Roo") { - print("xtype != Roo"); - this.loading = false; - return; - } - - // get the string from the rendered tree... - - var str = _this.file.toSource(); - - // print("setting str %d\n", str.length); - buf.set_text(str, str.length); - var lm = Gtk.SourceLanguageManager.get_default(); - - //?? is javascript going to work as js? - - ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language)); - - - Gtk.TextIter start; - Gtk.TextIter end; - - sbuf.get_bounds (out start, out end); - sbuf.remove_source_marks (start, end, null); // remove all marks.. - - GLib.Timeout.add(500, () => { - - print("RESORTING cursor to = %d\n", cpos); - Gtk.TextIter cpos_iter; - buf.get_iter_at_offset(out cpos_iter, cpos); - buf.place_cursor(cpos_iter); - - this.el.get_vadjustment().set_value(vadj_pos);; - this.onCursorChanged(); - _this.buffer.checkSyntax(); - return false; - }); - - this.loading = false; - _this.buffer.dirty = false; } public void highlightErrorsJson (string type, Json.Object obj) { // this is a hook for the vala code - it has no value in javascript @@ -1362,7 +1390,7 @@ public class Xcls_WindowRooView : Object } print("- PREVIEW EDITOR CHANGED--"); - + this.dirty = true; if (!this.checkSyntax()) { return; @@ -1370,7 +1398,7 @@ public class Xcls_WindowRooView : Object // what are we editing?? - + @@ -1441,15 +1469,16 @@ public class Xcls_WindowRooView : Object return false; // fake syntax error. } - + //Gee.HashMap ret_x; - return this.highlightErrors(p.validateJavascript( + return p.javascriptHasErrors( + _this.main_window.windowstate, str, "", // _this.key, "file", //_this.ptype, - _this.file, + _this.file, null - )); + ); } }