src/Builder4/DialogNewComponent.bjs
[app.Builder.js] / 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                                                         
180     }
181     public   void show (JsRender.JsRender c) 
182     {
183         this.project = c.project;
184         
185         //if (!this.el) {
186             //this.init();
187          //}
188         
189         _this.name.el.set_text(c.name);
190         _this.title.el.set_text(c.title);
191         _this.parent.el.set_text(c.parent);    
192         _this.region.el.set_text(c.region);
193         _this.modOrder.el.set_text(c.modOrder);
194          _this.permname.el.set_text(c.permname);
195         
196         if (c.path.length > 0) {
197             this.el.set_title("Edit File Details - " + c.name);
198         } else {
199             this.el.set_title("Create New File");
200         }
201         
202          var ar = new Gee.ArrayList<string>();
203          _this.dbmodel.loadData(ar);
204         // load the modules... if relivant..
205         if (this.project.xtype == "Gtk") {
206             var p = (Project.Gtk)c.project;
207               var cg = p.compilegroups;
208     
209             var iter = cg.map_iterator();
210            while(iter.next()) {
211                 var key = iter.get_key();
212                 if (key == "_default_") {
213                     continue;
214                 }
215                 ar.add(key);
216             };
217             _this.dbmodel.loadData(ar);
218     
219         }
220         
221          
222         _this.file = c;
223         //console.log('show all');
224         this.el.show_all();
225         
226         //this.success = c.success;
227         
228         
229     }
230     public class Xcls_VBox2 : Object 
231     {
232         public Gtk.VBox el;
233         private Xcls_DialogNewComponent  _this;
234
235
236             // my vars (def)
237
238         // ctor 
239         public Xcls_VBox2(Xcls_DialogNewComponent _owner )
240         {
241             _this = _owner;
242             this.el = new Gtk.VBox( true, 0 );
243
244             // my vars (dec)
245
246             // set gobject values
247             var child_0 = new Xcls_Table3( _this );
248             child_0.ref();
249             this.el.pack_start (  child_0.el , false,false,0 );
250         }
251
252         // user defined functions 
253     }
254     public class Xcls_Table3 : Object 
255     {
256         public Gtk.Table el;
257         private Xcls_DialogNewComponent  _this;
258
259
260             // my vars (def)
261
262         // ctor 
263         public Xcls_Table3(Xcls_DialogNewComponent _owner )
264         {
265             _this = _owner;
266             this.el = new Gtk.Table( 3, 2, true );
267
268             // my vars (dec)
269
270             // set gobject values
271             var child_0 = new Xcls_Label4( _this );
272             child_0.ref();
273             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
274             var child_1 = new Xcls_name( _this );
275             child_1.ref();
276             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
277             var child_2 = new Xcls_Label6( _this );
278             child_2.ref();
279             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
280             var child_3 = new Xcls_title( _this );
281             child_3.ref();
282             this.el.attach_defaults (  child_3.el , 1,2,1,2 );
283             var child_4 = new Xcls_Label8( _this );
284             child_4.ref();
285             this.el.attach_defaults (  child_4.el , 0,1,2,3 );
286             var child_5 = new Xcls_region( _this );
287             child_5.ref();
288             this.el.attach_defaults (  child_5.el , 1,2,2,3 );
289             var child_6 = new Xcls_Label10( _this );
290             child_6.ref();
291             this.el.attach_defaults (  child_6.el , 0,1,3,4 );
292             var child_7 = new Xcls_parent( _this );
293             child_7.ref();
294             this.el.attach_defaults (  child_7.el , 1,2,3,4 );
295             var child_8 = new Xcls_Label12( _this );
296             child_8.ref();
297             this.el.attach_defaults (  child_8.el , 0,1,4,5 );
298             var child_9 = new Xcls_permname( _this );
299             child_9.ref();
300             this.el.attach_defaults (  child_9.el , 1,2,4,5 );
301             var child_10 = new Xcls_Label14( _this );
302             child_10.ref();
303             this.el.attach_defaults (  child_10.el , 0,1,5,6 );
304             var child_11 = new Xcls_modOrder( _this );
305             child_11.ref();
306             this.el.attach_defaults (  child_11.el , 1,2,5,6 );
307             var child_12 = new Xcls_Label16( _this );
308             child_12.ref();
309             this.el.attach_defaults (  child_12.el , 0,1,6,7 );
310             var child_13 = new Xcls_build_module( _this );
311             child_13.ref();
312             this.el.attach_defaults (  child_13.el , 1,2,6,7 );
313         }
314
315         // user defined functions 
316     }
317     public class Xcls_Label4 : Object 
318     {
319         public Gtk.Label el;
320         private Xcls_DialogNewComponent  _this;
321
322
323             // my vars (def)
324
325         // ctor 
326         public Xcls_Label4(Xcls_DialogNewComponent _owner )
327         {
328             _this = _owner;
329             this.el = new Gtk.Label( "Component Name" );
330
331             // my vars (dec)
332
333             // set gobject values
334             this.el.justify = Gtk.Justification.RIGHT;
335             this.el.xalign = 0.900000f;
336         }
337
338         // user defined functions 
339     }
340     public class Xcls_name : Object 
341     {
342         public Gtk.Entry el;
343         private Xcls_DialogNewComponent  _this;
344
345
346             // my vars (def)
347
348         // ctor 
349         public Xcls_name(Xcls_DialogNewComponent _owner )
350         {
351             _this = _owner;
352             _this.name = this;
353             this.el = new Gtk.Entry();
354
355             // my vars (dec)
356
357             // set gobject values
358             this.el.visible = true;
359         }
360
361         // user defined functions 
362     }
363     public class Xcls_Label6 : Object 
364     {
365         public Gtk.Label el;
366         private Xcls_DialogNewComponent  _this;
367
368
369             // my vars (def)
370
371         // ctor 
372         public Xcls_Label6(Xcls_DialogNewComponent _owner )
373         {
374             _this = _owner;
375             this.el = new Gtk.Label( "Title" );
376
377             // my vars (dec)
378
379             // set gobject values
380             this.el.justify = Gtk.Justification.RIGHT;
381             this.el.xalign = 0.900000f;
382             this.el.visible = true;
383         }
384
385         // user defined functions 
386     }
387     public class Xcls_title : Object 
388     {
389         public Gtk.Entry el;
390         private Xcls_DialogNewComponent  _this;
391
392
393             // my vars (def)
394
395         // ctor 
396         public Xcls_title(Xcls_DialogNewComponent _owner )
397         {
398             _this = _owner;
399             _this.title = this;
400             this.el = new Gtk.Entry();
401
402             // my vars (dec)
403
404             // set gobject values
405             this.el.visible = true;
406         }
407
408         // user defined functions 
409     }
410     public class Xcls_Label8 : Object 
411     {
412         public Gtk.Label el;
413         private Xcls_DialogNewComponent  _this;
414
415
416             // my vars (def)
417
418         // ctor 
419         public Xcls_Label8(Xcls_DialogNewComponent _owner )
420         {
421             _this = _owner;
422             this.el = new Gtk.Label( "Region" );
423
424             // my vars (dec)
425
426             // set gobject values
427             this.el.justify = Gtk.Justification.RIGHT;
428             this.el.xalign = 0.900000f;
429             this.el.tooltip_text = "center, north, south, east, west";
430             this.el.visible = true;
431         }
432
433         // user defined functions 
434     }
435     public class Xcls_region : Object 
436     {
437         public Gtk.Entry el;
438         private Xcls_DialogNewComponent  _this;
439
440
441             // my vars (def)
442
443         // ctor 
444         public Xcls_region(Xcls_DialogNewComponent _owner )
445         {
446             _this = _owner;
447             _this.region = this;
448             this.el = new Gtk.Entry();
449
450             // my vars (dec)
451
452             // set gobject values
453             this.el.visible = true;
454         }
455
456         // user defined functions 
457     }
458     public class Xcls_Label10 : Object 
459     {
460         public Gtk.Label el;
461         private Xcls_DialogNewComponent  _this;
462
463
464             // my vars (def)
465
466         // ctor 
467         public Xcls_Label10(Xcls_DialogNewComponent _owner )
468         {
469             _this = _owner;
470             this.el = new Gtk.Label( "Parent Name" );
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     public class Xcls_parent : Object 
483     {
484         public Gtk.Entry el;
485         private Xcls_DialogNewComponent  _this;
486
487
488             // my vars (def)
489
490         // ctor 
491         public Xcls_parent(Xcls_DialogNewComponent _owner )
492         {
493             _this = _owner;
494             _this.parent = this;
495             this.el = new Gtk.Entry();
496
497             // my vars (dec)
498
499             // set gobject values
500             this.el.visible = true;
501         }
502
503         // user defined functions 
504     }
505     public class Xcls_Label12 : Object 
506     {
507         public Gtk.Label el;
508         private Xcls_DialogNewComponent  _this;
509
510
511             // my vars (def)
512
513         // ctor 
514         public Xcls_Label12(Xcls_DialogNewComponent _owner )
515         {
516             _this = _owner;
517             this.el = new Gtk.Label( "Permission Name" );
518
519             // my vars (dec)
520
521             // set gobject values
522             this.el.justify = Gtk.Justification.RIGHT;
523             this.el.xalign = 0.900000f;
524             this.el.visible = true;
525         }
526
527         // user defined functions 
528     }
529     public class Xcls_permname : Object 
530     {
531         public Gtk.Entry el;
532         private Xcls_DialogNewComponent  _this;
533
534
535             // my vars (def)
536
537         // ctor 
538         public Xcls_permname(Xcls_DialogNewComponent _owner )
539         {
540             _this = _owner;
541             _this.permname = this;
542             this.el = new Gtk.Entry();
543
544             // my vars (dec)
545
546             // set gobject values
547             this.el.visible = true;
548         }
549
550         // user defined functions 
551     }
552     public class Xcls_Label14 : Object 
553     {
554         public Gtk.Label el;
555         private Xcls_DialogNewComponent  _this;
556
557
558             // my vars (def)
559
560         // ctor 
561         public Xcls_Label14(Xcls_DialogNewComponent _owner )
562         {
563             _this = _owner;
564             this.el = new Gtk.Label( "Order (for tabs)" );
565
566             // my vars (dec)
567
568             // set gobject values
569             this.el.justify = Gtk.Justification.RIGHT;
570             this.el.xalign = 0.900000f;
571             this.el.visible = true;
572         }
573
574         // user defined functions 
575     }
576     public class Xcls_modOrder : Object 
577     {
578         public Gtk.Entry el;
579         private Xcls_DialogNewComponent  _this;
580
581
582             // my vars (def)
583
584         // ctor 
585         public Xcls_modOrder(Xcls_DialogNewComponent _owner )
586         {
587             _this = _owner;
588             _this.modOrder = this;
589             this.el = new Gtk.Entry();
590
591             // my vars (dec)
592
593             // set gobject values
594             this.el.visible = true;
595         }
596
597         // user defined functions 
598     }
599     public class Xcls_Label16 : Object 
600     {
601         public Gtk.Label el;
602         private Xcls_DialogNewComponent  _this;
603
604
605             // my vars (def)
606
607         // ctor 
608         public Xcls_Label16(Xcls_DialogNewComponent _owner )
609         {
610             _this = _owner;
611             this.el = new Gtk.Label( "Module to build (Vala only)" );
612
613             // my vars (dec)
614
615             // set gobject values
616             this.el.justify = Gtk.Justification.RIGHT;
617             this.el.xalign = 0.900000f;
618             this.el.visible = true;
619         }
620
621         // user defined functions 
622     }
623     public class Xcls_build_module : Object 
624     {
625         public Gtk.ComboBox el;
626         private Xcls_DialogNewComponent  _this;
627
628
629             // my vars (def)
630
631         // ctor 
632         public Xcls_build_module(Xcls_DialogNewComponent _owner )
633         {
634             _this = _owner;
635             _this.build_module = this;
636             this.el = new Gtk.ComboBox();
637
638             // my vars (dec)
639
640             // set gobject values
641             var child_0 = new Xcls_dbcellrenderer( _this );
642             child_0.ref();
643             this.el.pack_start (  child_0.el , true );
644             var child_1 = new Xcls_dbmodel( _this );
645             child_1.ref();
646             this.el.set_model (  child_1.el  );
647
648             // init method 
649
650             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
651         }
652
653         // user defined functions 
654     }
655     public class Xcls_dbcellrenderer : Object 
656     {
657         public Gtk.CellRendererText el;
658         private Xcls_DialogNewComponent  _this;
659
660
661             // my vars (def)
662
663         // ctor 
664         public Xcls_dbcellrenderer(Xcls_DialogNewComponent _owner )
665         {
666             _this = _owner;
667             _this.dbcellrenderer = this;
668             this.el = new Gtk.CellRendererText();
669
670             // my vars (dec)
671
672             // set gobject values
673         }
674
675         // user defined functions 
676     }
677     public class Xcls_dbmodel : Object 
678     {
679         public Gtk.ListStore el;
680         private Xcls_DialogNewComponent  _this;
681
682
683             // my vars (def)
684
685         // ctor 
686         public Xcls_dbmodel(Xcls_DialogNewComponent _owner )
687         {
688             _this = _owner;
689             _this.dbmodel = this;
690             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
691
692             // my vars (dec)
693
694             // set gobject values
695         }
696
697         // user defined functions 
698         public void loadData (Gee.ArrayList<string> data) {
699             this.el.clear();                                    
700             Gtk.TreeIter iter;
701             var el = this.el;
702             
703            /// el.append(out iter);
704             
705              
706            // el.set_value(iter, 0, "");
707            // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
708         
709             el.append(out iter);
710         
711             
712             el.set_value(iter, 0, "");
713             el.set_value(iter, 1, "-- select a module --");
714             
715             
716             for (var i = 0; i < data.size;i++) {
717             
718         
719                 el.append(out iter);
720                 
721                 el.set_value(iter, 0, data.get(i));
722                 el.set_value(iter, 1, data.get(i));
723                 
724             }
725              this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
726                                              
727         }
728     }
729     public class Xcls_Button20 : Object 
730     {
731         public Gtk.Button el;
732         private Xcls_DialogNewComponent  _this;
733
734
735             // my vars (def)
736
737         // ctor 
738         public Xcls_Button20(Xcls_DialogNewComponent _owner )
739         {
740             _this = _owner;
741             this.el = new Gtk.Button();
742
743             // my vars (dec)
744
745             // set gobject values
746             this.el.label = "Cancel";
747         }
748
749         // user defined functions 
750     }
751     public class Xcls_Button21 : Object 
752     {
753         public Gtk.Button el;
754         private Xcls_DialogNewComponent  _this;
755
756
757             // my vars (def)
758
759         // ctor 
760         public Xcls_Button21(Xcls_DialogNewComponent _owner )
761         {
762             _this = _owner;
763             this.el = new Gtk.Button();
764
765             // my vars (dec)
766
767             // set gobject values
768             this.el.label = "OK";
769         }
770
771         // user defined functions 
772     }
773 }