X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=src%2FBuilder4%2FWindowRooView.vala;h=5996176cf0736c8ba40e0f36d5778fecf5372f85;hb=497a66cfff975b566b929d3496d160ac6321fe02;hp=e2147f1098e59d611e51807686c3286a950ca837;hpb=d87233aad3ac30183374380b064bed9fc8aec92c;p=app.Builder.js diff --git a/src/Builder4/WindowRooView.vala b/src/Builder4/WindowRooView.vala index e2147f109..5996176cf 100644 --- a/src/Builder4/WindowRooView.vala +++ b/src/Builder4/WindowRooView.vala @@ -933,7 +933,8 @@ public class Xcls_WindowRooView : Object // my vars (def) public bool loading; public bool allow_node_scroll; - public string propSelected; + public string prop_selected; + public JsRender.Node? node_selected; // ctor public Xcls_sourceview(Xcls_WindowRooView _owner ) @@ -945,7 +946,8 @@ public class Xcls_WindowRooView : Object // my vars (dec) this.loading = true; this.allow_node_scroll = true; - this.propSelected = ""; + this.prop_selected = ""; + this.node_selected = null; // set gobject values this.el.editable = false; @@ -1029,6 +1031,10 @@ public class Xcls_WindowRooView : Object return false; }); + this.el.key_press_event.connect( () => { + this.onCursorChanged(); + return false; + }); } // user defined functions @@ -1059,7 +1065,7 @@ public class Xcls_WindowRooView : Object - + // ---------- this selects the tree's node... var ltree = _this.main_window.windowstate.left_tree; var tp = ltree.model.treePathFromNode(node); @@ -1074,7 +1080,7 @@ public class Xcls_WindowRooView : Object // let's try allowing editing on the methods. // a little klunky at present.. - this.propSelected = ""; + this.prop_selected = ""; if (prop != null) { //see if we can find it.. var kv = prop.split(":"); @@ -1082,10 +1088,10 @@ public class Xcls_WindowRooView : Object //var k = prop.get_key(kv[1]); // fixme -- need to determine if it's an editable property... - this.propSelected = prop; + this.prop_selected = prop; } else if (kv[0] == "l") { - this.propSelected = prop; + this.prop_selected = prop; } } @@ -1102,23 +1108,10 @@ public class Xcls_WindowRooView : Object // highlight the node.. } - public void nodeSelected (JsRender.Node? sel, bool scroll ) { - - - - // this is connected in widnowstate - print("node selected\n"); - var buf = this.el.get_buffer(); - - var sbuf = (Gtk.SourceBuffer) buf; - - - while(Gtk.events_pending()) { - Gtk.main_iteration(); - } + public void clearGreySelection () { + // clear all the marks.. + var sbuf = (Gtk.SourceBuffer)this.el.buffer; - - // clear all the marks.. Gtk.TextIter start; Gtk.TextIter end; @@ -1126,75 +1119,25 @@ public class Xcls_WindowRooView : Object sbuf.remove_source_marks (start, end, "grey"); - if (sel == null) { - print("no selected node\n"); - // no highlighting.. - return; - } - - print("highlight region %d to %d\n", sel.line_start,sel.line_end); - Gtk.TextIter iter; - sbuf.get_iter_at_line(out iter, sel.line_start); - - - Gtk.TextIter cur_iter; - sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position); - - //var cur_line = cur_iter.get_line(); - //if (cur_line > sel.line_start && cur_line < sel.line_end) { - - //} else { - if (scroll) { - print("scrolling to node -- should occur on node picking.\n"); - this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f); - } - - var start_line = sel.line_start; - var end_line = sel.line_end; - + } + public void nodeSelected (JsRender.Node? sel, bool scroll ) { + - this.el.editable = false; - // now if we have selected a property... - if (this.propSelected.length> 0 ) { + + // this is connected in widnowstate - int nstart, nend; - if (sel.getPropertyRange(this.propSelected, out nstart, out nend) && nend > nstart) { - start_line = nstart; - end_line = nend; - this.el.editable = true; - } - print("propSelected = %s range %d -> %d\n", this.propSelected, start_line, end_line); - - - } - - // check selection - if it's out of 'bounds' - if (this.el.editable && sbuf.get_has_selection()) { - Gtk.TextIter sel_start_iter, sel_end_iter; - sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter); - - if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line || - sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) { - // save? - this.el.editable = false; - } - + + // not sure why.... + while(Gtk.events_pending()) { + Gtk.main_iteration(); } + this.node_selected = sel; + this.updateGreySelection(scroll); - for (var i = 0; i < buf.get_line_count();i++) { - if (i < (start_line -1) || i > (end_line -1)) { - - sbuf.get_iter_at_line(out iter, i); - sbuf.create_source_mark(null, "grey", iter); - - } - - } - } public string toString () { Gtk.TextIter s; @@ -1250,20 +1193,153 @@ public class Xcls_WindowRooView : Object sbuf.remove_source_marks (start, end, null); // remove all marks.. GLib.Timeout.add(500, () => { - - print("RESORTING cursor to = %d\n", cpos); + + 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.. + return; + } + + print("highlight region %d to %d\n", sel.line_start,sel.line_end); + Gtk.TextIter iter; + sbuf.get_iter_at_line(out iter, sel.line_start); + + + Gtk.TextIter cur_iter; + sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position); + + var cursor_at_line = cur_iter.get_line(); + + + //var cur_line = cur_iter.get_line(); + //if (cur_line > sel.line_start && cur_line < sel.line_end) { + + //} else { + if (scroll) { + print("scrolling to node -- should occur on node picking.\n"); + this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f); + } + + var start_line = sel.line_start; + var end_line = sel.line_end; + + + this.el.editable = false; + + var colon_pos = 0; + + // now if we have selected a property... + if (this.prop_selected.length> 0 ) { + + int nstart, nend; + if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) { + start_line = nstart; + end_line = nend; + this.el.editable = true; + print("start line = %d, end line = %d\n", start_line, end_line); + + // see if we are 'right of ':' + // get an iter for the start of the line. + Gtk.TextIter start_line_iter,end_line_iter; + this.el.buffer.get_iter_at_line(out start_line_iter, start_line -1); + this.el.buffer.get_iter_at_line(out end_line_iter, start_line -1); + + + + + if (end_line_iter.forward_to_line_end()) { + 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(":") + 1; + } + print("colon_pos = %d\n", colon_pos); + } + print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line); + if (start_line - 1 == cursor_at_line) { + print("cursor is on current line.\n"); + var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false); + print("before cursor string = %s\n", before_cursor_string); + if (!before_cursor_string.contains(":")) { + this.el.editable = false; + } + + } + + + } + print("propSelected = %s range %d -> %d\n", this.prop_selected, start_line, end_line); + + + } + + print("checking selection\n"); + + + // check selection - if it's out of 'bounds' + if (this.el.editable && sbuf.get_has_selection()) { + Gtk.TextIter sel_start_iter, sel_end_iter; + sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter); + + if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line || + sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) { + // save? + this.el.editable = false; + } + if (colon_pos > 0 && + (sel_start_iter.get_offset() < colon_pos || sel_end_iter.get_offset() < colon_pos) + + ) { + this.el.editable = false; + } + + + + } + + + + + for (var i = 0; i < buf.get_line_count();i++) { + if (i < (start_line -1) || i > (end_line -1)) { + + sbuf.get_iter_at_line(out iter, i); + sbuf.create_source_mark(null, "grey", iter); + + } + + } + + } public void highlightErrorsJson (string type, Json.Object obj) { // this is a hook for the vala code - it has no value in javascript @@ -1309,11 +1385,16 @@ public class Xcls_WindowRooView : Object } print("- PREVIEW EDITOR CHANGED--"); + + this.dirty = true; + if (!this.checkSyntax()) { + return; + } - - this.checkSyntax(); + // what are we editing?? - this.dirty = true; + + return ; @@ -1324,7 +1405,7 @@ public class Xcls_WindowRooView : Object public bool highlightErrors ( Gee.HashMap validate_res) { this.error_line = validate_res.size; - + if (this.error_line < 1) { return true; } @@ -1370,33 +1451,30 @@ public class Xcls_WindowRooView : Object if (str.length < 1) { print("checkSyntax - empty string?\n"); - return true; + return false; } if (_this.file == null) { - return true; + return false; } var p = Palete.factory(_this.file.xtype); // returns Roo | Gtk | PlainFile - if (_this.file.language == "js") { - - print("calling validate javascript\n"); - return this.highlightErrors(p.validateJavascript( - str, - "|", // _this.key, - "file", //_this.ptype, - _this.file, - null - )); - - } - + if (_this.file.language != "js") { + return false; // fake syntax error. + } + - print("calling validate vala\n"); - + + return p.javascriptHasErrors( + _this.main_window.windowstate, + str, + "", // _this.key, + "file", //_this.ptype, + _this.file, + null + ); - return true; // at present allow saving - even if it's invalid.. } }