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