X-Git-Url: http://git.roojs.org/?p=app.Builder.js;a=blobdiff_plain;f=src%2FBuilder4%2FGtkView.vala;h=9851abb768cab54d888780c13fc5bd8e33447e6d;hp=3362046665d8ec62a799f2d02746d9b4f1c4884f;hb=HEAD;hpb=e9eef9bbc9a305315205647f593b85879174702c diff --git a/src/Builder4/GtkView.vala b/src/Builder4/GtkView.vala index 336204666..9851abb76 100644 --- a/src/Builder4/GtkView.vala +++ b/src/Builder4/GtkView.vala @@ -22,9 +22,10 @@ public class Xcls_GtkView : Object // my vars (def) public Gtk.Widget lastObj; public int width; + public int last_search_end; + public Gtk.SourceSearchContext searchcontext; public JsRender.JsRender file; public int height; - public Gtk.SourceSearchContext sourcecontext; public Xcls_MainWindow main_window; // ctor @@ -36,6 +37,7 @@ public class Xcls_GtkView : Object // my vars (dec) this.lastObj = null; this.width = 0; + this.last_search_end = 0; this.file = null; this.height = 0; @@ -47,10 +49,10 @@ public class Xcls_GtkView : Object //listeners this.el.size_allocate.connect( (aloc) => { - + this.width = aloc.width; this.height =aloc.height; - }); + }); } // user defined functions @@ -130,7 +132,7 @@ public class Xcls_GtkView : Object this.file = file; this.sourceview.loadFile(); - + this.searchcontext = null; if (this.lastObj != null) { @@ -173,14 +175,46 @@ public class Xcls_GtkView : Object } public int search (string txt) { + this.notebook.el.page = 1; var s = new Gtk.SourceSearchSettings(); var buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer(); - this.sourcecontext = new Gtk.SourceSearchContext(buf,s); - sctx.set_highlight(true); + this.searchcontext = new Gtk.SourceSearchContext(buf,s); + this.searchcontext.set_highlight(true); s.set_search_text(txt); - return this.sourcecontext.get_occurences_count(); + + Gtk.TextIter beg, st,en; + + buf.get_start_iter(out beg); + this.searchcontext.forward(beg, out st, out en); + this.last_search_end = 0; + return this.searchcontext.get_occurrences_count(); + } + public void forwardSearch (bool change_focus) { + + if (this.searchcontext == null) { + return; + } + this.notebook.el.page = 1; + Gtk.TextIter beg, st,en, stl; + + var buf = this.sourceview.el.get_buffer(); + buf.get_iter_at_offset(out beg, this.last_search_end); + if (!this.searchcontext.forward(beg, out st, out en)) { + this.last_search_end = 0; + } else { + this.last_search_end = en.get_offset(); + if (change_focus) { + this.sourceview.el.grab_focus(); + } + buf.place_cursor(st); + var ln = st.get_line(); + buf.get_iter_at_line(out stl,ln); + + this.sourceview.el.scroll_to_iter(stl, 0.0f, true, 0.0f, 0.5f); + } + } public class Xcls_notebook : Object { @@ -366,6 +400,7 @@ public class Xcls_GtkView : Object // my vars (def) public bool loading; + public bool allow_node_scroll; // ctor public Xcls_sourceview(Xcls_GtkView _owner ) @@ -376,6 +411,7 @@ public class Xcls_GtkView : Object // my vars (dec) this.loading = true; + this.allow_node_scroll = true; // set gobject values this.el.editable = false; @@ -404,8 +440,9 @@ public class Xcls_GtkView : Object buf.get_iter_at_offset(out cpos, buf.cursor_position); var ln = cpos.get_line(); - + var node = _this.file.lineToNode(ln); + if (node == null) { print("can not find node\n"); return; @@ -414,7 +451,14 @@ public class Xcls_GtkView : Object var tp = ltree.model.treePathFromNode(node); print("got tree path %s\n", tp); if (tp != "") { + this.allow_node_scroll = false; + print("changing cursor on tree..\n"); ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false); + // scrolling is disabled... as node selection calls scroll 10ms after it changes. + GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => { + this.allow_node_scroll = true; + return false; + }); } // highlight the node.. @@ -484,7 +528,7 @@ public class Xcls_GtkView : Object // this is connected in widnowstate - print("node selected"); + print("Roo-view - node selected\n"); var buf = this.el.get_buffer(); var sbuf = (Gtk.SourceBuffer) buf; @@ -509,7 +553,21 @@ public class Xcls_GtkView : Object } Gtk.TextIter iter; sbuf.get_iter_at_line(out iter, sel.line_start); - this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f); + + + 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 (this.allow_node_scroll) { + + this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f); + } + + for (var i = 0; i < buf.get_line_count();i++) { if (i < sel.line_start || i > sel.line_end) {