resources/RooUsage.txt
[app.Builder.js] / src / Builder4 / GtkView.vala
index 9d80ab4..9851abb 100644 (file)
@@ -22,6 +22,8 @@ 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 Xcls_MainWindow main_window;
@@ -35,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;
 
@@ -46,25 +49,13 @@ public class Xcls_GtkView : Object
 
         //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 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;
-    }
     public void scroll_to_line (int line) {
        this.notebook.el.page = 1;// code preview...
        
@@ -141,7 +132,7 @@ public class Xcls_GtkView : Object
             
            this.file = file;     
             this.sourceview.loadFile();
-            
+            this.searchcontext = null;
             
     
             if (this.lastObj != null) {
@@ -182,6 +173,48 @@ 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.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
     {
@@ -367,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 )
@@ -377,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;
@@ -405,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;
@@ -415,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..
@@ -485,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;
@@ -510,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) {