Merge branch 'master' of http://git.roojs.com/roobuilder
[roobuilder] / src / Builder4 / PopoverAddProp.bjs
1 {
2  "build_module" : "",
3  "gen_extended" : false,
4  "items" : [
5   {
6    "# JsRender.NodePropType ptype" : "",
7    "$ xns" : "Gtk",
8    "* ctor" : "new Gtk.Popover()",
9    "Gtk.PositionType position" : "Gtk.PositionType.RIGHT",
10    "JsRender.Node? node" : "null",
11    "Xcls_MainWindow mainwindow" : "",
12    "bool active" : false,
13    "bool hexpand" : false,
14    "bool modal" : true,
15    "id" : "PopoverAddProp",
16    "int height_request" : 800,
17    "int width_request" : 900,
18    "items" : [
19     {
20      "$ shadow_type" : "Gtk.ShadowType.IN",
21      "$ xns" : "Gtk",
22      "* pack" : "set_child",
23      "Gtk.PolicyType hscrollbar_policy" : "Gtk.PolicyType.AUTOMATIC",
24      "Gtk.PolicyType vscrollbar_policy" : "Gtk.PolicyType.AUTOMATIC",
25      "id" : "viewwin",
26      "items" : [
27       {
28        "$ xns" : "Gtk",
29        "* pack" : "set_child",
30        "bool hexpand" : true,
31        "bool reorderable" : true,
32        "bool show_column_separators" : true,
33        "bool show_row_separators" : true,
34        "bool single_click_activate" : false,
35        "bool vexpand" : true,
36        "id" : "view",
37        "items" : [
38         {
39          "$ xns" : "Gtk",
40          "listeners" : {
41           "pressed" : [
42            "(n_press, x, y) => {",
43            " ",
44            "\tif (n_press < 2) { /// doubleclick?",
45            "\t\treturn;",
46            "\t}",
47            "\t//string pos;",
48            "\t",
49            "\t",
50            "\t// use selection?!",
51            "\tvar tr = (Gtk.TreeListRow)_this.selmodel.el.selected_item;",
52            "\tGLib.debug(\"SELECTED = %s\", tr.item.get_type().name());",
53            "\tvar prop = (JsRender.NodeProp) tr.item;",
54            "",
55            "\t",
56            "\t",
57            "\t// double press ? ",
58            "//\tvar row = _this.view.getRowAt(x,y, out pos );",
59            "//\tvar prop  = _this.sortmodel.getNodeAt(row);",
60            " ",
61            "//\t_this.select(np);",
62            "\t",
63            "\tif (!prop.name.contains(\"[]\") && _this.node.has_prop_key(prop)) {",
64            "\t\tGLib.debug(\"node already has this key.\");",
65            "\t\treturn; // cant add it twice? --  ",
66            "\t}",
67            "\t// you can not click on ones with children.",
68            "\t",
69            "\tif (prop.childstore.n_items > 0 ) {",
70            "\t\tGLib.debug(\"no clicking on expandables\");",
71            "\t\treturn;",
72            "\t}",
73            "\t// if it's a node...",
74            "\tif (prop.add_node != null) {",
75            "",
76            "\t\tif (!prop.name.contains(\"[]\") && null != _this.node.findProp(prop.name)) {",
77            "\t\t\tGLib.debug(\"Add Child already contains child with %s\", prop.name);\t",
78            "\t\t\treturn;\t\t\t\t\t",
79            "\t\t}",
80            "\t\t GLib.debug(\"Add Child Node %s\", prop.name);\t\t\t",
81            "\t\t _this.el.hide();",
82            "\t\t var add = prop.add_node.deepClone();",
83            "\t\t_this.node.appendChild(add);",
84            "\t\t _this.mainwindow.windowstate.left_props.changed();",
85            "\t\t _this.mainwindow.windowstate.left_tree.model.selectNode(add);",
86            "\t\t ",
87            "\t\treturn;",
88            "\t}",
89            "\t",
90            "\t_this.el.hide();",
91            "\tGLib.debug(\"Add %s\", prop.name);",
92            "\tvar add = prop.dupe();",
93            "\t_this.node.add_prop(add);",
94            "\t _this.mainwindow.windowstate.left_props.changed();",
95            " \t_this.mainwindow.windowstate.left_props.view.editProp(add);",
96            "\t",
97            "",
98            "\t //_this.mainwindow.windowstate.left_props.changed();",
99            "",
100            "}",
101            ""
102           ]
103          },
104          "xtype" : "GestureClick"
105         },
106         {
107          "$ xns" : "Gtk",
108          "* prop" : "model",
109          "bool can_unselect" : true,
110          "id" : "selmodel",
111          "items" : [
112           {
113            "$ xns" : "Gtk",
114            "* init" : [
115             "{",
116             "\t//this.el.set_sorter(new Gtk.TreeListRowSorter(_this.view.el.sorter));",
117             "}",
118             ""
119            ],
120            "* prop" : "model",
121            "id" : "sortmodel",
122            "items" : [
123             {
124              "$ xns" : "Gtk",
125              "* ctor" : [
126               "new Gtk.TreeListModel(",
127               "    new GLib.ListStore(typeof(JsRender.NodeProp)), //..... << that's our store..",
128               "    false, // passthru",
129               "    false, // autexpand",
130               "    (item) => {",
131               "    \treturn ((JsRender.NodeProp)item).childstore;",
132               "    ",
133               "    }",
134               "    ",
135               "    ",
136               ")"
137              ],
138              "* prop" : "model",
139              "id" : "model",
140              "xtype" : "TreeListModel",
141              "| JsRender.NodeProp getNodeAt" : [
142               "(uint row) {",
143               "",
144               "   var tr = (Gtk.TreeListRow)this.el.get_item(row);",
145               "    ",
146               "   return (JsRender.NodeProp)tr.get_item();",
147               "\t ",
148               "}"
149              ]
150             },
151             {
152              "$ xns" : "Gtk",
153              "* prop" : "sorter",
154              "items" : [
155               {
156                "$ xns" : "Gtk",
157                "* prop" : "sorter",
158                "items" : [
159                 {
160                  "$ xns" : "Gtk",
161                  "* prop" : "expression",
162                  "GLib.Type this_type" : "typeof(JsRender.NodeProp)",
163                  "string property_name" : "sort_name",
164                  "xtype" : "PropertyExpression"
165                 }
166                ],
167                "xtype" : "StringSorter"
168               }
169              ],
170              "xtype" : "TreeListRowSorter"
171             }
172            ],
173            "xtype" : "SortListModel",
174            "| JsRender.NodeProp? getNodeAt" : [
175             "(uint row) {",
176             "",
177             "   var tr = (Gtk.TreeListRow)this.el.get_item(row);",
178             "   ",
179             "    // GLib.debug(\"get_item (2) = %s\", a.get_type().name());",
180             "  \t",
181             "   ",
182             "   return (JsRender.NodeProp)tr.get_item();",
183             "\t ",
184             "}"
185            ]
186           }
187          ],
188          "xtype" : "SingleSelection",
189          "| JsRender.NodeProp? getNodeAt" : [
190           "(uint row) {",
191           "",
192           "   var tr = (Gtk.TreeListRow)this.el.get_item(row);",
193           "   ",
194           "   var a = tr.get_item();;   ",
195           "   GLib.debug(\"get_item (2) = %s\", a.get_type().name());",
196           "    ",
197           "   return (JsRender.NodeProp)tr.get_item();",
198           "\t ",
199           "}"
200          ]
201         },
202         {
203          "$ xns" : "Gtk",
204          "* init" : [
205           "{",
206           "\t this.el.set_sorter(  new Gtk.StringSorter(",
207           "\t \tnew Gtk.PropertyExpression(typeof(JsRender.NodeProp), null, \"name\")",
208           " \t));",
209           "\t\t",
210           "}",
211           ""
212          ],
213          "* pack" : "append_column",
214          "bool expand" : true,
215          "bool resizable" : true,
216          "id" : "name",
217          "items" : [
218           {
219            "$ xns" : "Gtk",
220            "* prop" : "factory",
221            "listeners" : {
222             "bind" : [
223              "(listitem) => {",
224              "\t //GLib.debug(\"listitme is is %s\", ((Gtk.ListItem)listitem).get_type().name());",
225              "\t",
226              "\t",
227              "\t",
228              "\t//var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();",
229              "\tvar expand = (Gtk.TreeExpander)  ((Gtk.ListItem)listitem).get_child();",
230              "\t  ",
231              " ",
232              "\tvar lbl = (Gtk.Label) expand.child;",
233              "\t",
234              "\t if (lbl.label != \"\") { // do not update",
235              "\t \treturn;",
236              " \t}",
237              "\t",
238              "",
239              "\tvar lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();",
240              "\tvar np = (JsRender.NodeProp) lr.get_item();",
241              "\tGLib.debug(\"change  %s to %s\", lbl.label, np.name);",
242              "\tlbl.label = np.to_property_option_markup(np.propertyof == _this.node.fqn());",
243              "\tlbl.tooltip_markup = np.to_property_option_tooltip();",
244              "\t ",
245              "    expand.set_hide_expander(  np.childstore.n_items < 1);",
246              " \texpand.set_list_row(lr);",
247              " ",
248              " \t ",
249              " \t// bind image...",
250              " \t",
251              "}",
252              ""
253             ],
254             "setup" : [
255              "(listitem) => {",
256              "\t",
257              "\tvar expand = new Gtk.TreeExpander();",
258              "\t ",
259              "\texpand.set_indent_for_depth(true);",
260              "\texpand.set_indent_for_icon(true);",
261              "\t ",
262              "\tvar lbl = new Gtk.Label(\"\");",
263              "\tlbl.use_markup = true;",
264              "\t",
265              "\t",
266              " \tlbl.halign = Gtk.Align.START;",
267              " \tlbl.xalign = 0;",
268              "",
269              " ",
270              "\texpand.set_child(lbl);",
271              "\t((Gtk.ListItem)listitem).set_child(expand);",
272              "\t((Gtk.ListItem)listitem).activatable = false;",
273              "}",
274              ""
275             ]
276            },
277            "xtype" : "SignalListItemFactory"
278           }
279          ],
280          "string title" : "Double click to add",
281          "xtype" : "ColumnViewColumn"
282         },
283         {
284          "$ xns" : "Gtk",
285          "* init" : [
286           "{",
287           "\t this.el.set_sorter(  new Gtk.StringSorter(",
288           "\t \tnew Gtk.PropertyExpression(typeof(JsRender.NodeProp), null, \"rtype\")",
289           " \t));",
290           "\t\t",
291           "}",
292           ""
293          ],
294          "* pack" : "append_column",
295          "bool expand" : true,
296          "bool resizable" : true,
297          "items" : [
298           {
299            "$ xns" : "Gtk",
300            "* prop" : "factory",
301            "listeners" : {
302             "bind" : [
303              "(listitem) => {",
304              "\t",
305              " \tvar lbl = (Gtk.Label) ((Gtk.ListItem)listitem).get_child(); ",
306              " \tvar lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();",
307              "\tvar np = (JsRender.NodeProp) lr.get_item();",
308              "\t",
309              "  if (lbl.label != \"\") { // do not update",
310              "\t \treturn;",
311              " \t}",
312              "\tlbl.label = np.rtype;",
313              " \t ",
314              "}",
315              ""
316             ],
317             "setup" : [
318              "(listitem) => {",
319              "",
320              "\t ",
321              "\tvar label = new Gtk.Label(\"\");",
322              " \tlabel.halign = Gtk.Align.START;",
323              " \tlabel.xalign = 0;",
324              "\t((Gtk.ListItem)listitem).set_child(label);",
325              "\t((Gtk.ListItem)listitem).activatable = false;",
326              "}",
327              ""
328             ]
329            },
330            "xtype" : "SignalListItemFactory"
331           }
332          ],
333          "string title" : "Type",
334          "xtype" : "ColumnViewColumn"
335         },
336         {
337          "$ xns" : "Gtk",
338          "* init" : [
339           "{",
340           "\t this.el.set_sorter(  new Gtk.StringSorter(",
341           "\t \tnew Gtk.PropertyExpression(typeof(JsRender.NodeProp), null, \"propertyof\")",
342           " \t));",
343           "\t\t",
344           "}",
345           ""
346          ],
347          "* pack" : "append_column",
348          "bool expand" : true,
349          "bool resizable" : true,
350          "items" : [
351           {
352            "$ xns" : "Gtk",
353            "* prop" : "factory",
354            "listeners" : {
355             "bind" : [
356              "(listitem) => {",
357              "",
358              " \tvar lbl = (Gtk.Label) ((Gtk.ListItem)listitem).get_child(); ",
359              " \tvar lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();",
360              "\tvar np = (JsRender.NodeProp) lr.get_item();",
361              "\t",
362              "  if (lbl.label != \"\") { // do not update",
363              "\t \treturn;",
364              " \t}",
365              "\tlbl.label = np.propertyof;",
366              " \t ",
367              "}",
368              ""
369             ],
370             "setup" : [
371              "(listitem) => {",
372              "",
373              "\t ",
374              "\tvar label = new Gtk.Label(\"\");",
375              "\tlabel.halign = Gtk.Align.START;",
376              " \tlabel.xalign = 0;",
377              "\t((Gtk.ListItem)listitem).set_child(label);",
378              "\t((Gtk.ListItem)listitem).activatable = false;",
379              "}",
380              ""
381             ]
382            },
383            "xtype" : "SignalListItemFactory"
384           }
385          ],
386          "string title" : "Property of",
387          "xtype" : "ColumnViewColumn"
388         }
389        ],
390        "xtype" : "ColumnView",
391        "| int getRowAt" : [
392         "(double x,  double in_y, out string pos) {",
393         "",
394         "",
395         "\t ",
396         "",
397         "/*",
398         "    \t",
399         "from    \thttps://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465",
400         "    \tvar colview = gesture.widget;",
401         "    \tvar line_no = check_list_widget(colview, x,y);",
402         "         if (line_no > -1) {",
403         "    \t\tvar item = colview.model.get_item(line_no);",
404         "    \t\t ",
405         "    \t}",
406         "    \t*/",
407         " \t\t ",
408         " \t\t",
409         " \t\t//GLib.debug(\"offset = %d  y = %d\", (int) voff, (int) in_y);",
410         "    \tvar y = in_y + _this.viewwin.el.vadjustment.value; ",
411         "        var  child = this.el.get_first_child(); ",
412         "    \t//Gtk.Allocation alloc = { 0, 0, 0, 0 };",
413         "    \tvar line_no = -1; ",
414         "    \tvar reading_header = true;",
415         "    \tvar real_y = 0;",
416         "    \tvar header_height  = 0;",
417         "    \tpos = \"none\";",
418         "    \tvar h = 0;",
419         "    \twhile (child != null) {",
420         "\t\t\t//GLib.debug(\"Got %s\", child.get_type().name());",
421         "    \t    if (reading_header) {",
422         "\t\t\t\t",
423         "",
424         "\t\t\t\tif (child.get_type().name() != \"GtkColumnListView\") {",
425         "\t\t\t        h += child.get_height();",
426         "\t\t\t\t\tchild = child.get_next_sibling();",
427         "\t\t\t\t\tcontinue;",
428         "\t\t\t\t}",
429         "\t\t\t\t// should be columnlistview",
430         "\t\t\t\tchild = child.get_first_child(); ",
431         "\t\t\t    GLib.debug(\"header height=%d\", h);",
432         "\t\t\t\theader_height =  h;",
433         "\t\t\t\t",
434         "\t\t\t\treading_header = false;",
435         "\t\t\t\t",
436         "\t        }",
437         "\t        ",
438         "\t\t    if (child.get_type().name() != \"GtkColumnViewRowWidget\") {",
439         "    \t\t    child = child.get_next_sibling();",
440         "    \t\t    continue;",
441         "\t\t    }",
442         "\t\t    ",
443         "\t\t \tif (y < header_height) {",
444         "\t\t    \treturn -1;",
445         "\t    \t}",
446         "\t\t    ",
447         "\t\t    line_no++;",
448         "\t\t\tvar hh = child.get_height();",
449         "\t\t\t//child.get_allocation(out alloc);",
450         "\t\t\t//GLib.debug(\"got cell xy = %d,%d  w,h= %d,%d\", alloc.x, alloc.y, alloc.width, alloc.height);",
451         "\t\t\t//GLib.debug(\"row %d y= %d %s\", line_no, (int) (header_height + alloc.y),",
452         "\t\t\t",
453         "\t\t\t//\tchild.visible ? \"VIS\" : \"hidden\");",
454         "",
455         "\t\t    if (y >  (header_height + real_y) && y <= (header_height +  real_y + hh) ) {",
456         "\t\t    \tif (y > ( header_height + real_y + (hh * 0.8))) {",
457         "\t\t    \t\tpos = \"below\";",
458         "\t    \t\t} else if (y > ( header_height + real_y + (hh * 0.2))) {",
459         "\t    \t\t\tpos = \"over\";",
460         "    \t\t\t} else {",
461         "    \t\t\t\tpos = \"above\";",
462         "\t\t\t\t}",
463         "\t\t    \t GLib.debug(\"getRowAt return : %d, %s\", line_no, pos);",
464         "\t\t\t    return line_no;",
465         "\t\t    }",
466         " ",
467         "",
468         "\t\t    if (real_y + hh > y) {",
469         "\t\t        return -1;",
470         "\t        }",
471         "\t        real_y += hh;",
472         "\t        child = child.get_next_sibling(); ",
473         "    \t}",
474         "        return -1;",
475         "",
476         " }"
477        ]
478       }
479      ],
480      "xtype" : "ScrolledWindow"
481     }
482    ],
483    "xtype" : "Popover",
484    "| void clear" : [
485     "() {",
486     "  var m = (GLib.ListStore) _this.model.el.model;",
487     "\tm.remove_all();",
488     "",
489     "}",
490     ""
491    ],
492    "| void hide" : [
493     "() {",
494     "\tthis.ptype = JsRender.NodePropType.NONE;",
495     "\tthis.el.hide();",
496     "\tthis.node = null;",
497     "}",
498     ""
499    ],
500    "| void show" : [
501     "(Palete.Palete pal, JsRender.NodePropType ptype, JsRender.Node node ,  Gtk.Widget onbtn) {",
502     "",
503     "    /// what does this do?",
504     "    //if (this.prop_or_listener  != \"\" && this.prop_or_listener == prop_or_listener) {",
505     "    //\tthis.prop_or_listener = \"\";",
506     "    //\tthis.el.hide();",
507     "    //\treturn;",
508     "\t//}",
509     "\tthis.node = node;",
510     "\t",
511     "\tvar xtype = node.fqn();",
512     "\t",
513     "\t// ",
514     "\t",
515     "    this.ptype = ptype;",
516     "    ",
517     " \t var m = (GLib.ListStore) _this.model.el.model;",
518     "\t m.remove_all();",
519     " ",
520     "    ",
521     "    ///Gee.HashMap<string,GirObject>",
522     "    var elementList = pal.getPropertiesFor( xtype, ptype);",
523     "     ",
524     "    //print (\"GOT \" + elementList.length + \" items for \" + fullpath + \"|\" + type);",
525     "           // console.dump(elementList);",
526     "           ",
527     "    var miter = elementList.map_iterator();",
528     "    while (miter.next()) {",
529     "        var p = miter.get_value(); // nodeprop.",
530     "          ",
531     "\t\tvar prop = p.toNodeProp(pal, xtype);",
532     "\t\tif (prop == null) {",
533     "\t\t\tcontinue;",
534     "\t\t}",
535     "\t\tif (node.has_prop_key(prop)) {",
536     "\t\t\tGLib.debug(\"Skip - has key already %s\",  prop.name);",
537     "\t\t\tcontinue;\t\t\t",
538     "\t\t}",
539     "\t\t//JsRender.NodeProp",
540     "\t\tGLib.debug(\"Prop add %s\",  prop.name);",
541     "\t \t m.append(prop);",
542     "    }",
543     "    ",
544     "    // set size up...",
545     "    ",
546     " ",
547     "     var win = this.mainwindow.el;",
548     "   // var  w = win.get_width();",
549     "    var h = win.get_height() - 50;",
550     "",
551     "",
552     "    // left tree = 250, editor area = 500?",
553     "    ",
554     "    // min 450?",
555     "\t// max hieght ...",
556     "    this.el.set_size_request( 550, h);",
557     "    //this.el.set_parent(onbtn);",
558     "\t_this.view.el.sort_by_column(null, Gtk.SortType.ASCENDING);",
559     "\t_this.view.el.sort_by_column(_this.name.el, Gtk.SortType.ASCENDING);",
560     "",
561     "\t//Gtk.Allocation rect;",
562     "\t//onbtn.get_allocation(out rect);",
563     "\t//this.el.set_pointing_to(rect);",
564     "    this.el.show();",
565     "   ",
566     "    //while(Gtk.events_pending()) { ",
567     "    //        Gtk.main_iteration();   // why?",
568     "    //}       ",
569     " //   this.hpane.el.set_position( 0);",
570     "}",
571     ""
572    ]
573   }
574  ],
575  "name" : "PopoverAddProp"
576 }