Fix #8044 - fixing varous crashes, correct tree drop location and empty nodes after...
[roobuilder] / src / Builder4 / WindowRooView.vala
index fbf63dc..83c4804 100644 (file)
@@ -23,6 +23,7 @@ public class Xcls_WindowRooView : 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;
@@ -697,36 +698,37 @@ public class Xcls_WindowRooView : Object
 
                        //listeners
                        this.el.script_dialog.connect( (dialog) => {
-                           
-                           
-                           if (this.el == null) {
-                               return true;
-                           }
-                           
-                            var msg = dialog.get_message();
-                            if (msg.length < 4) {
-                               return false;
-                            }
-                            
-                            GLib.debug("script dialog got %s", msg);
-                            
-                            if (msg.substring(0,4) != "IPC:") {
-                                return false;
-                            }
-                            var ar = msg.split(":", 3);
-                           if (ar.length < 3) {
-                               return false;
-                           }
                        
-                           switch(ar[1]) {
-                               case "SAVEHTML":
-                                       GLib.debug("GOT saveHTML %d", ar[2].length);
-                                   _this.file.saveHTML(ar[2]);
-                                   _this.createThumb();
-                                   return true;
-                               default:
-                                   return false;
-                           }
+                               if (this.el == null) {
+                                       return true;
+                               }
+                       
+                               var msg = dialog.get_message();
+                               if (msg.length < 4) {
+                                       return false;
+                               }
+                                
+                                //GLib.debug("script dialog got %s", msg);
+                                
+                               if (msg.substring(0,4) != "IPC:") {
+                                       return false;
+                               }
+                               var ar = msg.split(":", 3);
+                               if (ar.length < 3) {
+                                       return false;
+                               }
+                       
+                               switch(ar[1]) {
+                               
+                                       case "SAVEHTML":
+                                        //   GLib.debug("GOT saveHTML %d", ar[2].length);
+                                           _this.file.saveHTML(ar[2]);
+                                           _this.createThumb();
+                                           return true;
+                                           
+                                       default:
+                                           return false;
+                               }
                            
                        });
                        this.el.ready_to_show.connect( ( ) => {
@@ -794,6 +796,7 @@ public class Xcls_WindowRooView : Object
                    }
                     
                    this.refreshRequired  = true;
+                   
                }
                public void reInit () {
                   print("reInit?");
@@ -836,8 +839,7 @@ public class Xcls_WindowRooView : Object
                {
                    // this is run every 2 seconds from the init..
                
-                 
-                   
+                  
                    if (!this.refreshRequired) {
                       // print("no refresh required");
                        return;
@@ -893,7 +895,7 @@ public class Xcls_WindowRooView : Object
                    uint8[] builderhtml;
                    
                    try {
-                       GLib. File.new_for_uri("resources:///html/roo.builder.js").load_contents(null,  out   builderhtml, null);
+                       GLib. File.new_for_uri("resource:///html/roo.builder.js").load_contents(null,  out   builderhtml, null);
                    } catch (Error e) {
                        builderhtml = {};
                    }
@@ -907,12 +909,12 @@ public class Xcls_WindowRooView : Object
                
                    uint8[] inhtml;
                    var base_template = project.base_template;
-                   var f = GLib. File.new_for_uri("resources:///html/" + base_template);
+                   var f = GLib. File.new_for_uri("resource:///html/" + base_template);
                    
                    if (base_template.length > 0 && !f.query_exists(null)) {
                       
-                          GLib.debug("invalid base_template name - using default:  %Scanner", base_template);
-                          f = GLib. File.new_for_uri("resources:///html/roo.builder.html");
+                          GLib.debug("invalid base_template name - using default:  %s", base_template);
+                          f = GLib. File.new_for_uri("resource:///html/roo.builder.html");
                    
                    }
                    try {
@@ -920,6 +922,7 @@ public class Xcls_WindowRooView : Object
                         
                    
                    } catch (Error e) {
+                       GLib.debug("error loading %s : %s", f.get_uri(),e.message);
                        inhtml = {};
                    }    
                    this.renderedData = js;
@@ -947,6 +950,8 @@ public class Xcls_WindowRooView : Object
                    var fc =    FakeServerCache.factory_with_data(js_src);
                    this.runjs = fc.fname;
                    var html  = (string) inhtml;
+                   html = html == null ? "" : html; // fix null?
+                   
                        html = html.replace("</head>", runhtml + this.runhtml + 
                        "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +   
                          //  "<script type=\"text/javascript\">\n" +
@@ -1025,7 +1030,7 @@ public class Xcls_WindowRooView : Object
                        this.el.vexpand = true;
                        new Xcls_sourceviewscroll( _this );
                        this.el.append( _this.sourceviewscroll.el );
-                       var child_2 = new Xcls_Box17( _this );
+                       var child_2 = new Xcls_Box18( _this );
                        child_2.ref();
                        this.el.append( child_2.el );
                }
@@ -1096,9 +1101,11 @@ public class Xcls_WindowRooView : Object
                        this.el.css_classes = { "code-editor" };
                        new Xcls_buffer( _this );
                        this.el.set_buffer ( _this.buffer.el  );
-                       var child_2 = new Xcls_EventControllerKey16( _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_EventControllerScroll17( _this );
+                       child_3.ref();
+                       this.el.add_controller(  child_3.el );
 
                        // init method
 
@@ -1638,28 +1645,40 @@ public class Xcls_WindowRooView : Object
                }
        }
 
-       public class Xcls_EventControllerKey16 : Object
+       public class Xcls_keystate : Object
        {
                public Gtk.EventControllerKey el;
                private Xcls_WindowRooView  _this;
 
 
                        // my vars (def)
+               public bool is_control;
 
                // ctor
-               public Xcls_EventControllerKey16(Xcls_WindowRooView _owner )
+               public Xcls_keystate(Xcls_WindowRooView _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");
@@ -1685,9 +1704,54 @@ public class Xcls_WindowRooView : Object
                // user defined functions
        }
 
+       public class Xcls_EventControllerScroll17 : Object
+       {
+               public Gtk.EventControllerScroll el;
+               private Xcls_WindowRooView  _this;
+
+
+                       // my vars (def)
+               public double distance;
+
+               // ctor
+               public Xcls_EventControllerScroll17(Xcls_WindowRooView _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_Box17 : Object
+       public class Xcls_Box18 : Object
        {
                public Gtk.Box el;
                private Xcls_WindowRooView  _this;
@@ -1696,7 +1760,7 @@ public class Xcls_WindowRooView : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_Box17(Xcls_WindowRooView _owner )
+               public Xcls_Box18(Xcls_WindowRooView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
@@ -1714,7 +1778,7 @@ public class Xcls_WindowRooView : Object
                        this.el.append( _this.nextBtn.el );
                        new Xcls_backBtn( _this );
                        this.el.append( _this.backBtn.el );
-                       var child_5 = new Xcls_MenuButton23( _this );
+                       var child_5 = new Xcls_MenuButton24( _this );
                        child_5.ref();
                        this.el.append( child_5.el );
                }
@@ -1742,7 +1806,7 @@ public class Xcls_WindowRooView : Object
                        this.el.name = "roo-search-entry";
                        this.el.hexpand = true;
                        this.el.placeholder_text = "Press enter to search";
-                       var child_1 = new Xcls_EventControllerKey19( _this );
+                       var child_1 = new Xcls_EventControllerKey20( _this );
                        child_1.ref();
                        this.el.add_controller(  child_1.el );
 
@@ -1787,7 +1851,7 @@ public class Xcls_WindowRooView : Object
                        
                }
        }
-       public class Xcls_EventControllerKey19 : Object
+       public class Xcls_EventControllerKey20 : Object
        {
                public Gtk.EventControllerKey el;
                private Xcls_WindowRooView  _this;
@@ -1796,7 +1860,7 @@ public class Xcls_WindowRooView : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_EventControllerKey19(Xcls_WindowRooView _owner )
+               public Xcls_EventControllerKey20(Xcls_WindowRooView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.EventControllerKey();
@@ -1947,7 +2011,7 @@ public class Xcls_WindowRooView : Object
                // user defined functions
        }
 
-       public class Xcls_MenuButton23 : Object
+       public class Xcls_MenuButton24 : Object
        {
                public Gtk.MenuButton el;
                private Xcls_WindowRooView  _this;
@@ -1957,7 +2021,7 @@ public class Xcls_WindowRooView : Object
                public bool always_show_image;
 
                // ctor
-               public Xcls_MenuButton23(Xcls_WindowRooView _owner )
+               public Xcls_MenuButton24(Xcls_WindowRooView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.MenuButton();
@@ -1991,13 +2055,14 @@ public class Xcls_WindowRooView : Object
                        // my vars (dec)
 
                        // set gobject values
-                       var child_1 = new Xcls_Box25( _this );
+                       var child_1 = new Xcls_Box26( _this );
+                       child_1.ref();
                        this.el.child = child_1.el;
                }
 
                // user defined functions
        }
-       public class Xcls_Box25 : Object
+       public class Xcls_Box26 : Object
        {
                public Gtk.Box el;
                private Xcls_WindowRooView  _this;
@@ -2006,7 +2071,7 @@ public class Xcls_WindowRooView : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_Box25(Xcls_WindowRooView _owner )
+               public Xcls_Box26(Xcls_WindowRooView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );