fix language server save, node edit trigger compile, render update on gtkview source
[roobuilder] / src / Builder4 / PopoverProperty.bjs
1 {
2  "build_module" : "builder",
3  "gen_extended" : false,
4  "items" : [
5   {
6    "# Gtk.PositionType position" : "Gtk.PositionType.RIGHT",
7    "# JsRender.Node node" : "",
8    "# JsRender.NodeProp? original_prop" : "null",
9    "# JsRender.NodeProp? prop" : "null",
10    "# Xcls_MainWindow mainwindow" : "null",
11    "# string key_type" : "",
12    "# string old_keyname" : "",
13    "$ xns" : "Gtk",
14    "* ctor" : "new Gtk.Popover()",
15    "@ void success" : "(Project.Project pr, JsRender.JsRender file)",
16    "bool autohide" : true,
17    "bool done" : false,
18    "bool is_new" : false,
19    "id" : "PopoverProperty",
20    "items" : [
21     {
22      "$ xns" : "Gtk",
23      "* pack" : "set_child",
24      "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
25      "bool homogeneous" : false,
26      "items" : [
27       {
28        "$ xns" : "Gtk",
29        "bool show_title_buttons" : false,
30        "id" : "header",
31        "items" : [
32         {
33          "$ xns" : "Gtk",
34          "* prop" : "title_widget",
35          "id" : "headertitle",
36          "string label" : "Add / Edit property",
37          "xtype" : "Label"
38         }
39        ],
40        "xtype" : "HeaderBar"
41       },
42       {
43        "$ xns" : "Gtk",
44        "bool show_row_separators" : true,
45        "bool show_separators" : true,
46        "id" : "ptype",
47        "items" : [
48         {
49          "$ xns" : "Gtk",
50          "* prop" : "model",
51          "id" : "pselmodel",
52          "items" : [
53           {
54            "$ xns" : "GLib",
55            "* ctor" : "new GLib.ListStore(typeof(JsRender.NodeProp));",
56            "* init" : [
57             "{",
58             "",
59             "",
60             "\tthis.el.append( new JsRender.NodeProp.prop(\"\"));",
61             "\tthis.el.append( new JsRender.NodeProp.raw(\"\"));",
62             "\tthis.el.append( new JsRender.NodeProp.valamethod(\"\"));",
63             "\tthis.el.append( new JsRender.NodeProp.special(\"\"));\t",
64             "\tthis.el.append( new JsRender.NodeProp.listener(\"\"));\t\t",
65             "\tthis.el.append( new JsRender.NodeProp.user(\"\"));\t",
66             "\tthis.el.append( new JsRender.NodeProp.sig(\"\"));\t",
67             "\t",
68             "",
69             "}",
70             ""
71            ],
72            "* prop" : "model",
73            "id" : "pmodel",
74            "xtype" : "ListStore"
75           }
76          ],
77          "xtype" : "SingleSelection"
78         },
79         {
80          "$ xns" : "Gtk",
81          "* pack" : "append_column",
82          "items" : [
83           {
84            "$ xns" : "Gtk",
85            "* prop" : "factory",
86            "listeners" : {
87             "bind" : [
88              "(listitem) => {",
89              "",
90              " \tvar lbl = (Gtk.Label) ((Gtk.ListItem)listitem).get_child(); ",
91              " \tvar np = (JsRender.NodeProp)((Gtk.ListItem)listitem).get_item();",
92              " ",
93              "\t",
94              "  ",
95              "\tlbl.label = np.ptype.to_name();",
96              " \t ",
97              "}",
98              ""
99             ],
100             "setup" : [
101              "(listitem) => {",
102              "",
103              "\t ",
104              "\tvar label = new Gtk.Label(\"\");",
105              "\tlabel.xalign = 0;",
106              "\t ",
107              "\t((Gtk.ListItem)listitem).set_child(label);",
108              "\t((Gtk.ListItem)listitem).activatable = false;",
109              "\t",
110              "}",
111              ""
112             ]
113            },
114            "xtype" : "SignalListItemFactory"
115           }
116          ],
117          "string title" : "Property Type",
118          "xtype" : "ColumnViewColumn"
119         }
120        ],
121        "xtype" : "ColumnView",
122        "| JsRender.NodePropType getValue" : [
123         "() {",
124         "\t",
125         "\tvar li =  (JsRender.NodeProp) _this.pmodel.el.get_item(",
126         "\t\t_this.pselmodel.el.get_selected()",
127         "\t\t);",
128         "\treturn li.ptype;",
129         "",
130         "}"
131        ],
132        "| void setValue" : [
133         "(JsRender.NodePropType pt) ",
134         "{",
135         " \tfor (var i = 0; i < _this.pmodel.el.n_items; i++) {",
136         "\t \tvar li = (JsRender.NodeProp) _this.pmodel.el.get_item(i);",
137         " \t\tif (li.ptype == pt) {",
138         " \t\t\t_this.pselmodel.el.set_selected(i);",
139         " \t\t\treturn;",
140         "\t\t}",
141         "\t}",
142         "\tGLib.debug(\"failed to set selected ptype\");",
143         "\t_this.pselmodel.el.set_selected(0);",
144         "}"
145        ]
146       },
147       {
148        "$ visible" : true,
149        "$ xns" : "Gtk",
150        "Gtk.Align halign" : "Gtk.Align.START",
151        "Gtk.Justification justify" : "Gtk.Justification.LEFT",
152        "int margin_top" : 12,
153        "label" : "Type or Return Type",
154        "x_options" : 4,
155        "xtype" : "Label"
156       },
157       {
158        "$ visible" : true,
159        "$ xns" : "Gtk",
160        "id" : "ktype",
161        "xtype" : "Entry"
162       },
163       {
164        "$ visible" : true,
165        "$ xns" : "Gtk",
166        "Gtk.Align halign" : "Gtk.Align.START",
167        "Gtk.Justification justify" : "Gtk.Justification.LEFT",
168        "int margin_top" : 12,
169        "label" : "Name",
170        "tooltip_text" : "center, north, south, east, west",
171        "x_options" : 4,
172        "xtype" : "Label"
173       },
174       {
175        "$ visible" : true,
176        "$ xns" : "Gtk",
177        "id" : "kname",
178        "items" : [
179         {
180          "$ xns" : "Gtk",
181          "listeners" : {
182           "leave" : [
183            "( ) => {",
184            "",
185            "    _this.error.setError(\"\");",
186            "\tvar val = _this.kname.el.get_text().strip(); ",
187            "\tif (val.length < 1) {",
188            "\t\t_this.error.setError(\"Name can not be empty\");",
189            "\t}",
190            "",
191            "}",
192            ""
193           ]
194          },
195          "xtype" : "EventControllerFocus"
196         },
197         {
198          "$ xns" : "Gtk",
199          "listeners" : {
200           "key_released" : [
201            "(keyval, keycode, state) => {",
202            "",
203            "    _this.error.setError(\"\");",
204            "\tvar val = _this.kname.el.get_text().strip(); ",
205            "\tif (val.length < 1) {",
206            "\t\t_this.error.setError(\"Name can not be empty\");",
207            "\t}",
208            "",
209            "}",
210            ""
211           ]
212          },
213          "xtype" : "EventControllerKey"
214         }
215        ],
216        "xtype" : "Entry"
217       },
218       {
219        "$ visible" : true,
220        "$ xns" : "Gtk",
221        "Gtk.Align halign" : "Gtk.Align.START",
222        "Gtk.Justification justify" : "Gtk.Justification.LEFT",
223        "bool use_markup" : true,
224        "id" : "error",
225        "int margin_top" : 0,
226        "label" : "<span color=\"red\">Error Message</span>",
227        "tooltip_text" : "center, north, south, east, west",
228        "x_options" : 4,
229        "xtype" : "Label",
230        "| void setError" : [
231         "(string err)   {",
232         "\tif (err == \"\") {",
233         "\t\tthis.el.label = \"\";",
234         "\t} else {",
235         "",
236         "\t\t",
237         "\t\tthis.el.label = \"<span color=\\\"red\\\">\" + err + \"</span>\";",
238         "\t}",
239         "}",
240         ""
241        ]
242       },
243       {
244        "$ xns" : "Gtk",
245        "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
246        "id" : "buttonbar",
247        "int margin_top" : 20,
248        "items" : [
249         {
250          "$ xns" : "Gtk",
251          "bool always_show_image" : true,
252          "bool hexpand" : true,
253          "listeners" : {
254           "clicked" : [
255            "() => {",
256            "\t_this.prop = null;",
257            "\t_this.is_new = false;",
258            "\t_this.kname.el.set_text(\"Cancel\");",
259            "\t_this.el.hide();",
260            "\t",
261            "}"
262           ]
263          },
264          "string label" : "Cancel",
265          "xtype" : "Button"
266         },
267         {
268          "$ xns" : "Gtk",
269          "bool always_show_image" : true,
270          "bool hexpand" : true,
271          "listeners" : {
272           "clicked" : [
273            "() => {",
274            "\t// check if text is not empty..",
275            "\tif ( _this.kname.el.get_text().strip().length < 1) {",
276            "\t",
277            "\t\t// error should already be showing?",
278            "\t\treturn;",
279            "\t}",
280            "\t ",
281            "\t// since we can't add listeners?!?!?",
282            "\t// only check props.",
283            "\t// check if property already exists in node.\t",
284            "",
285            "",
286            "\tvar prop = new JsRender.NodeProp(",
287            "\t\t_this.kname.el.get_text().strip(),",
288            "\t\t_this.ptype.getValue(),",
289            "\t\t_this.ktype.el.get_text().strip(),",
290            "\t\t_this.prop.val",
291            "\t);",
292            "",
293            "\tif (_this.node.props.has_key(prop.to_index_key())) {",
294            "\t\t_this.error.setError(\"Property already exists\");",
295            "\t\treturn;\t",
296            "\t}",
297            "\t",
298            "\t",
299            "\t",
300            "\t_this.node.add_prop(prop);",
301            "\t// hide self",
302            "\t_this.prop = null; // skip checks..",
303            "\t_this.is_new = false;",
304            "\t_this.el.hide();",
305            " \t_this.mainwindow.windowstate.left_props.changed();",
306            "\t_this.mainwindow.windowstate.left_props.view.editProp(prop);",
307            "",
308            "\t",
309            "\t",
310            "}"
311           ]
312          },
313          "string label" : "Add Property",
314          "xtype" : "Button"
315         }
316        ],
317        "xtype" : "Box"
318       }
319      ],
320      "xtype" : "Box"
321     }
322    ],
323    "listeners" : {
324     "closed" : [
325      "() => {",
326      "",
327      " \tGLib.debug(\"popover closed\");",
328      "\tif (_this.is_new) {",
329      "\t\t// dont allow hiding if we are creating a new one.",
330      "\t\t// on.hide will reshow it.",
331      "\t\treturn;",
332      "\t}",
333      "\tif (_this.prop == null) {",
334      "\t\t// hide and dont update.",
335      "\t\treturn;",
336      "\t}",
337      "\tif (this.kname.el.get_text().strip().length < 1) {",
338      "\t\treturn;",
339      "\t}",
340      "\t",
341      " ",
342      "         \t",
343      "         ",
344      "  \tthis.updateProp();",
345      "        ",
346      "\t ",
347      "",
348      "",
349      "  ",
350      "} "
351     ],
352     "hide" : [
353      "() => {",
354      "  \tGLib.debug(\"popover hidden\");",
355      "\tif (_this.is_new || this.kname.el.get_text().strip().length < 1) {",
356      "\t\t// dont allow hiding if we are creating a new one.",
357      "\t\tGLib.debug(\"prevent hiding as its new or text is empty\"); ",
358      "\t\tthis.el.show();",
359      "\t\treturn;",
360      "",
361      "\t}",
362      "\tif (this.original_prop != null && !this.prop.equals(this.original_prop)) {",
363      "\t\t// this is convoluted..",
364      "\t\t_this.mainwindow.windowstate.left_props.changed(); ",
365      "\t}",
366      "\t",
367      "\t",
368      "}"
369     ]
370    },
371    "xtype" : "Popover",
372    "| void show" : [
373     "(",
374     "\tGtk.Widget btn, ",
375     "\tJsRender.Node node, ",
376     "\tJsRender.NodeProp prop, ",
377     "\tint y,",
378     "\tbool is_new = false",
379     "\t ) ",
380     "{",
381     "\t",
382     "    this.original_prop = prop.dupe();",
383     "\tthis.is_new = is_new; ",
384     "\tvar pref = is_new ? \"Add \" : \"Modify \";",
385     "\tif (prop.ptype == JsRender.NodePropType.LISTENER) {",
386     "\t\tthis.headertitle.el.label = pref + \"Event Listener\"; // cant really happen yet?",
387     "\t} else {",
388     "\t\tthis.headertitle.el.label = pref + \"Property\";",
389     "\t}",
390     "\tthis.prop = prop;",
391     "\tthis.node = node;",
392     "\t",
393     "\t_this.kname.el.set_text(prop.name);",
394     "\t_this.ktype.el.set_text(prop.rtype);",
395     "\t",
396     " \t_this.ptype.setValue(prop.ptype);",
397     "\t// does node have this property...",
398     "",
399     "",
400     "\t_this.node = node;",
401     "\t//console.log('show all');",
402     "\t",
403     "\tGLib.debug(\"set parent = %s\", btn.get_type().name());",
404     "\tvar par = btn.get_parent();",
405     "\t",
406     "\tif (par == null) {",
407     "\t\tGLib.debug(\"parent of that is null - not showing\");",
408     "\t\treturn;",
409     "\t}",
410     "\tif (this.el.parent == null) {",
411     "\t\tthis.el.set_parent(btn);",
412     "\t}",
413     "\tvar  r = Gdk.Rectangle() {",
414     "\t\t\tx = btn.get_width(), // align left...",
415     "\t\t\ty = 0,",
416     "\t\t\twidth = 1,",
417     "\t\t\theight = 1",
418     "\t\t};",
419     "\t//Gtk.Allocation rect;",
420     "\t//btn.get_allocation(out rect);",
421     "    this.el.set_pointing_to(r);",
422     "    ",
423     "",
424     "\t ",
425     "\tif (y > -1) {",
426     "\t\t ",
427     "\t\t r = Gdk.Rectangle() {",
428     "\t\t\tx = btn.get_width(), // align left...",
429     "\t\t\ty = y,",
430     "\t\t\twidth = 1,",
431     "\t\t\theight = 1",
432     "\t\t};",
433     "\t\tthis.el.set_pointing_to( r);",
434     "\t}",
435     "\t",
436     "\t",
437     "",
438     "\t//this.el.set_position(Gtk.PositionType.TOP);",
439     "",
440     "\t// window + header?",
441     "\t GLib.debug(\"SHOWALL - POPIP\\n\");",
442     "\t",
443     "\tthis.kname.el.grab_focus();",
444     "\tthis.buttonbar.el.hide();",
445     "\tif (this.is_new) {",
446     "\t\tthis.buttonbar.el.show();",
447     "\t}",
448     "\tthis.error.setError(\"\");",
449     "\tthis.el.show();",
450     "\t//this.success = c.success;",
451     " ",
452     "}"
453    ],
454    "| void updateProp" : [
455     "() {",
456     " \tGLib.debug(\"updateProp called\");",
457     "",
458     "\t",
459     "\t",
460     "\t_this.prop.name = this.kname.el.get_text().strip();",
461     "\t_this.prop.ptype = this.ptype.getValue();",
462     "\t_this.prop.rtype = this.ktype.el.get_text().strip();",
463     "\t",
464     "\t  ",
465     "}",
466     ""
467    ]
468   }
469  ],
470  "name" : "PopoverProperty"
471 }