src/Builder4/Editor.bjs
[app.Builder.js] / src / Builder4 / Editor.vala
index c4823b1..872b603 100644 (file)
@@ -49,6 +49,7 @@ public class Editor : Object
 
         // set gobject values
         this.el.homogeneous = false;
+        this.el.hexpand = true;
         var child_0 = new Xcls_Box2( _this );
         child_0.ref();
         this.el.pack_start (  child_0.el , false,true );
@@ -58,6 +59,29 @@ public class Editor : Object
     }
 
     // user defined functions
+    public Gee.ArrayList<int> search (string txt) {
+    
+       var s = new Gtk.SourceSearchSettings();
+       
+       var sctx = new Gtk.SourceSearchContext(this.buffer.el,s);
+       sctx.set_highlight(true);
+       s.set_search_text(txt);
+       
+    
+    
+       var ret =  new Gee.ArrayList<int>();
+    
+       var str = this.buffer.toString();
+    
+       var lines = str.split("\n");
+       for (var i = 0 ; i < lines.length; i++)  {
+       if (lines[i].contains(txt)) {
+               ret.add(i);
+       }
+      
+       }
+       return ret;
+    }
     public   bool saveContents ()  {
         
         
@@ -66,8 +90,7 @@ public class Editor : Object
         }
         
         
-        
-        
+       
        
          
          var str = _this.buffer.toString();
@@ -98,6 +121,21 @@ public class Editor : Object
         return true;
     
     }
+    public void scroll_to_line (int line) {
+    
+       GLib.Timeout.add(500, () => {
+       
+               var buf = this.view.el.get_buffer();
+    
+               var sbuf = (Gtk.SourceBuffer) buf;
+    
+    
+               Gtk.TextIter iter;   
+               sbuf.get_iter_at_line(out iter,  line);
+               this.view.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
+               return false;
+       });   
+    }
     public   void show (JsRender.JsRender file, JsRender.Node? node, string ptype, string key)
     {
         this.file = file;    
@@ -263,6 +301,8 @@ public class Editor : Object
             this.el.show_line_marks = true;
             this.el.insert_spaces_instead_of_tabs = true;
             this.el.show_line_numbers = true;
+            this.el.draw_spaces = Gtk.SourceDrawSpacesFlags.LEADING + Gtk.SourceDrawSpacesFlags.TRAILING + Gtk.SourceDrawSpacesFlags.TAB + Gtk.SourceDrawSpacesFlags.SPACE;
+            this.el.tab_width = 4;
             this.el.highlight_current_line = true;
             var child_0 = new Xcls_buffer( _this );
             child_0.ref();
@@ -271,10 +311,16 @@ public class Editor : Object
             // init method
 
             var description =   Pango.FontDescription.from_string("monospace");
-                description.set_size(8000);
-                this.el.override_font(description);
-            
-            
+                       description.set_size(8000);
+                        this.el.override_font(description);
+                
+               
+               this.el.completion.add_provider(new Palete.CompletionProvider(_this));
+               this.el.completion.unblock_interactive();
+               this.el.completion.select_on_show                       = true; // select
+               this.el.completion.show_headers                 = false;
+               this.el.completion.remember_info_visibility             = true;
+                
               
                 var attrs = new Gtk.SourceMarkAttributes();
                 var  pink =   Gdk.RGBA();
@@ -347,14 +393,20 @@ public class Editor : Object
                  lang = _this.file.language;
             }
             print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
-         
-            ((Gtk.SourceBuffer)(this.el.get_buffer())) .set_language(
-                    _this.file.content_type.length > 0  ?
+            var lg = _this.file.content_type.length > 0  ?
                     lm.guess_language(_this.file.path, _this.file.content_type) :
-                    lm.get_language(lang)
-                );
-         
+                    lm.get_language(lang);
              
+           
+            ((Gtk.SourceBuffer)(this.el.get_buffer())) .set_language(lg); 
+        
+            this.el.insert_spaces_instead_of_tabs = true;
+            if (lg != null) {
+                       print("sourcelanguage  = %s\n", lg.name);
+                       if (lg.name == "Vala") {
+                           this.el.insert_spaces_instead_of_tabs = false;
+                       }
+             }
             _this.dirty = false;
             this.el.grab_focus();
             _this.save_button.el.sensitive = false;