1 static Xcls_PopoverAddObject _PopoverAddObject;
3 public class Xcls_PopoverAddObject : Object
6 private Xcls_PopoverAddObject _this;
8 public static Xcls_PopoverAddObject singleton()
10 if (_PopoverAddObject == null) {
11 _PopoverAddObject= new Xcls_PopoverAddObject();
13 return _PopoverAddObject;
15 public Xcls_viewwin viewwin;
16 public Xcls_view view;
17 public Xcls_selmodel selmodel;
18 public Xcls_model model;
19 public Xcls_maincol maincol;
22 public signal void before_node_change (JsRender.Node? node);
24 public signal void after_node_change (JsRender.Node? node);
26 public Xcls_MainWindow mainwindow;
29 public Xcls_PopoverAddObject()
32 this.el = new Gtk.Popover();
39 this.el.width_request = 900;
40 this.el.height_request = 800;
41 this.el.hexpand = false;
42 this.el.position = Gtk.PositionType.RIGHT;
43 new Xcls_viewwin( _this );
44 this.el.set_child ( _this.viewwin.el );
47 // user defined functions
48 public void a_clear () {
49 var m = (GLib.ListStore) _this.model.el.model;
55 public void show (Palete.Palete pal, string cls, Gtk.Widget onbtn) {
59 var tr = pal.getChildList(cls, false);
60 var m = (GLib.ListStore) _this.model.el.model;
64 // new version will not support properties here..
65 // they will be part of the properties, clicking will add a node..
66 // will change the return list above eventually?
69 foreach (var dname in tr) {
72 GLib.debug("add to model: %s", dname);
73 m.append(pal.fqnToNode(dname));
77 return Posix.strcmp( ((JsRender.Node)a).fqn(), ((JsRender.Node)b).fqn());
82 var win = this.mainwindow.el;
83 //var w = win.get_width();
84 var h = win.get_height();
87 // left tree = 250, editor area = 500?
91 this.el.set_size_request( 350, h); // full height?
93 this.el.set_parent(onbtn);
95 //if (this.el.relative_to == null) {
96 //Gtk.Allocation rect;
97 //onbtn.get_allocation(out rect);
98 // this.el.set_pointing_to(rect);
100 this.selmodel.el.set_selected(Gtk.INVALID_LIST_POSITION);
104 public void hide () {
108 public class Xcls_viewwin : Object
110 public Gtk.ScrolledWindow el;
111 private Xcls_PopoverAddObject _this;
117 public Xcls_viewwin(Xcls_PopoverAddObject _owner )
120 _this.viewwin = this;
121 this.el = new Gtk.ScrolledWindow();
125 // set gobject values
126 new Xcls_view( _this );
127 this.el.set_child ( _this.view.el );
131 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
132 this.el.set_size_request(-1,200);
135 // user defined functions
137 public class Xcls_view : Object
139 public Gtk.ColumnView el;
140 private Xcls_PopoverAddObject _this;
146 public Xcls_view(Xcls_PopoverAddObject _owner )
150 new Xcls_selmodel( _this );
151 this.el = new Gtk.ColumnView( _this.selmodel.el );
155 // set gobject values
156 this.el.hexpand = true;
157 this.el.vexpand = true;
158 var child_2 = new Xcls_DragSource4( _this );
160 this.el.add_controller( child_2.el );
161 new Xcls_maincol( _this );
162 this.el.append_column ( _this.maincol.el );
163 var child_4 = new Xcls_GestureClick9( _this );
165 this.el.add_controller( child_4.el );
168 // user defined functions
169 public Gtk.Widget? getWidgetAtRow (uint row) {
171 // ?? could be done with model?
173 from https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
174 var colview = gesture.widget;
175 var line_no = check_list_widget(colview, x,y);
177 var item = colview.model.get_item(line_no);
181 GLib.debug("Get Widget At Row %d", (int)row);
182 var child = this.el.get_first_child();
184 var reading_header = true;
186 while (child != null) {
187 GLib.debug("Got %s", child.get_type().name());
188 if (reading_header) {
191 if (child.get_type().name() != "GtkColumnListView") {
192 child = child.get_next_sibling();
195 child = child.get_first_child();
196 reading_header = false;
198 if (child.get_type().name() != "GtkColumnViewRowWidget") {
199 child = child.get_next_sibling();
203 if (line_no == row) {
204 GLib.debug("Returning widget %s", child.get_type().name());
205 return (Gtk.Widget)child;
207 child = child.get_next_sibling();
209 GLib.debug("Rturning null");
213 public int getRowAt (double x, double in_y, out string pos) {
220 from https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
221 var colview = gesture.widget;
222 var line_no = check_list_widget(colview, x,y);
224 var item = colview.model.get_item(line_no);
230 //GLib.debug("offset = %d y = %d", (int) voff, (int) in_y);
231 var y = in_y + _this.viewwin.el.vadjustment.value;
232 var child = this.el.get_first_child();
233 //Gtk.Allocation alloc = { 0, 0, 0, 0 };
235 var reading_header = true;
237 var header_height = 0;
240 while (child != null) {
241 //GLib.debug("Got %s", child.get_type().name());
242 if (reading_header) {
245 if (child.get_type().name() != "GtkColumnListView") {
246 h += child.get_height();
247 child = child.get_next_sibling();
250 // should be columnlistview
251 child = child.get_first_child();
252 GLib.debug("header height=%d", h);
255 reading_header = false;
259 if (child.get_type().name() != "GtkColumnViewRowWidget") {
260 child = child.get_next_sibling();
264 if (y < header_height) {
269 var hh = child.get_height();
270 //child.get_allocation(out alloc);
271 //GLib.debug("got cell xy = %d,%d w,h= %d,%d", alloc.x, alloc.y, alloc.width, alloc.height);
272 //GLib.debug("row %d y= %d %s", line_no, (int) (header_height + alloc.y),
274 // child.visible ? "VIS" : "hidden");
276 if (y > (header_height + real_y) && y <= (header_height + real_y + hh) ) {
277 if (y > ( header_height + real_y + (hh * 0.8))) {
279 } else if (y > ( header_height + real_y + (hh * 0.2))) {
284 GLib.debug("getRowAt return : %d, %s", line_no, pos);
289 if (real_y + hh > y) {
293 child = child.get_next_sibling();
298 public Gtk.Widget? getWidgetAt (double x, double in_y) {
301 from https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
302 var colview = gesture.widget;
303 var line_no = check_list_widget(colview, x,y);
305 var item = colview.model.get_item(line_no);
309 var y = in_y + _this.viewwin.el.vadjustment.value;
310 var child = this.el.get_first_child();
311 //Gtk.Allocation alloc = { 0, 0, 0, 0 };
313 var reading_header = true;
315 var header_height = 0;
317 while (child != null) {
318 //GLib.debug("Got %s", child.get_type().name());
319 if (reading_header) {
322 if (child.get_type().name() != "GtkColumnListView") {
323 h += child.get_height();
324 child = child.get_next_sibling();
327 // should be columnlistview
328 child = child.get_first_child();
329 GLib.debug("header height=%d", h);
332 reading_header = false;
337 if (y < header_height) {
341 var hh = child.get_height();
342 //GLib.debug("got cell xy = %d,%d w,h= %d,%d", alloc.x, alloc.y, alloc.width, alloc.height);
344 if (y > curr_y && y <= header_height + hh + curr_y ) {
345 return (Gtk.Widget)child;
352 child = child.get_next_sibling();
358 public class Xcls_DragSource4 : Object
360 public Gtk.DragSource el;
361 private Xcls_PopoverAddObject _this;
367 public Xcls_DragSource4(Xcls_PopoverAddObject _owner )
370 this.el = new Gtk.DragSource();
374 // set gobject values
375 this.el.actions = Gdk.DragAction.COPY | Gdk.DragAction.MOVE ;
378 this.el.prepare.connect( (x, y) => {
382 /// ( drag_context, data, info, time) => {
385 //print("drag-data-get");
386 var ndata = _this.selmodel.getSelectedNode();
388 GLib.debug("return empty string - no selection..");
394 //data.set_text(tp,tp.length);
396 var str = ndata.toJsonString();
397 GLib.debug("prepare store: %s", str);
398 GLib.Value ov = GLib.Value(typeof(string));
400 var cont = new Gdk.ContentProvider.for_value(ov);
402 //GLib.Value v = GLib.Value(typeof(string));
403 //var str = drop.read_text( [ "text/plain" ] 0);
405 //cont.get_value(ref v);
406 //GLib.debug("set %s", v.get_string());
411 this.el.drag_begin.connect( ( drag ) => {
412 GLib.debug("SOURCE: drag-begin");
414 // find what is selected in our tree...
415 var data = _this.selmodel.getSelectedNode();
420 var xname = data.fqn();
421 GLib.debug ("XNAME IS %s", xname);
423 var widget = _this.view.getWidgetAtRow(_this.selmodel.el.selected);
426 var paintable = new Gtk.WidgetPaintable(widget);
427 this.el.set_icon(paintable, 0,0);
431 this.el.drag_end.connect( (drag, delete_data) => {
437 // user defined functions
440 public class Xcls_selmodel : Object
442 public Gtk.SingleSelection el;
443 private Xcls_PopoverAddObject _this;
449 public Xcls_selmodel(Xcls_PopoverAddObject _owner )
452 _this.selmodel = this;
453 new Xcls_model( _this );
454 this.el = new Gtk.SingleSelection( _this.model.el );
458 // set gobject values
461 // user defined functions
462 public JsRender.Node? getSelectedNode () {
463 if (this.el.selected_item == null) {
466 var tr = (Gtk.TreeListRow)this.el.selected_item;
467 return (JsRender.Node)tr.get_item();
470 public JsRender.Node getNodeAt (uint row) {
472 var tr = (Gtk.TreeListRow)this.el.get_item(row);
474 var a = tr.get_item();;
475 GLib.debug("get_item (2) = %s", a.get_type().name());
477 return (JsRender.Node)tr.get_item();
481 public class Xcls_model : Object
483 public Gtk.TreeListModel el;
484 private Xcls_PopoverAddObject _this;
490 public Xcls_model(Xcls_PopoverAddObject _owner )
494 this.el = new Gtk.TreeListModel(
495 new GLib.ListStore(typeof(JsRender.Node)), //..... << that's our store..
499 return ((JsRender.Node)item).childstore;
508 // set gobject values
511 // user defined functions
515 public class Xcls_maincol : Object
517 public Gtk.ColumnViewColumn el;
518 private Xcls_PopoverAddObject _this;
524 public Xcls_maincol(Xcls_PopoverAddObject _owner )
527 _this.maincol = this;
528 var child_1 = new Xcls_SignalListItemFactory8( _this );
530 this.el = new Gtk.ColumnViewColumn( "Drag to add Object", child_1.el );
534 // set gobject values
535 this.el.id = "maincol";
536 this.el.expand = true;
539 // user defined functions
541 public class Xcls_SignalListItemFactory8 : Object
543 public Gtk.SignalListItemFactory el;
544 private Xcls_PopoverAddObject _this;
550 public Xcls_SignalListItemFactory8(Xcls_PopoverAddObject _owner )
553 this.el = new Gtk.SignalListItemFactory();
557 // set gobject values
560 this.el.setup.connect( (listitem) => {
563 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
564 var icon = new Gtk.Image();
565 var lbl = new Gtk.Label("");
566 lbl.use_markup = true;
569 lbl.justify = Gtk.Justification.LEFT;
571 lbl.margin_start = 4;
572 // listitem.activatable = true; ??
577 ((Gtk.ListItem)listitem).set_child(hbox);
580 this.el.bind.connect( (listitem) => {
581 //GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
583 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
586 var hbox = (Gtk.Box) ((Gtk.ListItem)listitem).get_child();
590 var img = (Gtk.Image) hbox.get_first_child();
591 var lbl = (Gtk.Label) img.get_next_sibling();
593 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
597 var node = (JsRender.Node) lr.get_item();
599 GLib.debug("node is %s", node.get_type().name());
600 GLib.debug("lbl is %s", lbl.get_type().name());
601 GLib.debug("node fqn %s", node.fqn());
602 // was item (1) in old layout
605 img.file = node.iconFilename;
606 lbl.label = node.fqn();
607 // lbl.tooltip_markup = node.nodeTip();
615 // user defined functions
619 public class Xcls_GestureClick9 : Object
621 public Gtk.GestureClick el;
622 private Xcls_PopoverAddObject _this;
628 public Xcls_GestureClick9(Xcls_PopoverAddObject _owner )
631 this.el = new Gtk.GestureClick();
635 // set gobject values
638 this.el.pressed.connect( (n_press, x, y) => {
639 if (n_press < 2) { /// doubleclick?
643 // find left tree selected node
644 var addto = _this.mainwindow.windowstate.left_tree.selmodel.getSelectedNode();
645 //var row = _this.view.getRowAt(x,y, out pos);
647 var add = _this.selmodel.getSelectedNode().deepClone();
648 addto.appendChild(add);
649 _this.mainwindow.windowstate.left_props.changed();
650 _this.mainwindow.windowstate.left_tree.model.selectNode(add);
654 // user defined functions