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 (Gtk.Window pwindow, 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( pwindow);
67          this.el.set_transient_for( pwindow);
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 JsRender.RooDatabase(project);
75          _this.dbcombo.loadData(db.readTablesGee());
76          
77          
78          _this.dbcombo.el.set_active(-1);
79          
80          
81        
82         var res = this.el.run();
83         this.el.hide();    
84         //var ix = _this.combo.el.get_active();
85         if (res < 1 ) {
86             return null; // 0 = cancel.
87         }
88         if (res < 2 ) {
89             return node; // 1 = just add it..
90         }
91         
92        Gtk.TreeIter iter;
93         _this.combo.el.get_active_iter (out iter);
94         Value vfname;
95         this.model.el.get_value (iter, 0, out vfname);
96         
97         
98         return pal.loadTemplate((string)vfname);
99     
100     }
101     public class Xcls_VBox2 : Object 
102     {
103         public Gtk.VBox el;
104         private DialogTemplateSelect  _this;
105
106
107             // my vars (def)
108
109         // ctor 
110         public Xcls_VBox2(DialogTemplateSelect _owner )
111         {
112             _this = _owner;
113             this.el = new Gtk.VBox( true, 0 );
114
115             // my vars (dec)
116
117             // set gobject values
118             var child_0 = new Xcls_HBox3( _this );
119             child_0.ref();
120             this.el.pack_start (  child_0.el , false,false,0 );
121             var child_1 = new Xcls_HBox8( _this );
122             child_1.ref();
123             this.el.pack_start (  child_1.el , false,false,0 );
124         }
125
126         // user defined functions 
127     }
128     public class Xcls_HBox3 : Object 
129     {
130         public Gtk.HBox el;
131         private DialogTemplateSelect  _this;
132
133
134             // my vars (def)
135
136         // ctor 
137         public Xcls_HBox3(DialogTemplateSelect _owner )
138         {
139             _this = _owner;
140             this.el = new Gtk.HBox( true, 0 );
141
142             // my vars (dec)
143
144             // set gobject values
145             this.el.margin = 3;
146             var child_0 = new Xcls_Label4( _this );
147             child_0.ref();
148             this.el.pack_start (  child_0.el , false,false );
149             var child_1 = new Xcls_combo( _this );
150             child_1.ref();
151             this.el.add (  child_1.el  );
152         }
153
154         // user defined functions 
155     }
156     public class Xcls_Label4 : Object 
157     {
158         public Gtk.Label el;
159         private DialogTemplateSelect  _this;
160
161
162             // my vars (def)
163
164         // ctor 
165         public Xcls_Label4(DialogTemplateSelect _owner )
166         {
167             _this = _owner;
168             this.el = new Gtk.Label( "Select Template : " );
169
170             // my vars (dec)
171
172             // set gobject values
173         }
174
175         // user defined functions 
176     }
177     public class Xcls_combo : Object 
178     {
179         public Gtk.ComboBox el;
180         private DialogTemplateSelect  _this;
181
182
183             // my vars (def)
184
185         // ctor 
186         public Xcls_combo(DialogTemplateSelect _owner )
187         {
188             _this = _owner;
189             _this.combo = this;
190             this.el = new Gtk.ComboBox();
191
192             // my vars (dec)
193
194             // set gobject values
195             var child_0 = new Xcls_cellrenderer( _this );
196             child_0.ref();
197             this.el.pack_start (  child_0.el , true );
198             var child_1 = new Xcls_model( _this );
199             child_1.ref();
200             this.el.set_model (  child_1.el  );
201
202             // init method 
203
204             this.el.add_attribute(_this.cellrenderer.el , "markup", 1 );
205         }
206
207         // user defined functions 
208     }
209     public class Xcls_cellrenderer : Object 
210     {
211         public Gtk.CellRendererText el;
212         private DialogTemplateSelect  _this;
213
214
215             // my vars (def)
216
217         // ctor 
218         public Xcls_cellrenderer(DialogTemplateSelect _owner )
219         {
220             _this = _owner;
221             _this.cellrenderer = this;
222             this.el = new Gtk.CellRendererText();
223
224             // my vars (dec)
225
226             // set gobject values
227         }
228
229         // user defined functions 
230     }
231     public class Xcls_model : Object 
232     {
233         public Gtk.ListStore el;
234         private DialogTemplateSelect  _this;
235
236
237             // my vars (def)
238
239         // ctor 
240         public Xcls_model(DialogTemplateSelect _owner )
241         {
242             _this = _owner;
243             _this.model = this;
244             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
245
246             // my vars (dec)
247
248             // set gobject values
249         }
250
251         // user defined functions 
252         public void loadData (GLib.List<string> data) {
253             this.el.clear();                                    
254             Gtk.TreeIter iter;
255             var el = this.el;
256             
257            /// el.append(out iter);
258             
259              
260            // el.set_value(iter, 0, "");
261            // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
262             
263             for (var i = 0; i < data.length();i++) {
264             
265         
266                 el.append(out iter);
267                 var str = data.nth_data(i);
268                 var fn = Path.get_basename (str);
269                 fn.replace(".json", "");
270                 
271                 el.set_value(iter, 0, str);
272                 el.set_value(iter, 1, fn);
273                 
274             }
275             this.el.set_sort_column_id(1, Gtk.SortType.ASCENDING);          
276                                              
277         }
278     }
279     public class Xcls_HBox8 : Object 
280     {
281         public Gtk.HBox el;
282         private DialogTemplateSelect  _this;
283
284
285             // my vars (def)
286
287         // ctor 
288         public Xcls_HBox8(DialogTemplateSelect _owner )
289         {
290             _this = _owner;
291             this.el = new Gtk.HBox( true, 0 );
292
293             // my vars (dec)
294
295             // set gobject values
296             this.el.margin = 3;
297             var child_0 = new Xcls_Label9( _this );
298             child_0.ref();
299             this.el.pack_start (  child_0.el , false,false );
300             var child_1 = new Xcls_dbcombo( _this );
301             child_1.ref();
302             this.el.add (  child_1.el  );
303         }
304
305         // user defined functions 
306     }
307     public class Xcls_Label9 : Object 
308     {
309         public Gtk.Label el;
310         private DialogTemplateSelect  _this;
311
312
313             // my vars (def)
314
315         // ctor 
316         public Xcls_Label9(DialogTemplateSelect _owner )
317         {
318             _this = _owner;
319             this.el = new Gtk.Label( "Select Database Table : " );
320
321             // my vars (dec)
322
323             // set gobject values
324         }
325
326         // user defined functions 
327     }
328     public class Xcls_dbcombo : Object 
329     {
330         public Gtk.ComboBox el;
331         private DialogTemplateSelect  _this;
332
333
334             // my vars (def)
335
336         // ctor 
337         public Xcls_dbcombo(DialogTemplateSelect _owner )
338         {
339             _this = _owner;
340             _this.dbcombo = this;
341             this.el = new Gtk.ComboBox();
342
343             // my vars (dec)
344
345             // set gobject values
346             var child_0 = new Xcls_dbcellrenderer( _this );
347             child_0.ref();
348             this.el.pack_start (  child_0.el , true );
349             var child_1 = new Xcls_dbmodel( _this );
350             child_1.ref();
351             this.el.set_model (  child_1.el  );
352
353             // init method 
354
355             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
356         }
357
358         // user defined functions 
359     }
360     public class Xcls_dbcellrenderer : Object 
361     {
362         public Gtk.CellRendererText el;
363         private DialogTemplateSelect  _this;
364
365
366             // my vars (def)
367
368         // ctor 
369         public Xcls_dbcellrenderer(DialogTemplateSelect _owner )
370         {
371             _this = _owner;
372             _this.dbcellrenderer = this;
373             this.el = new Gtk.CellRendererText();
374
375             // my vars (dec)
376
377             // set gobject values
378         }
379
380         // user defined functions 
381     }
382     public class Xcls_dbmodel : Object 
383     {
384         public Gtk.ListStore el;
385         private DialogTemplateSelect  _this;
386
387
388             // my vars (def)
389
390         // ctor 
391         public Xcls_dbmodel(DialogTemplateSelect _owner )
392         {
393             _this = _owner;
394             _this.dbmodel = this;
395             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
396
397             // my vars (dec)
398
399             // set gobject values
400         }
401
402         // user defined functions 
403         public void loadData (Gee.ArrayList<string> data) {
404             this.el.clear();                                    
405             Gtk.TreeIter iter;
406             var el = this.el;
407             
408            /// el.append(out iter);
409             
410              
411            // el.set_value(iter, 0, "");
412            // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
413         
414             el.append(out iter);
415         
416             
417             el.set_value(iter, 0, "");
418             el.set_value(iter, 1, "-- select a table --");
419             
420             
421             for (var i = 0; i < data.length();i++) {
422             
423         
424                 el.append(out iter);
425                 
426                 el.set_value(iter, 0, data.get(i));
427                 el.set_value(iter, 1, data.get(i));
428                 
429             }
430              this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
431                                              
432         }
433     }
434     public class Xcls_Button13 : Object 
435     {
436         public Gtk.Button el;
437         private DialogTemplateSelect  _this;
438
439
440             // my vars (def)
441
442         // ctor 
443         public Xcls_Button13(DialogTemplateSelect _owner )
444         {
445             _this = _owner;
446             this.el = new Gtk.Button();
447
448             // my vars (dec)
449
450             // set gobject values
451             this.el.label = "Cancel";
452         }
453
454         // user defined functions 
455     }
456     public class Xcls_Button14 : Object 
457     {
458         public Gtk.Button el;
459         private DialogTemplateSelect  _this;
460
461
462             // my vars (def)
463
464         // ctor 
465         public Xcls_Button14(DialogTemplateSelect _owner )
466         {
467             _this = _owner;
468             this.el = new Gtk.Button();
469
470             // my vars (dec)
471
472             // set gobject values
473             this.el.label = "Just add it";
474         }
475
476         // user defined functions 
477     }
478     public class Xcls_Button15 : Object 
479     {
480         public Gtk.Button el;
481         private DialogTemplateSelect  _this;
482
483
484             // my vars (def)
485
486         // ctor 
487         public Xcls_Button15(DialogTemplateSelect _owner )
488         {
489             _this = _owner;
490             this.el = new Gtk.Button();
491
492             // my vars (dec)
493
494             // set gobject values
495             this.el.label = "OK";
496         }
497
498         // user defined functions 
499     }
500 }