Fix #8045 - roo base template not getting set correctly, clear warnings in roo settin...
[roobuilder] / src / Builder4 / RooProjectSettings.bjs
1 {
2  "build_module" : "builder",
3  "gen_extended" : false,
4  "items" : [
5   {
6    "# Project.Roo project" : "",
7    "# bool done" : false,
8    "$ xns" : "Gtk",
9    "@ void buttonPressed" : "(string btn)",
10    "bool modal" : true,
11    "id" : "RooProjectSettings",
12    "items" : [
13     {
14      "$ homogeneous" : false,
15      "$ xns" : "Gtk",
16      "* pack" : "set_child",
17      "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
18      "border_width" : 5,
19      "items" : [
20       {
21        "$ xns" : "Gtk",
22        "items" : [
23         {
24          "$ xns" : "Gtk",
25          "* pack" : false,
26          "id" : "label_global",
27          "utf8 label" : "Global",
28          "xtype" : "Label"
29         },
30         {
31          "$ xns" : "Gtk",
32          "* pack" : false,
33          "id" : "label_database",
34          "utf8 label" : "Database",
35          "xtype" : "Label"
36         },
37         {
38          "$ xns" : "Gtk",
39          "* pack" : "append_page,_this.label_global.el",
40          "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
41          "gboolean homogeneous" : false,
42          "items" : [
43           {
44            "$ homogeneous" : true,
45            "$ xns" : "Gtk",
46            "id" : "grid",
47            "int margin_end" : 4,
48            "int margin_start" : 4,
49            "items" : [
50             {
51              "$ xns" : "Gtk",
52              "* pack" : "attach,0,0,1,1",
53              "int margin_bottom" : 3,
54              "int margin_end" : 3,
55              "int margin_start" : 3,
56              "int margin_top" : 3,
57              "label" : "Filename",
58              "xalign" : 0,
59              "xtype" : "Label"
60             },
61             {
62              "$ xns" : "Gtk",
63              "* pack" : "attach,1,0,1,1",
64              "id" : "path",
65              "int margin_bottom" : 3,
66              "int margin_end" : 3,
67              "int margin_start" : 3,
68              "int margin_top" : 3,
69              "label" : "filename",
70              "xalign" : 0,
71              "xtype" : "Label"
72             },
73             {
74              "$ xns" : "Gtk",
75              "* pack" : "attach,0,1,1,1",
76              "int margin_bottom" : 3,
77              "int margin_end" : 3,
78              "int margin_start" : 3,
79              "int margin_top" : 3,
80              "label" : "HTML template file",
81              "xtype" : "Label"
82             },
83             {
84              "# bool loading" : false,
85              "$ xns" : "Gtk",
86              "* pack" : "attach,1,1,1,1",
87              "id" : "base_template",
88              "items" : [
89               {
90                "$ xns" : "Gtk",
91                "* prop" : "model",
92                "strings" : [
93                 "{ ",
94                 "\t\"roo.builder.html\",",
95                 "\t\"bootstrap.builder.html\",",
96                 "\t\"bootstrap4.builder.html\",",
97                 "\t\"mailer.builder.html\"",
98                 "}"
99                ],
100                "xtype" : "StringList"
101               }
102              ],
103              "listeners" : {
104               "notify[\"selected\"]" : [
105                "() => {",
106                "",
107                " ",
108                "\t// this get's called when we are filling in the data... ???",
109                "\tif (this.loading) {",
110                "\t\treturn;",
111                "\t}",
112                "\tvar sm = (Gtk.StringList) this.el.model;",
113                "\t_this.project.base_template = sm.get_string(this.el.selected);",
114                "\t\t",
115                "\t\t print(\"\\nSET base template to %s\\n\", _this.project.base_template );",
116                "\t\t// is_bjs = ((string)vfname) == \"bjs\";",
117                "",
118                "",
119                " }"
120               ]
121              },
122              "xtype" : "DropDown"
123             },
124             {
125              "$ xns" : "Gtk",
126              "* pack" : "attach,0,2,1,1",
127              "int margin_bottom" : 3,
128              "int margin_end" : 3,
129              "int margin_start" : 3,
130              "int margin_top" : 3,
131              "label" : "root URL",
132              "xtype" : "Label"
133             },
134             {
135              "$ xns" : "Gtk",
136              "* pack" : "attach,1,2,1,1",
137              "id" : "rootURL",
138              "xtype" : "Entry"
139             },
140             {
141              "$ xns" : "Gtk",
142              "* pack" : "attach,0,3,1,1",
143              "label" : "Generate HTML in",
144              "xtype" : "Label"
145             },
146             {
147              "# bool loading" : false,
148              "$ xns" : "Gtk",
149              "* pack" : "attach,1,3,1,1",
150              "id" : "html_gen",
151              "items" : [
152               {
153                "$ xns" : "Gtk",
154                "* prop" : "model",
155                "strings" : [
156                 "{ ",
157                 "\t\"Do not Generate\", // \"\"",
158                 "\t\"same directory as BJS file\", // bjs",
159                 "\t\"in templates subdirectory\"  // tmeplate",
160                 " ",
161                 "}  "
162                ],
163                "xtype" : "StringList"
164               }
165              ],
166              "listeners" : {
167               "notify[\"selected\"]" : [
168                "() => {",
169                "",
170                " ",
171                "\t// this get's called when we are filling in the data... ???",
172                "\tif (this.loading) {",
173                "\t\treturn;",
174                "\t}",
175                "\tvar sm = (Gtk.StringList) this.el.model;",
176                "\t_this.project.base_template = sm.get_string(this.el.selected);",
177                "\t\t",
178                "\t\t print(\"\\nSET base template to %s\\n\", _this.project.base_template );",
179                "\t\t// is_bjs = ((string)vfname) == \"bjs\";",
180                "",
181                "",
182                " }"
183               ]
184              },
185              "xtype" : "DropDown"
186             }
187            ],
188            "n_columns" : 2,
189            "n_rows" : 7,
190            "uint row_spacing" : 2,
191            "xtype" : "Grid"
192           },
193           {
194            "$ xns" : "Gtk",
195            "label" : "HTML To insert at end of <HEAD>",
196            "xtype" : "Label"
197           },
198           {
199            "$ xns" : "Gtk",
200            "bool vexpand" : true,
201            "items" : [
202             {
203              "$ xns" : "GtkSource",
204              "* pack" : "set_child",
205              "css_classes" : "{ \"code-editor\" }",
206              "id" : "view",
207              "items" : [
208               {
209                "$ xns" : "Gtk",
210                "listeners" : {
211                 "key_released" : [
212                  "(keyval, keycode, state) => {",
213                  "",
214                  "",
215                  "    if (keyval != 115) {",
216                  "        return;",
217                  "         ",
218                  "    }",
219                  "    if   ( (state & Gdk.ModifierType.CONTROL_MASK ) < 1 ) {",
220                  "        return;",
221                  "    }",
222                  "     var buf =    _this.view.el.get_buffer();",
223                  "    Gtk.TextIter s;",
224                  "    Gtk.TextIter e;",
225                  "    buf.get_start_iter(out s);",
226                  "    buf.get_end_iter(out e);",
227                  "    _this.project.runhtml = buf.get_text(s,e,true);",
228                  "    ",
229                  "          ",
230                  "    _this.buttonPressed(\"save\");",
231                  "   ",
232                  "         ",
233                  "",
234                  "}",
235                  ""
236                 ]
237                },
238                "xtype" : "EventControllerKey"
239               }
240              ],
241              "xtype" : "View"
242             }
243            ],
244            "xtype" : "ScrolledWindow"
245           }
246          ],
247          "xtype" : "Box"
248         },
249         {
250          "$ xns" : "Gtk",
251          "* pack" : "append_page,_this.label_database.el",
252          "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
253          "gboolean homogeneous" : false,
254          "items" : [
255           {
256            "$ xns" : "Gtk",
257            "label" : "Type (eg. MySQL or PostgreSQL)",
258            "xalign" : 0,
259            "xtype" : "Label"
260           },
261           {
262            "$ xns" : "Gtk",
263            "id" : "database_DBTYPE",
264            "items" : [
265             {
266              "$ xns" : "Gtk",
267              "listeners" : {
268               "key_pressed" : [
269                "(keyval, keycode, state) => {",
270                "    if (keyval == Gdk.Key.Tab) {",
271                "        _this.database_DBNAME.el.grab_focus();",
272                "        return true;",
273                "    }",
274                "",
275                "",
276                "\treturn false;",
277                "}",
278                ""
279               ]
280              },
281              "xtype" : "EventControllerKey"
282             }
283            ],
284            "xtype" : "Entry"
285           },
286           {
287            "$ xns" : "Gtk",
288            "label" : "Name",
289            "xalign" : 0,
290            "xtype" : "Label"
291           },
292           {
293            "$ xns" : "Gtk",
294            "id" : "database_DBNAME",
295            "items" : [
296             {
297              "$ xns" : "Gtk",
298              "listeners" : {
299               "key_pressed" : [
300                "(keyval, keycode, state) => {",
301                "    if (keyval == Gdk.Key.Tab) {",
302                "        _this.database_DBUSERNAME.el.grab_focus();",
303                "        return true;",
304                "    }",
305                "",
306                "",
307                "\treturn false;",
308                "\t ",
309                "}",
310                ""
311               ]
312              },
313              "xtype" : "EventControllerKey"
314             }
315            ],
316            "xtype" : "Entry"
317           },
318           {
319            "$ xns" : "Gtk",
320            "listeners" : {
321             "clicked" : [
322              "() => {",
323              "",
324              "",
325              "  _this.database_ERROR.el.label    = \"\";",
326              " /*",
327              "    Gda.Connection cnc;",
328              "    try {",
329              "        // assumes localhost...",
330              "         cnc = Gda.Connection.open_from_string (",
331              "\t\t\t_this.database_DBTYPE.el.get_text(),",
332              "\t\t\t\"DB_NAME=\" + _this.database_DBNAME.el.get_text(), ",
333              "\t\t\t\"USERNAME=\" + _this.database_DBUSERNAME.el.get_text() + ",
334              "\t\t\t\";PASSWORD=\" + _this.database_DBPASSWORD.el.get_text(),",
335              "\t\t\tGda.ConnectionOptions.NONE",
336              "\t\t);",
337              "   //} catch (Gda.ConnectionError ce) { ",
338              "   //   _this.database_ERROR.el.label = ce.message;        ",
339              "   } catch(GLib.Error ue) {",
340              "      _this.database_ERROR.el.label = ue.message;",
341              "        return;",
342              "   }  ",
343              "  _this.database_ERROR.el.label = \"Connection Succeeded\";",
344              "   cnc.close();",
345              "  */",
346              "}"
347             ]
348            },
349            "utf8 label" : "Check Connection",
350            "xtype" : "Button"
351           },
352           {
353            "$ xns" : "Gtk",
354            "id" : "database_ERROR",
355            "label" : " ",
356            "xalign" : 0,
357            "xtype" : "Label"
358           }
359          ],
360          "xtype" : "Box"
361         }
362        ],
363        "xtype" : "Notebook"
364       }
365      ],
366      "xtype" : "Box"
367     },
368     {
369      "$ xns" : "Gtk",
370      "* prop" : "titlebar",
371      "bool show_title_buttons" : false,
372      "items" : [
373       {
374        "$ xns" : "Gtk",
375        "* pack" : "pack_start",
376        "listeners" : {
377         "clicked" : [
378          "() => { ",
379          "",
380          "  _this.done = true;",
381          "    _this.el.hide(); ",
382          "}"
383         ]
384        },
385        "string label" : "Cancel",
386        "xtype" : "Button"
387       },
388       {
389        "$ xns" : "Gtk",
390        "* pack" : "pack_end",
391        "css_classes" : "{ \"suggested-action\" }",
392        "listeners" : {
393         "clicked" : [
394          "( ) =>  { ",
395          "",
396          " ",
397          " _this.buttonPressed(\"save\");",
398          " ",
399          "\t// what about .js ?",
400          "   _this.done = true;",
401          "\t_this.el.hide();",
402          "",
403          "// hopefull this will work with bjs files..",
404          "\t",
405          " ",
406          "   ",
407          "}"
408         ]
409        },
410        "string label" : "Save",
411        "xtype" : "Button"
412       }
413      ],
414      "xtype" : "HeaderBar"
415     }
416    ],
417    "string title" : "Edit Project settings",
418    "xtype" : "Window",
419    "| void save" : [
420     "() {",
421     "   var buf =    _this.view.el.get_buffer();",
422     "   Gtk.TextIter s;",
423     "     Gtk.TextIter e;",
424     "    buf.get_start_iter(out s);",
425     "    buf.get_end_iter(out e);",
426     "\t_this.project.runhtml = buf.get_text(s,e,true);",
427     "      ",
428     "    _this.project.rootURL = _this.rootURL.el.get_text();",
429     "    ",
430     "     ",
431     "    ",
432     "      ",
433     "\tvar val  = \"\";",
434     "\tswitch (this.html_gen.el.selected) {",
435     "\t\tcase 1: val = \"bjs\"; break;",
436     "\t\tcase 2: val = \"template\"; break;",
437     "\t}",
438     "    ",
439     "    _this.project.html_gen = val;",
440     "    ",
441     "    // set by event changed...",
442     "    //_this.project.base_template = _this.base_template.el.get_text();    ",
443     "    ",
444     "    var js = _this.project;",
445     "    js.DBTYPE = _this.database_DBTYPE.el.get_text();",
446     "   js.DBNAME= _this.database_DBNAME.el.get_text();",
447     "   // js.DBUSERNAME= _this.database_DBUSERNAME.el.get_text();",
448     "   // js.DBPASSWORD= _this.database_DBPASSWORD.el.get_text();",
449     "//    _this.project.set_string_member(\"DBHOST\", _this.DBTYPE.el.get_text());    ",
450     "    ",
451     "    // need to re-init the database ",
452     "    \tjs.save();",
453     "    _this.project.initDatabase();",
454     "     ",
455     "    ",
456     "}"
457    ],
458    "| void show" : [
459     " (Gtk.Window pwin, Project.Roo project) {",
460     "    _this.done = false;",
461     "    ",
462     "    _this.project = project;",
463     "    _this.path.el.label = project.path;",
464     "    // get the active project.",
465     "     var lm = GtkSource.LanguageManager.get_default();",
466     "                ",
467     "    ((GtkSource.Buffer)(_this.view.el.get_buffer())) .set_language(",
468     "        lm.get_language(\"html\")",
469     "    );",
470     "  ",
471     "    //print (project.fn);",
472     "    //project.runhtml = project.runhtml || '';",
473     "    _this.view.el.get_buffer().set_text(project.runhtml);",
474     "     ",
475     "      ",
476     "    _this.rootURL.el.set_text( _this.project.rootURL );",
477     "    ",
478     " ",
479     "    var tv = 0;",
480     "    switch (this.project.html_gen) {",
481     "    \tcase \"bjs\": tv = 1; break;",
482     "    \tcase \"template\": tv = 2; break;",
483     "    }",
484     "    this.html_gen.el.selected = tv;",
485     "   ",
486     "    ",
487     "",
488     "\tvar sm = (Gtk.StringList)     _this.base_template.el.model;",
489     "\tthis.base_template.loading = true;",
490     "\tthis.base_template.el.selected = Gtk.INVALID_LIST_POSITION;",
491     "\tfor(var i=0;i< sm.get_n_items(); i++) {",
492     "\t\tif (sm.get_string( i ) ==  this.project.base_template) {",
493     "\t\t\tthis.base_template.el.selected = i;",
494     "\t\t\tbreak;",
495     "\t\t}",
496     "\t}",
497     "    this.base_template.loading = false;",
498     "     //var js = _this.project;",
499     "    _this.database_DBTYPE.el.set_text(    _this.project.DBTYPE );",
500     "    _this.database_DBNAME.el.set_text(    _this.project.DBNAME );",
501     "    //_this.database_DBUSERNAME.el.set_text(  _this.project.DBUSERNAME );",
502     "    //_this.database_DBPASSWORD.el.set_text(  _this.project.DBPASSWORD );",
503     "    ",
504     "    \t//console.log('show all');",
505     "",
506     "\t",
507     "    this.el.set_transient_for(pwin);",
508     "\t// window + header?",
509     "\t print(\"SHOWALL - POPIP\\n\");",
510     "\tthis.el.show();",
511     "\tthis.el.set_size_request(800,600);",
512     "\tthis.view.el.grab_focus();",
513     "\t",
514     "    ",
515     "    //this.el.show_all();",
516     "}",
517     ""
518    ]
519   }
520  ],
521  "name" : "RooProjectSettings"
522 }