1ee36a108ecff70d8a6b1626adfed9b98c6860df
[roobuilder] / 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     public Xcls_MainWindow window;
24     public signal void complete (JsRender.Node? node);
25     public Palete.Palete palete;
26     public Project.Project project;
27     public JsRender.Node node;
28
29     // ctor
30     public DialogTemplateSelect()
31     {
32         _this = this;
33         this.el = new Gtk.Dialog();
34
35         // my vars (dec)
36
37         // set gobject values
38         this.el.title = "Add an Object";
39         this.el.default_height = 200;
40         this.el.default_width = 400;
41         this.el.modal = true;
42         var child_0 = new Xcls_Box2( _this );
43         child_0.ref();
44         this.el.get_content_area().append (  child_0.el  );
45         var child_1 = new Xcls_Button13( _this );
46         child_1.ref();
47         this.el.add_action_widget (  child_1.el , 0 );
48         var child_2 = new Xcls_Button14( _this );
49         child_2.ref();
50         this.el.add_action_widget (  child_2.el , 1 );
51         var child_3 = new Xcls_Button15( _this );
52         child_3.ref();
53         this.el.add_action_widget (  child_3.el , 2 );
54
55         //listeners
56         this.el.close_request.connect( ( ) => {
57         
58          this.el.hide();
59             return true;;
60         });
61         this.el.response.connect( (res) => {
62         
63                 //var node = _this.node;
64                 //var project = _this.project;
65                 return;
66            /*
67            
68            if (this.plugin == null) {
69                    this.plugin = new Xcls_DialogPluginWebkit();
70                    this.plugin.complete.connect((json_str) => {
71                                 print("json_str = %s\n", json_str);
72                     if (json_str.length < 1) {
73                                         this.complete(_this.node);
74                                         return; 
75                     }
76                     var pa = new Json.Parser();
77                     try {
78         
79                                 pa.load_from_data(json_str);
80                                 } catch(Error e) {
81                                      this.complete(node);
82                                 return; // 1 = just add it..
83                         }
84                         var new_node = pa.get_root();
85                         
86                                 if (new_node.get_node_type () != Json.NodeType.OBJECT) {
87                                          this.complete(node);
88                                                         return; 
89                                 }
90                                 var obj = new_node.get_object ();
91         
92                                 var ret = new JsRender.Node();
93         
94                                 ret.loadFromJson(obj, 1);
95                                 this.complete(ret);
96                         });
97           
98            }
99            
100            
101              
102                 
103              this.el.hide();    
104             //var ix = _this.combo.el.get_active();
105             if (res < 1 ) {
106                 this.complete(null);
107                 return; // 0 = cancel.
108             }
109             if (res < 2 ) {
110                 this.complete(node);
111                 return; // 1 = just add it..
112             }
113             
114             
115             // have they selected a table??
116             
117            Gtk.TreeIter iter; 
118             Value vfname;   
119             if (_this.dbcombo.el.get_active_iter (out iter)) {    
120                  this.dbmodel.el.get_value (iter, 0, out vfname);
121                  if (((string)vfname).length > 0 && this.plugin.has_plugin(node.fqn())) {
122                     this.plugin.showIt(this.window.el, project, node.fqn(), (string)vfname);
123                     return;
124                 }
125                     this.complete(node);
126                  return; // 1 = just add it..
127                  
128                 
129             }
130         
131             if (!_this.combo.el.get_active_iter (out iter)) {
132         
133                  this.complete(node);
134                 return; // 1 = just add it../ nothing selected...
135             }
136            
137             this.model.el.get_value (iter, 0, out vfname);
138             
139              this.complete(this.palete.loadTemplate((string)vfname));
140               return; // 1 = just add it..
141           
142         */
143         });
144     }
145
146     // user defined functions
147     public void showIt (
148         Xcls_MainWindow mwindow, 
149         Palete.Palete pal, 
150          JsRender.Node node, 
151          Project.Project project
152      ) {
153     
154         this.el.show();
155     
156         var opts = pal.listTemplates(node);
157         if (opts.length() < 1) {
158         this.el.hide();
159                 this.complete(node);
160                 return; 
161         }
162         this.el.set_transient_for( mwindow.el);
163     
164         //opts.unshift({ path: '' , name :'Just add Element' });
165         _this.model.loadData(opts);
166         _this.combo.el.set_active(-1);
167     
168     
169         var db =  new Palete.RooDatabase.from_project((Project.Roo) project);
170         _this.dbmodel.loadData(db.readTablesGee());
171     
172     
173         _this.dbcombo.el.set_active(-1);
174     
175         this.window = mwindow;
176         this.palete = pal;
177         this.node = node;
178         this.project = project;
179        
180     }
181     public class Xcls_Box2 : Object
182     {
183         public Gtk.Box el;
184         private DialogTemplateSelect  _this;
185
186
187             // my vars (def)
188
189         // ctor
190         public Xcls_Box2(DialogTemplateSelect _owner )
191         {
192             _this = _owner;
193             this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
194
195             // my vars (dec)
196
197             // set gobject values
198             var child_0 = new Xcls_Box3( _this );
199             child_0.ref();
200             this.el.append (  child_0.el  );
201             var child_1 = new Xcls_Box8( _this );
202             child_1.ref();
203             this.el.append (  child_1.el  );
204         }
205
206         // user defined functions
207     }
208     public class Xcls_Box3 : Object
209     {
210         public Gtk.Box el;
211         private DialogTemplateSelect  _this;
212
213
214             // my vars (def)
215
216         // ctor
217         public Xcls_Box3(DialogTemplateSelect _owner )
218         {
219             _this = _owner;
220             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
221
222             // my vars (dec)
223
224             // set gobject values
225             this.el.margin_end = 3;
226             this.el.margin_start = 3;
227             var child_0 = new Xcls_Label4( _this );
228             child_0.ref();
229             this.el.append (  child_0.el  );
230             var child_1 = new Xcls_combo( _this );
231             child_1.ref();
232             this.el.append (  child_1.el  );
233         }
234
235         // user defined functions
236     }
237     public class Xcls_Label4 : Object
238     {
239         public Gtk.Label el;
240         private DialogTemplateSelect  _this;
241
242
243             // my vars (def)
244
245         // ctor
246         public Xcls_Label4(DialogTemplateSelect _owner )
247         {
248             _this = _owner;
249             this.el = new Gtk.Label( "Select Template : " );
250
251             // my vars (dec)
252
253             // set gobject values
254         }
255
256         // user defined functions
257     }
258
259     public class Xcls_combo : Object
260     {
261         public Gtk.ComboBox el;
262         private DialogTemplateSelect  _this;
263
264
265             // my vars (def)
266
267         // ctor
268         public Xcls_combo(DialogTemplateSelect _owner )
269         {
270             _this = _owner;
271             _this.combo = this;
272             this.el = new Gtk.ComboBox();
273
274             // my vars (dec)
275
276             // set gobject values
277             var child_0 = new Xcls_cellrenderer( _this );
278             child_0.ref();
279             this.el.pack_start (  child_0.el , true );
280             var child_1 = new Xcls_model( _this );
281             child_1.ref();
282             this.el.set_model (  child_1.el  );
283
284             // init method
285
286             this.el.add_attribute(_this.cellrenderer.el , "markup", 1 );
287         }
288
289         // user defined functions
290     }
291     public class Xcls_cellrenderer : Object
292     {
293         public Gtk.CellRendererText el;
294         private DialogTemplateSelect  _this;
295
296
297             // my vars (def)
298
299         // ctor
300         public Xcls_cellrenderer(DialogTemplateSelect _owner )
301         {
302             _this = _owner;
303             _this.cellrenderer = this;
304             this.el = new Gtk.CellRendererText();
305
306             // my vars (dec)
307
308             // set gobject values
309         }
310
311         // user defined functions
312     }
313
314     public class Xcls_model : Object
315     {
316         public Gtk.ListStore el;
317         private DialogTemplateSelect  _this;
318
319
320             // my vars (def)
321
322         // ctor
323         public Xcls_model(DialogTemplateSelect _owner )
324         {
325             _this = _owner;
326             _this.model = this;
327             this.el = new Gtk.ListStore.newv(  { typeof(string),typeof(string) }  );
328
329             // my vars (dec)
330
331             // set gobject values
332         }
333
334         // user defined functions
335         public void loadData (GLib.List<string> data) {
336             this.el.clear();                                    
337             Gtk.TreeIter iter;
338             var el = this.el;
339             
340            /// el.append(out iter);
341             
342              
343            // el.set_value(iter, 0, "");
344            // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
345             
346             for (var i = 0; i < data.length();i++) {
347             
348         
349                 el.append(out iter);
350                 var str = data.nth_data(i);
351                 var fn = Path.get_basename (str);
352                 fn.replace(".json", "");
353                 
354                 el.set_value(iter, 0, str);
355                 el.set_value(iter, 1, fn);
356                 
357             }
358             this.el.set_sort_column_id(1, Gtk.SortType.ASCENDING);          
359                                              
360         }
361     }
362
363
364
365     public class Xcls_Box8 : Object
366     {
367         public Gtk.Box el;
368         private DialogTemplateSelect  _this;
369
370
371             // my vars (def)
372
373         // ctor
374         public Xcls_Box8(DialogTemplateSelect _owner )
375         {
376             _this = _owner;
377             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
378
379             // my vars (dec)
380
381             // set gobject values
382             this.el.margin_end = 3;
383             this.el.margin_start = 3;
384             var child_0 = new Xcls_Label9( _this );
385             child_0.ref();
386             this.el.append (  child_0.el  );
387             var child_1 = new Xcls_dbcombo( _this );
388             child_1.ref();
389             this.el.append (  child_1.el  );
390         }
391
392         // user defined functions
393     }
394     public class Xcls_Label9 : Object
395     {
396         public Gtk.Label el;
397         private DialogTemplateSelect  _this;
398
399
400             // my vars (def)
401
402         // ctor
403         public Xcls_Label9(DialogTemplateSelect _owner )
404         {
405             _this = _owner;
406             this.el = new Gtk.Label( "Select Database Table : " );
407
408             // my vars (dec)
409
410             // set gobject values
411         }
412
413         // user defined functions
414     }
415
416     public class Xcls_dbcombo : Object
417     {
418         public Gtk.ComboBox el;
419         private DialogTemplateSelect  _this;
420
421
422             // my vars (def)
423
424         // ctor
425         public Xcls_dbcombo(DialogTemplateSelect _owner )
426         {
427             _this = _owner;
428             _this.dbcombo = this;
429             this.el = new Gtk.ComboBox();
430
431             // my vars (dec)
432
433             // set gobject values
434             var child_0 = new Xcls_dbcellrenderer( _this );
435             child_0.ref();
436             this.el.pack_start (  child_0.el , true );
437             var child_1 = new Xcls_dbmodel( _this );
438             child_1.ref();
439             this.el.set_model (  child_1.el  );
440
441             // init method
442
443             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
444         }
445
446         // user defined functions
447     }
448     public class Xcls_dbcellrenderer : Object
449     {
450         public Gtk.CellRendererText el;
451         private DialogTemplateSelect  _this;
452
453
454             // my vars (def)
455
456         // ctor
457         public Xcls_dbcellrenderer(DialogTemplateSelect _owner )
458         {
459             _this = _owner;
460             _this.dbcellrenderer = this;
461             this.el = new Gtk.CellRendererText();
462
463             // my vars (dec)
464
465             // set gobject values
466         }
467
468         // user defined functions
469     }
470
471     public class Xcls_dbmodel : Object
472     {
473         public Gtk.ListStore el;
474         private DialogTemplateSelect  _this;
475
476
477             // my vars (def)
478
479         // ctor
480         public Xcls_dbmodel(DialogTemplateSelect _owner )
481         {
482             _this = _owner;
483             _this.dbmodel = this;
484             this.el = new Gtk.ListStore.newv(  { typeof(string),typeof(string) }  );
485
486             // my vars (dec)
487
488             // set gobject values
489         }
490
491         // user defined functions
492         public void loadData (Gee.ArrayList<string> data) {
493             this.el.clear();                                    
494             Gtk.TreeIter iter;
495             var el = this.el;
496             
497            /// el.append(out iter);
498             
499              
500            // el.set_value(iter, 0, "");
501            // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
502         
503             el.append(out iter);
504         
505             
506             el.set_value(iter, 0, "");
507             el.set_value(iter, 1, "-- select a table --");
508             
509             
510             for (var i = 0; i < data.size;i++) {
511             
512         
513                 el.append(out iter);
514                 
515                 el.set_value(iter, 0, data.get(i));
516                 el.set_value(iter, 1, data.get(i));
517                 
518             }
519              this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
520                                              
521         }
522     }
523
524
525
526
527     public class Xcls_Button13 : Object
528     {
529         public Gtk.Button el;
530         private DialogTemplateSelect  _this;
531
532
533             // my vars (def)
534
535         // ctor
536         public Xcls_Button13(DialogTemplateSelect _owner )
537         {
538             _this = _owner;
539             this.el = new Gtk.Button();
540
541             // my vars (dec)
542
543             // set gobject values
544             this.el.label = "Cancel";
545         }
546
547         // user defined functions
548     }
549
550     public class Xcls_Button14 : Object
551     {
552         public Gtk.Button el;
553         private DialogTemplateSelect  _this;
554
555
556             // my vars (def)
557
558         // ctor
559         public Xcls_Button14(DialogTemplateSelect _owner )
560         {
561             _this = _owner;
562             this.el = new Gtk.Button();
563
564             // my vars (dec)
565
566             // set gobject values
567             this.el.label = "Just add it";
568         }
569
570         // user defined functions
571     }
572
573     public class Xcls_Button15 : Object
574     {
575         public Gtk.Button el;
576         private DialogTemplateSelect  _this;
577
578
579             // my vars (def)
580
581         // ctor
582         public Xcls_Button15(DialogTemplateSelect _owner )
583         {
584             _this = _owner;
585             this.el = new Gtk.Button();
586
587             // my vars (dec)
588
589             // set gobject values
590             this.el.label = "OK";
591         }
592
593         // user defined functions
594     }
595
596 }