// 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 Xcls_MainWindow main_window;
// my vars (dec)
this.lastObj = null;
this.width = 0;
+ this.last_search_end = 0;
this.file = null;
this.height = 0;
//listeners
this.el.size_allocate.connect( (aloc) => {
-
+
this.width = aloc.width;
this.height =aloc.height;
- });
+ });
}
// user defined functions
- public Gee.ArrayList<int> search (string txt) {
- var ret = new Gee.ArrayList<int>();
- var str = this.sourceview.toString();
-
-
- return ret;
- }
public void scroll_to_line (int line) {
this.notebook.el.page = 1;// code preview...
this.file = file;
this.sourceview.loadFile();
-
+ this.searchcontext = null;
if (this.lastObj != null) {
+ }
+ 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.searchcontext = new Gtk.SourceSearchContext(buf,s);
+ this.searchcontext.set_highlight(true);
+ s.set_search_text(txt);
+
+ 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
{
// my vars (def)
public bool loading;
+ public bool allow_node_scroll;
// ctor
public Xcls_sourceview(Xcls_GtkView _owner )
// my vars (dec)
this.loading = true;
+ this.allow_node_scroll = true;
// set gobject values
this.el.editable = false;
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;
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..
// 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;
}
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) {