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