X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=src%2FBuilder4%2FWindowRooView.vala;h=2f7c10a2ab094308045a77e6e3be45b57c6304a6;hb=700f970c58ea880664ac6d459472b93dab1c41f4;hp=6906c4176196359295c9135fa34b7051ba69fe2d;hpb=6b47d4fc5bda7c979e3860e27bbd54bf211574b8;p=app.Builder.js diff --git a/src/Builder4/WindowRooView.vala b/src/Builder4/WindowRooView.vala index 6906c4176..2f7c10a2a 100644 --- a/src/Builder4/WindowRooView.vala +++ b/src/Builder4/WindowRooView.vala @@ -933,8 +933,8 @@ public class Xcls_WindowRooView : Object // my vars (def) public bool loading; public bool allow_node_scroll; - public JsRender.Node? node; - public string propSelected; + public string prop_selected; + public JsRender.Node? node_selected; // ctor public Xcls_sourceview(Xcls_WindowRooView _owner ) @@ -946,8 +946,8 @@ public class Xcls_WindowRooView : Object // my vars (dec) this.loading = true; this.allow_node_scroll = true; - this.node = null; - this.propSelected = ""; + this.prop_selected = ""; + this.node_selected = null; // set gobject values this.el.editable = false; @@ -1031,6 +1031,15 @@ public class Xcls_WindowRooView : Object return false; }); + this.el.key_press_event.connect( () => { + this.onCursorChanged(); + return false; + }); + this.el.key_release_event.connect( () => { + // in theory this should be after a change has been done.. + + + }); } // user defined functions @@ -1061,7 +1070,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); @@ -1076,7 +1085,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(":"); @@ -1084,10 +1093,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; } } @@ -1103,6 +1112,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,20 +1137,90 @@ public class Xcls_WindowRooView : Object Gtk.main_iteration(); } - - 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.. @@ -1165,10 +1256,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; @@ -1187,7 +1278,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); } @@ -1204,7 +1295,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); } @@ -1247,75 +1338,6 @@ 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 (_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 @@ -1361,7 +1383,7 @@ public class Xcls_WindowRooView : Object } print("- PREVIEW EDITOR CHANGED--"); - + this.dirty = true; if (!this.checkSyntax()) { return; @@ -1369,7 +1391,7 @@ public class Xcls_WindowRooView : Object // what are we editing?? - +