Fix #8011 - add resources
[roobuilder] / src / Builder4 / PopoverAddObject.bjs
1 {
2  "build_module" : "",
3  "gen_extended" : false,
4  "items" : [
5   {
6    "$ xns" : "Gtk",
7    "@ void after_node_change" : "(JsRender.Node? node)",
8    "@ void before_node_change" : "(JsRender.Node? node)",
9    "Gtk.PositionType position" : "Gtk.PositionType.RIGHT",
10    "Xcls_MainWindow mainwindow" : "",
11    "bool active" : false,
12    "bool hexpand" : false,
13    "bool modal" : true,
14    "id" : "PopoverAddObject",
15    "int height_request" : 800,
16    "int width_request" : 900,
17    "items" : [
18     {
19      "$ shadow_type" : "Gtk.ShadowType.IN",
20      "$ xns" : "Gtk",
21      "* init" : [
22       "  this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
23       "   this.el.set_size_request(-1,200);",
24       " ",
25       ""
26      ],
27      "* pack" : "set_child",
28      "id" : "viewwin",
29      "items" : [
30       {
31        "$ xns" : "Gtk",
32        "* pack" : "set_child",
33        "bool hexpand" : true,
34        "bool vexpand" : true,
35        "id" : "view",
36        "items" : [
37         {
38          "$ Gdk.DragAction[] actions" : "Gdk.DragAction.COPY   | Gdk.DragAction.MOVE   ",
39          "$ xns" : "Gtk",
40          "listeners" : {
41           "drag_begin" : [
42            "( drag )  => {",
43            "\tGLib.debug(\"SOURCE: drag-begin\");",
44            "\t ",
45            "    // find what is selected in our tree...",
46            "   var data = _this.selmodel.getSelectedNode();",
47            "\tif (data == null) {",
48            "\t\treturn  ;",
49            "\t}",
50            "\t ",
51            "    var xname = data.fqn();",
52            "    GLib.debug (\"XNAME  IS %s\", xname);",
53            "",
54            " \tvar widget = _this.view.getWidgetAtRow(_this.selmodel.el.selected);",
55            " \t",
56            " \t",
57            "    var paintable = new Gtk.WidgetPaintable(widget);",
58            "    this.el.set_icon(paintable, 0,0);",
59            "            ",
60            " ",
61            "}"
62           ],
63           "drag_end" : [
64            "(drag, delete_data) => {",
65            "\t_this.hide();",
66            "",
67            "}",
68            ""
69           ],
70           "prepare" : [
71            "(x, y) => {",
72            "",
73            "\t",
74            "\t",
75            "///\t( drag_context, data, info, time) => {",
76            "            ",
77            "",
78            "\t//print(\"drag-data-get\");",
79            " \tvar ndata = _this.selmodel.getSelectedNode();",
80            "\tif (ndata == null) {",
81            "\t \tGLib.debug(\"return empty string - no selection..\");",
82            "\t\treturn null;",
83            "\t ",
84            "\t}",
85            "",
86            "  ",
87            "\t//data.set_text(tp,tp.length);   ",
88            "",
89            "\tvar \tstr = ndata.toJsonString();",
90            "\tGLib.debug(\"prepare  store: %s\", str);",
91            "\tGLib.Value ov = GLib.Value(typeof(string));",
92            "\tov.set_string(str);",
93            " \tvar cont = new Gdk.ContentProvider.for_value(ov);",
94            "    ",
95            "\t//GLib.Value v = GLib.Value(typeof(string));",
96            "\t//var str = drop.read_text( [ \"text/plain\" ] 0);",
97            "\t ",
98            "\t//cont.get_value(ref v);",
99            "\t//GLib.debug(\"set %s\", v.get_string());",
100            "        ",
101            " \treturn cont;",
102            "\t  ",
103            "}",
104            ""
105           ]
106          },
107          "xtype" : "DragSource"
108         },
109         {
110          "$ xns" : "Gtk",
111          "* prop" : "model",
112          "id" : "selmodel",
113          "items" : [
114           {
115            "$ xns" : "Gtk",
116            "* ctor" : [
117             "new Gtk.TreeListModel(",
118             "    new GLib.ListStore(typeof(JsRender.Node)), //..... << that's our store..",
119             "    false, // passthru",
120             "    true, // autexpand",
121             "    (item) => {",
122             "    \treturn ((JsRender.Node)item).childstore;",
123             "    ",
124             "    }",
125             "    ",
126             "    ",
127             ")"
128            ],
129            "* prop" : "model",
130            "id" : "model",
131            "xtype" : "TreeListModel"
132           }
133          ],
134          "xtype" : "SingleSelection",
135          "| JsRender.Node getNodeAt" : [
136           "(uint row) {",
137           "",
138           "   var tr = (Gtk.TreeListRow)this.el.get_item(row);",
139           "   ",
140           "   var a = tr.get_item();;   ",
141           "   GLib.debug(\"get_item (2) = %s\", a.get_type().name());",
142           "    ",
143           "   return (JsRender.Node)tr.get_item();",
144           "\t ",
145           "}"
146          ],
147          "| JsRender.Node? getSelectedNode" : [
148           "() {",
149           "  if (this.el.selected_item == null) {",
150           "\t\treturn null;",
151           "  }\t\t\t        ",
152           "   var tr = (Gtk.TreeListRow)this.el.selected_item;",
153           "   return (JsRender.Node)tr.get_item();",
154           "\t ",
155           "}"
156          ]
157         },
158         {
159          "$ xns" : "Gtk",
160          "* pack" : "append_column",
161          "bool expand" : true,
162          "id" : "maincol",
163          "items" : [
164           {
165            "$ xns" : "Gtk",
166            "* prop" : "factory",
167            "listeners" : {
168             "bind" : [
169              "(listitem) => {",
170              "\t //GLib.debug(\"listitme is is %s\", ((Gtk.ListItem)listitem).get_type().name());",
171              "\t",
172              "\t//var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();",
173              " ",
174              "\t ",
175              " \tvar hbox = (Gtk.Box)  ((Gtk.ListItem)listitem).get_child();",
176              " ",
177              " ",
178              "\t",
179              "\tvar img = (Gtk.Image) hbox.get_first_child();",
180              "\tvar lbl = (Gtk.Label) img.get_next_sibling();",
181              "\t",
182              "\tvar lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();",
183              "\t",
184              "\t",
185              "\t",
186              "\tvar node = (JsRender.Node) lr.get_item();",
187              "\t",
188              "   GLib.debug(\"node is %s\", node.get_type().name());",
189              "   GLib.debug(\"lbl is %s\", lbl.get_type().name());",
190              "   GLib.debug(\"node fqn %s\", node.fqn());",
191              "// was item (1) in old layout",
192              "",
193              "\t ",
194              " \timg.resource = node.iconResourceName;",
195              " \tlbl.label =  node.fqn();",
196              "// \tlbl.tooltip_markup = node.nodeTip();",
197              " ",
198              "  ",
199              " \t// bind image...",
200              " \t",
201              "}",
202              ""
203             ],
204             "setup" : [
205              "(listitem) => {",
206              "\t",
207              " ",
208              "\tvar hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);",
209              "\tvar icon = new Gtk.Image();",
210              "\tvar lbl = new Gtk.Label(\"\");",
211              "\tlbl.use_markup = true;",
212              "\t",
213              "\t",
214              " \tlbl.justify = Gtk.Justification.LEFT;",
215              " \tlbl.xalign = 0;",
216              "\tlbl.margin_start = 4;",
217              "//\tlistitem.activatable = true; ??",
218              "\t",
219              "\thbox.append(icon);",
220              "\thbox.append(lbl);",
221              "\t ",
222              "\t((Gtk.ListItem)listitem).set_child(hbox);",
223              "\t ",
224              "}",
225              ""
226             ]
227            },
228            "xtype" : "SignalListItemFactory"
229           }
230          ],
231          "title" : "Drag to add Object",
232          "xtype" : "ColumnViewColumn"
233         },
234         {
235          "$ xns" : "Gtk",
236          "listeners" : {
237           "pressed" : [
238            "(n_press, x, y) => {",
239            "\tif (n_press < 2) { /// doubleclick?",
240            "\t\treturn;",
241            "\t}",
242            "\t//var pos = \"\";",
243            "\t// find left tree selected node",
244            "\tvar addto = _this.mainwindow.windowstate.left_tree.selmodel.getSelectedNode();",
245            "\t//var row = _this.view.getRowAt(x,y, out pos);",
246            "\t",
247            " \t var add = _this.selmodel.getSelectedNode().deepClone();",
248            "\taddto.appendChild(add);",
249            "\t_this.mainwindow.windowstate.left_props.changed();",
250            "\t_this.mainwindow.windowstate.left_tree.model.selectNode(add);",
251            "}",
252            ""
253           ]
254          },
255          "xtype" : "GestureClick"
256         }
257        ],
258        "xtype" : "ColumnView",
259        "| Gtk.Widget? getWidgetAt" : [
260         "(double x,  double in_y) {",
261         "/*",
262         "    \t",
263         "from    \thttps://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465",
264         "    \tvar colview = gesture.widget;",
265         "    \tvar line_no = check_list_widget(colview, x,y);",
266         "         if (line_no > -1) {",
267         "    \t\tvar item = colview.model.get_item(line_no);",
268         "    \t\t ",
269         "    \t}",
270         "    \t*/",
271         "    \tvar y = in_y + _this.viewwin.el.vadjustment.value; ",
272         "        var  child = this.el.get_first_child(); ",
273         "    \t//Gtk.Allocation alloc = { 0, 0, 0, 0 };",
274         "    \tvar line_no = -1; ",
275         "    \tvar reading_header = true;",
276         "    \tvar curr_y = 0;",
277         "    \tvar header_height  = 0;",
278         "    \tvar h = 0;",
279         "    \twhile (child != null) {",
280         "\t\t\t//GLib.debug(\"Got %s\", child.get_type().name());",
281         "\t        if (reading_header) {",
282         "\t\t\t\t",
283         "",
284         "\t\t\t\tif (child.get_type().name() != \"GtkColumnListView\") {",
285         "\t\t\t        h += child.get_height();",
286         "\t\t\t\t\tchild = child.get_next_sibling();",
287         "\t\t\t\t\tcontinue;",
288         "\t\t\t\t}",
289         "\t\t\t\t// should be columnlistview",
290         "\t\t\t\tchild = child.get_first_child(); ",
291         "\t\t\t    GLib.debug(\"header height=%d\", h);",
292         "\t\t\t\theader_height =  h;",
293         "\t\t\t\t",
294         "\t\t\t\treading_header = false;",
295         "\t\t\t\t",
296         "\t        }",
297         "\t\t    line_no++;",
298         "",
299         "\t\t\tif (y < header_height) {",
300         "\t\t    \treturn null;",
301         "\t    \t}",
302         "",
303         "\t\t\tvar hh = child.get_height();",
304         "\t\t\t//GLib.debug(\"got cell xy = %d,%d  w,h= %d,%d\", alloc.x, alloc.y, alloc.width, alloc.height);",
305         "",
306         "\t\t    if (y > curr_y && y <= header_height + hh + curr_y ) {",
307         "\t\t\t    return (Gtk.Widget)child;",
308         "\t\t    }",
309         "\t\t    curr_y +=  hh ;",
310         "",
311         "\t\t    if (curr_y > y) {",
312         "\t\t        return null;",
313         "\t        }",
314         "\t        child = child.get_next_sibling(); ",
315         "    \t}",
316         "        return null;",
317         "",
318         " }"
319        ],
320        "| Gtk.Widget? getWidgetAtRow" : [
321         "(uint row) {",
322         "/*",
323         "// ?? could be done with model?",
324         "    \t",
325         "from    \thttps://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465",
326         "    \tvar colview = gesture.widget;",
327         "    \tvar line_no = check_list_widget(colview, x,y);",
328         "         if (line_no > -1) {",
329         "    \t\tvar item = colview.model.get_item(line_no);",
330         "    \t\t ",
331         "    \t}",
332         "    \t*/",
333         "\t\tGLib.debug(\"Get Widget At Row %d\", (int)row);",
334         "        var  child = this.el.get_first_child(); ",
335         "    \tvar line_no = -1; ",
336         "    \tvar reading_header = true;",
337         "",
338         "    \twhile (child != null) {",
339         "\t\t\tGLib.debug(\"Got %s\", child.get_type().name());",
340         "    \t    if (reading_header) {",
341         "\t\t\t ",
342         "\t\t\t   ",
343         "\t\t\t\tif (child.get_type().name() != \"GtkColumnListView\") {",
344         "\t\t\t\t\tchild = child.get_next_sibling();",
345         "\t\t\t\t\tcontinue;",
346         "\t\t\t\t}",
347         "\t\t\t\tchild = child.get_first_child(); ",
348         "\t\t\t\treading_header = false;",
349         "\t        }",
350         "\t\t    if (child.get_type().name() != \"GtkColumnViewRowWidget\") {",
351         "    \t\t    child = child.get_next_sibling();",
352         "    \t\t    continue;",
353         "\t\t    }",
354         "\t\t    line_no++;",
355         "\t\t\tif (line_no == row) {",
356         "\t\t\t\tGLib.debug(\"Returning widget %s\", child.get_type().name());",
357         "\t\t\t    return (Gtk.Widget)child;",
358         "\t\t    }",
359         "\t        child = child.get_next_sibling(); ",
360         "    \t}",
361         "\t\tGLib.debug(\"Rturning null\");",
362         "        return null;",
363         "",
364         " }"
365        ],
366        "| int getRowAt" : [
367         "(double x,  double in_y, out string pos) {",
368         "",
369         "",
370         "\t ",
371         "",
372         "/*",
373         "    \t",
374         "from    \thttps://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465",
375         "    \tvar colview = gesture.widget;",
376         "    \tvar line_no = check_list_widget(colview, x,y);",
377         "         if (line_no > -1) {",
378         "    \t\tvar item = colview.model.get_item(line_no);",
379         "    \t\t ",
380         "    \t}",
381         "    \t*/",
382         " \t\t ",
383         " \t\t",
384         " \t\t//GLib.debug(\"offset = %d  y = %d\", (int) voff, (int) in_y);",
385         "    \tvar y = in_y + _this.viewwin.el.vadjustment.value; ",
386         "        var  child = this.el.get_first_child(); ",
387         "    \t//Gtk.Allocation alloc = { 0, 0, 0, 0 };",
388         "    \tvar line_no = -1; ",
389         "    \tvar reading_header = true;",
390         "    \tvar real_y = 0;",
391         "    \tvar header_height  = 0;",
392         "    \tpos = \"none\";",
393         "    \tvar h = 0;",
394         "    \twhile (child != null) {",
395         "\t\t\t//GLib.debug(\"Got %s\", child.get_type().name());",
396         "    \t    if (reading_header) {",
397         "\t\t\t\t",
398         "",
399         "\t\t\t\tif (child.get_type().name() != \"GtkColumnListView\") {",
400         "\t\t\t        h += child.get_height();",
401         "\t\t\t\t\tchild = child.get_next_sibling();",
402         "\t\t\t\t\tcontinue;",
403         "\t\t\t\t}",
404         "\t\t\t\t// should be columnlistview",
405         "\t\t\t\tchild = child.get_first_child(); ",
406         "\t\t\t    GLib.debug(\"header height=%d\", h);",
407         "\t\t\t\theader_height =  h;",
408         "\t\t\t\t",
409         "\t\t\t\treading_header = false;",
410         "\t\t\t\t",
411         "\t        }",
412         "\t        ",
413         "\t\t    if (child.get_type().name() != \"GtkColumnViewRowWidget\") {",
414         "    \t\t    child = child.get_next_sibling();",
415         "    \t\t    continue;",
416         "\t\t    }",
417         "\t\t    ",
418         "\t\t \tif (y < header_height) {",
419         "\t\t    \treturn -1;",
420         "\t    \t}",
421         "\t\t    ",
422         "\t\t    line_no++;",
423         "\t\t\tvar hh = child.get_height();",
424         "\t\t\t//child.get_allocation(out alloc);",
425         "\t\t\t//GLib.debug(\"got cell xy = %d,%d  w,h= %d,%d\", alloc.x, alloc.y, alloc.width, alloc.height);",
426         "\t\t\t//GLib.debug(\"row %d y= %d %s\", line_no, (int) (header_height + alloc.y),",
427         "\t\t\t",
428         "\t\t\t//\tchild.visible ? \"VIS\" : \"hidden\");",
429         "",
430         "\t\t    if (y >  (header_height + real_y) && y <= (header_height +  real_y + hh) ) {",
431         "\t\t    \tif (y > ( header_height + real_y + (hh * 0.8))) {",
432         "\t\t    \t\tpos = \"below\";",
433         "\t    \t\t} else if (y > ( header_height + real_y + (hh * 0.2))) {",
434         "\t    \t\t\tpos = \"over\";",
435         "    \t\t\t} else {",
436         "    \t\t\t\tpos = \"above\";",
437         "\t\t\t\t}",
438         "\t\t    \t GLib.debug(\"getRowAt return : %d, %s\", line_no, pos);",
439         "\t\t\t    return line_no;",
440         "\t\t    }",
441         " ",
442         "",
443         "\t\t    if (real_y + hh > y) {",
444         "\t\t        return -1;",
445         "\t        }",
446         "\t        real_y += hh;",
447         "\t        child = child.get_next_sibling(); ",
448         "    \t}",
449         "        return -1;",
450         "",
451         " }"
452        ]
453       }
454      ],
455      "xtype" : "ScrolledWindow"
456     }
457    ],
458    "xtype" : "Popover",
459    "| void a_clear" : [
460     "() {",
461     "    var m = (GLib.ListStore) _this.model.el.model;",
462     "\tm.remove_all();",
463     "",
464     "\t",
465     "",
466     "}",
467     ""
468    ],
469    "| void hide" : [
470     "() {",
471     " ",
472     "\tthis.el.hide();",
473     "}",
474     ""
475    ],
476    "| void show" : [
477     "(Palete.Palete pal, string cls,  Gtk.Widget onbtn) {",
478     "",
479     "     ",
480     "",
481     "    var tr = pal.getChildList(cls, false);",
482     "    var m = (GLib.ListStore) _this.model.el.model;",
483     "\tm.remove_all();",
484     "",
485     "\t",
486     "\t// new version will not support properties here..",
487     "\t// they will be part of the properties, clicking will add a node..",
488     "\t// will change the return list above eventually?",
489     "\t",
490     " ",
491     "\tforeach (var dname in tr) {",
492     "\t\t ",
493     "",
494     "\t\tGLib.debug(\"add to model: %s\", dname);\t\t",
495     "\t\tm.append(pal.fqnToNode(dname));",
496     "\t}",
497     "\t m.sort( (a, b) => {",
498     "",
499     "\t\t\treturn Posix.strcmp( ((JsRender.Node)a).fqn(),  ((JsRender.Node)b).fqn());",
500     "\t\t\t",
501     "\t\t});",
502     "\t ",
503     "    ",
504     "    var win = this.mainwindow.el;",
505     "    //var  w = win.get_width();",
506     "    var h = win.get_height();",
507     "",
508     "    ",
509     "    // left tree = 250, editor area = 500?",
510     "    ",
511     "    // min 450?",
512     "\t// max hieght ...",
513     "    this.el.set_size_request( 350, h); // full height?",
514     "",
515     "      this.el.set_parent(onbtn);",
516     "",
517     "    //if (this.el.relative_to == null) {",
518     "    \t//Gtk.Allocation rect;",
519     "    \t//onbtn.get_allocation(out rect);",
520     "      //  this.el.set_pointing_to(rect);",
521     "    //}",
522     "    this.selmodel.el.set_selected(Gtk.INVALID_LIST_POSITION);",
523     "    this.el.show();",
524     "   ",
525     "}",
526     ""
527    ]
528   }
529  ],
530  "name" : "PopoverAddObject"
531 }