Fix #7250 - better handling of adding properties
[roobuilder] / src / Builder4 / DialogNewComponent.bjs
1 {
2  "build_module" : "",
3  "items" : [
4   {
5    "# JsRender.JsRender file" : "null",
6    "# Project.Project project" : "",
7    "$ deletable" : true,
8    "$ modal" : true,
9    "$ xns" : "Gtk",
10    "@ void success" : "(Project.Project pr, JsRender.JsRender file)",
11    "default_height" : 200,
12    "default_width" : 500,
13    "id" : "DialogNewComponent",
14    "items" : [
15     {
16      "$ pack" : "get_content_area().add",
17      "$ xns" : "Gtk",
18      "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
19      "items" : [
20       {
21        "$ homogeneous" : true,
22        "$ xns" : "Gtk",
23        "* pack" : "pack_start,false,false,0",
24        "items" : [
25         {
26          "$ xns" : "Gtk",
27          "* pack" : "attach_defaults,0,1,0,1",
28          "Gtk.Justification justify" : "Gtk.Justification.RIGHT",
29          "label" : "Component Name",
30          "x_options" : 4,
31          "xalign" : 0.90000000000000002,
32          "xtype" : "Label"
33         },
34         {
35          "$ visible" : true,
36          "$ xns" : "Gtk",
37          "* pack" : "attach_defaults,1,2,0,1",
38          "id" : "name",
39          "xtype" : "Entry"
40         },
41         {
42          "$ justify" : "Gtk.Justification.RIGHT",
43          "$ visible" : true,
44          "$ xns" : "Gtk",
45          "* pack" : "attach_defaults,0,1,1,2",
46          "Gtk.Justification justify" : "Gtk.Justification.RIGHT",
47          "label" : "Title",
48          "x_options" : 4,
49          "xalign" : 0.90000000000000002,
50          "xtype" : "Label"
51         },
52         {
53          "$ visible" : true,
54          "$ xns" : "Gtk",
55          "* pack" : "attach_defaults,1,2,1,2",
56          "id" : "title",
57          "xtype" : "Entry"
58         },
59         {
60          "$ justify" : "Gtk.Justification.RIGHT",
61          "$ visible" : true,
62          "$ xns" : "Gtk",
63          "* pack" : "attach_defaults,0,1,2,3",
64          "label" : "Region",
65          "tooltip_text" : "center, north, south, east, west",
66          "x_options" : 4,
67          "xalign" : 0.90000000000000002,
68          "xtype" : "Label"
69         },
70         {
71          "$ visible" : true,
72          "$ xns" : "Gtk",
73          "* pack" : "attach_defaults,1,2,2,3",
74          "id" : "region",
75          "xtype" : "Entry"
76         },
77         {
78          "$ justify" : "Gtk.Justification.RIGHT",
79          "$ visible" : true,
80          "$ xns" : "Gtk",
81          "* pack" : "attach_defaults,0,1,3,4",
82          "label" : "Parent Name",
83          "x_options" : 4,
84          "xalign" : 0.90000000000000002,
85          "xtype" : "Label"
86         },
87         {
88          "$ visible" : true,
89          "$ xns" : "Gtk",
90          "* pack" : "attach_defaults,1,2,3,4",
91          "id" : "parent",
92          "xtype" : "Entry"
93         },
94         {
95          "$ justify" : "Gtk.Justification.RIGHT",
96          "$ visible" : true,
97          "$ xns" : "Gtk",
98          "* pack" : "attach_defaults,0,1,4,5",
99          "label" : "Permission Name",
100          "x_options" : 4,
101          "xalign" : 0.90000000000000002,
102          "xtype" : "Label"
103         },
104         {
105          "$ visible" : true,
106          "$ xns" : "Gtk",
107          "* pack" : "attach_defaults,1,2,4,5",
108          "id" : "permname",
109          "xtype" : "Entry"
110         },
111         {
112          "$ justify" : "Gtk.Justification.RIGHT",
113          "$ visible" : true,
114          "$ xns" : "Gtk",
115          "* pack" : "attach_defaults,0,1,5,6",
116          "label" : "Order (for tabs)",
117          "x_options" : 4,
118          "xalign" : 0.90000000000000002,
119          "xtype" : "Label"
120         },
121         {
122          "$ visible" : true,
123          "$ xns" : "Gtk",
124          "* pack" : "attach_defaults,1,2,5,6",
125          "id" : "modOrder",
126          "xtype" : "Entry"
127         },
128         {
129          "$ justify" : "Gtk.Justification.RIGHT",
130          "$ visible" : true,
131          "$ xns" : "Gtk",
132          "* pack" : "attach_defaults,0,1,6,7",
133          "label" : "Module to build (Vala only)",
134          "x_options" : 4,
135          "xalign" : 0.90000000000000002,
136          "xtype" : "Label"
137         },
138         {
139          "$ xns" : "Gtk",
140          "* init" : "this.el.add_attribute(_this.dbcellrenderer.el , \"markup\", 1 );",
141          "* pack" : "attach_defaults,1,2,6,7",
142          "id" : "build_module",
143          "items" : [
144           {
145            "$ xns" : "Gtk",
146            "* pack" : "pack_start,true",
147            "id" : "dbcellrenderer",
148            "xtype" : "CellRendererText"
149           },
150           {
151            "$ columns" : "typeof(string),typeof(string)",
152            "$ xns" : "Gtk",
153            "* pack" : "set_model",
154            "id" : "dbmodel",
155            "n_columns" : 2,
156            "xtype" : "ListStore",
157            "| void loadData" : [
158             "  (Gee.ArrayList<string> data, string cur) {",
159             "    this.el.clear();                                    ",
160             "    Gtk.TreeIter iter;",
161             "    var el = this.el;",
162             "    ",
163             "   /// el.append(out iter);",
164             "    ",
165             "     ",
166             "   // el.set_value(iter, 0, \"\");",
167             "   // el.set_value(iter, 1, \"aaa  - Just add Element - aaa\");",
168             "",
169             "    el.append(out iter);",
170             "",
171             "    ",
172             "    el.set_value(iter, 0, \"\");",
173             "    el.set_value(iter, 1, \"-- select a module --\");",
174             "    _this.build_module.el.set_active_iter(iter);",
175             "    ",
176             "    for (var i = 0; i < data.size;i++) {",
177             "    ",
178             "",
179             "        el.append(out iter);",
180             "        ",
181             "        el.set_value(iter, 0, data.get(i));",
182             "        el.set_value(iter, 1, data.get(i));",
183             "        ",
184             "        if (data.get(i) == cur) {",
185             "            _this.build_module.el.set_active_iter(iter);",
186             "        }",
187             "        ",
188             "    }",
189             "     this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          ",
190             "                                     ",
191             "}",
192             ""
193            ]
194           }
195          ],
196          "xtype" : "ComboBox"
197         }
198        ],
199        "n_columns" : 2,
200        "n_rows" : 3,
201        "xtype" : "Table"
202       }
203      ],
204      "xtype" : "Box"
205     },
206     {
207      "$ xns" : "Gtk",
208      "* pack" : "add_action_widget,0",
209      "label" : "Cancel",
210      "xtype" : "Button"
211     },
212     {
213      "$ xns" : "Gtk",
214      "* pack" : "add_action_widget,1",
215      "label" : "OK",
216      "xtype" : "Button"
217     }
218    ],
219    "listeners" : {
220     "delete_event" : [
221      "(self, event) => {",
222      "    this.el.hide();",
223      "    return true; ",
224      "    //test  ",
225      "} "
226     ],
227     "response" : [
228      " (self, response_id) =>  { ",
229      "  ",
230      "\tif (response_id < 1) { // cancel!",
231      "            this.el.hide();",
232      "            return;",
233      "        }",
234      "",
235      "",
236      "",
237      "        if (_this.name.el.get_text().length  < 1) {",
238      "            Xcls_StandardErrorDialog.singleton().show(",
239      "                this.el,",
240      "                \"You have to set Component name \"",
241      "            );",
242      "             ",
243      "            return;",
244      "        }",
245      "        // what does this do?",
246      "        ",
247      "        var isNew = _this.file.name.length  > 0 ? false : true;",
248      "        /*",
249      "        if (!isNew && this.file.name != _this.name.el.get_text()) {",
250      "            Xcls_StandardErrorDialog.singleton().show(",
251      "                this.el,",
252      "                \"Sorry changing names does not work yet. \"",
253      "            );",
254      "             ",
255      "            return;",
256      "        }",
257      "        */",
258      "         ",
259      "        ",
260      "      ",
261      "        // FIXME - this may be more complicated...",
262      "        //for (var i in this.def) {",
263      "        //    this.file[i] =  this.get(i).el.get_text();",
264      "        //}",
265      "",
266      "        if (!isNew) {",
267      "            try {",
268      "                 this.updateFileFromEntry();",
269      "             } catch( JsRender.Error.RENAME_FILE_EXISTS er) {",
270      "                  Xcls_StandardErrorDialog.singleton().show(",
271      "                    this.el,",
272      "                    \"The name you used already exists \"",
273      "                );",
274      "                return;",
275      "                 ",
276      "             }",
277      "                                                        ",
278      "        ",
279      "            _this.file.save();",
280      "            this.el.hide();",
281      "            return;",
282      "        }",
283      "        var fn = this.name.el.get_text();",
284      "        var dir = _this.project.firstPath();",
285      "       ",
286      "        if (GLib.FileUtils.test(dir + \"/\" + fn + \".bjs\", GLib.FileTest.EXISTS)) {",
287      "            Xcls_StandardErrorDialog.singleton().show(",
288      "                this.el,",
289      "                \"That file already exists\"",
290      "            ); ",
291      "            return;",
292      "        }",
293      "       ",
294      "       var f =  JsRender.JsRender.factory(",
295      "                _this.file.project.xtype,  ",
296      "                _this.file.project, ",
297      "                dir + \"/\" + fn + \".bjs\");",
298      "",
299      "        _this.file = f;",
300      "        ",
301      "",
302      "        ",
303      "        this.updateFileFromEntry();",
304      "        _this.file.save();",
305      "        _this.file.project.addFile(_this.file);",
306      "        ",
307      "\t ",
308      "        // what about .js ?",
309      "       ",
310      "        this.el.hide();",
311      "        ",
312      "        ",
313      "        //var tmpl = this.project.loadFileOnly(DialogNewComponent.get('template').getValue());",
314      "         ",
315      "        //var nf = _this.project.create(dir + \"/\" + _this.file.name + \".bjs\");",
316      "        //for (var i in this.file) {",
317      "        //    nf[i] = this.file[i];",
318      "        //}",
319      "        _this.success(_this.project, _this.file);",
320      "        /*",
321      "",
322      "        -- fixme -- needs to be a signal..",
323      "        if (DialogNewComponent.success != null) {",
324      "            DialogNewComponent.success(_this.project, nf);",
325      "        }",
326      "        */",
327      "}"
328     ],
329     "show" : [
330      "(self)  => {",
331      "  this.el.show_all();",
332      "  //test",
333      "}"
334     ]
335    },
336    "title" : "New Component",
337    "xtype" : "Dialog",
338    "|   void show" : [
339     "(JsRender.JsRender c) ",
340     "{",
341     "    this.project = c.project;",
342     "    ",
343     "    //if (!this.el) {",
344     "        //this.init();",
345     "     //}",
346     "    ",
347     "    _this.name.el.set_text(c.name);",
348     "    _this.title.el.set_text(c.title);",
349     "    _this.parent.el.set_text(c.parent);    ",
350     "    _this.region.el.set_text(c.region);",
351     "    _this.modOrder.el.set_text(c.modOrder);",
352     "     _this.permname.el.set_text(c.permname);",
353     "    ",
354     "    if (c.path.length > 0) {",
355     "        this.el.set_title(\"Edit File Details - \" + c.name);",
356     "    } else {",
357     "        this.el.set_title(\"Create New File\");",
358     "    }",
359     "    ",
360     "     var ar = new Gee.ArrayList<string>();",
361     "     _this.dbmodel.loadData(ar,\"\");",
362     "    // load the modules... if relivant..",
363     "    if (this.project.xtype == \"Gtk\") {",
364     "        var p = (Project.Gtk)c.project;",
365     "          var cg = p.compilegroups;",
366     "",
367     "        var iter = cg.map_iterator();",
368     "       while(iter.next()) {",
369     "            var key = iter.get_key();",
370     "            if (key == \"_default_\") {",
371     "                continue;",
372     "            }",
373     "            ar.add(key);",
374     "        };",
375     "        _this.dbmodel.loadData(ar, c.build_module);",
376     "",
377     "    } ",
378     "     ",
379     "    _this.file = c;",
380     "    //console.log('show all');",
381     "    this.el.show_all();",
382     "    ",
383     "    //this.success = c.success;",
384     "    ",
385     "    ",
386     "}"
387    ],
388    "|   void updateFileFromEntry" : [
389     "() {",
390     "",
391     "        _this.file.title = _this.title.el.get_text();",
392     "        _this.file.region = _this.region.el.get_text();            ",
393     "        _this.file.parent = _this.parent.el.get_text();                        ",
394     "        _this.file.permname = _this.permname.el.get_text();                                    ",
395     "        _this.file.modOrder = _this.modOrder.el.get_text();",
396     "        ",
397     "        if (_this.file.name.length  > 0 && _this.file.name != _this.name.el.get_text()) {",
398     "            _this.file.renameTo(_this.name.el.get_text());",
399     "        }",
400     "        // store the module...",
401     "        _this.file.build_module = \"\";        ",
402     "         Gtk.TreeIter iter; ",
403     "        if (_this.build_module.el.get_active_iter (out iter)) {",
404     "             Value vfname;",
405     "             this.dbmodel.el.get_value (iter, 0, out vfname);",
406     "             if (((string)vfname).length > 0) {",
407     "                 _this.file.build_module = (string)vfname;",
408     "             }",
409     "    ",
410     "        }",
411     "        ",
412     "        ",
413     "",
414     "                                                    ",
415     "}    "
416    ]
417   }
418  ],
419  "modOrder" : "",
420  "name" : "DialogNewComponent",
421  "parent" : "",
422  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/DialogNewComponent.bjs",
423  "permname" : "",
424  "title" : ""
425 }