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