66b261e056d00f73f43a52f7c18ea4e0e70113ed
[roobuilder] / src / Builder4 / DialogTemplateSelect.bjs
1 {
2  "build_module" : "builder",
3  "items" : [
4   {
5    "# JsRender.Node node" : "",
6    "# Palete.Palete palete" : "",
7    "# Project.Project project" : "",
8    "# Xcls_MainWindow window" : "",
9    "$ modal" : true,
10    "$ xns" : "Gtk",
11    "@ void complete" : "(JsRender.Node? node)",
12    "default_height" : 200,
13    "default_width" : 400,
14    "items" : [
15     {
16      "$ xns" : "Gtk",
17      "* pack" : "get_content_area().append",
18      "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
19      "items" : [
20       {
21        "$ xns" : "Gtk",
22        "* pack" : "append",
23        "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
24        "int margin_end" : 3,
25        "int margin_start" : 3,
26        "items" : [
27         {
28          "$ xns" : "Gtk",
29          "* pack" : "append",
30          "label" : "Select Template : ",
31          "xtype" : "Label"
32         },
33         {
34          "$ xns" : "Gtk",
35          "* init" : "this.el.add_attribute(_this.cellrenderer.el , \"markup\", 1 );",
36          "* pack" : "append",
37          "id" : "combo",
38          "items" : [
39           {
40            "$ xns" : "Gtk",
41            "* pack" : "pack_start,true",
42            "id" : "cellrenderer",
43            "xtype" : "CellRendererText"
44           },
45           {
46            "$ columns" : "typeof(string),typeof(string)",
47            "$ xns" : "Gtk",
48            "* pack" : "set_model",
49            "id" : "model",
50            "n_columns" : 2,
51            "xtype" : "ListStore",
52            "| void loadData" : [
53             "  (GLib.List<string> data) {",
54             "    this.el.clear();                                    ",
55             "    Gtk.TreeIter iter;",
56             "    var el = this.el;",
57             "    ",
58             "   /// el.append(out iter);",
59             "    ",
60             "     ",
61             "   // el.set_value(iter, 0, \"\");",
62             "   // el.set_value(iter, 1, \"aaa  - Just add Element - aaa\");",
63             "    ",
64             "    for (var i = 0; i < data.length();i++) {",
65             "    ",
66             "",
67             "        el.append(out iter);",
68             "        var str = data.nth_data(i);",
69             "        var fn = Path.get_basename (str);",
70             "        fn.replace(\".json\", \"\");",
71             "        ",
72             "        el.set_value(iter, 0, str);",
73             "        el.set_value(iter, 1, fn);",
74             "        ",
75             "    }",
76             "    this.el.set_sort_column_id(1, Gtk.SortType.ASCENDING);          ",
77             "                                     ",
78             "}",
79             ""
80            ]
81           }
82          ],
83          "xtype" : "ComboBox"
84         }
85        ],
86        "xtype" : "Box"
87       },
88       {
89        "$ xns" : "Gtk",
90        "* pack" : "append",
91        "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
92        "int margin_end" : 3,
93        "int margin_start" : 3,
94        "items" : [
95         {
96          "$ xns" : "Gtk",
97          "* pack" : "append",
98          "label" : "Select Database Table : ",
99          "xtype" : "Label"
100         },
101         {
102          "$ xns" : "Gtk",
103          "* init" : "this.el.add_attribute(_this.dbcellrenderer.el , \"markup\", 1 );",
104          "* pack" : "append",
105          "id" : "dbcombo",
106          "items" : [
107           {
108            "$ xns" : "Gtk",
109            "* pack" : "pack_start,true",
110            "id" : "dbcellrenderer",
111            "xtype" : "CellRendererText"
112           },
113           {
114            "$ columns" : "typeof(string),typeof(string)",
115            "$ xns" : "Gtk",
116            "* pack" : "set_model",
117            "id" : "dbmodel",
118            "n_columns" : 2,
119            "xtype" : "ListStore",
120            "| void loadData" : [
121             "  (Gee.ArrayList<string> data) {",
122             "    this.el.clear();                                    ",
123             "    Gtk.TreeIter iter;",
124             "    var el = this.el;",
125             "    ",
126             "   /// el.append(out iter);",
127             "    ",
128             "     ",
129             "   // el.set_value(iter, 0, \"\");",
130             "   // el.set_value(iter, 1, \"aaa  - Just add Element - aaa\");",
131             "",
132             "    el.append(out iter);",
133             "",
134             "    ",
135             "    el.set_value(iter, 0, \"\");",
136             "    el.set_value(iter, 1, \"-- select a table --\");",
137             "    ",
138             "    ",
139             "    for (var i = 0; i < data.size;i++) {",
140             "    ",
141             "",
142             "        el.append(out iter);",
143             "        ",
144             "        el.set_value(iter, 0, data.get(i));",
145             "        el.set_value(iter, 1, data.get(i));",
146             "        ",
147             "    }",
148             "     this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          ",
149             "                                     ",
150             "}",
151             ""
152            ]
153           }
154          ],
155          "xtype" : "ComboBox"
156         }
157        ],
158        "xtype" : "Box"
159       }
160      ],
161      "xtype" : "Box"
162     },
163     {
164      "$ xns" : "Gtk",
165      "* pack" : "add_action_widget,0",
166      "label" : "Cancel",
167      "xtype" : "Button"
168     },
169     {
170      "$ xns" : "Gtk",
171      "* pack" : "add_action_widget,1",
172      "label" : "Just add it",
173      "xtype" : "Button"
174     },
175     {
176      "$ xns" : "Gtk",
177      "* pack" : "add_action_widget,2",
178      "label" : "OK",
179      "xtype" : "Button"
180     }
181    ],
182    "listeners" : {
183     "close_request" : [
184      "( ) => {",
185      "",
186      " this.el.hide();",
187      "    return true;;",
188      "}",
189      ""
190     ],
191     "response" : [
192      "(res) => {",
193      "",
194      "\t//var node = _this.node;",
195      "\t//var project = _this.project;",
196      "\treturn;",
197      "   /*",
198      "   ",
199      "   if (this.plugin == null) {",
200      "\t   this.plugin = new Xcls_DialogPluginWebkit();",
201      "\t   this.plugin.complete.connect((json_str) => {",
202      "  \t\t\tprint(\"json_str = %s\\n\", json_str);",
203      "            if (json_str.length < 1) {",
204      "\t\t\t\tthis.complete(_this.node);",
205      "\t\t\t\treturn; ",
206      "            }",
207      "            var pa = new Json.Parser();",
208      "            try {",
209      "",
210      "\t        \tpa.load_from_data(json_str);",
211      "\t\t\t} catch(Error e) {",
212      "\t\t\t     this.complete(node);",
213      "        \t\treturn; // 1 = just add it..",
214      "    \t\t}",
215      "    \t\tvar new_node = pa.get_root();",
216      "\t\t",
217      "\t\t\tif (new_node.get_node_type () != Json.NodeType.OBJECT) {",
218      "\t\t\t\t this.complete(node);",
219      "\t\t\t\t\t\treturn; ",
220      "\t\t\t}",
221      "\t\t\tvar obj = new_node.get_object ();",
222      "",
223      "\t\t\tvar ret = new JsRender.Node();",
224      "",
225      "\t\t\tret.loadFromJson(obj, 1);",
226      "\t \t\tthis.complete(ret);",
227      "  \t\t});",
228      "  ",
229      "   }",
230      "   ",
231      "   ",
232      "     ",
233      "\t",
234      "     this.el.hide();    ",
235      "    //var ix = _this.combo.el.get_active();",
236      "    if (res < 1 ) {",
237      "    \tthis.complete(null);",
238      "        return; // 0 = cancel.",
239      "    }",
240      "    if (res < 2 ) {",
241      "        this.complete(node);",
242      "        return; // 1 = just add it..",
243      "    }",
244      "    ",
245      "    ",
246      "    // have they selected a table??",
247      "    ",
248      "   Gtk.TreeIter iter; ",
249      "    Value vfname;   ",
250      "    if (_this.dbcombo.el.get_active_iter (out iter)) {    ",
251      "         this.dbmodel.el.get_value (iter, 0, out vfname);",
252      "         if (((string)vfname).length > 0 && this.plugin.has_plugin(node.fqn())) {",
253      "            this.plugin.showIt(this.window.el, project, node.fqn(), (string)vfname);",
254      "            return;",
255      "        }",
256      "\t    this.complete(node);",
257      "         return; // 1 = just add it..",
258      "         ",
259      "        ",
260      "    }",
261      "",
262      "    if (!_this.combo.el.get_active_iter (out iter)) {",
263      "",
264      "         this.complete(node);",
265      "        return; // 1 = just add it../ nothing selected...",
266      "    }",
267      "   ",
268      "    this.model.el.get_value (iter, 0, out vfname);",
269      "    ",
270      "     this.complete(this.palete.loadTemplate((string)vfname));",
271      "      return; // 1 = just add it..",
272      "  ",
273      "*/",
274      "}",
275      ""
276     ]
277    },
278    "title" : "Add an Object",
279    "xtype" : "Dialog",
280    "| void showIt" : [
281     " (",
282     " \tXcls_MainWindow mwindow, ",
283     " \tPalete.Palete pal, ",
284     "\t JsRender.Node node, ",
285     "\t Project.Project project",
286     " ) {",
287     "",
288     "\tthis.el.show();",
289     "",
290     "\tvar opts = pal.listTemplates(node);",
291     "\tif (opts.length() < 1) {",
292     "\tthis.el.hide();",
293     "\t\tthis.complete(node);",
294     "\t\treturn; ",
295     "\t}",
296     "\tthis.el.set_transient_for( mwindow.el);",
297     "",
298     "\t//opts.unshift({ path: '' , name :'Just add Element' });",
299     "\t_this.model.loadData(opts);",
300     "\t_this.combo.el.set_active(-1);",
301     "",
302     "",
303     "\tvar db =  new Palete.RooDatabase.from_project((Project.Roo) project);",
304     "\t_this.dbmodel.loadData(db.readTablesGee());",
305     "",
306     "",
307     "\t_this.dbcombo.el.set_active(-1);",
308     "",
309     "\tthis.window = mwindow;",
310     "\tthis.palete = pal;",
311     "\tthis.node = node;",
312     "\tthis.project = project;",
313     "   ",
314     "}",
315     ""
316    ]
317   }
318  ],
319  "modOrder" : "",
320  "name" : "DialogTemplateSelect",
321  "parent" : "",
322  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/DialogTemplateSelect.bjs",
323  "permname" : "",
324  "title" : ""
325 }