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