Fix #7250 - better handling of adding properties
[roobuilder] / src / Builder4 / ProjectSettings.bjs
1 {
2  "build_module" : "builder",
3  "items" : [
4   {
5    "# Project.Project project" : "",
6    "$ homogeneous" : false,
7    "$ xns" : "Gtk",
8    "@ void buttonPressed" : "(string btn)",
9    "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
10    "border_width" : 5,
11    "id" : "RooProjectSettings",
12    "items" : [
13     {
14      "$ homogeneous" : true,
15      "$ xns" : "Gtk",
16      "* pack" : "pack_start,false,false,0",
17      "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
18      "gboolean expand" : false,
19      "gboolean vexpand" : false,
20      "items" : [
21       {
22        "$ xns" : "Gtk",
23        "* pack" : "add",
24        "label" : "Apply",
25        "listeners" : {
26         "button_press_event" : [
27          "() => {",
28          "    _this.save();",
29          "          ",
30          "    _this.buttonPressed(\"apply\");",
31          "        return false;",
32          "}"
33         ]
34        },
35        "xtype" : "Button"
36       },
37       {
38        "$ xns" : "Gtk",
39        "* pack" : "add",
40        "label" : "Save",
41        "listeners" : {
42         "button_press_event" : [
43          "() => {",
44          "       _this.save();",
45          "          ",
46          "    _this.buttonPressed(\"save\");",
47          "        return false;",
48          "}"
49         ]
50        },
51        "xtype" : "Button"
52       }
53      ],
54      "xtype" : "Box"
55     },
56     {
57      "$ xns" : "Gtk",
58      "* pack" : "pack_end,true,true,0",
59      "items" : [
60       {
61        "$ xns" : "Gtk",
62        "* pack" : false,
63        "id" : "label_global",
64        "utf8 label" : "Global",
65        "xtype" : "Label"
66       },
67       {
68        "$ xns" : "Gtk",
69        "* pack" : false,
70        "id" : "label_database",
71        "utf8 label" : "Database",
72        "xtype" : "Label"
73       },
74       {
75        "$ xns" : "Gtk",
76        "* pack" : "append_page,_this.label_global.el",
77        "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
78        "gboolean homogeneous" : false,
79        "items" : [
80         {
81          "$ xns" : "Gtk",
82          "* pack" : "pack_start,false,false,0",
83          "gint margin" : 3,
84          "id" : "path",
85          "label" : "filename",
86          "xalign" : 0,
87          "xtype" : "Label"
88         },
89         {
90          "$ homogeneous" : false,
91          "$ xns" : "Gtk",
92          "* pack" : "pack_start,false,false,0",
93          "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
94          "gboolean expand" : false,
95          "items" : [
96           {
97            "$ xns" : "Gtk",
98            "* pack" : "pack_start,false,false,0",
99            "gint margin" : 3,
100            "label" : "HTML template file",
101            "xtype" : "Label"
102           },
103           {
104            "$ xns" : "Gtk",
105            "* pack" : "add",
106            "id" : "base_template",
107            "xtype" : "Entry"
108           }
109          ],
110          "xtype" : "Box"
111         },
112         {
113          "$ homogeneous" : false,
114          "$ xns" : "Gtk",
115          "* pack" : "pack_start,false,false,0",
116          "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
117          "gboolean expand" : false,
118          "items" : [
119           {
120            "$ xns" : "Gtk",
121            "* pack" : "pack_start,false,false,0",
122            "gint margin" : 3,
123            "label" : "root URL",
124            "xtype" : "Label"
125           },
126           {
127            "$ xns" : "Gtk",
128            "* pack" : "add",
129            "id" : "rootURL",
130            "xtype" : "Entry"
131           }
132          ],
133          "xtype" : "Box"
134         },
135         {
136          "$ xns" : "Gtk",
137          "* pack" : "pack_start,false,false,0",
138          "label" : "HTML To insert at end of <HEAD>",
139          "xtype" : "Label"
140         },
141         {
142          "$ xns" : "Gtk",
143          "* pack" : "pack_start,true,true,0",
144          "items" : [
145           {
146            "$ xns" : "GtkSource",
147            "* init" : [
148             " ",
149             "    var description =   Pango.FontDescription.from_string(\"monospace\");",
150             "    description.set_size(9000);",
151             "    this.el.override_font(description);"
152            ],
153            "* pack" : "add",
154            "id" : "view",
155            "listeners" : {
156             "key_release_event" : [
157              " ( event) =>{",
158              "    if (event.keyval != 115) {",
159              "        return false;",
160              "         ",
161              "    }",
162              "    if   ( (event.state & Gdk.ModifierType.CONTROL_MASK ) < 1 ) {",
163              "        return false;",
164              "    }",
165              "     var buf =    this.el.get_buffer();",
166              "    Gtk.TextIter s;",
167              "    Gtk.TextIter e;",
168              "    buf.get_start_iter(out s);",
169              "    buf.get_end_iter(out e);",
170              "    _this.project.runhtml = buf.get_text(s,e,true);",
171              "    ",
172              "          ",
173              "    _this.buttonPressed(\"save\");",
174              "     ",
175              "    return false;",
176              "         ",
177              "}"
178             ]
179            },
180            "xtype" : "View"
181           }
182          ],
183          "xtype" : "ScrolledWindow"
184         }
185        ],
186        "xtype" : "Box"
187       },
188       {
189        "$ xns" : "Gtk",
190        "* pack" : "append_page,_this.label_database.el",
191        "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
192        "gboolean homogeneous" : false,
193        "items" : [
194         {
195          "$ xns" : "Gtk",
196          "* pack" : "pack_start,false,false,0",
197          "label" : "Type (eg. MySQL or PostgreSQL)",
198          "xalign" : 0,
199          "xtype" : "Label"
200         },
201         {
202          "$ xns" : "Gtk",
203          "* pack" : "pack_start,false,false,0",
204          "id" : "database_DBTYPE",
205          "listeners" : {
206           "key_press_event" : [
207            "(ev) => {",
208            "",
209            "    if (ev.keyval == Gdk.Key.Tab) {",
210            "        _this.database_DBNAME.el.grab_focus();",
211            "        return true;",
212            "    }",
213            "",
214            "",
215            "    return false;",
216            "}",
217            ""
218           ]
219          },
220          "xtype" : "Entry"
221         },
222         {
223          "$ xns" : "Gtk",
224          "* pack" : "pack_start,false,false,0",
225          "label" : "Name",
226          "xalign" : 0,
227          "xtype" : "Label"
228         },
229         {
230          "$ xns" : "Gtk",
231          "* pack" : "pack_start,false,false,0",
232          "id" : "database_DBNAME",
233          "listeners" : {
234           "key_press_event" : [
235            "(ev) => {",
236            "",
237            "    if (ev.keyval == Gdk.Key.Tab) {",
238            "        _this.database_DBUSERNAME.el.grab_focus();",
239            "        return true;",
240            "    }",
241            "",
242            "",
243            "    return false;",
244            "}",
245            ""
246           ]
247          },
248          "xtype" : "Entry"
249         },
250         {
251          "$ xns" : "Gtk",
252          "* pack" : "pack_start,false,false,0",
253          "label" : "Username",
254          "xalign" : 0,
255          "xtype" : "Label"
256         },
257         {
258          "$ xns" : "Gtk",
259          "* pack" : "pack_start,false,false,0",
260          "id" : "database_DBUSERNAME",
261          "listeners" : {
262           "key_press_event" : [
263            "(ev) => {",
264            "",
265            "    if (ev.keyval == Gdk.Key.Tab) {",
266            "        _this.database_DBPASSWORD.el.grab_focus();",
267            "        return true;",
268            "    }",
269            "",
270            "",
271            "    return false;",
272            "}",
273            ""
274           ]
275          },
276          "xtype" : "Entry"
277         },
278         {
279          "$ xns" : "Gtk",
280          "* pack" : "pack_start,false,false,0",
281          "label" : "Password",
282          "xalign" : 0,
283          "xtype" : "Label"
284         },
285         {
286          "$ xns" : "Gtk",
287          "* pack" : "pack_start,false,false,0",
288          "id" : "database_DBPASSWORD",
289          "xtype" : "Entry"
290         },
291         {
292          "$ xns" : "Gtk",
293          "* pack" : "pack_start,false,false,0",
294          "listeners" : {
295           "clicked" : [
296            "() => {",
297            "",
298            "",
299            "  _this.database_ERROR.el.label    = \"\";",
300            "    Gda.Connection cnc;",
301            "    try {",
302            "        // assumes localhost...",
303            "         cnc = Gda.Connection.open_from_string (",
304            "\t\t\t_this.database_DBTYPE.el.get_text(),",
305            "\t\t\t\"DB_NAME=\" + _this.database_DBNAME.el.get_text(), ",
306            "\t\t\t\"USERNAME=\" + _this.database_DBUSERNAME.el.get_text() + ",
307            "\t\t\t\";PASSWORD=\" + _this.database_DBPASSWORD.el.get_text(),",
308            "\t\t\tGda.ConnectionOptions.NONE",
309            "\t\t);",
310            "   //} catch (Gda.ConnectionError ce) { ",
311            "   //   _this.database_ERROR.el.label = ce.message;        ",
312            "   } catch(Gda.ConnectionError ue) {",
313            "      _this.database_ERROR.el.label = ue.message;",
314            "        return;",
315            "   }  catch(Gda.ConfigError ue) {",
316            "      _this.database_ERROR.el.label = ue.message;",
317            "        return;",
318            "   }",
319            "  _this.database_ERROR.el.label = \"Connection Succeeded\";",
320            "   cnc.close();",
321            "}"
322           ]
323          },
324          "utf8 label" : "Check Connection",
325          "xtype" : "Button"
326         },
327         {
328          "$ xns" : "Gtk",
329          "* pack" : "pack_start,false,false,0",
330          "gint margin" : 3,
331          "id" : "database_ERROR",
332          "label" : " ",
333          "xalign" : 0,
334          "xtype" : "Label"
335         }
336        ],
337        "xtype" : "Box"
338       }
339      ],
340      "xtype" : "Notebook"
341     }
342    ],
343    "xtype" : "Box",
344    "| void save" : [
345     "()",
346     "{",
347     "   var buf =    _this.view.el.get_buffer();",
348     "   Gtk.TextIter s;",
349     "     Gtk.TextIter e;",
350     "    buf.get_start_iter(out s);",
351     "    buf.get_end_iter(out e);",
352     "      _this.project.runhtml = buf.get_text(s,e,true);",
353     "      ",
354     "    _this.project.rootURL = _this.rootURL.el.get_text();",
355     "    _this.project.base_template = _this.base_template.el.get_text();    ",
356     "    ",
357     "    var js = _this.project.json_project_data;",
358     "    js.set_string_member(\"DBTYPE\", _this.database_DBTYPE.el.get_text());",
359     "   js.set_string_member(\"DBNAME\", _this.database_DBNAME.el.get_text());",
360     "    js.set_string_member(\"DBUSERNAME\", _this.database_DBUSERNAME.el.get_text());",
361     "    js.set_string_member(\"DBPASSWORD\", _this.database_DBPASSWORD.el.get_text());",
362     "//    _this.project.set_string_member(\"DBHOST\", _this.DBTYPE.el.get_text());    ",
363     "    ",
364     "    // need to re-init the database ",
365     "    ",
366     "    _this.project.initRooDatabase();",
367     "      ",
368     "}"
369    ],
370    "| void show" : [
371     " (Project.Project project) {",
372     "    _this.project = project;",
373     "    _this.path.el.label = project.firstPath();",
374     "    // get the active project.",
375     "     var lm = Gtk.SourceLanguageManager.get_default();",
376     "                ",
377     "    ((Gtk.SourceBuffer)(_this.view.el.get_buffer())) .set_language(",
378     "    ",
379     "        lm.get_language(\"html\"));",
380     "  ",
381     "    //print (project.fn);",
382     "    //project.runhtml = project.runhtml || '';",
383     "    _this.view.el.get_buffer().set_text(project.runhtml);",
384     "    ",
385     "       ",
386     "    _this.rootURL.el.set_text( _this.project.rootURL );",
387     "    _this.base_template.el.set_text(_this.project.base_template);    ",
388     "     var js = _this.project;",
389     "    _this.database_DBTYPE.el.set_text(     js.get_string_member(\"DBTYPE\") );",
390     "    _this.database_DBNAME.el.set_text(    js.get_string_member(\"DBNAME\") );",
391     "    _this.database_DBUSERNAME.el.set_text(    js.get_string_member(\"DBUSERNAME\") );",
392     "    _this.database_DBPASSWORD.el.set_text(    js.get_string_member(\"DBPASSWORD\") );",
393     "    //this.el.show_all();",
394     "}",
395     ""
396    ]
397   }
398  ],
399  "modOrder" : "",
400  "name" : "ProjectSettings",
401  "parent" : "",
402  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/ProjectSettings.bjs",
403  "permname" : "",
404  "title" : ""
405 }