Fix #8101 - new roo bjs files fail and fix top drop
[roobuilder] / src / Builder4 / PopoverFileDetails.vala
1 static Xcls_PopoverFileDetails  _PopoverFileDetails;
2
3 public class Xcls_PopoverFileDetails : Object
4 {
5         public Gtk.Window el;
6         private Xcls_PopoverFileDetails  _this;
7
8         public static Xcls_PopoverFileDetails singleton()
9         {
10                 if (_PopoverFileDetails == null) {
11                     _PopoverFileDetails= new Xcls_PopoverFileDetails();
12                 }
13                 return _PopoverFileDetails;
14         }
15         public Xcls_grid grid;
16         public Xcls_filetype_lbl filetype_lbl;
17         public Xcls_filetype filetype;
18         public Xcls_filetype_model filetype_model;
19         public Xcls_dir_dropdown_lbl dir_dropdown_lbl;
20         public Xcls_dir_dropdown dir_dropdown;
21         public Xcls_dir_model dir_model;
22         public Xcls_name_lbl name_lbl;
23         public Xcls_name name;
24         public Xcls_title_lbl title_lbl;
25         public Xcls_title title;
26         public Xcls_region_lbl region_lbl;
27         public Xcls_region region;
28         public Xcls_parent_lbl parent_lbl;
29         public Xcls_parent parent;
30         public Xcls_permname_lbl permname_lbl;
31         public Xcls_permname permname;
32         public Xcls_modOrder_lbl modOrder_lbl;
33         public Xcls_modOrder modOrder;
34         public Xcls_build_module_lbl build_module_lbl;
35         public Xcls_build_module build_module;
36         public Xcls_build_module_model build_module_model;
37         public Xcls_path_lbl path_lbl;
38         public Xcls_path path;
39         public Xcls_gen_lbl gen_lbl;
40         public Xcls_gen gen;
41         public Xcls_save_btn save_btn;
42
43                 // my vars (def)
44         public bool is_new;
45         public bool new_window;
46         public signal void success (Project.Project pr, JsRender.JsRender file);
47         public JsRender.JsRender file;
48         public Project.Project project;
49         public uint border_width;
50         public bool done;
51         public Xcls_MainWindow mainwindow;
52
53         // ctor
54         public Xcls_PopoverFileDetails()
55         {
56                 _this = this;
57                 this.el = new Gtk.Window();
58
59                 // my vars (dec)
60                 this.is_new = true;
61                 this.new_window = true;
62                 this.file = null;
63                 this.border_width = 0;
64                 this.done = false;
65                 this.mainwindow = null;
66
67                 // set gobject values
68                 this.el.title = "Add / Edit File";
69                 this.el.modal = true;
70                 var child_1 = new Xcls_Box1( _this );
71                 child_1.ref();
72                 this.el.set_child ( child_1.el  );
73                 var child_2 = new Xcls_HeaderBar28( _this );
74                 child_2.ref();
75                 this.el.titlebar = child_2.el;
76
77                 //listeners
78                 this.el.close_request.connect( ( ) => {
79                         _this.el.hide();
80                         return true;
81                 });
82         }
83
84         // user defined functions
85         public void onDirChanged () {
86         if (this.dir_dropdown.el.selected == Gtk.INVALID_LIST_POSITION) {
87                         this.build_module_lbl.el.hide();
88                         this.build_module.el.hide();
89                         this.name_lbl.el.hide();
90                         this.name.el.hide();
91                          
92                 this.gen_lbl.el.hide();
93                         this.gen.el.hide();
94             
95                         return;
96                         
97                 
98                 }
99                 // directory selected
100                 var sel = this.filetype.getValue();
101                 
102                 if (this.file.project.xtype=="Gtk" && (sel == "bjs" || sel == "vala")) {
103                         this.build_module_lbl.el.show();
104                         this.build_module.el.show();
105                 }
106                 this.name_lbl.el.show();
107                 this.name.el.show();
108                 
109                 if (sel == "bjs") {
110                 _this.gen_lbl.el.show();
111                 _this.gen.el.show();
112             }
113             
114             if (this.file.project.xtype == "Roo" && sel == "bjs") {
115                 this.title_lbl.el.show();
116                         this.title.el.show();
117                         
118                         this.region_lbl.el.show();
119                         this.region.el.show();
120                         
121                         this.parent_lbl.el.show();
122                         this.parent.el.show();
123                         
124                         this.permname_lbl.el.show();
125                         this.permname.el.show();
126                         
127                         this.modOrder_lbl.el.show();
128                         this.modOrder.el.show();
129                 }
130             
131                 
132         }
133         public void showEditFile () {
134                 this.save_btn.el.set_label("Save");
135                 this.filetype_lbl.el.hide();
136                 this.filetype.el.hide();
137                          
138                 var sel = this.filetype.getValue();
139                 switch(_this.project.xtype) {
140                         case "Roo":      
141                                  if (sel == "bjs") {
142                                         _this.title_lbl.el.show();
143                                         _this.title.el.show();
144                                         
145                                         _this.region_lbl.el.show();
146                                         _this.region.el.show();
147                                         
148                                         _this.parent_lbl.el.show();
149                                         _this.parent.el.show();
150                                         
151                                         _this.permname_lbl.el.show();
152                                         _this.permname.el.show();
153                                         
154                                         _this.modOrder_lbl.el.show();
155                                         _this.modOrder.el.show();
156                                 
157                                 }
158                                 break;
159                         default:
160                                 _this.build_module_lbl.el.show();
161                                 _this.build_module.el.show();   
162                                 
163                                 if (sel == "bjs") {
164                                 
165                                          _this.gen_lbl.el.show();
166                                         _this.gen.el.show();
167                                 }
168                                 break;
169                 }
170                 this.path.el.show();
171                 this.path_lbl.el.show();
172                 this.path.el.set_text(_this.file.relpath);
173         }
174         public void show (JsRender.JsRender  c, Gtk.Window pwin, bool new_window) 
175         {
176             
177             this.project = c.project;
178             this.done = false;
179             this.new_window = new_window;
180             
181             //if (!this.el) {
182                 //this.init();
183              //} 
184              
185               this.is_new = c.name == "";
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            _this.gen.el.active = c.gen_extended;
195            
196         
197             
198             if (this.project.xtype == "Gtk") {
199                 var p = (Project.Gtk) this.project;
200                     this.build_module_model.load(p.compilegroups);
201                     // it will select first if available...
202                     // only for new files.
203                     if (!this.is_new) {
204                             this.build_module.setValue(c.build_module);
205                     }
206             }
207                      
208              
209             _this.file = c;
210            
211            // this.el.set_size_request( 550, 100); // should expand height, but give  a min width.
212         
213             this.el.set_transient_for(pwin);
214             
215             // window + header?
216              this.hideAll();
217             this.el.show();
218            // this.name.el.grab_focus();
219             
220             
221             if (!this.is_new) {
222                    this.showEditFile();
223             } else {
224                 this.showNewFile();
225                          
226               
227                     
228             }
229             
230             
231             //this.success = c.success;
232             
233             
234         }
235         public void updateFileFromEntry () {
236         
237                 _this.file.title = _this.title.el.get_text();
238                 _this.file.region = _this.region.el.get_text();            
239                 _this.file.parent = _this.parent.el.get_text();                        
240                 _this.file.permname = _this.permname.el.get_text();                                    
241                 _this.file.modOrder = _this.modOrder.el.get_text();
242                 _this.file.gen_extended = _this.gen.el.active;
243                 var new_name =  _this.name.el.get_text();
244                 if (_this.file.name.length  > 0 && _this.file.name != new_name) {
245                     try {
246                         _this.file.renameTo( new_name );
247                         } catch (JsRender.Error e) { } // do nothing?
248                 }
249                 
250                 _this.file.build_module = _this.build_module.getValue();
251                         
252                 
253                 
254         
255                                                             
256         }
257         public void onFileTypeChange () {
258                 if (this.filetype.el.selected == Gtk.INVALID_LIST_POSITION) {
259                         this.dir_dropdown.el.hide();
260                         this.dir_dropdown_lbl.el.hide();
261                         this.build_module_lbl.el.hide();
262                         this.build_module.el.hide();
263                         this.name_lbl.el.hide();
264                         this.name.el.hide();
265                  
266                 this.gen_lbl.el.hide();
267                         this.gen.el.hide();
268             
269             
270                 this.title_lbl.el.hide();
271                         this.title.el.hide();
272                         
273                         this.region_lbl.el.hide();
274                         this.region.el.hide();
275                         
276                         this.parent_lbl.el.hide();
277                         this.parent.el.hide();
278                         
279                         this.permname_lbl.el.hide();
280                         this.permname.el.hide();
281                         
282                         this.modOrder_lbl.el.hide();
283                         this.modOrder.el.hide();
284          
285                         return;
286                          
287                 }
288                 
289                 this.dir_dropdown.el.show();
290                 this.dir_dropdown_lbl.el.show();
291                 var sel = this.filetype.getValue();
292                 
293                 var old_sel = _this.dir_dropdown.el.selected != Gtk.INVALID_LIST_POSITION;
294                 var olddir = this.dir_dropdown.getValue();
295                 GLib.debug("old dir = %s", olddir);
296                 if (this.file.project.xtype=="Gtk" && (sel == "bjs" || sel == "vala")) {
297                         _this.project.loadDirsToStringList(_this.dir_model.el, "/src");
298                         if (old_sel && olddir.has_prefix("/src")) {
299                                 this.dir_dropdown.setValue(olddir);
300                         } else {
301                              _this.dir_dropdown.el.selected = Gtk.INVALID_LIST_POSITION;
302                     }
303                  
304                 } else {
305         
306                 _this.project.loadDirsToStringList(_this.dir_model.el, "");
307                         if (old_sel) {
308                                 this.dir_dropdown.setValue(olddir);
309                         } else {
310                              _this.dir_dropdown.el.selected = Gtk.INVALID_LIST_POSITION;
311                      }
312                
313             }
314         
315          
316             // is this confusing?  - should we just strip out / add if necessary..
317             if (sel == "bjs" || sel == "vala" || sel == "js" || sel == "css" || sel == "php") {
318                 _this.name_lbl.el.label = "Component Name (Filename with-out extension)";                                
319             } else {
320                     _this.name_lbl.el.label = "File Name (with extension)";
321             }
322          
323         }
324         public void showNewFile () {
325                 this.save_btn.el.set_label("Create");
326                 this.hideAll();
327                 this.filetype.el.show();
328             this.filetype_lbl.el.show();
329             this.filetype_model.load();
330                 this.filetype.el.selected = Gtk.INVALID_LIST_POSITION;
331          
332                     
333         }
334         public void hideAll () {
335         
336                 // exiting only
337                 this.path_lbl.el.hide();
338             this.path.el.hide();
339              
340             // new 
341             this.name_lbl.el.hide();
342             this.name.el.hide();
343             //new 
344             this.dir_dropdown_lbl.el.hide();
345             this.dir_dropdown.el.hide();
346                 // roo
347                 this.title_lbl.el.hide();
348                 this.title.el.hide();
349                 
350                 this.region_lbl.el.hide();
351                 this.region.el.hide();
352                 
353                 this.parent_lbl.el.hide();
354                 this.parent.el.hide();
355                 
356                 this.permname_lbl.el.hide();
357                 this.permname.el.hide();
358                 
359                 this.modOrder_lbl.el.hide();
360                 this.modOrder.el.hide();
361                 
362                 this.build_module_lbl.el.hide();
363                 this.build_module.el.hide();
364                 
365                 this.gen_lbl.el.hide();
366                 this.gen.el.hide();
367                         this.filetype_lbl.el.hide();
368                         this.filetype.el.hide();
369         }
370         public class Xcls_Box1 : Object
371         {
372                 public Gtk.Box el;
373                 private Xcls_PopoverFileDetails  _this;
374
375
376                         // my vars (def)
377
378                 // ctor
379                 public Xcls_Box1(Xcls_PopoverFileDetails _owner )
380                 {
381                         _this = _owner;
382                         this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
383
384                         // my vars (dec)
385
386                         // set gobject values
387                         this.el.homogeneous = false;
388                         this.el.margin_end = 4;
389                         this.el.margin_start = 4;
390                         this.el.hexpand = true;
391                         this.el.margin_bottom = 4;
392                         this.el.margin_top = 4;
393                         new Xcls_grid( _this );
394                         this.el.append ( _this.grid.el  );
395                 }
396
397                 // user defined functions
398         }
399         public class Xcls_grid : Object
400         {
401                 public Gtk.Grid el;
402                 private Xcls_PopoverFileDetails  _this;
403
404
405                         // my vars (def)
406
407                 // ctor
408                 public Xcls_grid(Xcls_PopoverFileDetails _owner )
409                 {
410                         _this = _owner;
411                         _this.grid = this;
412                         this.el = new Gtk.Grid();
413
414                         // my vars (dec)
415
416                         // set gobject values
417                         this.el.margin_end = 4;
418                         this.el.margin_start = 4;
419                         this.el.hexpand = true;
420                         this.el.column_spacing = 4;
421                         this.el.row_spacing = 2;
422                         new Xcls_filetype_lbl( _this );
423                         this.el.attach( _this.filetype_lbl.el, 0, 0, 1, 1 );
424                         new Xcls_filetype( _this );
425                         this.el.attach( _this.filetype.el, 1, 0, 1, 1 );
426                         new Xcls_dir_dropdown_lbl( _this );
427                         this.el.attach( _this.dir_dropdown_lbl.el, 0, 1, 1, 1 );
428                         new Xcls_dir_dropdown( _this );
429                         this.el.attach( _this.dir_dropdown.el, 1, 1, 1, 1 );
430                         new Xcls_name_lbl( _this );
431                         this.el.attach( _this.name_lbl.el, 0, 2, 1, 1 );
432                         new Xcls_name( _this );
433                         this.el.attach( _this.name.el, 1, 2, 1, 1 );
434                         new Xcls_title_lbl( _this );
435                         this.el.attach( _this.title_lbl.el, 0, 3, 1, 1 );
436                         new Xcls_title( _this );
437                         this.el.attach( _this.title.el, 1, 3, 1, 1 );
438                         new Xcls_region_lbl( _this );
439                         this.el.attach( _this.region_lbl.el, 0, 4, 1, 1 );
440                         new Xcls_region( _this );
441                         this.el.attach( _this.region.el, 1, 4, 1, 1 );
442                         new Xcls_parent_lbl( _this );
443                         this.el.attach( _this.parent_lbl.el, 0, 5, 1, 1 );
444                         new Xcls_parent( _this );
445                         this.el.attach( _this.parent.el, 1, 5, 1, 1 );
446                         new Xcls_permname_lbl( _this );
447                         this.el.attach( _this.permname_lbl.el, 0, 6, 1, 1 );
448                         new Xcls_permname( _this );
449                         this.el.attach( _this.permname.el, 1, 6, 1, 1 );
450                         new Xcls_modOrder_lbl( _this );
451                         this.el.attach( _this.modOrder_lbl.el, 0, 7, 1, 1 );
452                         new Xcls_modOrder( _this );
453                         this.el.attach( _this.modOrder.el, 1, 7, 1, 1 );
454                         new Xcls_build_module_lbl( _this );
455                         this.el.attach( _this.build_module_lbl.el, 0, 8, 1, 1 );
456                         new Xcls_build_module( _this );
457                         this.el.attach( _this.build_module.el, 1, 8, 1, 1 );
458                         new Xcls_path_lbl( _this );
459                         this.el.attach( _this.path_lbl.el, 0, 9, 1, 1 );
460                         new Xcls_path( _this );
461                         this.el.attach( _this.path.el, 1, 9, 1, 1 );
462                         new Xcls_gen_lbl( _this );
463                         this.el.attach( _this.gen_lbl.el, 0, 10, 1, 1 );
464                         new Xcls_gen( _this );
465                         this.el.attach( _this.gen.el, 1, 10, 1, 1 );
466                 }
467
468                 // user defined functions
469                 public void xhideRow (int row) 
470                 {
471                         var el = _this.grid.el.get_child_at(0,row);
472                 
473                         el.hide();
474                         el = _this.grid.el.get_child_at(1,row);
475                         el.hide();
476                 
477                 }
478                 public void xshowAllRows () {
479                         for (var i = 2; i < 10;i++) {
480                                 var el = _this.grid.el.get_child_at(0,i);
481                                 el.show();
482                                 el = _this.grid.el.get_child_at(1,i);
483                                 el.show();
484                     }
485                 }
486         }
487         public class Xcls_filetype_lbl : Object
488         {
489                 public Gtk.Label el;
490                 private Xcls_PopoverFileDetails  _this;
491
492
493                         // my vars (def)
494
495                 // ctor
496                 public Xcls_filetype_lbl(Xcls_PopoverFileDetails _owner )
497                 {
498                         _this = _owner;
499                         _this.filetype_lbl = this;
500                         this.el = new Gtk.Label( "File type" );
501
502                         // my vars (dec)
503
504                         // set gobject values
505                         this.el.justify = Gtk.Justification.RIGHT;
506                         this.el.xalign = 0.900000f;
507                 }
508
509                 // user defined functions
510         }
511
512         public class Xcls_filetype : Object
513         {
514                 public Gtk.DropDown el;
515                 private Xcls_PopoverFileDetails  _this;
516
517
518                         // my vars (def)
519                 public bool in_showhide;
520
521                 // ctor
522                 public Xcls_filetype(Xcls_PopoverFileDetails _owner )
523                 {
524                         _this = _owner;
525                         _this.filetype = this;
526                         new Xcls_filetype_model( _this );
527                         this.el = new Gtk.DropDown( _this.filetype_model.el, null );
528
529                         // my vars (dec)
530                         this.in_showhide = false;
531
532                         // set gobject values
533                         this.el.hexpand = true;
534
535                         //listeners
536                         this.el.notify["selected"].connect( () => {
537                         
538                                 _this.onFileTypeChange();
539                         
540                          });
541                 }
542
543                 // user defined functions
544                 public string getValue () {
545                         
546                         if (!_this.is_new) {
547                                 return _this.file.xtype != "Plainfile" ? "bjs" :  _this.file.file_ext;
548                         }
549                         
550                         if (this.el.selected == Gtk.INVALID_LIST_POSITION) {
551                                 return "";
552                         }
553                         
554                         return _this.filetype_model.el.get_string(this.el.selected).split(" ")[0];
555                 }
556                 public void setValue (string cur) {
557                         var el  = _this.filetype_model.el;
558                         for(var i= 0; i < el.get_n_items();i++)  {
559                                 if (el.get_string(i).has_prefix(cur)) {
560                                         this.el.selected = i;
561                                         break;
562                                 }
563                         }
564                 }
565         }
566         public class Xcls_filetype_model : Object
567         {
568                 public Gtk.StringList el;
569                 private Xcls_PopoverFileDetails  _this;
570
571
572                         // my vars (def)
573
574                 // ctor
575                 public Xcls_filetype_model(Xcls_PopoverFileDetails _owner )
576                 {
577                         _this = _owner;
578                         _this.filetype_model = this;
579                         this.el = new Gtk.StringList( {} );
580
581                         // my vars (dec)
582
583                         // set gobject values
584                 }
585
586                 // user defined functions
587                 public void load () {
588                     var el = this.el;
589                     
590                     while (el.get_n_items() > 0) {
591                         el.remove(0);
592                         }
593                         el.append("bjs - User Interface File");
594                  
595                     
596                  switch(_this.project.xtype) {
597                         case "Roo":
598                                 el.append("js - Javascript File");
599                                 el.append("css - CSS File");
600                                 el.append("php - Javascript File");
601                                 
602                                 break;
603                 
604                         case "Gtk":             
605                                         
606                                 el.append("vala - Vala File");
607                                 el.append("css - CSS File");
608                                 el.append("other - Other Type");
609                                 break;
610                          default : 
611                                 break;
612                         }
613                 
614                         
615                         
616                         
617                 }
618         }
619
620
621         public class Xcls_dir_dropdown_lbl : Object
622         {
623                 public Gtk.Label el;
624                 private Xcls_PopoverFileDetails  _this;
625
626
627                         // my vars (def)
628
629                 // ctor
630                 public Xcls_dir_dropdown_lbl(Xcls_PopoverFileDetails _owner )
631                 {
632                         _this = _owner;
633                         _this.dir_dropdown_lbl = this;
634                         this.el = new Gtk.Label( "Create File in this Directory" );
635
636                         // my vars (dec)
637
638                         // set gobject values
639                         this.el.justify = Gtk.Justification.RIGHT;
640                         this.el.xalign = 0.900000f;
641                         this.el.visible = true;
642                 }
643
644                 // user defined functions
645         }
646
647         public class Xcls_dir_dropdown : Object
648         {
649                 public Gtk.DropDown el;
650                 private Xcls_PopoverFileDetails  _this;
651
652
653                         // my vars (def)
654                 public int colspan;
655
656                 // ctor
657                 public Xcls_dir_dropdown(Xcls_PopoverFileDetails _owner )
658                 {
659                         _this = _owner;
660                         _this.dir_dropdown = this;
661                         new Xcls_dir_model( _this );
662                         this.el = new Gtk.DropDown( _this.dir_model.el, null );
663
664                         // my vars (dec)
665                         this.colspan = 1;
666
667                         // set gobject values
668
669                         //listeners
670                         this.el.notify["selected"].connect( () => {
671                         
672                                  _this.onDirChanged();
673                                 
674                                 
675                                 
676                          });
677                 }
678
679                 // user defined functions
680                 public string getValue () {
681                         return _this.dir_model.el.get_string(this.el.selected);
682                 }
683                 public void setValue (string cur) {
684                         var el  = _this.dir_model.el;
685                         for(var i= 0; i < el.get_n_items();i++)  {
686                                 if (el.get_string(i) == cur) {
687                                         this.el.selected = i;
688                                         break;
689                                 }
690                         }
691                 }
692         }
693         public class Xcls_dir_model : Object
694         {
695                 public Gtk.StringList el;
696                 private Xcls_PopoverFileDetails  _this;
697
698
699                         // my vars (def)
700
701                 // ctor
702                 public Xcls_dir_model(Xcls_PopoverFileDetails _owner )
703                 {
704                         _this = _owner;
705                         _this.dir_model = this;
706                         this.el = new Gtk.StringList( {} );
707
708                         // my vars (dec)
709
710                         // set gobject values
711                 }
712
713                 // user defined functions
714         }
715
716
717         public class Xcls_name_lbl : Object
718         {
719                 public Gtk.Label el;
720                 private Xcls_PopoverFileDetails  _this;
721
722
723                         // my vars (def)
724
725                 // ctor
726                 public Xcls_name_lbl(Xcls_PopoverFileDetails _owner )
727                 {
728                         _this = _owner;
729                         _this.name_lbl = this;
730                         this.el = new Gtk.Label( "Component Name (File name without extension)" );
731
732                         // my vars (dec)
733
734                         // set gobject values
735                         this.el.justify = Gtk.Justification.RIGHT;
736                         this.el.xalign = 0.900000f;
737                 }
738
739                 // user defined functions
740         }
741
742         public class Xcls_name : Object
743         {
744                 public Gtk.Entry el;
745                 private Xcls_PopoverFileDetails  _this;
746
747
748                         // my vars (def)
749
750                 // ctor
751                 public Xcls_name(Xcls_PopoverFileDetails _owner )
752                 {
753                         _this = _owner;
754                         _this.name = this;
755                         this.el = new Gtk.Entry();
756
757                         // my vars (dec)
758
759                         // set gobject values
760                         this.el.hexpand = true;
761                         this.el.visible = true;
762                 }
763
764                 // user defined functions
765         }
766
767         public class Xcls_title_lbl : Object
768         {
769                 public Gtk.Label el;
770                 private Xcls_PopoverFileDetails  _this;
771
772
773                         // my vars (def)
774
775                 // ctor
776                 public Xcls_title_lbl(Xcls_PopoverFileDetails _owner )
777                 {
778                         _this = _owner;
779                         _this.title_lbl = this;
780                         this.el = new Gtk.Label( "Title" );
781
782                         // my vars (dec)
783
784                         // set gobject values
785                         this.el.justify = Gtk.Justification.RIGHT;
786                         this.el.xalign = 0.900000f;
787                         this.el.visible = true;
788                 }
789
790                 // user defined functions
791         }
792
793         public class Xcls_title : Object
794         {
795                 public Gtk.Entry el;
796                 private Xcls_PopoverFileDetails  _this;
797
798
799                         // my vars (def)
800
801                 // ctor
802                 public Xcls_title(Xcls_PopoverFileDetails _owner )
803                 {
804                         _this = _owner;
805                         _this.title = this;
806                         this.el = new Gtk.Entry();
807
808                         // my vars (dec)
809
810                         // set gobject values
811                         this.el.hexpand = true;
812                         this.el.visible = true;
813                 }
814
815                 // user defined functions
816         }
817
818         public class Xcls_region_lbl : Object
819         {
820                 public Gtk.Label el;
821                 private Xcls_PopoverFileDetails  _this;
822
823
824                         // my vars (def)
825
826                 // ctor
827                 public Xcls_region_lbl(Xcls_PopoverFileDetails _owner )
828                 {
829                         _this = _owner;
830                         _this.region_lbl = this;
831                         this.el = new Gtk.Label( "Region" );
832
833                         // my vars (dec)
834
835                         // set gobject values
836                         this.el.justify = Gtk.Justification.RIGHT;
837                         this.el.xalign = 0.900000f;
838                         this.el.tooltip_text = "center, north, south, east, west";
839                         this.el.visible = true;
840                 }
841
842                 // user defined functions
843         }
844
845         public class Xcls_region : Object
846         {
847                 public Gtk.Entry el;
848                 private Xcls_PopoverFileDetails  _this;
849
850
851                         // my vars (def)
852
853                 // ctor
854                 public Xcls_region(Xcls_PopoverFileDetails _owner )
855                 {
856                         _this = _owner;
857                         _this.region = this;
858                         this.el = new Gtk.Entry();
859
860                         // my vars (dec)
861
862                         // set gobject values
863                         this.el.hexpand = true;
864                         this.el.visible = true;
865                 }
866
867                 // user defined functions
868         }
869
870         public class Xcls_parent_lbl : Object
871         {
872                 public Gtk.Label el;
873                 private Xcls_PopoverFileDetails  _this;
874
875
876                         // my vars (def)
877
878                 // ctor
879                 public Xcls_parent_lbl(Xcls_PopoverFileDetails _owner )
880                 {
881                         _this = _owner;
882                         _this.parent_lbl = this;
883                         this.el = new Gtk.Label( "Parent Name" );
884
885                         // my vars (dec)
886
887                         // set gobject values
888                         this.el.justify = Gtk.Justification.RIGHT;
889                         this.el.xalign = 0.900000f;
890                         this.el.visible = true;
891                 }
892
893                 // user defined functions
894         }
895
896         public class Xcls_parent : Object
897         {
898                 public Gtk.Entry el;
899                 private Xcls_PopoverFileDetails  _this;
900
901
902                         // my vars (def)
903
904                 // ctor
905                 public Xcls_parent(Xcls_PopoverFileDetails _owner )
906                 {
907                         _this = _owner;
908                         _this.parent = this;
909                         this.el = new Gtk.Entry();
910
911                         // my vars (dec)
912
913                         // set gobject values
914                         this.el.visible = true;
915                 }
916
917                 // user defined functions
918         }
919
920         public class Xcls_permname_lbl : Object
921         {
922                 public Gtk.Label el;
923                 private Xcls_PopoverFileDetails  _this;
924
925
926                         // my vars (def)
927
928                 // ctor
929                 public Xcls_permname_lbl(Xcls_PopoverFileDetails _owner )
930                 {
931                         _this = _owner;
932                         _this.permname_lbl = this;
933                         this.el = new Gtk.Label( "Permission Name" );
934
935                         // my vars (dec)
936
937                         // set gobject values
938                         this.el.justify = Gtk.Justification.RIGHT;
939                         this.el.xalign = 0.900000f;
940                         this.el.visible = true;
941                 }
942
943                 // user defined functions
944         }
945
946         public class Xcls_permname : Object
947         {
948                 public Gtk.Entry el;
949                 private Xcls_PopoverFileDetails  _this;
950
951
952                         // my vars (def)
953
954                 // ctor
955                 public Xcls_permname(Xcls_PopoverFileDetails _owner )
956                 {
957                         _this = _owner;
958                         _this.permname = this;
959                         this.el = new Gtk.Entry();
960
961                         // my vars (dec)
962
963                         // set gobject values
964                         this.el.visible = true;
965                 }
966
967                 // user defined functions
968         }
969
970         public class Xcls_modOrder_lbl : Object
971         {
972                 public Gtk.Label el;
973                 private Xcls_PopoverFileDetails  _this;
974
975
976                         // my vars (def)
977
978                 // ctor
979                 public Xcls_modOrder_lbl(Xcls_PopoverFileDetails _owner )
980                 {
981                         _this = _owner;
982                         _this.modOrder_lbl = this;
983                         this.el = new Gtk.Label( "Order (for tabs)" );
984
985                         // my vars (dec)
986
987                         // set gobject values
988                         this.el.justify = Gtk.Justification.RIGHT;
989                         this.el.xalign = 0.900000f;
990                         this.el.visible = true;
991                 }
992
993                 // user defined functions
994         }
995
996         public class Xcls_modOrder : Object
997         {
998                 public Gtk.Entry el;
999                 private Xcls_PopoverFileDetails  _this;
1000
1001
1002                         // my vars (def)
1003
1004                 // ctor
1005                 public Xcls_modOrder(Xcls_PopoverFileDetails _owner )
1006                 {
1007                         _this = _owner;
1008                         _this.modOrder = this;
1009                         this.el = new Gtk.Entry();
1010
1011                         // my vars (dec)
1012
1013                         // set gobject values
1014                         this.el.visible = true;
1015                 }
1016
1017                 // user defined functions
1018         }
1019
1020         public class Xcls_build_module_lbl : Object
1021         {
1022                 public Gtk.Label el;
1023                 private Xcls_PopoverFileDetails  _this;
1024
1025
1026                         // my vars (def)
1027
1028                 // ctor
1029                 public Xcls_build_module_lbl(Xcls_PopoverFileDetails _owner )
1030                 {
1031                         _this = _owner;
1032                         _this.build_module_lbl = this;
1033                         this.el = new Gtk.Label( "Module to build" );
1034
1035                         // my vars (dec)
1036
1037                         // set gobject values
1038                         this.el.justify = Gtk.Justification.RIGHT;
1039                         this.el.xalign = 0.900000f;
1040                         this.el.visible = true;
1041                 }
1042
1043                 // user defined functions
1044         }
1045
1046         public class Xcls_build_module : Object
1047         {
1048                 public Gtk.DropDown el;
1049                 private Xcls_PopoverFileDetails  _this;
1050
1051
1052                         // my vars (def)
1053
1054                 // ctor
1055                 public Xcls_build_module(Xcls_PopoverFileDetails _owner )
1056                 {
1057                         _this = _owner;
1058                         _this.build_module = this;
1059                         new Xcls_build_module_model( _this );
1060                         this.el = new Gtk.DropDown( _this.build_module_model.el, null );
1061
1062                         // my vars (dec)
1063
1064                         // set gobject values
1065                 }
1066
1067                 // user defined functions
1068                 public string getValue () {
1069                         if (this.el.selected < 0) {
1070                                 return "";
1071                         }
1072                         
1073                         return _this.build_module_model.el.get_string(this.el.selected);
1074                 }
1075                 public void setValue (string str) {
1076                         var m = _this.build_module_model.el;
1077                         for(var i = 0; i < m.get_n_items(); i++) {
1078                                 if (m.get_string(i) == str) {
1079                                         this.el.selected = i;
1080                                         return;
1081                                 }
1082                         }
1083                                 
1084                 }
1085         }
1086         public class Xcls_build_module_model : Object
1087         {
1088                 public Gtk.StringList el;
1089                 private Xcls_PopoverFileDetails  _this;
1090
1091
1092                         // my vars (def)
1093
1094                 // ctor
1095                 public Xcls_build_module_model(Xcls_PopoverFileDetails _owner )
1096                 {
1097                         _this = _owner;
1098                         _this.build_module_model = this;
1099                         this.el = new Gtk.StringList( {} );
1100
1101                         // my vars (dec)
1102
1103                         // set gobject values
1104                 }
1105
1106                 // user defined functions
1107                 public void load (Gee.HashMap<string,Project.GtkValaSettings>? compilegroups)
1108                 {
1109                         
1110                         _this.build_module.el.hide();
1111                                 _this.build_module_lbl.el.hide();
1112                         var el = _this.build_module_model.el;
1113                          while (el.get_n_items() > 0) {
1114                                         el.remove(0);
1115                         }
1116                         
1117                         if (compilegroups == null) {
1118                                 return;
1119                         }
1120                         foreach(var k in compilegroups.keys) {
1121                                 this.el.append(k);
1122                         }
1123                         if (compilegroups.keys.size > 0) {
1124                                 _this.build_module.el.selected = 0;
1125                                 _this.build_module.el.show();
1126                                 _this.build_module_lbl.el.show();
1127                         } else {
1128                                 
1129                         }
1130                         
1131                 }
1132         }
1133
1134
1135         public class Xcls_path_lbl : Object
1136         {
1137                 public Gtk.Label el;
1138                 private Xcls_PopoverFileDetails  _this;
1139
1140
1141                         // my vars (def)
1142                 public int colspan;
1143
1144                 // ctor
1145                 public Xcls_path_lbl(Xcls_PopoverFileDetails _owner )
1146                 {
1147                         _this = _owner;
1148                         _this.path_lbl = this;
1149                         this.el = new Gtk.Label( "Full path" );
1150
1151                         // my vars (dec)
1152                         this.colspan = 1;
1153
1154                         // set gobject values
1155                         this.el.justify = Gtk.Justification.RIGHT;
1156                         this.el.xalign = 0.900000f;
1157                         this.el.visible = true;
1158                 }
1159
1160                 // user defined functions
1161         }
1162
1163         public class Xcls_path : Object
1164         {
1165                 public Gtk.Entry el;
1166                 private Xcls_PopoverFileDetails  _this;
1167
1168
1169                         // my vars (def)
1170                 public int colspan;
1171
1172                 // ctor
1173                 public Xcls_path(Xcls_PopoverFileDetails _owner )
1174                 {
1175                         _this = _owner;
1176                         _this.path = this;
1177                         this.el = new Gtk.Entry();
1178
1179                         // my vars (dec)
1180                         this.colspan = 1;
1181
1182                         // set gobject values
1183                         this.el.editable = false;
1184                         this.el.hexpand = true;
1185                         this.el.visible = true;
1186                 }
1187
1188                 // user defined functions
1189         }
1190
1191         public class Xcls_gen_lbl : Object
1192         {
1193                 public Gtk.Label el;
1194                 private Xcls_PopoverFileDetails  _this;
1195
1196
1197                         // my vars (def)
1198                 public int colspan;
1199
1200                 // ctor
1201                 public Xcls_gen_lbl(Xcls_PopoverFileDetails _owner )
1202                 {
1203                         _this = _owner;
1204                         _this.gen_lbl = this;
1205                         this.el = new Gtk.Label( "Generate as Extended (no working)" );
1206
1207                         // my vars (dec)
1208                         this.colspan = 1;
1209
1210                         // set gobject values
1211                         this.el.justify = Gtk.Justification.RIGHT;
1212                         this.el.xalign = 0.900000f;
1213                         this.el.visible = true;
1214                 }
1215
1216                 // user defined functions
1217         }
1218
1219         public class Xcls_gen : Object
1220         {
1221                 public Gtk.CheckButton el;
1222                 private Xcls_PopoverFileDetails  _this;
1223
1224
1225                         // my vars (def)
1226
1227                 // ctor
1228                 public Xcls_gen(Xcls_PopoverFileDetails _owner )
1229                 {
1230                         _this = _owner;
1231                         _this.gen = this;
1232                         this.el = new Gtk.CheckButton();
1233
1234                         // my vars (dec)
1235
1236                         // set gobject values
1237                         this.el.label = "Wrapped";
1238
1239                         //listeners
1240                         this.el.toggled.connect( ( ) => {
1241                                   
1242                                 this.el.label = this.el.active ? "Extended" : "Wrapped";
1243                         
1244                         });
1245                 }
1246
1247                 // user defined functions
1248         }
1249
1250
1251
1252         public class Xcls_HeaderBar28 : Object
1253         {
1254                 public Gtk.HeaderBar el;
1255                 private Xcls_PopoverFileDetails  _this;
1256
1257
1258                         // my vars (def)
1259
1260                 // ctor
1261                 public Xcls_HeaderBar28(Xcls_PopoverFileDetails _owner )
1262                 {
1263                         _this = _owner;
1264                         this.el = new Gtk.HeaderBar();
1265
1266                         // my vars (dec)
1267
1268                         // set gobject values
1269                         this.el.show_title_buttons = false;
1270                         var child_1 = new Xcls_Button29( _this );
1271                         child_1.ref();
1272                         this.el.pack_start ( child_1.el  );
1273                         new Xcls_save_btn( _this );
1274                         this.el.pack_end ( _this.save_btn.el  );
1275                 }
1276
1277                 // user defined functions
1278         }
1279         public class Xcls_Button29 : Object
1280         {
1281                 public Gtk.Button el;
1282                 private Xcls_PopoverFileDetails  _this;
1283
1284
1285                         // my vars (def)
1286
1287                 // ctor
1288                 public Xcls_Button29(Xcls_PopoverFileDetails _owner )
1289                 {
1290                         _this = _owner;
1291                         this.el = new Gtk.Button();
1292
1293                         // my vars (dec)
1294
1295                         // set gobject values
1296                         this.el.label = "Cancel";
1297
1298                         //listeners
1299                         this.el.clicked.connect( () => { 
1300                                 _this.done = true;
1301                             _this.el.hide(); 
1302                         });
1303                 }
1304
1305                 // user defined functions
1306         }
1307
1308         public class Xcls_save_btn : Object
1309         {
1310                 public Gtk.Button el;
1311                 private Xcls_PopoverFileDetails  _this;
1312
1313
1314                         // my vars (def)
1315                 public bool always_show_image;
1316
1317                 // ctor
1318                 public Xcls_save_btn(Xcls_PopoverFileDetails _owner )
1319                 {
1320                         _this = _owner;
1321                         _this.save_btn = this;
1322                         this.el = new Gtk.Button();
1323
1324                         // my vars (dec)
1325                         this.always_show_image = true;
1326
1327                         // set gobject values
1328                         this.el.icon_name = "document-save";
1329                         this.el.hexpand = false;
1330                         this.el.css_classes = { "suggested-action" };
1331                         this.el.label = "Save";
1332
1333                         //listeners
1334                         this.el.clicked.connect( ( ) =>  { 
1335                         
1336                          
1337                         
1338                         
1339                                 if (_this.name.el.get_text().length  < 1) {
1340                                    var msg = new Adw.MessageDialog(
1341                                         _this.mainwindow.el,
1342                                         "Opps",
1343                                         "You have to set a Component name "
1344                                     );
1345                                     msg.modal = true;
1346                                     msg.present();
1347                                      
1348                                     return;
1349                                 }
1350                                  
1351                         
1352                                 if (!_this.is_new) {
1353                                   //  try {
1354                                   
1355                                         var old_target = _this.file.build_module;
1356                                  _this.updateFileFromEntry();
1357                                     if (_this.project.xtype == "Gtk" && old_target != _this.file.build_module) {
1358                                         var gp = (JsRender.Gtk)_this.file;
1359                                         gp.updateCompileGroup(old_target,  _this.file.build_module);
1360                                 }
1361                         
1362                                       _this.done = true;
1363                                     _this.file.save();
1364                                     _this.el.hide();
1365                                     return;
1366                                 }  
1367                                 
1368                                 // ---------------- NEW FILES...
1369                                 var ftype = _this.filetype.getValue();
1370                         
1371                                 if (ftype == "") {
1372                                         // should not happen...
1373                                         // so we are jut going to return without 
1374                                         Xcls_StandardErrorDialog.singleton().show(
1375                                         _this.mainwindow.el,
1376                                         "You must select a file type. "
1377                                     );
1378                                     return;
1379                                          
1380                                 }
1381                                 
1382                                 
1383                                 var fn = _this.name.el.get_text();
1384                                 
1385                                  
1386                                 var ext = ftype;
1387                                 //var dir = _this.project.path; 
1388                                  
1389                                  var dir = _this.dir_dropdown.getValue();
1390                                 
1391                                  
1392                                 
1393                                  
1394                                 var targetfile  = _this.project.path;
1395                                 if (dir != "") {
1396                                         targetfile += dir;
1397                                 }
1398                                 targetfile += "/" + fn;
1399                                 
1400                                 // strip the file type off the end..
1401                                 
1402                                 try {
1403                                         var rx = new GLib.Regex("\\." + ext + "$",GLib.RegexCompileFlags.CASELESS);
1404                                         fn = rx.replace(targetfile, targetfile.length, 0, ""); 
1405                                   } catch (RegexError e) {} // ignore.
1406                                   
1407                                   targetfile += "." + ext;
1408                                   
1409                                   
1410                                 if (GLib.FileUtils.test(targetfile, GLib.FileTest.EXISTS)) {
1411                                     Xcls_StandardErrorDialog.singleton().show(
1412                                         _this.mainwindow.el,
1413                                         "That file already exists"
1414                                     ); 
1415                                     return;
1416                                 }
1417                                 JsRender.JsRender f;
1418                            try {
1419                                    f =  JsRender.JsRender.factory(
1420                                                 ext == "bjs" ? _this.file.project.xtype : "PlainFile",  
1421                                                 _this.file.project, 
1422                                                 targetfile);
1423                                 } catch (JsRender.Error e) {
1424                                         Xcls_StandardErrorDialog.singleton().show(
1425                                         _this.mainwindow.el,
1426                                         "Error creating file"
1427                                     ); 
1428                                         return;
1429                                 }
1430                                 _this.file = f;
1431                                 
1432                                 
1433                         
1434                                 
1435                                 _this.updateFileFromEntry();
1436                                 _this.file.loaded = true;
1437                                 _this.file.save();
1438                              _this.file.project.addFile(_this.file);
1439                              var sel = _this.filetype.getValue();
1440                                  if (_this.file.project.xtype == "Gtk" && 
1441                                         _this.file.build_module.length > 0 &&
1442                                         ( sel == "bjs" || sel == "vala")) {
1443                                  
1444                                         var pr = (Project.Gtk) _this.file.project;
1445                                         if (pr.compilegroups.has_key(_this.file.build_module)) {
1446                                                 var cg = pr.compilegroups.get(_this.file.build_module);
1447                                                 if (!cg.sources.contains(_this.file.relpath)) {
1448                                                         cg.sources.add(_this.file.relpath);
1449                                                 }
1450                                         }
1451                                 
1452                                 }
1453                                  
1454                          
1455                                 // what about .js ?
1456                            _this.done = true;
1457                                 _this.el.hide();
1458                         
1459                         // hopefull this will work with bjs files..
1460                                 
1461                                 _this.success(_this.project, _this.file);
1462                            
1463                         });
1464                 }
1465
1466                 // user defined functions
1467         }
1468
1469
1470 }