1 static Xcls_PopoverAddProp _PopoverAddProp;
3 public class Xcls_PopoverAddProp : Object
6 private Xcls_PopoverAddProp _this;
8 public static Xcls_PopoverAddProp singleton()
10 if (_PopoverAddProp == null) {
11 _PopoverAddProp= new Xcls_PopoverAddProp();
13 return _PopoverAddProp;
15 public Xcls_viewwin viewwin;
16 public Xcls_view view;
17 public Xcls_selmodel selmodel;
18 public Xcls_sortmodel sortmodel;
19 public Xcls_model model;
20 public Xcls_name name;
24 public JsRender.NodePropType ptype;
26 public Xcls_MainWindow mainwindow;
27 public JsRender.Node? node;
30 public Xcls_PopoverAddProp()
33 this.el = new Gtk.Popover();
41 this.el.width_request = 900;
42 this.el.height_request = 800;
43 this.el.hexpand = false;
44 this.el.position = Gtk.PositionType.RIGHT;
45 new Xcls_viewwin( _this );
46 this.el.set_child ( _this.viewwin.el );
49 // user defined functions
50 public void show (Palete.Palete pal, JsRender.NodePropType ptype, JsRender.Node node , Gtk.Widget onbtn) {
52 /// what does this do?
53 //if (this.prop_or_listener != "" && this.prop_or_listener == prop_or_listener) {
54 // this.prop_or_listener = "";
60 var xtype = node.fqn();
66 var m = (GLib.ListStore) _this.model.el.model;
70 ///Gee.HashMap<string,GirObject>
71 var elementList = pal.getPropertiesFor( xtype, ptype);
73 //print ("GOT " + elementList.length + " items for " + fullpath + "|" + type);
74 // console.dump(elementList);
76 var miter = elementList.map_iterator();
77 while (miter.next()) {
78 var p = miter.get_value(); // nodeprop.
80 var prop = p.toNodeProp(pal, xtype);
84 if (node.has_prop_key(prop)) {
85 GLib.debug("Skip - has key already %s", prop.name);
89 GLib.debug("Prop add %s", prop.name);
96 var win = this.mainwindow.el;
97 // var w = win.get_width();
98 var h = win.get_height() - 50;
101 // left tree = 250, editor area = 500?
105 this.el.set_size_request( 550, h);
106 //this.el.set_parent(onbtn);
107 _this.view.el.sort_by_column(null, Gtk.SortType.ASCENDING);
108 _this.view.el.sort_by_column(_this.name.el, Gtk.SortType.ASCENDING);
110 //Gtk.Allocation rect;
111 //onbtn.get_allocation(out rect);
112 //this.el.set_pointing_to(rect);
115 //while(Gtk.events_pending()) {
116 // Gtk.main_iteration(); // why?
118 // this.hpane.el.set_position( 0);
120 public void clear () {
121 var m = (GLib.ListStore) _this.model.el.model;
125 public void hide () {
126 this.ptype = JsRender.NodePropType.NONE;
130 public class Xcls_viewwin : Object
132 public Gtk.ScrolledWindow el;
133 private Xcls_PopoverAddProp _this;
139 public Xcls_viewwin(Xcls_PopoverAddProp _owner )
142 _this.viewwin = this;
143 this.el = new Gtk.ScrolledWindow();
147 // set gobject values
148 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
149 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
150 new Xcls_view( _this );
151 this.el.set_child ( _this.view.el );
154 // user defined functions
156 public class Xcls_view : Object
158 public Gtk.ColumnView el;
159 private Xcls_PopoverAddProp _this;
165 public Xcls_view(Xcls_PopoverAddProp _owner )
169 new Xcls_selmodel( _this );
170 this.el = new Gtk.ColumnView( _this.selmodel.el );
174 // set gobject values
175 this.el.single_click_activate = false;
176 this.el.hexpand = true;
177 this.el.vexpand = true;
178 this.el.show_row_separators = true;
179 this.el.show_column_separators = true;
180 this.el.reorderable = true;
181 var child_2 = new Xcls_GestureClick4( _this );
183 this.el.add_controller( child_2.el );
184 new Xcls_name( _this );
185 this.el.append_column ( _this.name.el );
186 var child_4 = new Xcls_ColumnViewColumn13( _this );
188 this.el.append_column ( child_4.el );
189 var child_5 = new Xcls_ColumnViewColumn15( _this );
191 this.el.append_column ( child_5.el );
194 // user defined functions
195 public int getRowAt (double x, double in_y, out string pos) {
202 from https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
203 var colview = gesture.widget;
204 var line_no = check_list_widget(colview, x,y);
206 var item = colview.model.get_item(line_no);
212 //GLib.debug("offset = %d y = %d", (int) voff, (int) in_y);
213 var y = in_y + _this.viewwin.el.vadjustment.value;
214 var child = this.el.get_first_child();
215 //Gtk.Allocation alloc = { 0, 0, 0, 0 };
217 var reading_header = true;
219 var header_height = 0;
222 while (child != null) {
223 //GLib.debug("Got %s", child.get_type().name());
224 if (reading_header) {
227 if (child.get_type().name() != "GtkColumnListView") {
228 h += child.get_height();
229 child = child.get_next_sibling();
232 // should be columnlistview
233 child = child.get_first_child();
234 GLib.debug("header height=%d", h);
237 reading_header = false;
241 if (child.get_type().name() != "GtkColumnViewRowWidget") {
242 child = child.get_next_sibling();
246 if (y < header_height) {
251 var hh = child.get_height();
252 //child.get_allocation(out alloc);
253 //GLib.debug("got cell xy = %d,%d w,h= %d,%d", alloc.x, alloc.y, alloc.width, alloc.height);
254 //GLib.debug("row %d y= %d %s", line_no, (int) (header_height + alloc.y),
256 // child.visible ? "VIS" : "hidden");
258 if (y > (header_height + real_y) && y <= (header_height + real_y + hh) ) {
259 if (y > ( header_height + real_y + (hh * 0.8))) {
261 } else if (y > ( header_height + real_y + (hh * 0.2))) {
266 GLib.debug("getRowAt return : %d, %s", line_no, pos);
271 if (real_y + hh > y) {
275 child = child.get_next_sibling();
281 public class Xcls_GestureClick4 : Object
283 public Gtk.GestureClick el;
284 private Xcls_PopoverAddProp _this;
290 public Xcls_GestureClick4(Xcls_PopoverAddProp _owner )
293 this.el = new Gtk.GestureClick();
297 // set gobject values
300 this.el.pressed.connect( (n_press, x, y) => {
302 if (n_press < 2) { /// doubleclick?
309 var tr = (Gtk.TreeListRow)_this.selmodel.el.selected_item;
310 GLib.debug("SELECTED = %s", tr.item.get_type().name());
311 var prop = (JsRender.NodeProp) tr.item;
316 // var row = _this.view.getRowAt(x,y, out pos );
317 // var prop = _this.sortmodel.getNodeAt(row);
321 if (!prop.name.contains("[]") && _this.node.has_prop_key(prop)) {
322 GLib.debug("node already has this key.");
323 return; // cant add it twice? --
325 // you can not click on ones with children.
327 if (prop.childstore.n_items > 0 ) {
328 GLib.debug("no clicking on expandables");
332 if (prop.add_node != null) {
334 if (!prop.name.contains("[]") && null != _this.node.findProp(prop.name)) {
335 GLib.debug("Add Child already contains child with %s", prop.name);
338 GLib.debug("Add Child Node %s", prop.name);
340 var add = prop.add_node.deepClone();
341 _this.node.appendChild(add);
342 _this.mainwindow.windowstate.left_props.changed();
343 _this.mainwindow.windowstate.left_tree.model.selectNode(add);
349 GLib.debug("Add %s", prop.name);
350 var add = prop.dupe();
351 _this.node.add_prop(add);
352 _this.mainwindow.windowstate.left_props.changed();
353 _this.mainwindow.windowstate.left_props.view.editProp(add);
356 //_this.mainwindow.windowstate.left_props.changed();
361 // user defined functions
364 public class Xcls_selmodel : Object
366 public Gtk.SingleSelection el;
367 private Xcls_PopoverAddProp _this;
373 public Xcls_selmodel(Xcls_PopoverAddProp _owner )
376 _this.selmodel = this;
377 new Xcls_sortmodel( _this );
378 this.el = new Gtk.SingleSelection( _this.sortmodel.el );
382 // set gobject values
383 this.el.can_unselect = true;
386 // user defined functions
387 public JsRender.NodeProp? getNodeAt (uint row) {
389 var tr = (Gtk.TreeListRow)this.el.get_item(row);
391 var a = tr.get_item();;
392 GLib.debug("get_item (2) = %s", a.get_type().name());
394 return (JsRender.NodeProp)tr.get_item();
398 public class Xcls_sortmodel : Object
400 public Gtk.SortListModel el;
401 private Xcls_PopoverAddProp _this;
407 public Xcls_sortmodel(Xcls_PopoverAddProp _owner )
410 _this.sortmodel = this;
411 new Xcls_model( _this );
412 var child_2 = new Xcls_TreeListRowSorter8( _this );
414 this.el = new Gtk.SortListModel( _this.model.el, child_2.el );
418 // set gobject values
423 //this.el.set_sorter(new Gtk.TreeListRowSorter(_this.view.el.sorter));
427 // user defined functions
428 public JsRender.NodeProp? getNodeAt (uint row) {
430 var tr = (Gtk.TreeListRow)this.el.get_item(row);
432 // GLib.debug("get_item (2) = %s", a.get_type().name());
435 return (JsRender.NodeProp)tr.get_item();
439 public class Xcls_model : Object
441 public Gtk.TreeListModel el;
442 private Xcls_PopoverAddProp _this;
448 public Xcls_model(Xcls_PopoverAddProp _owner )
452 this.el = new Gtk.TreeListModel(
453 new GLib.ListStore(typeof(JsRender.NodeProp)), //..... << that's our store..
457 return ((JsRender.NodeProp)item).childstore;
466 // set gobject values
469 // user defined functions
470 public JsRender.NodeProp getNodeAt (uint row) {
472 var tr = (Gtk.TreeListRow)this.el.get_item(row);
474 return (JsRender.NodeProp)tr.get_item();
479 public class Xcls_TreeListRowSorter8 : Object
481 public Gtk.TreeListRowSorter el;
482 private Xcls_PopoverAddProp _this;
488 public Xcls_TreeListRowSorter8(Xcls_PopoverAddProp _owner )
491 var child_1 = new Xcls_StringSorter9( _this );
493 this.el = new Gtk.TreeListRowSorter( child_1.el );
497 // set gobject values
500 // user defined functions
502 public class Xcls_StringSorter9 : Object
504 public Gtk.StringSorter el;
505 private Xcls_PopoverAddProp _this;
511 public Xcls_StringSorter9(Xcls_PopoverAddProp _owner )
514 var child_1 = new Xcls_PropertyExpression10( _this );
516 this.el = new Gtk.StringSorter( child_1.el );
520 // set gobject values
523 // user defined functions
525 public class Xcls_PropertyExpression10 : Object
527 public Gtk.PropertyExpression el;
528 private Xcls_PopoverAddProp _this;
534 public Xcls_PropertyExpression10(Xcls_PopoverAddProp _owner )
537 this.el = new Gtk.PropertyExpression( typeof(JsRender.NodeProp), null, "sort_name" );
541 // set gobject values
544 // user defined functions
551 public class Xcls_name : Object
553 public Gtk.ColumnViewColumn el;
554 private Xcls_PopoverAddProp _this;
560 public Xcls_name(Xcls_PopoverAddProp _owner )
564 var child_1 = new Xcls_SignalListItemFactory12( _this );
566 this.el = new Gtk.ColumnViewColumn( "Double click to add", child_1.el );
570 // set gobject values
572 this.el.expand = true;
573 this.el.resizable = true;
578 this.el.set_sorter( new Gtk.StringSorter(
579 new Gtk.PropertyExpression(typeof(JsRender.NodeProp), null, "name")
585 // user defined functions
587 public class Xcls_SignalListItemFactory12 : Object
589 public Gtk.SignalListItemFactory el;
590 private Xcls_PopoverAddProp _this;
596 public Xcls_SignalListItemFactory12(Xcls_PopoverAddProp _owner )
599 this.el = new Gtk.SignalListItemFactory();
603 // set gobject values
606 this.el.setup.connect( (listitem) => {
608 var expand = new Gtk.TreeExpander();
610 expand.set_indent_for_depth(true);
611 expand.set_indent_for_icon(true);
613 var lbl = new Gtk.Label("");
614 lbl.use_markup = true;
617 lbl.halign = Gtk.Align.START;
621 expand.set_child(lbl);
622 ((Gtk.ListItem)listitem).set_child(expand);
623 ((Gtk.ListItem)listitem).activatable = false;
625 this.el.bind.connect( (listitem) => {
626 //GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
630 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
631 var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
634 var lbl = (Gtk.Label) expand.child;
636 if (lbl.label != "") { // do not update
641 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
642 var np = (JsRender.NodeProp) lr.get_item();
643 GLib.debug("change %s to %s", lbl.label, np.name);
644 lbl.label = np.to_property_option_markup(np.propertyof == _this.node.fqn());
645 lbl.tooltip_markup = np.to_property_option_tooltip();
647 expand.set_hide_expander( np.childstore.n_items < 1);
648 expand.set_list_row(lr);
656 // user defined functions
660 public class Xcls_ColumnViewColumn13 : Object
662 public Gtk.ColumnViewColumn el;
663 private Xcls_PopoverAddProp _this;
669 public Xcls_ColumnViewColumn13(Xcls_PopoverAddProp _owner )
672 var child_1 = new Xcls_SignalListItemFactory14( _this );
674 this.el = new Gtk.ColumnViewColumn( "Type", child_1.el );
678 // set gobject values
679 this.el.expand = true;
680 this.el.resizable = true;
685 this.el.set_sorter( new Gtk.StringSorter(
686 new Gtk.PropertyExpression(typeof(JsRender.NodeProp), null, "rtype")
692 // user defined functions
694 public class Xcls_SignalListItemFactory14 : Object
696 public Gtk.SignalListItemFactory el;
697 private Xcls_PopoverAddProp _this;
703 public Xcls_SignalListItemFactory14(Xcls_PopoverAddProp _owner )
706 this.el = new Gtk.SignalListItemFactory();
710 // set gobject values
713 this.el.setup.connect( (listitem) => {
716 var label = new Gtk.Label("");
717 label.halign = Gtk.Align.START;
719 ((Gtk.ListItem)listitem).set_child(label);
720 ((Gtk.ListItem)listitem).activatable = false;
722 this.el.bind.connect( (listitem) => {
724 var lbl = (Gtk.Label) ((Gtk.ListItem)listitem).get_child();
725 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
726 var np = (JsRender.NodeProp) lr.get_item();
728 if (lbl.label != "") { // do not update
731 lbl.label = np.rtype;
736 // user defined functions
740 public class Xcls_ColumnViewColumn15 : Object
742 public Gtk.ColumnViewColumn el;
743 private Xcls_PopoverAddProp _this;
749 public Xcls_ColumnViewColumn15(Xcls_PopoverAddProp _owner )
752 var child_1 = new Xcls_SignalListItemFactory16( _this );
754 this.el = new Gtk.ColumnViewColumn( "Property of", child_1.el );
758 // set gobject values
759 this.el.expand = true;
760 this.el.resizable = true;
765 this.el.set_sorter( new Gtk.StringSorter(
766 new Gtk.PropertyExpression(typeof(JsRender.NodeProp), null, "propertyof")
772 // user defined functions
774 public class Xcls_SignalListItemFactory16 : Object
776 public Gtk.SignalListItemFactory el;
777 private Xcls_PopoverAddProp _this;
783 public Xcls_SignalListItemFactory16(Xcls_PopoverAddProp _owner )
786 this.el = new Gtk.SignalListItemFactory();
790 // set gobject values
793 this.el.setup.connect( (listitem) => {
796 var label = new Gtk.Label("");
797 label.halign = Gtk.Align.START;
799 ((Gtk.ListItem)listitem).set_child(label);
800 ((Gtk.ListItem)listitem).activatable = false;
802 this.el.bind.connect( (listitem) => {
804 var lbl = (Gtk.Label) ((Gtk.ListItem)listitem).get_child();
805 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
806 var np = (JsRender.NodeProp) lr.get_item();
808 if (lbl.label != "") { // do not update
811 lbl.label = np.propertyof;
816 // user defined functions