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