f30daccdf946f31731c120a20d11a9f1c47584ff
[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             var child_0 = new Xcls_Label5( _this );
219             child_0.ref();
220             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
221             var child_1 = new Xcls_name( _this );
222             child_1.ref();
223             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
224             var child_2 = new Xcls_Label7( _this );
225             child_2.ref();
226             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
227             var child_3 = new Xcls_title( _this );
228             child_3.ref();
229             this.el.attach_defaults (  child_3.el , 1,2,1,2 );
230             var child_4 = new Xcls_Label9( _this );
231             child_4.ref();
232             this.el.attach_defaults (  child_4.el , 0,1,2,3 );
233             var child_5 = new Xcls_region( _this );
234             child_5.ref();
235             this.el.attach_defaults (  child_5.el , 1,2,2,3 );
236             var child_6 = new Xcls_Label11( _this );
237             child_6.ref();
238             this.el.attach_defaults (  child_6.el , 0,1,3,4 );
239             var child_7 = new Xcls_parent( _this );
240             child_7.ref();
241             this.el.attach_defaults (  child_7.el , 1,2,3,4 );
242             var child_8 = new Xcls_Label13( _this );
243             child_8.ref();
244             this.el.attach_defaults (  child_8.el , 0,1,4,5 );
245             var child_9 = new Xcls_permname( _this );
246             child_9.ref();
247             this.el.attach_defaults (  child_9.el , 1,2,4,5 );
248             var child_10 = new Xcls_Label15( _this );
249             child_10.ref();
250             this.el.attach_defaults (  child_10.el , 0,1,5,6 );
251             var child_11 = new Xcls_modOrder( _this );
252             child_11.ref();
253             this.el.attach_defaults (  child_11.el , 1,2,5,6 );
254             var child_12 = new Xcls_Label17( _this );
255             child_12.ref();
256             this.el.attach_defaults (  child_12.el , 0,1,6,7 );
257             var child_13 = new Xcls_build_module( _this );
258             child_13.ref();
259             this.el.attach_defaults (  child_13.el , 1,2,6,7 );
260         }
261
262         // user defined functions 
263     }
264     public class Xcls_Label5 : Object 
265     {
266         public Gtk.Label el;
267         private Xcls_PopoverFileDetails  _this;
268
269
270             // my vars (def)
271
272         // ctor 
273         public Xcls_Label5(Xcls_PopoverFileDetails _owner )
274         {
275             _this = _owner;
276             this.el = new Gtk.Label( "Component Name" );
277
278             // my vars (dec)
279
280             // set gobject values
281             this.el.justify = Gtk.Justification.RIGHT;
282             this.el.xalign = 0.900000f;
283         }
284
285         // user defined functions 
286     }
287     public class Xcls_name : Object 
288     {
289         public Gtk.Entry el;
290         private Xcls_PopoverFileDetails  _this;
291
292
293             // my vars (def)
294
295         // ctor 
296         public Xcls_name(Xcls_PopoverFileDetails _owner )
297         {
298             _this = _owner;
299             _this.name = this;
300             this.el = new Gtk.Entry();
301
302             // my vars (dec)
303
304             // set gobject values
305             this.el.visible = true;
306         }
307
308         // user defined functions 
309     }
310     public class Xcls_Label7 : Object 
311     {
312         public Gtk.Label el;
313         private Xcls_PopoverFileDetails  _this;
314
315
316             // my vars (def)
317
318         // ctor 
319         public Xcls_Label7(Xcls_PopoverFileDetails _owner )
320         {
321             _this = _owner;
322             this.el = new Gtk.Label( "Title" );
323
324             // my vars (dec)
325
326             // set gobject values
327             this.el.justify = Gtk.Justification.RIGHT;
328             this.el.xalign = 0.900000f;
329             this.el.visible = true;
330         }
331
332         // user defined functions 
333     }
334     public class Xcls_title : Object 
335     {
336         public Gtk.Entry el;
337         private Xcls_PopoverFileDetails  _this;
338
339
340             // my vars (def)
341
342         // ctor 
343         public Xcls_title(Xcls_PopoverFileDetails _owner )
344         {
345             _this = _owner;
346             _this.title = this;
347             this.el = new Gtk.Entry();
348
349             // my vars (dec)
350
351             // set gobject values
352             this.el.visible = true;
353         }
354
355         // user defined functions 
356     }
357     public class Xcls_Label9 : Object 
358     {
359         public Gtk.Label el;
360         private Xcls_PopoverFileDetails  _this;
361
362
363             // my vars (def)
364
365         // ctor 
366         public Xcls_Label9(Xcls_PopoverFileDetails _owner )
367         {
368             _this = _owner;
369             this.el = new Gtk.Label( "Region" );
370
371             // my vars (dec)
372
373             // set gobject values
374             this.el.justify = Gtk.Justification.RIGHT;
375             this.el.xalign = 0.900000f;
376             this.el.tooltip_text = "center, north, south, east, west";
377             this.el.visible = true;
378         }
379
380         // user defined functions 
381     }
382     public class Xcls_region : Object 
383     {
384         public Gtk.Entry el;
385         private Xcls_PopoverFileDetails  _this;
386
387
388             // my vars (def)
389
390         // ctor 
391         public Xcls_region(Xcls_PopoverFileDetails _owner )
392         {
393             _this = _owner;
394             _this.region = this;
395             this.el = new Gtk.Entry();
396
397             // my vars (dec)
398
399             // set gobject values
400             this.el.visible = true;
401         }
402
403         // user defined functions 
404     }
405     public class Xcls_Label11 : Object 
406     {
407         public Gtk.Label el;
408         private Xcls_PopoverFileDetails  _this;
409
410
411             // my vars (def)
412
413         // ctor 
414         public Xcls_Label11(Xcls_PopoverFileDetails _owner )
415         {
416             _this = _owner;
417             this.el = new Gtk.Label( "Parent Name" );
418
419             // my vars (dec)
420
421             // set gobject values
422             this.el.justify = Gtk.Justification.RIGHT;
423             this.el.xalign = 0.900000f;
424             this.el.visible = true;
425         }
426
427         // user defined functions 
428     }
429     public class Xcls_parent : Object 
430     {
431         public Gtk.Entry el;
432         private Xcls_PopoverFileDetails  _this;
433
434
435             // my vars (def)
436
437         // ctor 
438         public Xcls_parent(Xcls_PopoverFileDetails _owner )
439         {
440             _this = _owner;
441             _this.parent = this;
442             this.el = new Gtk.Entry();
443
444             // my vars (dec)
445
446             // set gobject values
447             this.el.visible = true;
448         }
449
450         // user defined functions 
451     }
452     public class Xcls_Label13 : Object 
453     {
454         public Gtk.Label el;
455         private Xcls_PopoverFileDetails  _this;
456
457
458             // my vars (def)
459
460         // ctor 
461         public Xcls_Label13(Xcls_PopoverFileDetails _owner )
462         {
463             _this = _owner;
464             this.el = new Gtk.Label( "Permission Name" );
465
466             // my vars (dec)
467
468             // set gobject values
469             this.el.justify = Gtk.Justification.RIGHT;
470             this.el.xalign = 0.900000f;
471             this.el.visible = true;
472         }
473
474         // user defined functions 
475     }
476     public class Xcls_permname : Object 
477     {
478         public Gtk.Entry el;
479         private Xcls_PopoverFileDetails  _this;
480
481
482             // my vars (def)
483
484         // ctor 
485         public Xcls_permname(Xcls_PopoverFileDetails _owner )
486         {
487             _this = _owner;
488             _this.permname = this;
489             this.el = new Gtk.Entry();
490
491             // my vars (dec)
492
493             // set gobject values
494             this.el.visible = true;
495         }
496
497         // user defined functions 
498     }
499     public class Xcls_Label15 : Object 
500     {
501         public Gtk.Label el;
502         private Xcls_PopoverFileDetails  _this;
503
504
505             // my vars (def)
506
507         // ctor 
508         public Xcls_Label15(Xcls_PopoverFileDetails _owner )
509         {
510             _this = _owner;
511             this.el = new Gtk.Label( "Order (for tabs)" );
512
513             // my vars (dec)
514
515             // set gobject values
516             this.el.justify = Gtk.Justification.RIGHT;
517             this.el.xalign = 0.900000f;
518             this.el.visible = true;
519         }
520
521         // user defined functions 
522     }
523     public class Xcls_modOrder : Object 
524     {
525         public Gtk.Entry el;
526         private Xcls_PopoverFileDetails  _this;
527
528
529             // my vars (def)
530
531         // ctor 
532         public Xcls_modOrder(Xcls_PopoverFileDetails _owner )
533         {
534             _this = _owner;
535             _this.modOrder = this;
536             this.el = new Gtk.Entry();
537
538             // my vars (dec)
539
540             // set gobject values
541             this.el.visible = true;
542         }
543
544         // user defined functions 
545     }
546     public class Xcls_Label17 : Object 
547     {
548         public Gtk.Label el;
549         private Xcls_PopoverFileDetails  _this;
550
551
552             // my vars (def)
553
554         // ctor 
555         public Xcls_Label17(Xcls_PopoverFileDetails _owner )
556         {
557             _this = _owner;
558             this.el = new Gtk.Label( "Module to build (Vala only)" );
559
560             // my vars (dec)
561
562             // set gobject values
563             this.el.justify = Gtk.Justification.RIGHT;
564             this.el.xalign = 0.900000f;
565             this.el.visible = true;
566         }
567
568         // user defined functions 
569     }
570     public class Xcls_build_module : Object 
571     {
572         public Gtk.ComboBox el;
573         private Xcls_PopoverFileDetails  _this;
574
575
576             // my vars (def)
577
578         // ctor 
579         public Xcls_build_module(Xcls_PopoverFileDetails _owner )
580         {
581             _this = _owner;
582             _this.build_module = this;
583             this.el = new Gtk.ComboBox();
584
585             // my vars (dec)
586
587             // set gobject values
588             var child_0 = new Xcls_dbcellrenderer( _this );
589             child_0.ref();
590             this.el.pack_start (  child_0.el , true );
591             var child_1 = new Xcls_dbmodel( _this );
592             child_1.ref();
593             this.el.set_model (  child_1.el  );
594
595             // init method 
596
597             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
598         }
599
600         // user defined functions 
601     }
602     public class Xcls_dbcellrenderer : Object 
603     {
604         public Gtk.CellRendererText el;
605         private Xcls_PopoverFileDetails  _this;
606
607
608             // my vars (def)
609
610         // ctor 
611         public Xcls_dbcellrenderer(Xcls_PopoverFileDetails _owner )
612         {
613             _this = _owner;
614             _this.dbcellrenderer = this;
615             this.el = new Gtk.CellRendererText();
616
617             // my vars (dec)
618
619             // set gobject values
620         }
621
622         // user defined functions 
623     }
624     public class Xcls_dbmodel : Object 
625     {
626         public Gtk.ListStore el;
627         private Xcls_PopoverFileDetails  _this;
628
629
630             // my vars (def)
631
632         // ctor 
633         public Xcls_dbmodel(Xcls_PopoverFileDetails _owner )
634         {
635             _this = _owner;
636             _this.dbmodel = this;
637             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
638
639             // my vars (dec)
640
641             // set gobject values
642         }
643
644         // user defined functions 
645         public void loadData (Gee.ArrayList<string> data, string cur) {
646             this.el.clear();                                    
647             Gtk.TreeIter iter;
648             var el = this.el;
649             
650            /// el.append(out iter);
651             
652              
653            // el.set_value(iter, 0, "");
654            // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
655         
656             el.append(out iter);
657         
658             
659             el.set_value(iter, 0, "");
660             el.set_value(iter, 1, "-- select a module --");
661             _this.build_module.el.set_active_iter(iter);
662             
663             for (var i = 0; i < data.size;i++) {
664             
665         
666                 el.append(out iter);
667                 
668                 el.set_value(iter, 0, data.get(i));
669                 el.set_value(iter, 1, data.get(i));
670                 
671                 if (data.get(i) == cur) {
672                     _this.build_module.el.set_active_iter(iter);
673                 }
674                 
675             }
676              this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
677                                              
678         }
679     }
680     public class Xcls_HButtonBox21 : Object 
681     {
682         public Gtk.HButtonBox el;
683         private Xcls_PopoverFileDetails  _this;
684
685
686             // my vars (def)
687
688         // ctor 
689         public Xcls_HButtonBox21(Xcls_PopoverFileDetails _owner )
690         {
691             _this = _owner;
692             this.el = new Gtk.HButtonBox();
693
694             // my vars (dec)
695
696             // set gobject values
697             var child_0 = new Xcls_Button22( _this );
698             child_0.ref();
699             this.el.add (  child_0.el  );
700             var child_1 = new Xcls_save_btn( _this );
701             child_1.ref();
702             this.el.add (  child_1.el  );
703         }
704
705         // user defined functions 
706     }
707     public class Xcls_Button22 : Object 
708     {
709         public Gtk.Button el;
710         private Xcls_PopoverFileDetails  _this;
711
712
713             // my vars (def)
714
715         // ctor 
716         public Xcls_Button22(Xcls_PopoverFileDetails _owner )
717         {
718             _this = _owner;
719             this.el = new Gtk.Button();
720
721             // my vars (dec)
722
723             // set gobject values
724             this.el.label = "Cancel";
725
726             // listeners 
727             this.el.clicked.connect( () => { 
728             
729               _this.done = true;
730                 _this.el.hide(); 
731             });
732         }
733
734         // user defined functions 
735     }
736     public class Xcls_save_btn : Object 
737     {
738         public Gtk.Button el;
739         private Xcls_PopoverFileDetails  _this;
740
741
742             // my vars (def)
743
744         // ctor 
745         public Xcls_save_btn(Xcls_PopoverFileDetails _owner )
746         {
747             _this = _owner;
748             _this.save_btn = this;
749             this.el = new Gtk.Button();
750
751             // my vars (dec)
752
753             // set gobject values
754             this.el.label = "Save";
755
756             // listeners 
757             this.el.clicked.connect( ( ) =>  { 
758               
759                  
760             
761             
762                     if (_this.name.el.get_text().length  < 1) {
763                         StandardErrorDialog.show(
764                             _this.mainwindow.el,
765                             "You have to set Component name "
766                         );
767                          
768                         return;
769                     }
770                     // what does this do?
771                     
772                     var isNew = _this.file.name.length  > 0 ? false : true;
773                     /*
774                     if (!isNew && this.file.name != _this.name.el.get_text()) {
775                         Xcls_StandardErrorDialog.singleton().show(
776                             this.el,
777                             "Sorry changing names does not work yet. "
778                         );
779                          
780                         return;
781                     }
782                     */
783                      
784                     
785                   
786                     // FIXME - this may be more complicated...
787                     //for (var i in this.def) {
788                     //    this.file[i] =  this.get(i).el.get_text();
789                     //}
790             
791                     if (!isNew) {
792                         try {
793                              _this.updateFileFromEntry();
794                          } catch( JsRender.Error.RENAME_FILE_EXISTS er) {
795                               Xcls_StandardErrorDialog.singleton().show(
796                                 _this.mainwindow.el,
797                                 "The name you used already exists "
798                             );
799                             return;
800                              
801                          }
802                                                                     
803                           _this.done = true;
804                         _this.file.save();
805                         _this.el.hide();
806                         return;
807                     }
808                     var fn = _this.name.el.get_text();
809                     var dir = _this.project.firstPath();
810                    
811                     if (GLib.FileUtils.test(dir + "/" + fn + ".bjs", GLib.FileTest.EXISTS)) {
812                         Xcls_StandardErrorDialog.singleton().show(
813                             _this.mainwindow.el,
814                             "That file already exists"
815                         ); 
816                         return;
817                     }
818                    
819                    var f =  JsRender.JsRender.factory(
820                             _this.file.project.xtype,  
821                             _this.file.project, 
822                             dir + "/" + fn + ".bjs");
823             
824                     _this.file = f;
825                     
826             
827                     
828                     _this.updateFileFromEntry();
829                     _this.file.save();
830                     _this.file.project.addFile(_this.file);
831                     
832                  
833                     // what about .js ?
834                    _this.done = true;
835                     _this.el.hide();
836              
837                     
838                     
839                     _this.success(_this.project, _this.file);
840                    
841             });
842         }
843
844         // user defined functions 
845     }
846 }