remove tab event on roo setings dialog
[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            "xtype" : "Entry"
296           },
297           {
298            "$ xns" : "Gtk",
299            "listeners" : {
300             "clicked" : [
301              "() => {",
302              "",
303              "",
304              "  _this.database_ERROR.el.label    = \"\";",
305              " /*",
306              "    Gda.Connection cnc;",
307              "    try {",
308              "        // assumes localhost...",
309              "         cnc = Gda.Connection.open_from_string (",
310              "\t\t\t_this.database_DBTYPE.el.get_text(),",
311              "\t\t\t\"DB_NAME=\" + _this.database_DBNAME.el.get_text(), ",
312              "\t\t\t\"USERNAME=\" + _this.database_DBUSERNAME.el.get_text() + ",
313              "\t\t\t\";PASSWORD=\" + _this.database_DBPASSWORD.el.get_text(),",
314              "\t\t\tGda.ConnectionOptions.NONE",
315              "\t\t);",
316              "   //} catch (Gda.ConnectionError ce) { ",
317              "   //   _this.database_ERROR.el.label = ce.message;        ",
318              "   } catch(GLib.Error ue) {",
319              "      _this.database_ERROR.el.label = ue.message;",
320              "        return;",
321              "   }  ",
322              "  _this.database_ERROR.el.label = \"Connection Succeeded\";",
323              "   cnc.close();",
324              "  */",
325              "}"
326             ]
327            },
328            "utf8 label" : "Check Connection",
329            "xtype" : "Button"
330           },
331           {
332            "$ xns" : "Gtk",
333            "id" : "database_ERROR",
334            "label" : " ",
335            "xalign" : 0,
336            "xtype" : "Label"
337           }
338          ],
339          "xtype" : "Box"
340         }
341        ],
342        "xtype" : "Notebook"
343       }
344      ],
345      "xtype" : "Box"
346     },
347     {
348      "$ xns" : "Gtk",
349      "* prop" : "titlebar",
350      "bool show_title_buttons" : false,
351      "items" : [
352       {
353        "$ xns" : "Gtk",
354        "* pack" : "pack_start",
355        "listeners" : {
356         "clicked" : [
357          "() => { ",
358          "",
359          "  _this.done = true;",
360          "    _this.el.hide(); ",
361          "}"
362         ]
363        },
364        "string label" : "Cancel",
365        "xtype" : "Button"
366       },
367       {
368        "$ xns" : "Gtk",
369        "* pack" : "pack_end",
370        "css_classes" : "{ \"suggested-action\" }",
371        "listeners" : {
372         "clicked" : [
373          "( ) =>  { ",
374          "",
375          " ",
376          " _this.buttonPressed(\"save\");",
377          " ",
378          "\t// what about .js ?",
379          "   _this.done = true;",
380          "\t_this.el.hide();",
381          "",
382          "// hopefull this will work with bjs files..",
383          "\t",
384          " ",
385          "   ",
386          "}"
387         ]
388        },
389        "string label" : "Save",
390        "xtype" : "Button"
391       }
392      ],
393      "xtype" : "HeaderBar"
394     }
395    ],
396    "string title" : "Edit Project settings",
397    "xtype" : "Window",
398    "| void save" : [
399     "() {",
400     "   var buf =    _this.view.el.get_buffer();",
401     "   Gtk.TextIter s;",
402     "     Gtk.TextIter e;",
403     "    buf.get_start_iter(out s);",
404     "    buf.get_end_iter(out e);",
405     "\t_this.project.runhtml = buf.get_text(s,e,true);",
406     "      ",
407     "    _this.project.rootURL = _this.rootURL.el.get_text();",
408     "    ",
409     "     ",
410     "    ",
411     "      ",
412     "\tvar val  = \"\";",
413     "\tswitch (this.html_gen.el.selected) {",
414     "\t\tcase 1: val = \"bjs\"; break;",
415     "\t\tcase 2: val = \"template\"; break;",
416     "\t}",
417     "    ",
418     "    _this.project.html_gen = val;",
419     "    ",
420     "    // set by event changed...",
421     "    //_this.project.base_template = _this.base_template.el.get_text();    ",
422     "    ",
423     "    var js = _this.project;",
424     "    js.DBTYPE = _this.database_DBTYPE.el.get_text();",
425     "   js.DBNAME= _this.database_DBNAME.el.get_text();",
426     "   // js.DBUSERNAME= _this.database_DBUSERNAME.el.get_text();",
427     "   // js.DBPASSWORD= _this.database_DBPASSWORD.el.get_text();",
428     "//    _this.project.set_string_member(\"DBHOST\", _this.DBTYPE.el.get_text());    ",
429     "    ",
430     "    // need to re-init the database ",
431     "    \tjs.save();",
432     "    _this.project.initDatabase();",
433     "     ",
434     "    ",
435     "}"
436    ],
437    "| void show" : [
438     " (Gtk.Window pwin, Project.Roo project) {",
439     "    _this.done = false;",
440     "    ",
441     "    _this.project = project;",
442     "    _this.path.el.label = project.path;",
443     "    // get the active project.",
444     "     var lm = GtkSource.LanguageManager.get_default();",
445     "                ",
446     "    ((GtkSource.Buffer)(_this.view.el.get_buffer())) .set_language(",
447     "        lm.get_language(\"html\")",
448     "    );",
449     "  ",
450     "    //print (project.fn);",
451     "    //project.runhtml = project.runhtml || '';",
452     "    _this.view.el.get_buffer().set_text(project.runhtml);",
453     "     ",
454     "      ",
455     "    _this.rootURL.el.set_text( _this.project.rootURL );",
456     "    ",
457     " ",
458     "    var tv = 0;",
459     "    switch (this.project.html_gen) {",
460     "    \tcase \"bjs\": tv = 1; break;",
461     "    \tcase \"template\": tv = 2; break;",
462     "    }",
463     "    this.html_gen.el.selected = tv;",
464     "   ",
465     "    ",
466     "",
467     "\tvar sm = (Gtk.StringList)     _this.base_template.el.model;",
468     "\tthis.base_template.loading = true;",
469     "\tthis.base_template.el.selected = Gtk.INVALID_LIST_POSITION;",
470     "\tfor(var i=0;i< sm.get_n_items(); i++) {",
471     "\t\tif (sm.get_string( i ) ==  this.project.base_template) {",
472     "\t\t\tthis.base_template.el.selected = i;",
473     "\t\t\tbreak;",
474     "\t\t}",
475     "\t}",
476     "    this.base_template.loading = false;",
477     "     //var js = _this.project;",
478     "    _this.database_DBTYPE.el.set_text(    _this.project.DBTYPE );",
479     "    _this.database_DBNAME.el.set_text(    _this.project.DBNAME );",
480     "    //_this.database_DBUSERNAME.el.set_text(  _this.project.DBUSERNAME );",
481     "    //_this.database_DBPASSWORD.el.set_text(  _this.project.DBPASSWORD );",
482     "    ",
483     "    \t//console.log('show all');",
484     "",
485     "\t",
486     "    this.el.set_transient_for(pwin);",
487     "\t// window + header?",
488     "\t print(\"SHOWALL - POPIP\\n\");",
489     "\tthis.el.show();",
490     "\tthis.el.set_size_request(800,600);",
491     "\tthis.view.el.grab_focus();",
492     "\t",
493     "    ",
494     "    //this.el.show_all();",
495     "}",
496     ""
497    ]
498   }
499  ],
500  "name" : "RooProjectSettings"
501 }