src/Builder4/DialogTemplateSelect.bjs
[app.Builder.js] / src / Builder4 / DialogTemplateSelect.vala
1 static DialogTemplateSelect  _DialogTemplateSelect;
2
3 public class DialogTemplateSelect : Object 
4 {
5     public Gtk.Dialog el;
6     private DialogTemplateSelect  _this;
7
8     public static DialogTemplateSelect singleton()
9     {
10         if (_DialogTemplateSelect == null) {
11             _DialogTemplateSelect= new DialogTemplateSelect();
12         }
13         return _DialogTemplateSelect;
14     }
15     public Xcls_combo combo;
16     public Xcls_cellrenderer cellrenderer;
17     public Xcls_model model;
18     public Xcls_dbcombo dbcombo;
19     public Xcls_dbcellrenderer dbcellrenderer;
20     public Xcls_dbmodel dbmodel;
21
22         // my vars (def)
23
24     // ctor 
25     public DialogTemplateSelect()
26     {
27         _this = this;
28         this.el = new Gtk.Dialog();
29
30         // my vars (dec)
31
32         // set gobject values
33         this.el.title = "Add an Object";
34         this.el.default_height = 200;
35         this.el.default_width = 400;
36         this.el.modal = true;
37         var child_0 = new Xcls_VBox2( _this );
38         child_0.ref();
39         this.el.get_content_area().add (  child_0.el  );
40         var child_1 = new Xcls_Button13( _this );
41         child_1.ref();
42         this.el.add_action_widget (  child_1.el , 0 );
43         var child_2 = new Xcls_Button14( _this );
44         child_2.ref();
45         this.el.add_action_widget (  child_2.el , 1 );
46         var child_3 = new Xcls_Button15( _this );
47         child_3.ref();
48         this.el.add_action_widget (  child_3.el , 2 );
49
50         // listeners 
51         this.el.delete_event.connect( (self, event)  =>{
52             this.el.hide();
53             return true;
54         });
55     }
56
57     // user defined functions 
58     public JsRender.Node? show (Xcls_MainWindow mwindow, Palete.Palete pal, JsRender.Node node, Project.Project project) {
59         
60         this.el.show_all();
61         var opts = pal.listTemplates(node);
62         if (opts.length() < 1) {
63             this.el.hide();
64             return node;
65         }
66         this.el.set_attached_to( mwindow.el);
67         this.el.set_transient_for( mwindow.el);
68         
69         //opts.unshift({ path: '' , name :'Just add Element' });
70          _this.model.loadData(opts);
71          _this.combo.el.set_active(-1);
72          
73          
74          var db =  new Palete.RooDatabase.from_project(project);
75          _this.dbmodel.loadData(db.readTablesGee());
76          
77          var plug = mwindow.windowstate.webkit_plugin;
78          
79          _this.dbcombo.el.set_active(-1);
80          
81          
82        
83         var res = this.el.run();
84         this.el.hide();    
85         //var ix = _this.combo.el.get_active();
86         if (res < 1 ) {
87             return null; // 0 = cancel.
88         }
89         if (res < 2 ) {
90             return node; // 1 = just add it..
91         }
92         
93         // have they selected a table??
94         
95        Gtk.TreeIter iter; 
96         Value vfname;   
97         if (_this.dbcombo.el.get_active_iter (out iter)) {    
98              this.dbmodel.el.get_value (iter, 0, out vfname);
99              if (plug.has_plugin(node.fqn())) {
100                 var json_str = plug.show(mwindow.el, project, node.fqn(), (string)vfname);
101                 
102              }
103             
104         }
105     
106         if (!_this.combo.el.get_active_iter (out iter)) {
107     
108             return node; // nothing selected...
109         }
110        
111         this.model.el.get_value (iter, 0, out vfname);
112         
113         
114         return pal.loadTemplate((string)vfname);
115     
116     }
117     public class Xcls_VBox2 : Object 
118     {
119         public Gtk.VBox el;
120         private DialogTemplateSelect  _this;
121
122
123             // my vars (def)
124
125         // ctor 
126         public Xcls_VBox2(DialogTemplateSelect _owner )
127         {
128             _this = _owner;
129             this.el = new Gtk.VBox( true, 0 );
130
131             // my vars (dec)
132
133             // set gobject values
134             var child_0 = new Xcls_HBox3( _this );
135             child_0.ref();
136             this.el.pack_start (  child_0.el , false,false,0 );
137             var child_1 = new Xcls_HBox8( _this );
138             child_1.ref();
139             this.el.pack_start (  child_1.el , false,false,0 );
140         }
141
142         // user defined functions 
143     }
144     public class Xcls_HBox3 : Object 
145     {
146         public Gtk.HBox el;
147         private DialogTemplateSelect  _this;
148
149
150             // my vars (def)
151
152         // ctor 
153         public Xcls_HBox3(DialogTemplateSelect _owner )
154         {
155             _this = _owner;
156             this.el = new Gtk.HBox( true, 0 );
157
158             // my vars (dec)
159
160             // set gobject values
161             this.el.margin = 3;
162             var child_0 = new Xcls_Label4( _this );
163             child_0.ref();
164             this.el.pack_start (  child_0.el , false,false );
165             var child_1 = new Xcls_combo( _this );
166             child_1.ref();
167             this.el.add (  child_1.el  );
168         }
169
170         // user defined functions 
171     }
172     public class Xcls_Label4 : Object 
173     {
174         public Gtk.Label el;
175         private DialogTemplateSelect  _this;
176
177
178             // my vars (def)
179
180         // ctor 
181         public Xcls_Label4(DialogTemplateSelect _owner )
182         {
183             _this = _owner;
184             this.el = new Gtk.Label( "Select Template : " );
185
186             // my vars (dec)
187
188             // set gobject values
189         }
190
191         // user defined functions 
192     }
193     public class Xcls_combo : Object 
194     {
195         public Gtk.ComboBox el;
196         private DialogTemplateSelect  _this;
197
198
199             // my vars (def)
200
201         // ctor 
202         public Xcls_combo(DialogTemplateSelect _owner )
203         {
204             _this = _owner;
205             _this.combo = this;
206             this.el = new Gtk.ComboBox();
207
208             // my vars (dec)
209
210             // set gobject values
211             var child_0 = new Xcls_cellrenderer( _this );
212             child_0.ref();
213             this.el.pack_start (  child_0.el , true );
214             var child_1 = new Xcls_model( _this );
215             child_1.ref();
216             this.el.set_model (  child_1.el  );
217
218             // init method 
219
220             this.el.add_attribute(_this.cellrenderer.el , "markup", 1 );
221         }
222
223         // user defined functions 
224     }
225     public class Xcls_cellrenderer : Object 
226     {
227         public Gtk.CellRendererText el;
228         private DialogTemplateSelect  _this;
229
230
231             // my vars (def)
232
233         // ctor 
234         public Xcls_cellrenderer(DialogTemplateSelect _owner )
235         {
236             _this = _owner;
237             _this.cellrenderer = this;
238             this.el = new Gtk.CellRendererText();
239
240             // my vars (dec)
241
242             // set gobject values
243         }
244
245         // user defined functions 
246     }
247     public class Xcls_model : Object 
248     {
249         public Gtk.ListStore el;
250         private DialogTemplateSelect  _this;
251
252
253             // my vars (def)
254
255         // ctor 
256         public Xcls_model(DialogTemplateSelect _owner )
257         {
258             _this = _owner;
259             _this.model = this;
260             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
261
262             // my vars (dec)
263
264             // set gobject values
265         }
266
267         // user defined functions 
268         public void loadData (GLib.List<string> data) {
269             this.el.clear();                                    
270             Gtk.TreeIter iter;
271             var el = this.el;
272             
273            /// el.append(out iter);
274             
275              
276            // el.set_value(iter, 0, "");
277            // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
278             
279             for (var i = 0; i < data.length();i++) {
280             
281         
282                 el.append(out iter);
283                 var str = data.nth_data(i);
284                 var fn = Path.get_basename (str);
285                 fn.replace(".json", "");
286                 
287                 el.set_value(iter, 0, str);
288                 el.set_value(iter, 1, fn);
289                 
290             }
291             this.el.set_sort_column_id(1, Gtk.SortType.ASCENDING);          
292                                              
293         }
294     }
295     public class Xcls_HBox8 : Object 
296     {
297         public Gtk.HBox el;
298         private DialogTemplateSelect  _this;
299
300
301             // my vars (def)
302
303         // ctor 
304         public Xcls_HBox8(DialogTemplateSelect _owner )
305         {
306             _this = _owner;
307             this.el = new Gtk.HBox( true, 0 );
308
309             // my vars (dec)
310
311             // set gobject values
312             this.el.margin = 3;
313             var child_0 = new Xcls_Label9( _this );
314             child_0.ref();
315             this.el.pack_start (  child_0.el , false,false );
316             var child_1 = new Xcls_dbcombo( _this );
317             child_1.ref();
318             this.el.add (  child_1.el  );
319         }
320
321         // user defined functions 
322     }
323     public class Xcls_Label9 : Object 
324     {
325         public Gtk.Label el;
326         private DialogTemplateSelect  _this;
327
328
329             // my vars (def)
330
331         // ctor 
332         public Xcls_Label9(DialogTemplateSelect _owner )
333         {
334             _this = _owner;
335             this.el = new Gtk.Label( "Select Database Table : " );
336
337             // my vars (dec)
338
339             // set gobject values
340         }
341
342         // user defined functions 
343     }
344     public class Xcls_dbcombo : Object 
345     {
346         public Gtk.ComboBox el;
347         private DialogTemplateSelect  _this;
348
349
350             // my vars (def)
351
352         // ctor 
353         public Xcls_dbcombo(DialogTemplateSelect _owner )
354         {
355             _this = _owner;
356             _this.dbcombo = this;
357             this.el = new Gtk.ComboBox();
358
359             // my vars (dec)
360
361             // set gobject values
362             var child_0 = new Xcls_dbcellrenderer( _this );
363             child_0.ref();
364             this.el.pack_start (  child_0.el , true );
365             var child_1 = new Xcls_dbmodel( _this );
366             child_1.ref();
367             this.el.set_model (  child_1.el  );
368
369             // init method 
370
371             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
372         }
373
374         // user defined functions 
375     }
376     public class Xcls_dbcellrenderer : Object 
377     {
378         public Gtk.CellRendererText el;
379         private DialogTemplateSelect  _this;
380
381
382             // my vars (def)
383
384         // ctor 
385         public Xcls_dbcellrenderer(DialogTemplateSelect _owner )
386         {
387             _this = _owner;
388             _this.dbcellrenderer = this;
389             this.el = new Gtk.CellRendererText();
390
391             // my vars (dec)
392
393             // set gobject values
394         }
395
396         // user defined functions 
397     }
398     public class Xcls_dbmodel : Object 
399     {
400         public Gtk.ListStore el;
401         private DialogTemplateSelect  _this;
402
403
404             // my vars (def)
405
406         // ctor 
407         public Xcls_dbmodel(DialogTemplateSelect _owner )
408         {
409             _this = _owner;
410             _this.dbmodel = this;
411             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
412
413             // my vars (dec)
414
415             // set gobject values
416         }
417
418         // user defined functions 
419         public void loadData (Gee.ArrayList<string> data) {
420             this.el.clear();                                    
421             Gtk.TreeIter iter;
422             var el = this.el;
423             
424            /// el.append(out iter);
425             
426              
427            // el.set_value(iter, 0, "");
428            // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
429         
430             el.append(out iter);
431         
432             
433             el.set_value(iter, 0, "");
434             el.set_value(iter, 1, "-- select a table --");
435             
436             
437             for (var i = 0; i < data.size;i++) {
438             
439         
440                 el.append(out iter);
441                 
442                 el.set_value(iter, 0, data.get(i));
443                 el.set_value(iter, 1, data.get(i));
444                 
445             }
446              this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
447                                              
448         }
449     }
450     public class Xcls_Button13 : Object 
451     {
452         public Gtk.Button el;
453         private DialogTemplateSelect  _this;
454
455
456             // my vars (def)
457
458         // ctor 
459         public Xcls_Button13(DialogTemplateSelect _owner )
460         {
461             _this = _owner;
462             this.el = new Gtk.Button();
463
464             // my vars (dec)
465
466             // set gobject values
467             this.el.label = "Cancel";
468         }
469
470         // user defined functions 
471     }
472     public class Xcls_Button14 : Object 
473     {
474         public Gtk.Button el;
475         private DialogTemplateSelect  _this;
476
477
478             // my vars (def)
479
480         // ctor 
481         public Xcls_Button14(DialogTemplateSelect _owner )
482         {
483             _this = _owner;
484             this.el = new Gtk.Button();
485
486             // my vars (dec)
487
488             // set gobject values
489             this.el.label = "Just add it";
490         }
491
492         // user defined functions 
493     }
494     public class Xcls_Button15 : Object 
495     {
496         public Gtk.Button el;
497         private DialogTemplateSelect  _this;
498
499
500             // my vars (def)
501
502         // ctor 
503         public Xcls_Button15(DialogTemplateSelect _owner )
504         {
505             _this = _owner;
506             this.el = new Gtk.Button();
507
508             // my vars (dec)
509
510             // set gobject values
511             this.el.label = "OK";
512         }
513
514         // user defined functions 
515     }
516 }