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