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