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