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_Button18( _this );
47         child_1.ref();
48         this.el.add_action_widget (  child_1.el , 0 );
49         var child_2 = new Xcls_Button19( _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,5,6 );
288             var child_13 = new Xcls_modOrder( _this );
289             child_13.ref();
290             this.el.attach_defaults (  child_13.el , 1,2,5,6 );
291         }
292
293         // user defined functions 
294     }
295     public class Xcls_Label4 : Object 
296     {
297         public Gtk.Label el;
298         private Xcls_DialogNewComponent  _this;
299
300
301             // my vars (def)
302
303         // ctor 
304         public Xcls_Label4(Xcls_DialogNewComponent _owner )
305         {
306             _this = _owner;
307             this.el = new Gtk.Label( "Component Name" );
308
309             // my vars (dec)
310
311             // set gobject values
312             this.el.justify = Gtk.Justification.RIGHT;
313             this.el.xalign = 0.900000f;
314         }
315
316         // user defined functions 
317     }
318     public class Xcls_name : Object 
319     {
320         public Gtk.Entry el;
321         private Xcls_DialogNewComponent  _this;
322
323
324             // my vars (def)
325
326         // ctor 
327         public Xcls_name(Xcls_DialogNewComponent _owner )
328         {
329             _this = _owner;
330             _this.name = this;
331             this.el = new Gtk.Entry();
332
333             // my vars (dec)
334
335             // set gobject values
336             this.el.visible = true;
337         }
338
339         // user defined functions 
340     }
341     public class Xcls_Label6 : Object 
342     {
343         public Gtk.Label el;
344         private Xcls_DialogNewComponent  _this;
345
346
347             // my vars (def)
348
349         // ctor 
350         public Xcls_Label6(Xcls_DialogNewComponent _owner )
351         {
352             _this = _owner;
353             this.el = new Gtk.Label( "Title" );
354
355             // my vars (dec)
356
357             // set gobject values
358             this.el.justify = Gtk.Justification.RIGHT;
359             this.el.xalign = 0.900000f;
360             this.el.visible = true;
361         }
362
363         // user defined functions 
364     }
365     public class Xcls_title : Object 
366     {
367         public Gtk.Entry el;
368         private Xcls_DialogNewComponent  _this;
369
370
371             // my vars (def)
372
373         // ctor 
374         public Xcls_title(Xcls_DialogNewComponent _owner )
375         {
376             _this = _owner;
377             _this.title = this;
378             this.el = new Gtk.Entry();
379
380             // my vars (dec)
381
382             // set gobject values
383             this.el.visible = true;
384         }
385
386         // user defined functions 
387     }
388     public class Xcls_Label8 : Object 
389     {
390         public Gtk.Label el;
391         private Xcls_DialogNewComponent  _this;
392
393
394             // my vars (def)
395
396         // ctor 
397         public Xcls_Label8(Xcls_DialogNewComponent _owner )
398         {
399             _this = _owner;
400             this.el = new Gtk.Label( "Region" );
401
402             // my vars (dec)
403
404             // set gobject values
405             this.el.justify = Gtk.Justification.RIGHT;
406             this.el.xalign = 0.900000f;
407             this.el.tooltip_text = "center, north, south, east, west";
408             this.el.visible = true;
409         }
410
411         // user defined functions 
412     }
413     public class Xcls_region : Object 
414     {
415         public Gtk.Entry el;
416         private Xcls_DialogNewComponent  _this;
417
418
419             // my vars (def)
420
421         // ctor 
422         public Xcls_region(Xcls_DialogNewComponent _owner )
423         {
424             _this = _owner;
425             _this.region = this;
426             this.el = new Gtk.Entry();
427
428             // my vars (dec)
429
430             // set gobject values
431             this.el.visible = true;
432         }
433
434         // user defined functions 
435     }
436     public class Xcls_Label10 : Object 
437     {
438         public Gtk.Label el;
439         private Xcls_DialogNewComponent  _this;
440
441
442             // my vars (def)
443
444         // ctor 
445         public Xcls_Label10(Xcls_DialogNewComponent _owner )
446         {
447             _this = _owner;
448             this.el = new Gtk.Label( "Parent Name" );
449
450             // my vars (dec)
451
452             // set gobject values
453             this.el.justify = Gtk.Justification.RIGHT;
454             this.el.xalign = 0.900000f;
455             this.el.visible = true;
456         }
457
458         // user defined functions 
459     }
460     public class Xcls_parent : Object 
461     {
462         public Gtk.Entry el;
463         private Xcls_DialogNewComponent  _this;
464
465
466             // my vars (def)
467
468         // ctor 
469         public Xcls_parent(Xcls_DialogNewComponent _owner )
470         {
471             _this = _owner;
472             _this.parent = this;
473             this.el = new Gtk.Entry();
474
475             // my vars (dec)
476
477             // set gobject values
478             this.el.visible = true;
479         }
480
481         // user defined functions 
482     }
483     public class Xcls_Label12 : Object 
484     {
485         public Gtk.Label el;
486         private Xcls_DialogNewComponent  _this;
487
488
489             // my vars (def)
490
491         // ctor 
492         public Xcls_Label12(Xcls_DialogNewComponent _owner )
493         {
494             _this = _owner;
495             this.el = new Gtk.Label( "Permission Name" );
496
497             // my vars (dec)
498
499             // set gobject values
500             this.el.justify = Gtk.Justification.RIGHT;
501             this.el.xalign = 0.900000f;
502             this.el.visible = true;
503         }
504
505         // user defined functions 
506     }
507     public class Xcls_permname : Object 
508     {
509         public Gtk.Entry el;
510         private Xcls_DialogNewComponent  _this;
511
512
513             // my vars (def)
514
515         // ctor 
516         public Xcls_permname(Xcls_DialogNewComponent _owner )
517         {
518             _this = _owner;
519             _this.permname = this;
520             this.el = new Gtk.Entry();
521
522             // my vars (dec)
523
524             // set gobject values
525             this.el.visible = true;
526         }
527
528         // user defined functions 
529     }
530     public class Xcls_Label14 : Object 
531     {
532         public Gtk.Label el;
533         private Xcls_DialogNewComponent  _this;
534
535
536             // my vars (def)
537
538         // ctor 
539         public Xcls_Label14(Xcls_DialogNewComponent _owner )
540         {
541             _this = _owner;
542             this.el = new Gtk.Label( "Order (for tabs)" );
543
544             // my vars (dec)
545
546             // set gobject values
547             this.el.justify = Gtk.Justification.RIGHT;
548             this.el.xalign = 0.900000f;
549             this.el.visible = true;
550         }
551
552         // user defined functions 
553     }
554     public class Xcls_modOrder : Object 
555     {
556         public Gtk.Entry el;
557         private Xcls_DialogNewComponent  _this;
558
559
560             // my vars (def)
561
562         // ctor 
563         public Xcls_modOrder(Xcls_DialogNewComponent _owner )
564         {
565             _this = _owner;
566             _this.modOrder = this;
567             this.el = new Gtk.Entry();
568
569             // my vars (dec)
570
571             // set gobject values
572             this.el.visible = true;
573         }
574
575         // user defined functions 
576     }
577     public class Xcls_Label16 : Object 
578     {
579         public Gtk.Label el;
580         private Xcls_DialogNewComponent  _this;
581
582
583             // my vars (def)
584
585         // ctor 
586         public Xcls_Label16(Xcls_DialogNewComponent _owner )
587         {
588             _this = _owner;
589             this.el = new Gtk.Label( "Order (for tabs)" );
590
591             // my vars (dec)
592
593             // set gobject values
594             this.el.justify = Gtk.Justification.RIGHT;
595             this.el.xalign = 0.900000f;
596             this.el.visible = true;
597         }
598
599         // user defined functions 
600     }
601     public class Xcls_modOrder : Object 
602     {
603         public Gtk.Entry el;
604         private Xcls_DialogNewComponent  _this;
605
606
607             // my vars (def)
608
609         // ctor 
610         public Xcls_modOrder(Xcls_DialogNewComponent _owner )
611         {
612             _this = _owner;
613             _this.modOrder = this;
614             this.el = new Gtk.Entry();
615
616             // my vars (dec)
617
618             // set gobject values
619             this.el.visible = true;
620         }
621
622         // user defined functions 
623     }
624     public class Xcls_Button18 : Object 
625     {
626         public Gtk.Button el;
627         private Xcls_DialogNewComponent  _this;
628
629
630             // my vars (def)
631
632         // ctor 
633         public Xcls_Button18(Xcls_DialogNewComponent _owner )
634         {
635             _this = _owner;
636             this.el = new Gtk.Button();
637
638             // my vars (dec)
639
640             // set gobject values
641             this.el.label = "Cancel";
642         }
643
644         // user defined functions 
645     }
646     public class Xcls_Button19 : Object 
647     {
648         public Gtk.Button el;
649         private Xcls_DialogNewComponent  _this;
650
651
652             // my vars (def)
653
654         // ctor 
655         public Xcls_Button19(Xcls_DialogNewComponent _owner )
656         {
657             _this = _owner;
658             this.el = new Gtk.Button();
659
660             // my vars (dec)
661
662             // set gobject values
663             this.el.label = "OK";
664         }
665
666         // user defined functions 
667     }
668 }