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