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