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