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