f49aefaba31c11af57d296aa6d65773e7878925d
[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     ],
228     "response" : [
229      " (self, response_id) =>  { ",
230      "  ",
231      "\tif (response_id < 1) { // cancel!",
232      "            this.el.hide();",
233      "            return;",
234      "        }",
235      "",
236      "",
237      "",
238      "        if (_this.name.el.get_text().length  < 1) {",
239      "            StandardErrorDialog.show(",
240      "                this.el,",
241      "                \"You have to set Component name \"",
242      "            );",
243      "             ",
244      "            return;",
245      "        }",
246      "        // what does this do?",
247      "        ",
248      "        var isNew = _this.file.name.length  > 0 ? false : true;",
249      "        /*",
250      "        if (!isNew && this.file.name != _this.name.el.get_text()) {",
251      "            Xcls_StandardErrorDialog.singleton().show(",
252      "                this.el,",
253      "                \"Sorry changing names does not work yet. \"",
254      "            );",
255      "             ",
256      "            return;",
257      "        }",
258      "        */",
259      "         ",
260      "        ",
261      "      ",
262      "        // FIXME - this may be more complicated...",
263      "        //for (var i in this.def) {",
264      "        //    this.file[i] =  this.get(i).el.get_text();",
265      "        //}",
266      "",
267      "        if (!isNew) {",
268      "            try {",
269      "                 this.updateFileFromEntry();",
270      "             } catch( JsRender.Error.RENAME_FILE_EXISTS er) {",
271      "                  Xcls_StandardErrorDialog.singleton().show(",
272      "                    this.el,",
273      "                    \"The name you used already exists \"",
274      "                );",
275      "                return;",
276      "                 ",
277      "             }",
278      "                                                        ",
279      "        ",
280      "            _this.file.save();",
281      "            this.el.hide();",
282      "            return;",
283      "        }",
284      "        var fn = this.name.el.get_text();",
285      "        var dir = _this.project.firstPath();",
286      "       ",
287      "        if (GLib.FileUtils.test(dir + \"/\" + fn + \".bjs\", GLib.FileTest.EXISTS)) {",
288      "            Xcls_StandardErrorDialog.singleton().show(",
289      "                this.el,",
290      "                \"That file already exists\"",
291      "            ); ",
292      "            return;",
293      "        }",
294      "       ",
295      "       var f =  JsRender.JsRender.factory(",
296      "                _this.file.project.xtype,  ",
297      "                _this.file.project, ",
298      "                dir + \"/\" + fn + \".bjs\");",
299      "",
300      "        _this.file = f;",
301      "        ",
302      "",
303      "        ",
304      "        this.updateFileFromEntry();",
305      "        _this.file.save();",
306      "        _this.file.project.addFile(_this.file);",
307      "        ",
308      "\t ",
309      "        // what about .js ?",
310      "       ",
311      "        this.el.hide();",
312      "        ",
313      "        ",
314      "        //var tmpl = this.project.loadFileOnly(DialogNewComponent.get('template').getValue());",
315      "         ",
316      "        //var nf = _this.project.create(dir + \"/\" + _this.file.name + \".bjs\");",
317      "        //for (var i in this.file) {",
318      "        //    nf[i] = this.file[i];",
319      "        //}",
320      "        _this.success(_this.project, _this.file);",
321      "        /*",
322      "",
323      "        -- fixme -- needs to be a signal..",
324      "        if (DialogNewComponent.success != null) {",
325      "            DialogNewComponent.success(_this.project, nf);",
326      "        }",
327      "        */",
328      "}"
329     ],
330     "show" : [
331      "(self)  => {",
332      "  this.el.show_all();",
333      "  //test",
334      "}"
335     ]
336    },
337    "title" : "New Component",
338    "xtype" : "Dialog",
339    "|   void show" : [
340     "(JsRender.JsRender c) ",
341     "{",
342     "    this.project = c.project;",
343     "    ",
344     "    //if (!this.el) {",
345     "        //this.init();",
346     "     //}",
347     "    ",
348     "    _this.name.el.set_text(c.name);",
349     "    _this.title.el.set_text(c.title);",
350     "    _this.parent.el.set_text(c.parent);    ",
351     "    _this.region.el.set_text(c.region);",
352     "    _this.modOrder.el.set_text(c.modOrder);",
353     "     _this.permname.el.set_text(c.permname);",
354     "    ",
355     "    if (c.path.length > 0) {",
356     "        this.el.set_title(\"Edit File Details - \" + c.name);",
357     "    } else {",
358     "        this.el.set_title(\"Create New File\");",
359     "    }",
360     "    ",
361     "     var ar = new Gee.ArrayList<string>();",
362     "     _this.dbmodel.loadData(ar,\"\");",
363     "    // load the modules... if relivant..",
364     "    if (this.project.xtype == \"Gtk\") {",
365     "        var p = (Project.Gtk)c.project;",
366     "          var cg = p.compilegroups;",
367     "",
368     "        var iter = cg.map_iterator();",
369     "       while(iter.next()) {",
370     "            var key = iter.get_key();",
371     "            if (key == \"_default_\") {",
372     "                continue;",
373     "            }",
374     "            ar.add(key);",
375     "        };",
376     "        _this.dbmodel.loadData(ar, c.build_module);",
377     "",
378     "    } ",
379     "     ",
380     "    _this.file = c;",
381     "    //console.log('show all');",
382     "    this.el.show_all();",
383     "    ",
384     "    //this.success = c.success;",
385     "    ",
386     "    ",
387     "}"
388    ],
389    "|   void updateFileFromEntry" : [
390     "() {",
391     "",
392     "        _this.file.title = _this.title.el.get_text();",
393     "        _this.file.region = _this.region.el.get_text();            ",
394     "        _this.file.parent = _this.parent.el.get_text();                        ",
395     "        _this.file.permname = _this.permname.el.get_text();                                    ",
396     "        _this.file.modOrder = _this.modOrder.el.get_text();",
397     "        ",
398     "        if (_this.file.name.length  > 0 && _this.file.name != _this.name.el.get_text()) {",
399     "            _this.file.renameTo(_this.name.el.get_text());",
400     "        }",
401     "        // store the module...",
402     "        _this.file.build_module = \"\";        ",
403     "         Gtk.TreeIter iter; ",
404     "        if (_this.build_module.el.get_active_iter (out iter)) {",
405     "             Value vfname;",
406     "             this.dbmodel.el.get_value (iter, 0, out vfname);",
407     "             if (((string)vfname).length > 0) {",
408     "                 _this.file.build_module = (string)vfname;",
409     "             }",
410     "    ",
411     "        }",
412     "        ",
413     "        ",
414     "",
415     "                                                    ",
416     "}    "
417    ]
418   }
419  ],
420  "modOrder" : "",
421  "name" : "DialogNewComponent",
422  "parent" : "",
423  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/DialogNewComponent.bjs",
424  "permname" : "",
425  "title" : ""
426 }