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