Fix #8089 - phase 1 - code ast navigation
[roobuilder] / src / Builder4 / GtkView.vala
index c560f25..1af7338 100644 (file)
@@ -20,6 +20,7 @@ public class Xcls_GtkView : Object
        public Xcls_sourceviewscroll sourceviewscroll;
        public Xcls_sourceview sourceview;
        public Xcls_buffer buffer;
+       public Xcls_keystate keystate;
        public Xcls_search_entry search_entry;
        public Xcls_search_results search_results;
        public Xcls_nextBtn nextBtn;
@@ -103,7 +104,17 @@ public class Xcls_GtkView : Object
                        }
                
                        var xmlstr = JsRender.NodeToGlade.mungeFile( file);
-                       var builder = new Gtk.Builder.from_string (xmlstr, xmlstr.length);
+                       var builder = new Gtk.Builder();
+                       try {
+                               if (!builder.add_from_string(xmlstr, xmlstr.length)) {
+                                       return;
+                               }
+                       } catch(GLib.Error e) {
+                               GLib.debug(e.message);
+                               return;
+                       }
+                       
+       
                        var obj = (Gtk.Widget) builder.get_object("w"+ file.tree.oid.to_string());
                         this.container.el.append(obj);
                    obj.show();
@@ -311,7 +322,7 @@ public class Xcls_GtkView : Object
        
        
         
-               GLib.debug("highlight errors");          
+               //GLib.debug("highlight errors");                
        
                 // we should highlight other types of errors..
        
@@ -332,7 +343,7 @@ public class Xcls_GtkView : Object
                        buf.remove_source_marks (start, end, "WARN");
                        buf.remove_source_marks (start, end, "DEPR");
                        this.last_error_counter = file.error_counter ;
-                       GLib.debug("higjlight has no errors");
+                       //GLib.debug("higjlight has no errors");
                        return;
                }
                if (this.last_error_counter == file.error_counter) {
@@ -577,7 +588,7 @@ public class Xcls_GtkView : Object
                        // set gobject values
                        new Xcls_sourceviewscroll( _this );
                        this.el.append( _this.sourceviewscroll.el );
-                       var child_2 = new Xcls_Box12( _this );
+                       var child_2 = new Xcls_Box13( _this );
                        child_2.ref();
                        this.el.append( child_2.el );
                }
@@ -629,7 +640,7 @@ public class Xcls_GtkView : Object
 
                        // my vars (dec)
                        this.loading = false;
-                       this.prop_selected = "";
+                       this.prop_selected = "\"\"";
 
                        // set gobject values
                        this.el.name = "gtkview-view";
@@ -640,9 +651,11 @@ public class Xcls_GtkView : Object
                        this.el.tab_width = 4;
                        new Xcls_buffer( _this );
                        this.el.set_buffer ( _this.buffer.el  );
-                       var child_2 = new Xcls_EventControllerKey11( _this );
-                       child_2.ref();
-                       this.el.add_controller(  child_2.el );
+                       new Xcls_keystate( _this );
+                       this.el.add_controller(  _this.keystate.el );
+                       var child_3 = new Xcls_EventControllerScroll12( _this );
+                       child_3.ref();
+                       this.el.add_controller(  child_3.el );
 
                        // init method
 
@@ -737,7 +750,7 @@ public class Xcls_GtkView : Object
                    this.loading = true;
                    var buf = this.el.get_buffer();
                    buf.set_text("",0);
-                   var sbuf = (GtkSource.Buffer) buf;
+                
                        var cpos = buf.cursor_position;
                    
                        print("BEFORE LOAD cursor = %d\n", cpos);
@@ -953,28 +966,39 @@ public class Xcls_GtkView : Object
                // user defined functions
        }
 
-       public class Xcls_EventControllerKey11 : Object
+       public class Xcls_keystate : Object
        {
                public Gtk.EventControllerKey el;
                private Xcls_GtkView  _this;
 
 
                        // my vars (def)
+               public bool is_control;
 
                // ctor
-               public Xcls_EventControllerKey11(Xcls_GtkView _owner )
+               public Xcls_keystate(Xcls_GtkView _owner )
                {
                        _this = _owner;
+                       _this.keystate = this;
                        this.el = new Gtk.EventControllerKey();
 
                        // my vars (dec)
+                       this.is_control = false;
 
                        // set gobject values
 
                        //listeners
+                       this.el.key_released.connect( (keyval, keycode, state) => {
+                       
+                                if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
+                                       this.is_control = false;
+                               }
+                       });
                        this.el.key_pressed.connect( (keyval, keycode, state) => {
                        
-                               
+                               if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
+                                       this.is_control = true;
+                               }
                                 
                                 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
                                    GLib.debug("SAVE: ctrl-g  pressed");
@@ -994,9 +1018,53 @@ public class Xcls_GtkView : Object
                // user defined functions
        }
 
+       public class Xcls_EventControllerScroll12 : Object
+       {
+               public Gtk.EventControllerScroll el;
+               private Xcls_GtkView  _this;
+
+
+                       // my vars (def)
+               public double distance;
+
+               // ctor
+               public Xcls_EventControllerScroll12(Xcls_GtkView _owner )
+               {
+                       _this = _owner;
+                       this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
+
+                       // my vars (dec)
+                       this.distance = 0.0f;
+
+                       // set gobject values
+
+                       //listeners
+                       this.el.scroll.connect( (dx, dy) => {
+                               if (!_this.keystate.is_control) {
+                                       return false;
+                               }
+                               //GLib.debug("scroll %f",  dy);
+                               
+                               this.distance += dy;
+                                if (this.distance < -1) {
+                                       BuilderApplication.settings.editor_font_size ++;
+                                       this.distance = 0;
+                               }
+                               if (this.distance > 1) {
+                                       BuilderApplication.settings.editor_font_size --;
+                                       this.distance = 0;
+                               }
+                       
+                               return true;
+                       });
+               }
+
+               // user defined functions
+       }
+
 
 
-       public class Xcls_Box12 : Object
+       public class Xcls_Box13 : Object
        {
                public Gtk.Box el;
                private Xcls_GtkView  _this;
@@ -1005,7 +1073,7 @@ public class Xcls_GtkView : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_Box12(Xcls_GtkView _owner )
+               public Xcls_Box13(Xcls_GtkView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
@@ -1023,7 +1091,7 @@ public class Xcls_GtkView : Object
                        this.el.append( _this.nextBtn.el );
                        new Xcls_backBtn( _this );
                        this.el.append( _this.backBtn.el );
-                       var child_5 = new Xcls_MenuButton18( _this );
+                       var child_5 = new Xcls_MenuButton19( _this );
                        child_5.ref();
                        this.el.append( child_5.el );
                }
@@ -1053,7 +1121,7 @@ public class Xcls_GtkView : Object
                        this.el.hexpand = true;
                        this.el.placeholder_text = "Press enter to search";
                        this.el.search_delay = 3;
-                       var child_1 = new Xcls_EventControllerKey14( _this );
+                       var child_1 = new Xcls_EventControllerKey15( _this );
                        child_1.ref();
                        this.el.add_controller(  child_1.el );
 
@@ -1101,7 +1169,7 @@ public class Xcls_GtkView : Object
                        
                }
        }
-       public class Xcls_EventControllerKey14 : Object
+       public class Xcls_EventControllerKey15 : Object
        {
                public Gtk.EventControllerKey el;
                private Xcls_GtkView  _this;
@@ -1110,7 +1178,7 @@ public class Xcls_GtkView : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_EventControllerKey14(Xcls_GtkView _owner )
+               public Xcls_EventControllerKey15(Xcls_GtkView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.EventControllerKey();
@@ -1260,7 +1328,7 @@ public class Xcls_GtkView : Object
                // user defined functions
        }
 
-       public class Xcls_MenuButton18 : Object
+       public class Xcls_MenuButton19 : Object
        {
                public Gtk.MenuButton el;
                private Xcls_GtkView  _this;
@@ -1270,7 +1338,7 @@ public class Xcls_GtkView : Object
                public bool always_show_image;
 
                // ctor
-               public Xcls_MenuButton18(Xcls_GtkView _owner )
+               public Xcls_MenuButton19(Xcls_GtkView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.MenuButton();
@@ -1305,14 +1373,14 @@ public class Xcls_GtkView : Object
                        // my vars (dec)
 
                        // set gobject values
-                       var child_1 = new Xcls_Box20( _this );
+                       var child_1 = new Xcls_Box21( _this );
                        child_1.ref();
                        this.el.set_child ( child_1.el  );
                }
 
                // user defined functions
        }
-       public class Xcls_Box20 : Object
+       public class Xcls_Box21 : Object
        {
                public Gtk.Box el;
                private Xcls_GtkView  _this;
@@ -1321,7 +1389,7 @@ public class Xcls_GtkView : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_Box20(Xcls_GtkView _owner )
+               public Xcls_Box21(Xcls_GtkView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );