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