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