adff8c904aa9f383049b17f7e5e6d4a9b51e0e35
[roobuilder] / src / Builder4 / RooProjectSettings.bjs
1 {
2  "build_module" : "builder",
3  "gen_extended" : false,
4  "items" : [
5   {
6    "$ xns" : "Gtk",
7    "@ void buttonPressed" : "(string btn)",
8    "Gtk.PositionType position" : "Gtk.PositionType.RIGHT",
9    "Project.Roo project" : "",
10    "bool autohide" : false,
11    "bool done" : false,
12    "bool modal" : true,
13    "id" : "RooProjectSettings",
14    "items" : [
15     {
16      "$ homogeneous" : false,
17      "$ xns" : "Gtk",
18      "* pack" : "set_child",
19      "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
20      "border_width" : 5,
21      "items" : [
22       {
23        "$ xns" : "Gtk",
24        "items" : [
25         {
26          "$ xns" : "Gtk",
27          "* pack" : false,
28          "id" : "label_global",
29          "utf8 label" : "Global",
30          "xtype" : "Label"
31         },
32         {
33          "$ xns" : "Gtk",
34          "* pack" : false,
35          "id" : "label_database",
36          "utf8 label" : "Database",
37          "xtype" : "Label"
38         },
39         {
40          "$ xns" : "Gtk",
41          "* pack" : "append_page,_this.label_global.el",
42          "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
43          "gboolean homogeneous" : false,
44          "items" : [
45           {
46            "$ homogeneous" : true,
47            "$ xns" : "Gtk",
48            "id" : "grid",
49            "int margin_end" : 4,
50            "int margin_start" : 4,
51            "items" : [
52             {
53              "$ xns" : "Gtk",
54              "* pack" : "attach,0,0,1,1",
55              "int margin_bottom" : 3,
56              "int margin_end" : 3,
57              "int margin_start" : 3,
58              "int margin_top" : 3,
59              "label" : "Filename",
60              "xalign" : 0,
61              "xtype" : "Label"
62             },
63             {
64              "$ xns" : "Gtk",
65              "* pack" : "attach,1,0,1,1",
66              "id" : "path",
67              "int margin_bottom" : 3,
68              "int margin_end" : 3,
69              "int margin_start" : 3,
70              "int margin_top" : 3,
71              "label" : "filename",
72              "xalign" : 0,
73              "xtype" : "Label"
74             },
75             {
76              "$ xns" : "Gtk",
77              "* pack" : "attach,0,1,1,1",
78              "int margin_bottom" : 3,
79              "int margin_end" : 3,
80              "int margin_start" : 3,
81              "int margin_top" : 3,
82              "label" : "HTML template file",
83              "xtype" : "Label"
84             },
85             {
86              "$ xns" : "Gtk",
87              "* init" : "this.el.add_attribute(_this.base_template_cellrenderer.el , \"markup\", 0 );",
88              "* pack" : "attach,1,1,1,1",
89              "bool loading" : false,
90              "id" : "base_template",
91              "items" : [
92               {
93                "$ xns" : "Gtk",
94                "* pack" : "pack_start,true",
95                "id" : "base_template_cellrenderer",
96                "xtype" : "CellRendererText"
97               },
98               {
99                "$ columns" : "typeof(string)",
100                "$ xns" : "Gtk",
101                "* pack" : "set_model",
102                "id" : "base_template_model",
103                "n_columns" : 1,
104                "xtype" : "ListStore",
105                "| void loadData" : [
106                 "  () {",
107                 "\t_this.base_template.loading = true;",
108                 "  ",
109                 "    this.el.clear();                                    ",
110                 "    Gtk.TreeIter iter;",
111                 "    var el = this.el;",
112                 "    ",
113                 "   /// el.append(out iter);",
114                 "    ",
115                 "   ",
116                 "    el.append(out iter);",
117                 "    el.set_value(iter, 0, \"roo.builder.html\");",
118                 "    _this.base_template.el.set_active_iter(iter);",
119                 "\tif (_this.project.base_template == \"roo.builder.html\") {",
120                 "\t   _this.base_template.el.set_active_iter(iter);",
121                 "    }",
122                 "",
123                 "    el.append(out iter);",
124                 "    el.set_value(iter, 0, \"bootstrap.builder.html\");",
125                 "  ",
126                 "\tprint(\"\\ncur template = %s\\n\", _this.project.base_template);",
127                 " ",
128                 "    if (_this.project.base_template == \"bootstrap.builder.html\") {",
129                 "\t   _this.base_template.el.set_active_iter(iter);",
130                 "    }",
131                 "\t  el.append(out iter);",
132                 "    el.set_value(iter, 0, \"bootstrap4.builder.html\");",
133                 "     if (_this.project.base_template == \"bootstrap4.builder.html\") {",
134                 "\t   _this.base_template.el.set_active_iter(iter);",
135                 "    }",
136                 "    ",
137                 "",
138                 "\tel.append(out iter);",
139                 "    el.set_value(iter, 0, \"mailer.builder.html\");",
140                 "",
141                 "\tif (_this.project.base_template == \"mailer.builder.html\") {",
142                 "\t    _this.base_template.el.set_active_iter(iter);",
143                 "    }",
144                 "\t_this.base_template.loading = false;",
145                 "                                     ",
146                 "}",
147                 ""
148                ]
149               }
150              ],
151              "listeners" : {
152               "changed" : [
153                "() => {",
154                "\tGtk.TreeIter iter;",
155                " ",
156                "\t// this get's called when we are filling in the data... ???",
157                "\tif (this.loading) {",
158                "\t\treturn;",
159                "\t}",
160                "\t",
161                " ",
162                "\tif (this.el.get_active_iter(out iter)) {",
163                "\t\tValue vfname;",
164                "\t\t_this.base_template_model.el.get_value (iter, 0, out vfname);",
165                "\t\t_this.project.base_template = ((string)vfname) ;",
166                "\t\t",
167                "\t\t print(\"\\nSET base template to %s\\n\", _this.project.base_template );",
168                "\t\t// is_bjs = ((string)vfname) == \"bjs\";",
169                "\t}",
170                "    ",
171                "  ",
172                "    // directory is only available for non-bjs ",
173                " ",
174                "",
175                "",
176                "}",
177                ""
178               ]
179              },
180              "xtype" : "ComboBox"
181             },
182             {
183              "$ xns" : "Gtk",
184              "* pack" : "attach,0,2,1,1",
185              "int margin_bottom" : 3,
186              "int margin_end" : 3,
187              "int margin_start" : 3,
188              "int margin_top" : 3,
189              "label" : "root URL",
190              "xtype" : "Label"
191             },
192             {
193              "$ xns" : "Gtk",
194              "* pack" : "attach,1,2,1,1",
195              "id" : "rootURL",
196              "xtype" : "Entry"
197             },
198             {
199              "$ xns" : "Gtk",
200              "* pack" : "attach,0,3,1,1",
201              "label" : "Generate HTML in",
202              "xtype" : "Label"
203             },
204             {
205              "$ xns" : "Gtk",
206              "* init" : "this.el.add_attribute(_this.html_gen_cellrenderer.el , \"markup\", 1 );",
207              "* pack" : "attach,1,3,1,1",
208              "id" : "html_gen",
209              "items" : [
210               {
211                "$ xns" : "Gtk",
212                "* pack" : "pack_start,true",
213                "id" : "html_gen_cellrenderer",
214                "xtype" : "CellRendererText"
215               },
216               {
217                "$ columns" : "typeof(string),typeof(string)",
218                "$ xns" : "Gtk",
219                "* pack" : "set_model",
220                "id" : "html_gen_model",
221                "n_columns" : 2,
222                "xtype" : "ListStore",
223                "| void loadData" : [
224                 "  (string cur) {",
225                 "    this.el.clear();                                    ",
226                 "    Gtk.TreeIter iter;",
227                 "    var el = this.el;",
228                 "    ",
229                 " ",
230                 "    el.append(out iter);",
231                 "",
232                 "    ",
233                 "    el.set_value(iter, 0, \"\");",
234                 "    el.set_value(iter, 1, \"Do not Generate\");",
235                 "    _this.html_gen.el.set_active_iter(iter);",
236                 "",
237                 "    el.append(out iter);",
238                 "    ",
239                 "    el.set_value(iter, 0, \"bjs\");",
240                 "    el.set_value(iter, 1, \"same directory as BJS file\");",
241                 "\tif (cur == \"bjs\") {",
242                 "\t    _this.html_gen.el.set_active_iter(iter);",
243                 "    }",
244                 "",
245                 "",
246                 "",
247                 "    el.append(out iter);",
248                 "    ",
249                 "    el.set_value(iter, 0, \"templates\");",
250                 "    el.set_value(iter, 1, \"in templates subdirectory\");",
251                 "",
252                 "\tif (cur == \"template\") {",
253                 "\t    _this.html_gen.el.set_active_iter(iter);",
254                 "    }",
255                 "",
256                 "                                     ",
257                 "}",
258                 ""
259                ]
260               }
261              ],
262              "xtype" : "ComboBox"
263             }
264            ],
265            "n_columns" : 2,
266            "n_rows" : 7,
267            "uint row_spacing" : 2,
268            "xtype" : "Grid"
269           },
270           {
271            "$ xns" : "Gtk",
272            "label" : "HTML To insert at end of <HEAD>",
273            "xtype" : "Label"
274           },
275           {
276            "$ xns" : "Gtk",
277            "bool vexpand" : true,
278            "items" : [
279             {
280              "$ xns" : "GtkSource",
281              "* init" : [
282               " ",
283               "    ",
284               "this.css = new Gtk.CssProvider();",
285               " ",
286               "\tthis.css.load_from_string(",
287               "\t\"#roo-project-settings-view{ font:  10px monospace;}\"",
288               ");",
289               " ",
290               "//this.el.get_style_context().add_provider(this.css,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);",
291               "        ",
292               "       Gtk.StyleContext.add_provider_for_display(",
293               "\t       Gdk.Display.get_default(), ",
294               "\t       this.css,",
295               "\t       Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION",
296               "       );"
297              ],
298              "* pack" : "set_child",
299              "Gtk.CssProvider css" : "",
300              "id" : "view",
301              "items" : [
302               {
303                "$ xns" : "Gtk",
304                "listeners" : {
305                 "key_released" : [
306                  "(keyval, keycode, state) => {",
307                  "",
308                  "",
309                  "    if (keyval != 115) {",
310                  "        return;",
311                  "         ",
312                  "    }",
313                  "    if   ( (state & Gdk.ModifierType.CONTROL_MASK ) < 1 ) {",
314                  "        return;",
315                  "    }",
316                  "     var buf =    _this.view.el.get_buffer();",
317                  "    Gtk.TextIter s;",
318                  "    Gtk.TextIter e;",
319                  "    buf.get_start_iter(out s);",
320                  "    buf.get_end_iter(out e);",
321                  "    _this.project.runhtml = buf.get_text(s,e,true);",
322                  "    ",
323                  "          ",
324                  "    _this.buttonPressed(\"save\");",
325                  "   ",
326                  "         ",
327                  "",
328                  "}",
329                  ""
330                 ]
331                },
332                "xtype" : "EventControllerKey"
333               }
334              ],
335              "string name" : "roo-project-settings-view",
336              "xtype" : "View"
337             }
338            ],
339            "xtype" : "ScrolledWindow"
340           }
341          ],
342          "xtype" : "Box"
343         },
344         {
345          "$ xns" : "Gtk",
346          "* pack" : "append_page,_this.label_database.el",
347          "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
348          "gboolean homogeneous" : false,
349          "items" : [
350           {
351            "$ xns" : "Gtk",
352            "label" : "Type (eg. MySQL or PostgreSQL)",
353            "xalign" : 0,
354            "xtype" : "Label"
355           },
356           {
357            "$ xns" : "Gtk",
358            "id" : "database_DBTYPE",
359            "items" : [
360             {
361              "$ xns" : "Gtk",
362              "listeners" : {
363               "key_pressed" : [
364                "(keyval, keycode, state) => {",
365                "    if (keyval == Gdk.Key.Tab) {",
366                "        _this.database_DBNAME.el.grab_focus();",
367                "        return true;",
368                "    }",
369                "",
370                "",
371                "\treturn false;",
372                "}",
373                ""
374               ]
375              },
376              "xtype" : "EventControllerKey"
377             }
378            ],
379            "xtype" : "Entry"
380           },
381           {
382            "$ xns" : "Gtk",
383            "label" : "Name",
384            "xalign" : 0,
385            "xtype" : "Label"
386           },
387           {
388            "$ xns" : "Gtk",
389            "id" : "database_DBNAME",
390            "items" : [
391             {
392              "$ xns" : "Gtk",
393              "listeners" : {
394               "key_pressed" : [
395                "(keyval, keycode, state) => {",
396                "    if (keyval == Gdk.Key.Tab) {",
397                "        _this.database_DBUSERNAME.el.grab_focus();",
398                "        return true;",
399                "    }",
400                "",
401                "",
402                "\treturn false;",
403                "\t ",
404                "}",
405                ""
406               ]
407              },
408              "xtype" : "EventControllerKey"
409             }
410            ],
411            "xtype" : "Entry"
412           },
413           {
414            "$ xns" : "Gtk",
415            "label" : "Username",
416            "xalign" : 0,
417            "xtype" : "Label"
418           },
419           {
420            "$ xns" : "Gtk",
421            "id" : "database_DBUSERNAME",
422            "items" : [
423             {
424              "$ xns" : "Gtk",
425              "listeners" : {
426               "key_pressed" : [
427                "(keyval, keycode, state) => {",
428                "    if (keyval == Gdk.Key.Tab) {",
429                "        _this.database_DBPASSWORD.el.grab_focus();",
430                "        return true;",
431                "    }",
432                "",
433                "",
434                "\treturn false;",
435                "\t ",
436                "",
437                "}",
438                ""
439               ]
440              },
441              "xtype" : "EventControllerKey"
442             }
443            ],
444            "xtype" : "Entry"
445           },
446           {
447            "$ xns" : "Gtk",
448            "label" : "Password",
449            "xalign" : 0,
450            "xtype" : "Label"
451           },
452           {
453            "$ xns" : "Gtk",
454            "id" : "database_DBPASSWORD",
455            "xtype" : "Entry"
456           },
457           {
458            "$ xns" : "Gtk",
459            "listeners" : {
460             "clicked" : [
461              "() => {",
462              "",
463              "",
464              "  _this.database_ERROR.el.label    = \"\";",
465              " /*",
466              "    Gda.Connection cnc;",
467              "    try {",
468              "        // assumes localhost...",
469              "         cnc = Gda.Connection.open_from_string (",
470              "\t\t\t_this.database_DBTYPE.el.get_text(),",
471              "\t\t\t\"DB_NAME=\" + _this.database_DBNAME.el.get_text(), ",
472              "\t\t\t\"USERNAME=\" + _this.database_DBUSERNAME.el.get_text() + ",
473              "\t\t\t\";PASSWORD=\" + _this.database_DBPASSWORD.el.get_text(),",
474              "\t\t\tGda.ConnectionOptions.NONE",
475              "\t\t);",
476              "   //} catch (Gda.ConnectionError ce) { ",
477              "   //   _this.database_ERROR.el.label = ce.message;        ",
478              "   } catch(GLib.Error ue) {",
479              "      _this.database_ERROR.el.label = ue.message;",
480              "        return;",
481              "   }  ",
482              "  _this.database_ERROR.el.label = \"Connection Succeeded\";",
483              "   cnc.close();",
484              "  */",
485              "}"
486             ]
487            },
488            "utf8 label" : "Check Connection",
489            "xtype" : "Button"
490           },
491           {
492            "$ xns" : "Gtk",
493            "id" : "database_ERROR",
494            "label" : " ",
495            "xalign" : 0,
496            "xtype" : "Label"
497           }
498          ],
499          "xtype" : "Box"
500         }
501        ],
502        "xtype" : "Notebook"
503       }
504      ],
505      "xtype" : "Box"
506     },
507     {
508      "$ xns" : "Gtk",
509      "* prop" : "titlebar",
510      "bool show_title_buttons" : false,
511      "items" : [
512       {
513        "$ xns" : "Gtk",
514        "* pack" : "pack_start",
515        "listeners" : {
516         "clicked" : [
517          "() => { ",
518          "",
519          "  _this.done = true;",
520          "    _this.el.hide(); ",
521          "}"
522         ]
523        },
524        "string label" : "Cancel",
525        "xtype" : "Button"
526       },
527       {
528        "$ xns" : "Gtk",
529        "* pack" : "pack_end",
530        "css_classes" : "{ \"suggested-action\" }",
531        "listeners" : {
532         "clicked" : [
533          "( ) =>  { ",
534          "",
535          " ",
536          " _this.buttonPressed(\"save\");",
537          " ",
538          "\t// what about .js ?",
539          "   _this.done = true;",
540          "\t_this.el.hide();",
541          "",
542          "// hopefull this will work with bjs files..",
543          "\t",
544          " ",
545          "   ",
546          "}"
547         ]
548        },
549        "string label" : "Save",
550        "xtype" : "Button"
551       }
552      ],
553      "xtype" : "HeaderBar"
554     }
555    ],
556    "string title" : "Edit Project settings",
557    "uint border_width" : 0,
558    "xtype" : "Window",
559    "| void save" : [
560     "() {",
561     "   var buf =    _this.view.el.get_buffer();",
562     "   Gtk.TextIter s;",
563     "     Gtk.TextIter e;",
564     "    buf.get_start_iter(out s);",
565     "    buf.get_end_iter(out e);",
566     "\t_this.project.runhtml = buf.get_text(s,e,true);",
567     "      ",
568     "    _this.project.rootURL = _this.rootURL.el.get_text();",
569     "    ",
570     "    ",
571     "    Gtk.TreeIter iter;",
572     "    Value html_gen_val;",
573     "    _this.html_gen.el.get_active_iter(out iter);",
574     "    _this.html_gen_model.el.get_value (iter, 0, out html_gen_val);",
575     "    ",
576     "    _this.project.html_gen = (string)html_gen_val;",
577     "    ",
578     "    // set by event changed...",
579     "    //_this.project.base_template = _this.base_template.el.get_text();    ",
580     "    ",
581     "    var js = _this.project;",
582     "    js.DBTYPE = _this.database_DBTYPE.el.get_text();",
583     "   js.DBNAME= _this.database_DBNAME.el.get_text();",
584     "    js.DBUSERNAME= _this.database_DBUSERNAME.el.get_text();",
585     "    js.DBPASSWORD= _this.database_DBPASSWORD.el.get_text();",
586     "//    _this.project.set_string_member(\"DBHOST\", _this.DBTYPE.el.get_text());    ",
587     "    ",
588     "    // need to re-init the database ",
589     "    \tjs.save();",
590     "    _this.project.initDatabase();",
591     "     ",
592     "    ",
593     "}"
594    ],
595    "| void show" : [
596     " (Gtk.Window pwin, Project.Roo project) {",
597     "    _this.done = false;",
598     "    ",
599     "    _this.project = project;",
600     "    _this.path.el.label = project.path;",
601     "    // get the active project.",
602     "     var lm = GtkSource.LanguageManager.get_default();",
603     "                ",
604     "    ((GtkSource.Buffer)(_this.view.el.get_buffer())) .set_language(",
605     "        lm.get_language(\"html\")",
606     "    );",
607     "  ",
608     "    //print (project.fn);",
609     "    //project.runhtml = project.runhtml || '';",
610     "    _this.view.el.get_buffer().set_text(project.runhtml);",
611     "     ",
612     "      ",
613     "    _this.rootURL.el.set_text( _this.project.rootURL );",
614     "    ",
615     "    _this.html_gen_model.loadData(_this.project.html_gen);",
616     "",
617     "    _this.base_template_model.loadData();",
618     "    ",
619     "     //var js = _this.project;",
620     "    _this.database_DBTYPE.el.set_text(    _this.project.DBTYPE );",
621     "    _this.database_DBNAME.el.set_text(    _this.project.DBNAME );",
622     "    _this.database_DBUSERNAME.el.set_text(  _this.project.DBUSERNAME );",
623     "    _this.database_DBPASSWORD.el.set_text(  _this.project.DBPASSWORD );",
624     "    ",
625     "    \t//console.log('show all');",
626     "",
627     "\t",
628     "    this.el.set_transient_for(pwin);",
629     "\t// window + header?",
630     "\t print(\"SHOWALL - POPIP\\n\");",
631     "\tthis.el.show();",
632     "\tthis.el.set_size_request(800,600);",
633     "\tthis.view.el.grab_focus();",
634     "\t",
635     "    ",
636     "    //this.el.show_all();",
637     "}",
638     ""
639    ]
640   }
641  ],
642  "name" : "RooProjectSettings"
643 }