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