src/Builder4/PopoverFileDetails.bjs
[app.Builder.js] / src / Builder4 / PopoverFileDetails.vala
1 static Xcls_PopoverFileDetails  _PopoverFileDetails;
2
3 public class Xcls_PopoverFileDetails : Object 
4 {
5     public Gtk.Popover el;
6     private Xcls_PopoverFileDetails  _this;
7
8     public static Xcls_PopoverFileDetails singleton()
9     {
10         if (_PopoverFileDetails == null) {
11             _PopoverFileDetails= new Xcls_PopoverFileDetails();
12         }
13         return _PopoverFileDetails;
14     }
15     public Xcls_name name;
16     public Xcls_title title;
17     public Xcls_region region;
18     public Xcls_parent parent;
19     public Xcls_permname permname;
20     public Xcls_modOrder modOrder;
21     public Xcls_build_module build_module;
22     public Xcls_dbcellrenderer dbcellrenderer;
23     public Xcls_dbmodel dbmodel;
24     public Xcls_save_btn save_btn;
25
26         // my vars (def)
27     public Project.Project project;
28     public JsRender.JsRender file;
29
30     // ctor 
31     public Xcls_PopoverFileDetails()
32     {
33         _this = this;
34         this.el = new Gtk.Popover( null );
35
36         // my vars (dec)
37         this.file = null;
38
39         // set gobject values
40         this.el.modal = true;
41         this.el.position = Gtk.PositionType.RIGHT;
42         var child_0 = new Xcls_VBox2( _this );
43         child_0.ref();
44         this.el.get_content_area().add (  child_0.el  );
45     }
46
47     // user defined functions 
48     public void show (JsRender.JsRender c, Gtk.Widget btn) 
49     {
50         this.project = c.project;
51         
52         
53         
54         //if (!this.el) {
55             //this.init();
56          //}
57         
58         _this.name.el.set_text(c.name);
59         _this.title.el.set_text(c.title);
60         _this.parent.el.set_text(c.parent);    
61         _this.region.el.set_text(c.region);
62         _this.modOrder.el.set_text(c.modOrder);
63          _this.permname.el.set_text(c.permname);
64         
65         if (c.path.length > 0) {
66         
67             this.save_btn.el.set_label("Save");
68         } else {
69             this.save_btn.el.set_label("Create");
70         }
71         
72          var ar = new Gee.ArrayList<string>();
73          _this.dbmodel.loadData(ar,"");
74         // load the modules... if relivant..
75         if (this.project.xtype == "Gtk") {
76             var p = (Project.Gtk)c.project;
77               var cg = p.compilegroups;
78     
79             var iter = cg.map_iterator();
80            while(iter.next()) {
81                 var key = iter.get_key();
82                 if (key == "_default_") {
83                     continue;
84                 }
85                 ar.add(key);
86             };
87             _this.dbmodel.loadData(ar, c.build_module);
88     
89         }
90         
91          
92         _this.file = c;
93         //console.log('show all');
94         this.el.set_relative_to(btn);
95         
96         
97         this.el.show_all();
98         
99         //this.success = c.success;
100         
101         
102     }
103     public class Xcls_VBox2 : Object 
104     {
105         public Gtk.VBox el;
106         private Xcls_PopoverFileDetails  _this;
107
108
109             // my vars (def)
110
111         // ctor 
112         public Xcls_VBox2(Xcls_PopoverFileDetails _owner )
113         {
114             _this = _owner;
115             this.el = new Gtk.VBox( true, 0 );
116
117             // my vars (dec)
118
119             // set gobject values
120             var child_0 = new Xcls_Table3( _this );
121             child_0.ref();
122             this.el.pack_start (  child_0.el , false,false,0 );
123             var child_1 = new Xcls_HButtonBox20( _this );
124             child_1.ref();
125             this.el.pack_end (  child_1.el , false,false,5 );
126         }
127
128         // user defined functions 
129     }
130     public class Xcls_Table3 : Object 
131     {
132         public Gtk.Table el;
133         private Xcls_PopoverFileDetails  _this;
134
135
136             // my vars (def)
137
138         // ctor 
139         public Xcls_Table3(Xcls_PopoverFileDetails _owner )
140         {
141             _this = _owner;
142             this.el = new Gtk.Table( 3, 2, true );
143
144             // my vars (dec)
145
146             // set gobject values
147             var child_0 = new Xcls_Label4( _this );
148             child_0.ref();
149             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
150             var child_1 = new Xcls_name( _this );
151             child_1.ref();
152             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
153             var child_2 = new Xcls_Label6( _this );
154             child_2.ref();
155             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
156             var child_3 = new Xcls_title( _this );
157             child_3.ref();
158             this.el.attach_defaults (  child_3.el , 1,2,1,2 );
159             var child_4 = new Xcls_Label8( _this );
160             child_4.ref();
161             this.el.attach_defaults (  child_4.el , 0,1,2,3 );
162             var child_5 = new Xcls_region( _this );
163             child_5.ref();
164             this.el.attach_defaults (  child_5.el , 1,2,2,3 );
165             var child_6 = new Xcls_Label10( _this );
166             child_6.ref();
167             this.el.attach_defaults (  child_6.el , 0,1,3,4 );
168             var child_7 = new Xcls_parent( _this );
169             child_7.ref();
170             this.el.attach_defaults (  child_7.el , 1,2,3,4 );
171             var child_8 = new Xcls_Label12( _this );
172             child_8.ref();
173             this.el.attach_defaults (  child_8.el , 0,1,4,5 );
174             var child_9 = new Xcls_permname( _this );
175             child_9.ref();
176             this.el.attach_defaults (  child_9.el , 1,2,4,5 );
177             var child_10 = new Xcls_Label14( _this );
178             child_10.ref();
179             this.el.attach_defaults (  child_10.el , 0,1,5,6 );
180             var child_11 = new Xcls_modOrder( _this );
181             child_11.ref();
182             this.el.attach_defaults (  child_11.el , 1,2,5,6 );
183             var child_12 = new Xcls_Label16( _this );
184             child_12.ref();
185             this.el.attach_defaults (  child_12.el , 0,1,6,7 );
186             var child_13 = new Xcls_build_module( _this );
187             child_13.ref();
188             this.el.attach_defaults (  child_13.el , 1,2,6,7 );
189         }
190
191         // user defined functions 
192     }
193     public class Xcls_Label4 : Object 
194     {
195         public Gtk.Label el;
196         private Xcls_PopoverFileDetails  _this;
197
198
199             // my vars (def)
200
201         // ctor 
202         public Xcls_Label4(Xcls_PopoverFileDetails _owner )
203         {
204             _this = _owner;
205             this.el = new Gtk.Label( "Component Name" );
206
207             // my vars (dec)
208
209             // set gobject values
210             this.el.justify = Gtk.Justification.RIGHT;
211             this.el.xalign = 0.900000f;
212         }
213
214         // user defined functions 
215     }
216     public class Xcls_name : Object 
217     {
218         public Gtk.Entry el;
219         private Xcls_PopoverFileDetails  _this;
220
221
222             // my vars (def)
223
224         // ctor 
225         public Xcls_name(Xcls_PopoverFileDetails _owner )
226         {
227             _this = _owner;
228             _this.name = this;
229             this.el = new Gtk.Entry();
230
231             // my vars (dec)
232
233             // set gobject values
234             this.el.visible = true;
235         }
236
237         // user defined functions 
238     }
239     public class Xcls_Label6 : Object 
240     {
241         public Gtk.Label el;
242         private Xcls_PopoverFileDetails  _this;
243
244
245             // my vars (def)
246
247         // ctor 
248         public Xcls_Label6(Xcls_PopoverFileDetails _owner )
249         {
250             _this = _owner;
251             this.el = new Gtk.Label( "Title" );
252
253             // my vars (dec)
254
255             // set gobject values
256             this.el.justify = Gtk.Justification.RIGHT;
257             this.el.xalign = 0.900000f;
258             this.el.visible = true;
259         }
260
261         // user defined functions 
262     }
263     public class Xcls_title : Object 
264     {
265         public Gtk.Entry el;
266         private Xcls_PopoverFileDetails  _this;
267
268
269             // my vars (def)
270
271         // ctor 
272         public Xcls_title(Xcls_PopoverFileDetails _owner )
273         {
274             _this = _owner;
275             _this.title = this;
276             this.el = new Gtk.Entry();
277
278             // my vars (dec)
279
280             // set gobject values
281             this.el.visible = true;
282         }
283
284         // user defined functions 
285     }
286     public class Xcls_Label8 : Object 
287     {
288         public Gtk.Label el;
289         private Xcls_PopoverFileDetails  _this;
290
291
292             // my vars (def)
293
294         // ctor 
295         public Xcls_Label8(Xcls_PopoverFileDetails _owner )
296         {
297             _this = _owner;
298             this.el = new Gtk.Label( "Region" );
299
300             // my vars (dec)
301
302             // set gobject values
303             this.el.justify = Gtk.Justification.RIGHT;
304             this.el.xalign = 0.900000f;
305             this.el.tooltip_text = "center, north, south, east, west";
306             this.el.visible = true;
307         }
308
309         // user defined functions 
310     }
311     public class Xcls_region : Object 
312     {
313         public Gtk.Entry el;
314         private Xcls_PopoverFileDetails  _this;
315
316
317             // my vars (def)
318
319         // ctor 
320         public Xcls_region(Xcls_PopoverFileDetails _owner )
321         {
322             _this = _owner;
323             _this.region = this;
324             this.el = new Gtk.Entry();
325
326             // my vars (dec)
327
328             // set gobject values
329             this.el.visible = true;
330         }
331
332         // user defined functions 
333     }
334     public class Xcls_Label10 : Object 
335     {
336         public Gtk.Label el;
337         private Xcls_PopoverFileDetails  _this;
338
339
340             // my vars (def)
341
342         // ctor 
343         public Xcls_Label10(Xcls_PopoverFileDetails _owner )
344         {
345             _this = _owner;
346             this.el = new Gtk.Label( "Parent Name" );
347
348             // my vars (dec)
349
350             // set gobject values
351             this.el.justify = Gtk.Justification.RIGHT;
352             this.el.xalign = 0.900000f;
353             this.el.visible = true;
354         }
355
356         // user defined functions 
357     }
358     public class Xcls_parent : Object 
359     {
360         public Gtk.Entry el;
361         private Xcls_PopoverFileDetails  _this;
362
363
364             // my vars (def)
365
366         // ctor 
367         public Xcls_parent(Xcls_PopoverFileDetails _owner )
368         {
369             _this = _owner;
370             _this.parent = this;
371             this.el = new Gtk.Entry();
372
373             // my vars (dec)
374
375             // set gobject values
376             this.el.visible = true;
377         }
378
379         // user defined functions 
380     }
381     public class Xcls_Label12 : Object 
382     {
383         public Gtk.Label el;
384         private Xcls_PopoverFileDetails  _this;
385
386
387             // my vars (def)
388
389         // ctor 
390         public Xcls_Label12(Xcls_PopoverFileDetails _owner )
391         {
392             _this = _owner;
393             this.el = new Gtk.Label( "Permission Name" );
394
395             // my vars (dec)
396
397             // set gobject values
398             this.el.justify = Gtk.Justification.RIGHT;
399             this.el.xalign = 0.900000f;
400             this.el.visible = true;
401         }
402
403         // user defined functions 
404     }
405     public class Xcls_permname : Object 
406     {
407         public Gtk.Entry el;
408         private Xcls_PopoverFileDetails  _this;
409
410
411             // my vars (def)
412
413         // ctor 
414         public Xcls_permname(Xcls_PopoverFileDetails _owner )
415         {
416             _this = _owner;
417             _this.permname = this;
418             this.el = new Gtk.Entry();
419
420             // my vars (dec)
421
422             // set gobject values
423             this.el.visible = true;
424         }
425
426         // user defined functions 
427     }
428     public class Xcls_Label14 : Object 
429     {
430         public Gtk.Label el;
431         private Xcls_PopoverFileDetails  _this;
432
433
434             // my vars (def)
435
436         // ctor 
437         public Xcls_Label14(Xcls_PopoverFileDetails _owner )
438         {
439             _this = _owner;
440             this.el = new Gtk.Label( "Order (for tabs)" );
441
442             // my vars (dec)
443
444             // set gobject values
445             this.el.justify = Gtk.Justification.RIGHT;
446             this.el.xalign = 0.900000f;
447             this.el.visible = true;
448         }
449
450         // user defined functions 
451     }
452     public class Xcls_modOrder : Object 
453     {
454         public Gtk.Entry el;
455         private Xcls_PopoverFileDetails  _this;
456
457
458             // my vars (def)
459
460         // ctor 
461         public Xcls_modOrder(Xcls_PopoverFileDetails _owner )
462         {
463             _this = _owner;
464             _this.modOrder = this;
465             this.el = new Gtk.Entry();
466
467             // my vars (dec)
468
469             // set gobject values
470             this.el.visible = true;
471         }
472
473         // user defined functions 
474     }
475     public class Xcls_Label16 : Object 
476     {
477         public Gtk.Label el;
478         private Xcls_PopoverFileDetails  _this;
479
480
481             // my vars (def)
482
483         // ctor 
484         public Xcls_Label16(Xcls_PopoverFileDetails _owner )
485         {
486             _this = _owner;
487             this.el = new Gtk.Label( "Module to build (Vala only)" );
488
489             // my vars (dec)
490
491             // set gobject values
492             this.el.justify = Gtk.Justification.RIGHT;
493             this.el.xalign = 0.900000f;
494             this.el.visible = true;
495         }
496
497         // user defined functions 
498     }
499     public class Xcls_build_module : Object 
500     {
501         public Gtk.ComboBox el;
502         private Xcls_PopoverFileDetails  _this;
503
504
505             // my vars (def)
506
507         // ctor 
508         public Xcls_build_module(Xcls_PopoverFileDetails _owner )
509         {
510             _this = _owner;
511             _this.build_module = this;
512             this.el = new Gtk.ComboBox();
513
514             // my vars (dec)
515
516             // set gobject values
517             var child_0 = new Xcls_dbcellrenderer( _this );
518             child_0.ref();
519             this.el.pack_start (  child_0.el , true );
520             var child_1 = new Xcls_dbmodel( _this );
521             child_1.ref();
522             this.el.set_model (  child_1.el  );
523
524             // init method 
525
526             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
527         }
528
529         // user defined functions 
530     }
531     public class Xcls_dbcellrenderer : Object 
532     {
533         public Gtk.CellRendererText el;
534         private Xcls_PopoverFileDetails  _this;
535
536
537             // my vars (def)
538
539         // ctor 
540         public Xcls_dbcellrenderer(Xcls_PopoverFileDetails _owner )
541         {
542             _this = _owner;
543             _this.dbcellrenderer = this;
544             this.el = new Gtk.CellRendererText();
545
546             // my vars (dec)
547
548             // set gobject values
549         }
550
551         // user defined functions 
552     }
553     public class Xcls_dbmodel : Object 
554     {
555         public Gtk.ListStore el;
556         private Xcls_PopoverFileDetails  _this;
557
558
559             // my vars (def)
560
561         // ctor 
562         public Xcls_dbmodel(Xcls_PopoverFileDetails _owner )
563         {
564             _this = _owner;
565             _this.dbmodel = this;
566             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
567
568             // my vars (dec)
569
570             // set gobject values
571         }
572
573         // user defined functions 
574         public void loadData (Gee.ArrayList<string> data, string cur) {
575             this.el.clear();                                    
576             Gtk.TreeIter iter;
577             var el = this.el;
578             
579            /// el.append(out iter);
580             
581              
582            // el.set_value(iter, 0, "");
583            // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
584         
585             el.append(out iter);
586         
587             
588             el.set_value(iter, 0, "");
589             el.set_value(iter, 1, "-- select a module --");
590             _this.build_module.el.set_active_iter(iter);
591             
592             for (var i = 0; i < data.size;i++) {
593             
594         
595                 el.append(out iter);
596                 
597                 el.set_value(iter, 0, data.get(i));
598                 el.set_value(iter, 1, data.get(i));
599                 
600                 if (data.get(i) == cur) {
601                     _this.build_module.el.set_active_iter(iter);
602                 }
603                 
604             }
605              this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
606                                              
607         }
608     }
609     public class Xcls_HButtonBox20 : Object 
610     {
611         public Gtk.HButtonBox el;
612         private Xcls_PopoverFileDetails  _this;
613
614
615             // my vars (def)
616
617         // ctor 
618         public Xcls_HButtonBox20(Xcls_PopoverFileDetails _owner )
619         {
620             _this = _owner;
621             this.el = new Gtk.HButtonBox();
622
623             // my vars (dec)
624
625             // set gobject values
626             var child_0 = new Xcls_Button21( _this );
627             child_0.ref();
628             this.el.add (  child_0.el  );
629             var child_1 = new Xcls_save_btn( _this );
630             child_1.ref();
631             this.el.add (  child_1.el  );
632         }
633
634         // user defined functions 
635     }
636     public class Xcls_Button21 : Object 
637     {
638         public Gtk.Button el;
639         private Xcls_PopoverFileDetails  _this;
640
641
642             // my vars (def)
643
644         // ctor 
645         public Xcls_Button21(Xcls_PopoverFileDetails _owner )
646         {
647             _this = _owner;
648             this.el = new Gtk.Button();
649
650             // my vars (dec)
651
652             // set gobject values
653             this.el.label = "Cancel";
654
655             // listeners 
656             this.el.activate.connect( () => { this.el.hide(); });
657         }
658
659         // user defined functions 
660     }
661     public class Xcls_save_btn : Object 
662     {
663         public Gtk.Button el;
664         private Xcls_PopoverFileDetails  _this;
665
666
667             // my vars (def)
668         public signal void success (Project.Project pr, JsRender.JsRender file);
669
670         // ctor 
671         public Xcls_save_btn(Xcls_PopoverFileDetails _owner )
672         {
673             _this = _owner;
674             _this.save_btn = this;
675             this.el = new Gtk.Button();
676
677             // my vars (dec)
678
679             // set gobject values
680             this.el.label = "Save";
681
682             // listeners 
683             this.el.activate.connect( ( ) =>  { 
684               
685                  
686             
687             
688                     if (_this.name.el.get_text().length  < 1) {
689                         StandardErrorDialog.show(
690                             this.el,
691                             "You have to set Component name "
692                         );
693                          
694                         return;
695                     }
696                     // what does this do?
697                     
698                     var isNew = _this.file.name.length  > 0 ? false : true;
699                     /*
700                     if (!isNew && this.file.name != _this.name.el.get_text()) {
701                         Xcls_StandardErrorDialog.singleton().show(
702                             this.el,
703                             "Sorry changing names does not work yet. "
704                         );
705                          
706                         return;
707                     }
708                     */
709                      
710                     
711                   
712                     // FIXME - this may be more complicated...
713                     //for (var i in this.def) {
714                     //    this.file[i] =  this.get(i).el.get_text();
715                     //}
716             
717                     if (!isNew) {
718                         try {
719                              this.updateFileFromEntry();
720                          } catch( JsRender.Error.RENAME_FILE_EXISTS er) {
721                               Xcls_StandardErrorDialog.singleton().show(
722                                 this.el,
723                                 "The name you used already exists "
724                             );
725                             return;
726                              
727                          }
728                                                                     
729                     
730                         _this.file.save();
731                         this.el.hide();
732                         return;
733                     }
734                     var fn = this.name.el.get_text();
735                     var dir = _this.project.firstPath();
736                    
737                     if (GLib.FileUtils.test(dir + "/" + fn + ".bjs", GLib.FileTest.EXISTS)) {
738                         Xcls_StandardErrorDialog.singleton().show(
739                             this.el,
740                             "That file already exists"
741                         ); 
742                         return;
743                     }
744                    
745                    var f =  JsRender.JsRender.factory(
746                             _this.file.project.xtype,  
747                             _this.file.project, 
748                             dir + "/" + fn + ".bjs");
749             
750                     _this.file = f;
751                     
752             
753                     
754                     this.updateFileFromEntry();
755                     _this.file.save();
756                     _this.file.project.addFile(_this.file);
757                     
758                  
759                     // what about .js ?
760                    
761                     this.el.hide();
762                     
763                     
764                     
765                     _this.success(_this.project, _this.file);
766                    
767             });
768         }
769
770         // user defined functions 
771     }
772 }