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