e8562219682f648bbfdf2aca65c92fa1c7fe2662
[roobuilder] / src / Builder4 / PopoverProperty.bjs
1 {
2  "build_module" : "builder",
3  "items" : [
4   {
5    "# JsRender.NodeProp? prop" : "",
6    "$ xns" : "Gtk",
7    "@ void success" : "(Project.Project pr, JsRender.JsRender file)",
8    "Gtk.PositionType position" : "Gtk.PositionType.RIGHT",
9    "JsRender.Node node" : "",
10    "Xcls_MainWindow mainwindow" : "null",
11    "bool done" : false,
12    "bool is_new" : false,
13    "bool modal" : true,
14    "id" : "PopoverProperty",
15    "items" : [
16     {
17      "$ pack" : "add",
18      "$ xns" : "Gtk",
19      "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
20      "bool homogeneous" : false,
21      "items" : [
22       {
23        "$ xns" : "Gtk",
24        "* pack" : "pack_start,false,true,0",
25        "id" : "header",
26        "string title" : "Modify / Create Property",
27        "xtype" : "HeaderBar"
28       },
29       {
30        "$ xns" : "Gtk",
31        "* pack" : "add",
32        "Gtk.Align halign" : "Gtk.Align.START",
33        "Gtk.Justification justify" : "Gtk.Justification.LEFT",
34        "int margin_top" : 12,
35        "label" : "Special Flags",
36        "x_options" : 4,
37        "xtype" : "Label"
38       },
39       {
40        "$ xns" : "Gtk",
41        "* init" : "this.el.add_attribute(_this.dbcellrenderer.el , \"markup\", 1 );",
42        "* pack" : "add",
43        "id" : "kflag",
44        "items" : [
45         {
46          "$ xns" : "Gtk",
47          "* pack" : "pack_start,true",
48          "id" : "dbcellrenderer",
49          "xtype" : "CellRendererText"
50         },
51         {
52          "$ columns" : "typeof(JsRender.NodePropType),typeof(string)",
53          "$ xns" : "Gtk",
54          "* pack" : "set_model",
55          "id" : "dbmodel",
56          "n_columns" : 2,
57          "xtype" : "ListStore",
58          "| void loadData" : [
59           "  (JsRender.NodeProp prop) {",
60           "    this.el.clear();                                    ",
61           "    Gtk.TreeIter iter;",
62           "    var el = this.el;",
63           "    ",
64           "    ",
65           "    // vala signal.. '@'",
66           "    // raw value '$'",
67           "    // user defined property '#'",
68           "    // user defined method '|'",
69           "    // special property '*' => prop  |args|ctor|init",
70           "    ",
71           "    ",
72           "    ",
73           "   /// el.append(out iter);",
74           "    ",
75           "     ",
76           "   // el.set_value(iter, 0, \"\");",
77           "   // el.set_value(iter, 1, \"aaa  - Just add Element - aaa\");",
78           "",
79           "    ",
80           "\tif (prop.ptype == JsRender.NodePropType.LISTENER) { ",
81           "\t\tel.append(out iter);",
82           "\t\tel.set(iter, 0, JsRender.NodePropType.LISTENER, 1,   \"Event Handler / Listener\", -1);",
83           "\t}\t ",
84           "\telse if (_this.mainwindow.windowstate.file.xtype == \"Gtk\") {",
85           "\t\t el.append(out iter);",
86           "\t    el.set(iter, 0, JsRender.NodePropType.PROP, 1,   \"Normal Property\", -1);",
87           "\t",
88           "\t\t",
89           "\t\tel.append(out iter);",
90           "\t\tel.set(iter, 0, JsRender.NodePropType.RAW, 1,   \"Raw Property (not escaped)\", -1);",
91           "\t\t ",
92           "\t\t",
93           "\t\tel.append(out iter);",
94           "\t\tel.set(iter, 0, JsRender.NodePropType.USER, 1,   \"User defined property\", -1);",
95           "\t\t ",
96           "\t\tel.append(out iter);",
97           "\t\tel.set(iter, 0, JsRender.NodePropType.METHOD, 1,   \"User defined method\", -1);",
98           "\t\t ",
99           "\t\tel.append(out iter);",
100           "\t\tel.set(iter, 0, JsRender.NodePropType.SPECIAL, 1,   \"Special property (eg. prop | args | ctor | init )\", -1);",
101           "\t\t ",
102           "\t\t",
103           "\t\tel.append(out iter);",
104           "\t    el.set(iter, 0, JsRender.NodePropType.SIGNAL, 1,   \"Vala Signal\", -1);",
105           "\t\t ",
106           "\t\t",
107           "\t} else { ",
108           "\t\t// javascript",
109           "\t    el.append(out iter);",
110           "\t    el.set(iter, 0, JsRender.NodePropType.PROP, 1,   \"Normal Property\", -1);",
111           "\t",
112           "\t\tel.append(out iter);",
113           "\t\tel.set(iter, 0, JsRender.NodePropType.RAW, 1,   \"Raw Property (not escaped)\", -1);",
114           "\t\t ",
115           "\t\tel.append(out iter);",
116           "\t\tel.set(iter, 0, JsRender.NodePropType.METHOD, 1,   \"User defined method\", -1);",
117           "\t ",
118           "\t\tel.append(out iter);",
119           "\t\tel.set(iter, 0,  JsRender.NodePropType.SPECIAL, 1,   \"(*) Special property (eg. prop )\", -1);",
120           "\t\t ",
121           "\t",
122           "\t}",
123           "\t// set selected, based on arg",
124           "\tel.foreach((tm, tp, titer) => {",
125           "\t\tGLib.Value val;",
126           "\t\tel.get_value(titer, 0, out val);",
127           "\t\t ",
128           "\t\t//print(\"check %s against %s\\n\", (string)val, _this.prop.ptype);",
129           "\t\tif (((JsRender.NodePropType)val) == prop.ptype) {",
130           "\t\t\t_this.kflag.el.set_active_iter(titer);",
131           "\t\t\treturn true;",
132           "\t\t}",
133           "\t\treturn false;",
134           "\t});",
135           "\t",
136           "",
137           "                                     ",
138           "}",
139           ""
140          ]
141         }
142        ],
143        "xtype" : "ComboBox"
144       },
145       {
146        "$ visible" : true,
147        "$ xns" : "Gtk",
148        "* pack" : "add",
149        "Gtk.Align halign" : "Gtk.Align.START",
150        "Gtk.Justification justify" : "Gtk.Justification.LEFT",
151        "int margin_top" : 12,
152        "label" : "Type or Return Type",
153        "x_options" : 4,
154        "xtype" : "Label"
155       },
156       {
157        "$ visible" : true,
158        "$ xns" : "Gtk",
159        "* pack" : "add",
160        "id" : "ktype",
161        "xtype" : "Entry"
162       },
163       {
164        "$ visible" : true,
165        "$ xns" : "Gtk",
166        "* pack" : "add",
167        "Gtk.Align halign" : "Gtk.Align.START",
168        "Gtk.Justification justify" : "Gtk.Justification.LEFT",
169        "int margin_top" : 12,
170        "label" : "Name",
171        "tooltip_text" : "center, north, south, east, west",
172        "x_options" : 4,
173        "xtype" : "Label"
174       },
175       {
176        "$ visible" : true,
177        "$ xns" : "Gtk",
178        "* pack" : "add",
179        "id" : "kname",
180        "listeners" : {
181         "focus_out_event" : [
182          "()=>{",
183          "\t_this.error.setError(\"\");",
184          "\tvar val = this.el.get_text().strip(); ",
185          "\tif (val.length < 1) {",
186          "\t\t_this.error.setError(\"Name can not be empty\");",
187          "\t}",
188          "\treturn true;",
189          "}",
190          "",
191          ""
192         ],
193         "key_release_event" : [
194          "()=>{",
195          "\t_this.error.setError(\"\");",
196          "\tvar val = this.el.get_text().strip(); ",
197          "\tif (val.length < 1) {",
198          "\t\t_this.error.setError(\"Name can not be empty\");",
199          "\t}",
200          "\treturn true;",
201          "}",
202          "",
203          ""
204         ]
205        },
206        "xtype" : "Entry"
207       },
208       {
209        "$ visible" : true,
210        "$ xns" : "Gtk",
211        "* pack" : "add",
212        "Gtk.Align halign" : "Gtk.Align.START",
213        "Gtk.Justification justify" : "Gtk.Justification.LEFT",
214        "bool use_markup" : true,
215        "id" : "error",
216        "int margin_top" : 0,
217        "label" : "<span color=\"red\">Error Message</span>",
218        "tooltip_text" : "center, north, south, east, west",
219        "x_options" : 4,
220        "xtype" : "Label",
221        "| void setError" : [
222         "(string err)   {",
223         "\tif (err == \"\") {",
224         "\t\tthis.el.hide();",
225         "\t} else {",
226         "\t\tthis.el.show();",
227         "\t\t",
228         "\t\tthis.el.label = \"<span color=\\\"red\\\">\" + err + \"</span>\";",
229         "\t}",
230         "}",
231         ""
232        ]
233       },
234       {
235        "$ xns" : "Gtk",
236        "* pack" : "add",
237        "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
238        "id" : "buttonbar",
239        "int margin_top" : 20,
240        "items" : [
241         {
242          "$ xns" : "Gtk",
243          "* pack" : "add",
244          "bool always_show_image" : true,
245          "bool hexpand" : true,
246          "items" : [
247           {
248            "$ xns" : "Gtk",
249            "* pack" : "composite_name",
250            "* prop" : "image",
251            "string icon_name" : "window-close",
252            "xtype" : "Image"
253           }
254          ],
255          "listeners" : {
256           "pressed" : [
257            "() => { ",
258            "",
259            "\t_this.prop = null;",
260            "\t_this.is_new = false;",
261            "\t_this.kname.el.set_text(\"Cancel\");",
262            "\t_this.el.hide();",
263            "",
264            "}"
265           ]
266          },
267          "string label" : "Cancel",
268          "xtype" : "Button"
269         },
270         {
271          "$ xns" : "Gtk",
272          "* pack" : "add",
273          "bool always_show_image" : true,
274          "bool hexpand" : true,
275          "items" : [
276           {
277            "$ xns" : "Gtk",
278            "* prop" : "image",
279            "string icon_name" : "list-add",
280            "xtype" : "Image"
281           }
282          ],
283          "listeners" : {
284           "pressed" : [
285            "() => {",
286            "\t// check if text is not empty..",
287            "\tif ( _this.kname.el.get_text().strip().length < 1) {",
288            "\t\t// error should already be showing?",
289            "\t\treturn;",
290            "\t}",
291            "\t_this.updateProp();",
292            "\t",
293            "\t// since we can't add listeners?!?!?",
294            "\t// only check props.",
295            "\t// check if property already exists in node.\t",
296            "\tvar prop = _this.prop;",
297            "\tif (_this.node.props.has_key(prop.to_index_key())) {",
298            "\t\t_this.error.setError(\"Property already exists\");",
299            "\t\treturn;\t",
300            "\t}",
301            "\t",
302            "\t",
303            "\t ",
304            "\t_this.is_new = false;\t",
305            "\t  ",
306            "\t// hide self",
307            "\t_this.prop = null; // skip checks..",
308            "\t_this.el.hide();",
309            "",
310            "// add it, ",
311            "\t// trigger editing of property.",
312            "\t// allow hide to work?",
313            "\twhile (Gtk.events_pending()) {",
314            "\t\tGtk.main_iteration();",
315            "\t}",
316            "\t",
317            "\t_this.mainwindow.windowstate.left_props.addProp(prop);\t\t",
318            "\t",
319            "",
320            "}"
321           ]
322          },
323          "string label" : "Add Property",
324          "xtype" : "Button"
325         }
326        ],
327        "xtype" : "Box"
328       }
329      ],
330      "xtype" : "Box"
331     }
332    ],
333    "listeners" : {
334     "closed" : [
335      "() => {",
336      "",
337      " \tGLib.debug(\"popover closed\");",
338      "\tif (_this.is_new) {",
339      "\t\t// dont allow hiding if we are creating a new one.",
340      "\t\t// on.hide will reshow it.",
341      "\t\treturn;",
342      "\t}",
343      "\tif (_this.prop == null) {",
344      "\t\t// hide and dont update.",
345      "\t\treturn;",
346      "\t}",
347      "\tif (this.kname.el.get_text().strip().length < 1) {",
348      "\t\treturn;",
349      "\t}",
350      "\t",
351      "\tvar oldkey = this.prop.to_index_key();\t",
352      "         \t",
353      "         ",
354      "  \tthis.updateProp();",
355      "         \t",
356      " \tvar newkey = this.prop.to_index_key();\t",
357      " \tif (oldkey != newkey) {",
358      " \t",
359      " \t\tif (_this.prop.ptype == JsRender.NodePropType.LISTENER) {",
360      " \t\t\tthis.node.listeners.unset(oldkey);",
361      " \t\t\tthis.node.listeners.set(newkey, _this.prop);",
362      " \t\t} else {",
363      " \t\t\tthis.node.props.unset(oldkey);",
364      " \t\t\tthis.node.props.set(newkey, _this.prop);",
365      " \t\t}",
366      " \t",
367      " \t}",
368      "\t_this.mainwindow.windowstate.left_props.reload();",
369      "",
370      "",
371      "  ",
372      "} "
373     ],
374     "hide" : [
375      "() => {",
376      "  \tGLib.debug(\"popover hidden\");",
377      "\tif (_this.is_new || this.kname.el.get_text().strip().length < 1) {",
378      "\t\t// dont allow hiding if we are creating a new one.",
379      "\t\tGLib.debug(\"prevent hiding as its new or text is empty\"); ",
380      "\t\tthis.el.show_all();",
381      "\t\treturn;",
382      "",
383      "\t}",
384      "\t",
385      "}"
386     ]
387    },
388    "string key_type" : "",
389    "string old_keyname" : "",
390    "uint border_width" : 0,
391    "xtype" : "Popover",
392    "| void show" : [
393     "(",
394     "\tGtk.Widget btn, ",
395     "\tJsRender.Node node, ",
396     "\tJsRender.NodeProp prop, ",
397     "\tint y,",
398     "\tbool is_new = false",
399     "\t ) ",
400     "{",
401     "\t",
402     "   ",
403     "\tthis.is_new = is_new; ",
404     "\tvar pref = is_new ? \"Add \" : \"Modify \";",
405     "\tif (prop.ptype == JsRender.NodePropType.LISTENER) {",
406     "\t\tthis.header.el.title = pref + \"Event Listener\"; // cant really happen yet?",
407     "\t} else {",
408     "\t\tthis.header.el.title = pref + \"Property\";",
409     "\t}",
410     "\tthis.prop = prop;",
411     "\tthis.node = node;",
412     "\t",
413     "\t_this.kname.el.set_text(prop.name);",
414     "\t_this.ktype.el.set_text(prop.rtype);",
415     "\t",
416     "\t_this.dbmodel.loadData(prop );",
417     "\t// does node have this property...",
418     "",
419     "",
420     "\t_this.node = node;",
421     "\t//console.log('show all');",
422     "\tthis.el.set_modal(true);",
423     "\tthis.el.set_relative_to(btn);",
424     "\tif (y > -1) {",
425     "\t\t",
426     "\t",
427     "\t\tvar  r = Gdk.Rectangle() {",
428     "\t\t\tx = btn.get_allocated_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 print(\"SHOWALL - POPIP\\n\");",
442     "\tthis.el.show_all();",
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     "\t this.error.setError(\"\");",
449     "",
450     "\t//this.success = c.success;",
451     " ",
452     "}"
453    ],
454    "| void updateProp" : [
455     "() {",
456     " ",
457     "\tGtk.TreeIter citer;",
458     "\tGLib.Value gval;",
459     "\tthis.kflag.el.get_active_iter(out citer);",
460     "\tthis.dbmodel.el.get_value(citer, 0, out  gval);",
461     "",
462     "",
463     "\t_this.prop.name = this.kname.el.get_text().strip(); ",
464     "\t_this.prop.rtype = this.ktype.el.get_text().strip(); ",
465     "\t_this.prop.ptype =  (JsRender.NodePropType) gval;",
466     "",
467     "}",
468     ""
469    ]
470   }
471  ],
472  "modOrder" : "",
473  "name" : "PopoverProperty",
474  "parent" : "",
475  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/PopoverProperty.bjs",
476  "permname" : "",
477  "title" : ""
478 }