edd9723e356d8966616b2df5827db5d5e1a3488b
[roobuilder] / src / Builder4 / EditProject.bjs
1 {
2  "build_module" : "builder",
3  "gen_extended" : false,
4  "items" : [
5   {
6    "# WindowState? windowstate" : "null",
7    "$ deletable" : true,
8    "$ xns" : "Gtk",
9    "@ void canceled" : "()",
10    "@ void selected" : "(Project.Project? proj)",
11    "bool modal" : true,
12    "default_width" : 600,
13    "items" : [
14     {
15      "$ xns" : "Gtk",
16      "* prop" : "titlebar",
17      "* title" : "New Project",
18      "bool show_title_buttons" : false,
19      "items" : [
20       {
21        "$ Gtk.Align halign" : "Gtk.Align.END",
22        "$ xns" : "Gtk",
23        "* pack" : "pack_start",
24        "bool hexpand" : false,
25        "label" : "Cancel",
26        "listeners" : {
27         "clicked" : [
28          "( ) => {",
29          "   ",
30          "    _this.el.hide();",
31          "\t_this.canceled();",
32          "    ",
33          "",
34          "}",
35          ""
36         ]
37        },
38        "xtype" : "Button"
39       },
40       {
41        "$ Gtk.Align halign" : "Gtk.Align.START",
42        "$ css_classes" : "{ \"suggested-action\" }",
43        "$ xns" : "Gtk",
44        "* pack" : "pack_end",
45        "bool hexpand" : false,
46        "id" : "ok_btn",
47        "label" : "OK",
48        "listeners" : {
49         "clicked" : [
50          "( ) => {",
51          "   var err_dialog = Xcls_StandardErrorDialog.singleton();",
52          "   ",
53          "   ",
54          "   \tif (_this.ptype_dd.getValue().length < 1) {",
55          "        err_dialog.show(_this.el,\"You have to set Project type\");             ",
56          "        return;",
57          "    }",
58          "   var fn = _this.parent_dd.getValue();",
59          "   var is_existing = false;",
60          "   var is_new_folder = false;",
61          "   switch (_this.type_dd.getValue()) {",
62          "\t   \tcase \"Existing Folder\":",
63          "\t\t   \tif (_this.folder_dd.getValue().length < 1) {",
64          "\t\t\t\terr_dialog.show(_this.el,\"You have to set Folder\");             ",
65          "\t\t\t\treturn;",
66          "\t\t\t}",
67          "\t\t\tfn += \"/\" + _this.folder_dd.getValue();",
68          "\t\t\tis_existing = true;",
69          "\t\t\tbreak;",
70          "\t   \t",
71          "\t   \tcase \"New Folder\":",
72          "\t\t   \tif (_this.name_entry.getValue().length < 1) {",
73          "\t\t\t\terr_dialog.show(_this.el,\"You have enter a Project Name\");             ",
74          "\t\t\t\treturn;",
75          "\t\t\t}",
76          "\t\t\tfn += \"/\" + _this.name_entry.getValue();\t   ",
77          "\t\t\t",
78          "\t\t\tif (FileUtils.test( fn ,FileTest.EXISTS)) {",
79          "\t\t\t\terr_dialog.show(_this.el,\"That folder already exists\");             ",
80          "\t\t\t\treturn;\t\t\t",
81          "\t\t\t}",
82          "\t\t\tvar dir = File.new_for_path(fn);",
83          "\t\t\ttry {",
84          "\t\t\t\tdir.make_directory();\t",
85          "\t\t\t} catch (Error e) {",
86          "\t\t\t\tGLib.error(\"Failed to make directory %s\", fn);",
87          "\t\t\t} ",
88          "\t\t\tis_new_folder = true;",
89          "\t\t\tbreak;",
90          "\t\t\t",
91          "\t   \tdefault:",
92          "\t   \t\treturn;",
93          "   \t\t",
94          "    }",
95          "   ",
96          "   ",
97          "  ",
98          "    ",
99          "    _this.el.hide();",
100          "    ",
101          "    ",
102          "",
103          "  ",
104          "    GLib.debug(\"add %s\\n\" , fn);",
105          "    try {",
106          "\t\tvar project = Project.Project.factory(_this.ptype_dd.getValue(), fn);",
107          "\t\tif (is_new_folder) {\t",
108          "\t\t\tproject.initialize();",
109          "\t\t\t",
110          "\t\t} else {",
111          "\t\t\tproject.load();",
112          "\t\t}",
113          "\t\t",
114          "\t\tproject.save();",
115          "\t\t Project.Project.saveProjectList();",
116          "\t\t_this.selected(project); // this should trigger a load()",
117          "\t\tif (is_new_folder || is_existing) {",
118          "\t    \t _this.windowstate.projectPopoverShow(_this.el, project);",
119          "    \t }",
120          "\t\t",
121          "\t\treturn;",
122          "\t} catch (Error e) {",
123          "\t\tGLib.debug(\"got error? %s\" , e.message);",
124          "\t}",
125          "\t ",
126          "",
127          "}",
128          ""
129         ]
130        },
131        "xtype" : "Button"
132       }
133      ],
134      "xtype" : "HeaderBar"
135     },
136     {
137      "$ homogeneous" : false,
138      "$ xns" : "Gtk",
139      "* prop" : "child",
140      "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
141      "bool expand" : true,
142      "int margin_bottom" : 10,
143      "int margin_end" : 10,
144      "int margin_start" : 10,
145      "int margin_top" : 10,
146      "items" : [
147       {
148        "$ xns" : "Gtk",
149        "* columns" : 2,
150        "int column_spacing" : 4,
151        "int margin_bottom" : 20,
152        "int row_spacing" : 4,
153        "items" : [
154         {
155          "$ Gtk.Align halign" : "Gtk.Align.START",
156          "$ xns" : "Gtk",
157          "id" : "type_lbl",
158          "string label" : "Create a Project from:",
159          "xtype" : "Label"
160         },
161         {
162          "$ uint selected" : "Gtk.INVALID_LIST_POSITION",
163          "$ xns" : "Gtk",
164          "* init" : [
165           "{",
166           "",
167           "}",
168           ""
169          ],
170          "bool hexpand" : true,
171          "id" : "type_dd",
172          "items" : [
173           {
174            "$ xns" : "Gtk",
175            "* prop" : "model",
176            "strings" : "{  \"New Folder\", \"Existing Folder\" /*,  \"Checkout from git\"  */ }",
177            "xtype" : "StringList"
178           }
179          ],
180          "listeners" : {
181           "notify[\"selected\"]" : [
182            "( ) => {",
183            "\t ",
184            "\tif (this.el.selected == Gtk.INVALID_LIST_POSITION) {",
185            "\t\treturn;",
186            "\t}",
187            "\tvar m = (Gtk.StringList) this.el.model;",
188            "\tGLib.debug(\"selected item: %s\", m.get_string(this.el.selected));",
189            "\t",
190            "\t_this.hideAll();",
191            "\t_this.parent_lbl.el.show();",
192            "\t_this.parent_dd.el.show();",
193            "\t_this.parent_dd.load();",
194            "\t/*",
195            "\t\t\t break;",
196            " \t",
197            " \tswitch (m.get_string(this.el.selected)) {",
198            "\t\tcase \"New Folder\":",
199            "\t\t    _this.name_lbl.el.show();          ",
200            "     \t\t_this.name_entry.el.show();     ",
201            "\t\t\t break;",
202            "\t\tcase \"Existing Folder\":",
203            "\t\t\t_this.folder_lbl.el.show();",
204            "\t\t\t _this.folder_dd.el.show();     \t",
205            "\t\t\t break;",
206            "\t\t\t ",
207            "\t\tcase \"Checkout from git\":",
208            "\t\t    _this.name_lbl.el.show();          ",
209            "\t\t\t_this.name_entry.el.show();  ",
210            "\t\t\tbreak;   ",
211            "\t\tdefault:",
212            "\t\t\t_this.hideAll();",
213            "\t\t\tbreak;",
214            "",
215            "\t}\t",
216            "\t",
217            "\t*/",
218            "\t ",
219            " ",
220            "              ",
221            "          ",
222            "    ",
223            "\t\t",
224            "} ",
225            ""
226           ]
227          },
228          "xtype" : "DropDown",
229          "| string getValue" : [
230           "() {",
231           "\tvar m = (Gtk.StringList) this.el.model;",
232           "\treturn  m.get_string(this.el.selected);",
233           "\t",
234           "}"
235          ]
236         },
237         {
238          "$ Gtk.Align halign" : "Gtk.Align.START",
239          "$ xns" : "Gtk",
240          "id" : "parent_lbl",
241          "string label" : "In Folder:",
242          "xtype" : "Label"
243         },
244         {
245          "$ xns" : "Gtk",
246          "bool hexpand" : true,
247          "id" : "parent_dd",
248          "items" : [
249           {
250            "$ xns" : "Gtk",
251            "* prop" : "model",
252            "strings" : "{ \"gitlive\", \"Projects\", \"Select\" }",
253            "xtype" : "StringList"
254           }
255          ],
256          "listeners" : {
257           "notify[\"selected\"]" : [
258            "( ) => {",
259            "\tif (this.el.selected == Gtk.INVALID_LIST_POSITION) {",
260            "\t\t_this.hideAll();",
261            "\t\t_this.parent_lbl.el.show();",
262            "     \t_this.parent_dd.el.show();   ",
263            " \t",
264            "\t\treturn;",
265            "\t}",
266            "\t",
267            "\t",
268            "\t",
269            "\tif (this.getValue() == \"Select Folder\") {",
270            "\t\tvar fd = new Gtk.FileDialog();",
271            "\t\tfd.title = \"Select Folder\";",
272            "\t\tfd.modal = true;",
273            "\t\t",
274            "\t\tfd.select_folder.begin(_this.el, null, (obj, res) => {",
275            "\t\t\ttry {",
276            "\t\t \tvar f = fd.select_folder.end(res);",
277            "\t\t\t\tthis.extra_value = f.get_path();",
278            "\t\t\t\tvar sl = (Gtk.StringList) this.el.model;\t",
279            "\t\t\t\t",
280            "\t\t\t\tsl.remove(sl.get_n_items()-1);",
281            "\t\t\t\t",
282            "\t\t\t\tsl.append(this.extra_value);",
283            "\t\t\t\tsl.append(\"Select Folder\");",
284            "\t\t\t\tthis.el.selected = sl.get_n_items()-2;",
285            "\t\t\t} catch (GLib.Error e) {",
286            "\t\t\t\t// do nothing?",
287            "\t\t\t}",
288            "\t\t\t",
289            "\t\t});",
290            "\t\treturn;",
291            "",
292            "\t}",
293            "\t_this.hideAll();",
294            "\t_this.parent_lbl.el.show();",
295            " \t_this.parent_dd.el.show();   ",
296            " \t",
297            "\t",
298            "   _this.ptype_lbl.el.show();          ",
299            "   _this.ptype_dd.el.show();  ",
300            "\t// folder selected...",
301            "\tswitch(_this.type_dd.getValue()) {",
302            "\t\tcase \"New Folder\":",
303            "\t\t   _this.name_lbl.el.show();          ",
304            "    \t   _this.name_entry.el.show(); ",
305            "    \t   _this.name_entry.el.text = \"\";",
306            "\t\t   _this.ptype_lbl.el.show();          ",
307            "\t\t   _this.ptype_dd.el.show();  ",
308            "    \t   break;",
309            "    \t   ",
310            "\t\tcase \"Existing Folder\":",
311            "\t\t\t_this.folder_lbl.el.show();",
312            "\t\t \t_this.folder_dd.el.show();",
313            "\t\t \t_this.folder_dd.load();",
314            "\t\t   ",
315            "\t\t \tbreak;",
316            "\t\t \t",
317            "\t\tcase \"Checkout from git\":",
318            "\t\t   _this.name_lbl.el.show();          ",
319            "    \t   _this.name_entry.el.show(); ",
320            "    \t   _this.name_lbl.el.label= \"not yet\";",
321            "    \t   _this.name_entry.el.text = \"this is not supported yet\";",
322            "\t\t\tbreak;",
323            "\t\tdefault:",
324            "\t\t\tbreak;",
325            "\t}",
326            "    ",
327            "\t",
328            "",
329            "}",
330            ""
331           ]
332          },
333          "string extra_value" : "",
334          "xtype" : "DropDown",
335          "| string getValue" : [
336           "() {",
337           "\tvar m = (Gtk.StringList) this.el.model;",
338           "\treturn  m.get_string(this.el.selected);",
339           "\t",
340           "}"
341          ],
342          "| void load" : [
343           "() {",
344           "",
345           "\tvar sl = (Gtk.StringList) this.el.model;\t",
346           "\tvar hd = GLib.Environment.get_home_dir();",
347           "\twhile(sl.get_n_items() > 0)  {",
348           "\t\tsl.remove(0);",
349           "\t}",
350           "\tif (FileUtils.test(hd + \"/gitlive\" ,FileTest.IS_DIR)) {",
351           "\t\tsl.append(hd + \"/gitlive\");",
352           "\t}",
353           "\tif (FileUtils.test(hd + \"/Projects\" ,FileTest.IS_DIR)) {",
354           "\t\tsl.append(hd + \"/Projects\");",
355           "\t}",
356           "\tif (this.extra_value != \"\" && FileUtils.test(this.extra_value ,FileTest.IS_DIR)) {",
357           "\t\tsl.append(this.extra_value);",
358           "\t}",
359           "\t",
360           "\tsl.append(\"Select Folder\");",
361           "\tthis.el.selected = Gtk.INVALID_LIST_POSITION;",
362           "\t",
363           "}"
364          ]
365         },
366         {
367          "$ Gtk.Align halign" : "Gtk.Align.START",
368          "$ xns" : "Gtk",
369          "id" : "folder_lbl",
370          "string label" : "Add Folder",
371          "xtype" : "Label"
372         },
373         {
374          "$ xns" : "Gtk",
375          "bool hexpand" : true,
376          "id" : "folder_dd",
377          "items" : [
378           {
379            "$ xns" : "Gtk",
380            "* prop" : "model",
381            "strings" : "{ \"gitlive\", \"Projects\", \"Select\" }",
382            "xtype" : "StringList"
383           }
384          ],
385          "listeners" : {
386           "notify[\"selected\"]" : [
387            "() => {",
388            "\tvar fn = this.getValue();",
389            "\tif (fn == \"\") {",
390            "\t\treturn;",
391            "\t}",
392            "\tvar p  = _this.parent_dd.getValue();",
393            "\tif (!FileUtils.test(p  + \"/\" + fn + \"/.roobuilder.jcfg\"  , GLib.FileTest.EXISTS)) {",
394            "\t\treturn;",
395            "\t}",
396            "\tvar ty = Project.Project.peekProjectType(p  + \"/\" + fn + \"/.roobuilder.jcfg\" );",
397            "\tif (ty == \"\") {",
398            "\t\treturn;",
399            "\t}",
400            "\t_this.ptype_dd.setValue(ty);",
401            "\t ",
402            " }",
403            " ",
404            " "
405           ]
406          },
407          "xtype" : "DropDown",
408          "| string getValue" : [
409           "() {",
410           "\tvar m = (Gtk.StringList) this.el.model;",
411           "\treturn this.el.selected  == Gtk.INVALID_LIST_POSITION ?",
412           "\t\t\t \"\" : m.get_string(this.el.selected);",
413           "\t",
414           "}"
415          ],
416          "| void load" : [
417           "() {",
418           "\tvar p  = _this.parent_dd.getValue();",
419           "\tvar f = File.new_for_path(p);",
420           "\tvar sl = (Gtk.StringList) this.el.model;\t",
421           "\twhile(sl.get_n_items() > 0)  {",
422           "\t\tsl.remove(0);",
423           "\t}",
424           "\tvar gstr = new Gee.ArrayList<string>();",
425           "\t",
426           "\t",
427           "\ttry {",
428           "\t\tvar file_enum = f.enumerate_children(",
429           "\t\t\tGLib.FileAttribute.STANDARD_DISPLAY_NAME, ",
430           "\t\t\tGLib.FileQueryInfoFlags.NONE, null);",
431           "\t  ",
432           " \t",
433           "\t\t",
434           "\t\tFileInfo next_file; ",
435           "\t\t ",
436           "\t\twhile ((next_file = file_enum.next_file(null)) != null) {",
437           "\t\t\tvar fn = next_file.get_display_name();",
438           "\t\t ",
439           "\t\t\tif (fn[0] == '.') { // skip hidden",
440           "\t\t\t\tcontinue;",
441           "\t\t\t}",
442           "\t\t\t ",
443           "\t\t\tif (!FileUtils.test(p  + \"/\" + fn, GLib.FileTest.IS_DIR)) {",
444           "\t\t\t\tcontinue;",
445           "\t\t\t}",
446           "\t\t\tif (null != Project.Project.getProjectByPath(p  + \"/\" + fn)) {",
447           "\t\t\t\tcontinue;",
448           "\t\t\t}",
449           "\t\t",
450           "\t\t\tgstr.add(fn);",
451           "\t\t}",
452           "\t} catch (GLib.Error e) {",
453           "\t\t// do nothing.. ",
454           "\t}",
455           "\tgstr.sort((a,b) => {",
456           "\t\treturn Posix.strcmp(a.down(), b.down());",
457           "\t});",
458           "",
459           "\tforeach(var str in gstr) {",
460           "\t\tsl.append(str);",
461           "\t}",
462           "\t ",
463           "}"
464          ]
465         },
466         {
467          "$ Gtk.Align halign" : "Gtk.Align.START",
468          "$ xns" : "Gtk",
469          "id" : "name_lbl",
470          "string label" : "Named (New Folder Name)",
471          "xtype" : "Label"
472         },
473         {
474          "$ xns" : "Gtk",
475          "bool hexpand" : true,
476          "id" : "name_entry",
477          "xtype" : "Entry",
478          "| string getValue" : [
479           "() {",
480           "\treturn this.el.text;",
481           "}"
482          ]
483         },
484         {
485          "$ Gtk.Align halign" : "Gtk.Align.START",
486          "$ xns" : "Gtk",
487          "id" : "ptype_lbl",
488          "label" : "Project type :",
489          "xtype" : "Label"
490         },
491         {
492          "$ xns" : "Gtk",
493          "bool hexpand" : true,
494          "id" : "ptype_dd",
495          "items" : [
496           {
497            "$ xns" : "Gtk",
498            "* prop" : "model",
499            "strings" : "{ \"Roo\", \"Gtk\" /*, \"WrappedGtk\", \"Flutter\" */ }",
500            "xtype" : "StringList"
501           }
502          ],
503          "listeners" : {
504           "notify[\"selected\"]" : [
505            "( ) => {",
506            "",
507            "\t_this.ok_btn.el.hide();\t",
508            "\tif (this.getValue() != \"\") {",
509            "\t   _this.ok_btn.el.show();",
510            "\t}",
511            "",
512            "}",
513            ""
514           ]
515          },
516          "xtype" : "DropDown",
517          "| string getValue" : [
518           "() {",
519           "\tvar m = (Gtk.StringList) this.el.model;",
520           "\treturn this.el.selected == Gtk.INVALID_LIST_POSITION ?",
521           "\t\t\t \"\" : m.get_string(this.el.selected);",
522           "\t",
523           "}"
524          ],
525          "| void setValue" : [
526           "(string val) {",
527           "\tvar m = (Gtk.StringList) this.el.model;",
528           "\tfor(var i = 0; i < m.get_n_items();i++) {",
529           "\t\tif (m.get_string(i) == val) {",
530           "\t\t\tthis.el.selected = i;",
531           "\t\t\tbreak;",
532           "\t\t}",
533           "\t}",
534           "\tthis.el.selected = Gtk.INVALID_LIST_POSITION;",
535           "",
536           "}"
537          ]
538         }
539        ],
540        "xtype" : "Grid"
541       }
542      ],
543      "xtype" : "Box"
544     }
545    ],
546    "name" : "EditProject",
547    "title" : "New Project",
548    "xtype" : "Window",
549    "| void hideAll" : [
550     "() {",
551     " \t_this.parent_lbl.el.hide();",
552     "     _this.parent_dd.el.hide();   ",
553     " \t",
554     " \t_this.folder_lbl.el.hide();",
555     "     _this.folder_dd.el.hide();     ",
556     "     _this.name_lbl.el.hide();          ",
557     "     _this.name_entry.el.hide();     ",
558     "     _this.ptype_lbl.el.hide();          ",
559     "     _this.ptype_dd.el.hide();          ",
560     "      _this.ok_btn.el.hide();   ",
561     "    ",
562     "}"
563    ],
564    "| void show" : [
565     "() {",
566     "     ",
567     "    _this.hideAll(); ",
568     "     // hide stuff..",
569     "     _this.type_dd.el.selected = Gtk.INVALID_LIST_POSITION;",
570     "     _this.folder_dd.el.selected = Gtk.INVALID_LIST_POSITION;",
571     "     _this.ptype_dd.el.selected = Gtk.INVALID_LIST_POSITION;",
572     "     _this.parent_dd.extra_value = \"\";",
573     "    //[ 'xtype'  ].forEach(function(k) {",
574     "    //    _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);",
575     "    //});",
576     "\t// shouild set path..",
577     "    ",
578     "    this.el.show();",
579     "    ",
580     "}"
581    ]
582   }
583  ],
584  "name" : "EditProject"
585 }