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