src/Builder4/GtkView.bjs
authorAlan Knowles <alan@roojs.com>
Tue, 2 Jun 2015 12:52:39 +0000 (20:52 +0800)
committerAlan Knowles <alan@roojs.com>
Tue, 2 Jun 2015 12:52:39 +0000 (20:52 +0800)
src/Builder4/GtkView.vala

src/Builder4/GtkView.bjs
src/Builder4/GtkView.vala

index 5861b62..90aec01 100644 (file)
@@ -11,7 +11,7 @@
    "listeners" : {
     "size_allocate" : "(aloc) => {\n\n    this.width = aloc.width;\n    this.height =aloc.height;\n    }\n"
    },
-   "| Gee.ArrayList<int> search" : "(string txt) {\n  var ret =  new Gee.ArrayList<int>();\n  var str = this.sourceview.toString();\n  \n  var lines = str.split(\"\\n\");\n  for (var i = 0 ; i < lines.length; i++)  {\n\tif (lines[i].contains(txt)) {\n\t\tret.add(i);\n\t}\n  \n  }\n  \n  \n  return ret;\n}\n",
+   "| Gee.ArrayList<int> search" : "(string txt) {\n \tvar s = new Gtk.SourceSearchSettings();\n\t\n\tthis.sourcecontext = new Gtk.SourceSearchContext(this.sourceview.el.get_buffer(),s);\n\tsctx.set_highlight(true);\n\ts.set_search_text(txt);\n\treturn this.sourcecontext.get_occurences_count();\n\n  \n  \n  return ret;\n}\n",
    "| void scroll_to_line" : "(int line) {\n   this.notebook.el.page = 1;// code preview...\n   \n   GLib.Timeout.add(500, () => {\n   \n   \n\t   \n\t   \n\t\t  var buf = this.sourceview.el.get_buffer();\n\t \n\t\tvar sbuf = (Gtk.SourceBuffer) buf;\n\n\n\t\tGtk.TextIter iter;   \n\t\tsbuf.get_iter_at_line(out iter,  line);\n\t\tthis.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);\n\t\treturn false;\n\t});   \n\n   \n}\n",
    "id" : "GtkView",
    "# Gtk.Widget lastObj" : "null",
index e53dad5..9d80ab4 100644 (file)
@@ -54,16 +54,13 @@ public class Xcls_GtkView : Object
 
     // user defined functions
     public Gee.ArrayList<int> search (string txt) {
-      var ret =  new Gee.ArrayList<int>();
-      var str = this.sourceview.toString();
-      
-      var lines = str.split("\n");
-      for (var i = 0 ; i < lines.length; i++)  {
-       if (lines[i].contains(txt)) {
-               ret.add(i);
-       }
-      
-      }
+       var s = new Gtk.SourceSearchSettings();
+       
+       this.sourcecontext = new Gtk.SourceSearchContext(this.sourceview.el.get_buffer(),s);
+       sctx.set_highlight(true);
+       s.set_search_text(txt);
+       return this.sourcecontext.get_occurences_count();
+    
       
       
       return ret;