Fix #7258 - close editor x, and remove text on edit - fix crash on delete prop
authorAlan <alan@roojs.com>
Thu, 9 Jun 2022 09:55:11 +0000 (17:55 +0800)
committerAlan <alan@roojs.com>
Thu, 9 Jun 2022 09:55:11 +0000 (17:55 +0800)
src/Builder4/Editor.bjs
src/Builder4/Editor.vala
src/Builder4/GladeuiView.bjs
src/Builder4/GladeuiView.vala
src/Builder4/WindowLeftProps.bjs
src/Builder4/WindowLeftProps.vala

index 09b381e..bc3ef1f 100644 (file)
      "items" : [
       {
        "$ xns" : "Gtk",
-       "* pack" : "pack_start,false,false",
+       "* pack" : "add",
+       "bool always_show_image" : true,
        "id" : "save_button",
+       "items" : [
+        {
+         "$ xns" : "Gtk",
+         "* prop" : "image",
+         "string icon_name" : "document-save",
+         "xtype" : "Image"
+        }
+       ],
        "label" : "Save",
        "listeners" : {
         "clicked" : [
       },
       {
        "$ xns" : "Gtk",
-       "* pack" : "pack_start,true,true",
-       "bool editable" : false,
-       "id" : "key_edit",
-       "int width_request" : 100,
-       "xtype" : "Entry"
+       "* pack" : "add",
+       "bool hexpand" : true,
+       "xtype" : "Label"
       },
       {
        "$ xns" : "Gtk",
         "}",
         ""
        ],
-       "* pack" : "pack_end,true,true",
+       "* pack" : "add",
        "bool draw_value" : true,
        "bool has_origin" : true,
        "bool sensitive" : true,
        "int digits" : 0,
+       "int width_request" : 200,
        "listeners" : {
         "change_value" : [
          "(st, val ) => {",
         ]
        },
        "xtype" : "HScale"
+      },
+      {
+       "$ xns" : "Gtk",
+       "* pack" : "add",
+       "bool always_show_image" : true,
+       "id" : "close_btn",
+       "items" : [
+        {
+         "$ xns" : "Gtk",
+         "* prop" : "image",
+         "string icon_name" : "window-close",
+         "xtype" : "Image"
+        }
+       ],
+       "listeners" : {
+        "clicked" : [
+         " () => { ",
+         "    _this.saveContents();",
+         "    _this.window.windowstate.switchState(WindowState.State.PREVIEW);",
+         "}",
+         "  "
+        ]
+       },
+       "xtype" : "Button"
       }
      ],
      "xtype" : "Box"
      "xtype" : "ScrolledWindow"
     }
    ],
-   "string id" : "Editor",
    "xtype" : "Box",
    "|   void show" : [
     "(JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)",
     "",
     "        // find the text for the node..",
     "        this.view.load( prop.val );",
-    "        this.key_edit.el.show();",
-    "        this.key_edit.el.text = prop.rtype +  \" \" + prop.name;  ",
+    "        this.close_btn.el.show();       ",
     "    ",
     "    } else {",
     "        this.view.load(        file.toSource() );",
-    "        this.key_edit.el.hide();",
+    "        this.close_btn.el.hide();",
     "    }",
     " ",
     "}"
     "",
     "\tif (this.searchcontext == null) {",
     "\t\treturn;",
-    "\t}",
+    "\t} ",
     "\t",
     "\tGtk.TextIter beg, st,en;",
     "\t ",
index 6e09c4e..47357be 100644 (file)
@@ -13,7 +13,7 @@ public class Editor : Object
         return _Editor;
     }
     public Xcls_save_button save_button;
-    public Xcls_key_edit key_edit;
+    public Xcls_close_btn close_btn;
     public Xcls_RightEditor RightEditor;
     public Xcls_view view;
     public Xcls_buffer buffer;
@@ -107,12 +107,11 @@ public class Editor : Object
     
             // find the text for the node..
             this.view.load( prop.val );
-            this.key_edit.el.show();
-            this.key_edit.el.text = prop.rtype +  " " + prop.name;  
+            this.close_btn.el.show();       
         
         } else {
             this.view.load(        file.toSource() );
-            this.key_edit.el.hide();
+            this.close_btn.el.hide();
         }
      
     }
@@ -154,7 +153,7 @@ public class Editor : Object
     
        if (this.searchcontext == null) {
                return;
-       }
+       } 
        
        Gtk.TextIter beg, st,en;
         
@@ -200,13 +199,16 @@ public class Editor : Object
             this.el.homogeneous = false;
             var child_0 = new Xcls_save_button( _this );
             child_0.ref();
-            this.el.pack_start (  child_0.el , false,false );
-            var child_1 = new Xcls_key_edit( _this );
+            this.el.add (  child_0.el  );
+            var child_1 = new Xcls_Label5( _this );
             child_1.ref();
-            this.el.pack_start (  child_1.el , true,true );
-            var child_2 = new Xcls_HScale5( _this );
+            this.el.add (  child_1.el  );
+            var child_2 = new Xcls_HScale6( _this );
             child_2.ref();
-            this.el.pack_end (  child_2.el , true,true );
+            this.el.add (  child_2.el  );
+            var child_3 = new Xcls_close_btn( _this );
+            child_3.ref();
+            this.el.add (  child_3.el  );
         }
 
         // user defined functions
@@ -229,7 +231,11 @@ public class Editor : Object
             // my vars (dec)
 
             // set gobject values
+            this.el.always_show_image = true;
             this.el.label = "Save";
+            var child_0 = new Xcls_Image4( _this );
+            child_0.ref();
+            this.el.image = child_0.el;
 
             //listeners
             this.el.clicked.connect( () => { 
@@ -239,33 +245,54 @@ public class Editor : Object
 
         // user defined functions
     }
+    public class Xcls_Image4 : Object
+    {
+        public Gtk.Image el;
+        private Editor  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_Image4(Editor _owner )
+        {
+            _this = _owner;
+            this.el = new Gtk.Image();
+
+            // my vars (dec)
+
+            // set gobject values
+            this.el.icon_name = "document-save";
+        }
 
-    public class Xcls_key_edit : Object
+        // user defined functions
+    }
+
+
+    public class Xcls_Label5 : Object
     {
-        public Gtk.Entry el;
+        public Gtk.Label el;
         private Editor  _this;
 
 
             // my vars (def)
 
         // ctor
-        public Xcls_key_edit(Editor _owner )
+        public Xcls_Label5(Editor _owner )
         {
             _this = _owner;
-            _this.key_edit = this;
-            this.el = new Gtk.Entry();
+            this.el = new Gtk.Label( null );
 
             // my vars (dec)
 
             // set gobject values
-            this.el.width_request = 100;
-            this.el.editable = false;
+            this.el.hexpand = true;
         }
 
         // user defined functions
     }
 
-    public class Xcls_HScale5 : Object
+    public class Xcls_HScale6 : Object
     {
         public Gtk.HScale el;
         private Editor  _this;
@@ -274,7 +301,7 @@ public class Editor : Object
             // my vars (def)
 
         // ctor
-        public Xcls_HScale5(Editor _owner )
+        public Xcls_HScale6(Editor _owner )
         {
             _this = _owner;
             this.el = new Gtk.HScale.with_range (6, 30, 1);
@@ -282,6 +309,7 @@ public class Editor : Object
             // my vars (dec)
 
             // set gobject values
+            this.el.width_request = 200;
             this.el.has_origin = true;
             this.el.draw_value = true;
             this.el.digits = 0;
@@ -308,6 +336,62 @@ public class Editor : Object
         // user defined functions
     }
 
+    public class Xcls_close_btn : Object
+    {
+        public Gtk.Button el;
+        private Editor  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_close_btn(Editor _owner )
+        {
+            _this = _owner;
+            _this.close_btn = this;
+            this.el = new Gtk.Button();
+
+            // my vars (dec)
+
+            // set gobject values
+            this.el.always_show_image = true;
+            var child_0 = new Xcls_Image8( _this );
+            child_0.ref();
+            this.el.image = child_0.el;
+
+            //listeners
+            this.el.clicked.connect( () => { 
+                _this.saveContents();
+                _this.window.windowstate.switchState(WindowState.State.PREVIEW);
+            });
+        }
+
+        // user defined functions
+    }
+    public class Xcls_Image8 : Object
+    {
+        public Gtk.Image el;
+        private Editor  _this;
+
+
+            // my vars (def)
+
+        // ctor
+        public Xcls_Image8(Editor _owner )
+        {
+            _this = _owner;
+            this.el = new Gtk.Image();
+
+            // my vars (dec)
+
+            // set gobject values
+            this.el.icon_name = "window-close";
+        }
+
+        // user defined functions
+    }
+
+
 
     public class Xcls_RightEditor : Object
     {
index e86094a..140566e 100644 (file)
         "     ",
         "}",
         ""
+       ],
+       "| void test" : [
+        "() {",
+        "",
+        "}"
        ]
       },
       {
index fcb43e0..fdbb057 100644 (file)
@@ -20,12 +20,12 @@ public class Xcls_GladeuiView : Object
 
         // my vars (def)
     public Gtk.Widget lastObj;
+    public Xcls_MainWindow main_window;
+    public Gtk.SourceSearchContext searchcontext;
     public int last_search_end;
     public int width;
-    public Gtk.SourceSearchContext searchcontext;
     public JsRender.JsRender file;
     public int height;
-    public Xcls_MainWindow main_window;
 
     // ctor
     public Xcls_GladeuiView()
@@ -56,26 +56,85 @@ public class Xcls_GladeuiView : Object
     }
 
     // user defined functions
-    public void scroll_to_line (int line) {
-       this.notebook.el.page = 1;// code preview...
-       
-       GLib.Timeout.add(500, () => {
-       
-       
-          
-          
-                 var buf = this.sourceview.el.get_buffer();
+    public void loadFile (JsRender.JsRender file)
+    {
+        
+    
+        this.file = file;
+        
+    
+            // clear existing elements from project?
+            
+            var  p = this.designview.el.get_project();
+            var    li = p.get_objects().copy();
+            // should remove all..
+            for (var i =0;    i < li.length(); i++) {   
+                p.remove_object(li.nth_data(i)); 
+            }
+    
+            if (file.tree == null) {
+                return;
+            }
+    
+    //        print("%s\n",tf.tree.toJsonString());
+       var x =  new JsRender.NodeToGlade((Project.Gtk) file.project, file.tree,  null);
+        Glade.App.set_window(_this.main_window.el); // see if setting it again forces it to go to the irght locations.
         
-               var sbuf = (Gtk.SourceBuffer) buf;
+    FileIOStream iostream;
+       var  f = File.new_tmp ("tpl-XXXXXX.glade", out iostream);
+       var ostream = iostream.output_stream;
+       var dostream = new DataOutputStream (ostream);
+       dostream.put_string (x.munge());
+       this.el.show();
+        print("LOADING %s\n",f.get_path ());
+          //p.load_from_file(f.get_path ());
+            
+         p.load_from_file("/tmp/glade.xml");
     
+    }
+    public void initGlade () {
+        _this.designview =  new Xcls_designview( _this );
+        
+        var box = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
+        
+        _this.notebook.el.append_page(box, _this.label_preview.el);
+            Glade.App.set_window(this.main_window.el);
+       // var  pal = new Glade.Palette();
+        //var ins = new Glade.Inspector();
     
-               Gtk.TextIter iter;   
-               sbuf.get_iter_at_line(out iter,  line);
-               this.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
-               return false;
-       });   
+        box.pack_start(_this.designview.el);
+       // box.pack_start(pal);
+        //box.pack_start(ins);
+         // pal.show();
+       // ins.show();
+        _this.designview.el.show();
+        box.show_all();         
+        
+    }
+    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 int search (string txt) {
        this.notebook.el.page = 1;
@@ -136,85 +195,26 @@ public class Xcls_GladeuiView : Object
         
          
     }
-    public void loadFile (JsRender.JsRender file)
-    {
-        
-    
-        this.file = file;
-        
-    
-            // clear existing elements from project?
-            
-            var  p = this.designview.el.get_project();
-            var    li = p.get_objects().copy();
-            // should remove all..
-            for (var i =0;    i < li.length(); i++) {   
-                p.remove_object(li.nth_data(i)); 
-            }
-    
-            if (file.tree == null) {
-                return;
-            }
-    
-    //        print("%s\n",tf.tree.toJsonString());
-       var x =  new JsRender.NodeToGlade((Project.Gtk) file.project, file.tree,  null);
-        Glade.App.set_window(_this.main_window.el); // see if setting it again forces it to go to the irght locations.
+    public void scroll_to_line (int line) {
+       this.notebook.el.page = 1;// code preview...
+       
+       GLib.Timeout.add(500, () => {
+       
+       
+          
+          
+                 var buf = this.sourceview.el.get_buffer();
         
-    FileIOStream iostream;
-       var  f = File.new_tmp ("tpl-XXXXXX.glade", out iostream);
-       var ostream = iostream.output_stream;
-       var dostream = new DataOutputStream (ostream);
-       dostream.put_string (x.munge());
-       this.el.show();
-        print("LOADING %s\n",f.get_path ());
-          //p.load_from_file(f.get_path ());
-            
-         p.load_from_file("/tmp/glade.xml");
-    
-    }
-    public void forwardSearch (bool change_focus) {
+               var sbuf = (Gtk.SourceBuffer) buf;
     
-       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 void initGlade () {
-        _this.designview =  new Xcls_designview( _this );
-        
-        var box = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
-        
-        _this.notebook.el.append_page(box, _this.label_preview.el);
-            Glade.App.set_window(this.main_window.el);
-       // var  pal = new Glade.Palette();
-        //var ins = new Glade.Inspector();
+               Gtk.TextIter iter;   
+               sbuf.get_iter_at_line(out iter,  line);
+               this.sourceview.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
+               return false;
+       });   
     
-        box.pack_start(_this.designview.el);
-       // box.pack_start(pal);
-        //box.pack_start(ins);
-         // pal.show();
-       // ins.show();
-        _this.designview.el.show();
-        box.show_all();         
-        
+       
     }
     public class Xcls_notebook : Object
     {
@@ -300,7 +300,6 @@ public class Xcls_GladeuiView : Object
 
 
             // my vars (def)
-        public JsRender.JsRender file;
 
         // ctor
         public Xcls_designview(Xcls_GladeuiView _owner )
@@ -310,9 +309,6 @@ public class Xcls_GladeuiView : Object
             this.el = _this.main_window == null ? null : new Glade.DesignView(_this.main_window.gladeproject);
 
             // my vars (dec)
-            this.file = null;
-
-            // set gobject values
 
             // init method
 
@@ -320,6 +316,9 @@ public class Xcls_GladeuiView : Object
         }
 
         // user defined functions
+        public void test () {
+        
+        }
         public void createThumb () {
             
             
@@ -473,73 +472,6 @@ public class Xcls_GladeuiView : Object
         }
 
         // user defined functions
-        public string toString () {
-           Gtk.TextIter s;
-            Gtk.TextIter e;
-            this.el.get_buffer().get_start_iter(out s);
-            this.el.get_buffer().get_end_iter(out e);
-            var ret = this.el.get_buffer().get_text(s,e,true);
-            //print("TO STRING? " + ret);
-            return ret;
-        }
-        public void nodeSelected (JsRender.Node? sel) {
-          
-            
-          
-            // this is connected in widnowstate
-            print("Roo-view - node selected\n");
-            var buf = this.el.get_buffer();
-         
-            var sbuf = (Gtk.SourceBuffer) buf;
-        
-           
-            while(Gtk.events_pending()) {
-                Gtk.main_iteration();
-            }
-            
-           
-            // clear all the marks..
-             Gtk.TextIter start;
-            Gtk.TextIter end;     
-                
-            sbuf.get_bounds (out start, out end);
-            sbuf.remove_source_marks (start, end, "grey");
-            
-            
-             if (sel == null) {
-                // no highlighting..
-                return;
-            }
-            Gtk.TextIter iter;   
-            sbuf.get_iter_at_line(out iter,  sel.line_start);
-            
-            
-            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) {
-                   
-                    sbuf.get_iter_at_line(out iter, i);
-                    sbuf.create_source_mark(null, "grey", iter);
-                    
-                }
-            
-            }
-            
-        
-        }
         public void loadFile ( ) {
         
             
@@ -610,6 +542,64 @@ public class Xcls_GladeuiView : Object
            // }
             
             this.loading = false; 
+        }
+        public void nodeSelected (JsRender.Node? sel) {
+          
+            
+          
+            // this is connected in widnowstate
+            print("Roo-view - node selected\n");
+            var buf = this.el.get_buffer();
+         
+            var sbuf = (Gtk.SourceBuffer) buf;
+        
+           
+            while(Gtk.events_pending()) {
+                Gtk.main_iteration();
+            }
+            
+           
+            // clear all the marks..
+             Gtk.TextIter start;
+            Gtk.TextIter end;     
+                
+            sbuf.get_bounds (out start, out end);
+            sbuf.remove_source_marks (start, end, "grey");
+            
+            
+             if (sel == null) {
+                // no highlighting..
+                return;
+            }
+            Gtk.TextIter iter;   
+            sbuf.get_iter_at_line(out iter,  sel.line_start);
+            
+            
+            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) {
+                   
+                    sbuf.get_iter_at_line(out iter, i);
+                    sbuf.create_source_mark(null, "grey", iter);
+                    
+                }
+            
+            }
+            
+        
         }
         public void highlightErrorsJson (string type, Json.Object obj) {
               Gtk.TextIter start;
@@ -683,6 +673,15 @@ public class Xcls_GladeuiView : Object
          
         
         
+        }
+        public string toString () {
+           Gtk.TextIter s;
+            Gtk.TextIter e;
+            this.el.get_buffer().get_start_iter(out s);
+            this.el.get_buffer().get_end_iter(out e);
+            var ret = this.el.get_buffer().get_text(s,e,true);
+            //print("TO STRING? " + ret);
+            return ret;
         }
     }
 
index 40d6613..4ff9887 100644 (file)
     "        GLib.Value gval;",
     "        mod.get_value(iter, 0 , out gval);",
     "        var prop = (JsRender.NodeProp)gval;",
-    "        ",
+    "        if (prop == null) {",
+    "        \treturn;",
+    "    \t}",
     "        switch(prop.ptype) {",
     "            case JsRender.NodePropType.LISTENER:",
     "                this.node.listeners.unset(prop.to_index_key());",
index ba6d570..fb97fd6 100644 (file)
@@ -355,7 +355,9 @@ public class Xcls_LeftProps : Object
             GLib.Value gval;
             mod.get_value(iter, 0 , out gval);
             var prop = (JsRender.NodeProp)gval;
-            
+            if (prop == null) {
+               return;
+               }
             switch(prop.ptype) {
                 case JsRender.NodePropType.LISTENER:
                     this.node.listeners.unset(prop.to_index_key());