src/Builder4/PopoverProperty.bjs
[app.Builder.js] / src / Builder4 / PopoverProperty.vala
1 static Xcls_PopoverProperty  _PopoverProperty;
2
3 public class Xcls_PopoverProperty : Object
4 {
5     public Gtk.Popover el;
6     private Xcls_PopoverProperty  _this;
7
8     public static Xcls_PopoverProperty singleton()
9     {
10         if (_PopoverProperty == null) {
11             _PopoverProperty= new Xcls_PopoverProperty();
12         }
13         return _PopoverProperty;
14     }
15     public Xcls_build_module build_module;
16     public Xcls_dbcellrenderer dbcellrenderer;
17     public Xcls_dbmodel dbmodel;
18     public Xcls_title title;
19     public Xcls_parent parent;
20     public Xcls_save_btn save_btn;
21
22         // my vars (def)
23     public signal void success (Project.Project pr, JsRender.JsRender file);
24     public bool done;
25     public Project.Project project;
26     public JsRender.JsRender file;
27     public Xcls_MainWindow mainwindow;
28
29     // ctor
30     public Xcls_PopoverProperty()
31     {
32         _this = this;
33         this.el = new Gtk.Popover( null );
34
35         // my vars (dec)
36         this.done = false;
37         this.file = null;
38         this.mainwindow = null;
39
40         // set gobject values
41         this.el.border_width = 0;
42         this.el.modal = true;
43         this.el.position = Gtk.PositionType.RIGHT;
44         var child_0 = new Xcls_Box2( _this );
45         child_0.ref();
46         this.el.add (  child_0.el  );
47
48         //listeners
49         this.el.closed.connect( () => {
50           if (!this.done) {
51             _this.el.show();
52           
53           }
54         });
55     }
56
57     // user defined functions
58     public   void updateFileFromEntry () {
59     
60             _this.file.title = _this.title.el.get_text();
61             _this.file.region = _this.region.el.get_text();            
62             _this.file.parent = _this.parent.el.get_text();                        
63             _this.file.permname = _this.permname.el.get_text();                                    
64             _this.file.modOrder = _this.modOrder.el.get_text();
65             
66             if (_this.file.name.length  > 0 && _this.file.name != _this.name.el.get_text()) {
67                 _this.file.renameTo(_this.name.el.get_text());
68             }
69             // store the module...
70             _this.file.build_module = "";        
71              Gtk.TreeIter iter; 
72             if (_this.build_module.el.get_active_iter (out iter)) {
73                  Value vfname;
74                  this.dbmodel.el.get_value (iter, 0, out vfname);
75                  if (((string)vfname).length > 0) {
76                      _this.file.build_module = (string)vfname;
77                  }
78         
79             }
80             
81             
82     
83                                                         
84     }
85     public void show (JsRender.JsRender c, Gtk.Widget btn) 
86     {
87         this.project = c.project;
88         this.done = false;
89         
90         
91         //if (!this.el) {
92             //this.init();
93          //}
94         
95         _this.name.el.set_text(c.name);
96         _this.title.el.set_text(c.title);
97         _this.parent.el.set_text(c.parent);    
98         _this.region.el.set_text(c.region);
99         _this.modOrder.el.set_text(c.modOrder);
100          _this.permname.el.set_text(c.permname);
101         
102         if (c.path.length > 0) {
103         
104             this.save_btn.el.set_label("Save");
105         } else {
106             this.save_btn.el.set_label("Create");
107         }
108         
109          var ar = new Gee.ArrayList<string>();
110          _this.dbmodel.loadData(ar,"");
111         // load the modules... if relivant..
112         if (this.project.xtype == "Gtk") {
113             var p = (Project.Gtk)c.project;
114               var cg = p.compilegroups;
115     
116             var iter = cg.map_iterator();
117            while(iter.next()) {
118                 var key = iter.get_key();
119                 if (key == "_default_") {
120                     continue;
121                 }
122                 ar.add(key);
123             };
124             _this.dbmodel.loadData(ar, c.build_module);
125     
126         }
127         
128          
129         _this.file = c;
130         //console.log('show all');
131        this.el.set_modal(true);
132         this.el.set_relative_to(btn);
133     
134         this.el.set_position(Gtk.PositionType.RIGHT);
135         
136         // window + header?
137          print("SHOWALL - POPIP\n");
138         this.el.show_all();
139         this.name.el.grab_focus();
140         
141         //this.success = c.success;
142         
143         
144     }
145     public class Xcls_Box2 : Object
146     {
147         public Gtk.Box el;
148         private Xcls_PopoverProperty  _this;
149
150
151             // my vars (def)
152
153         // ctor
154         public Xcls_Box2(Xcls_PopoverProperty _owner )
155         {
156             _this = _owner;
157             this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
158
159             // my vars (dec)
160
161             // set gobject values
162             this.el.homogeneous = false;
163             var child_0 = new Xcls_HeaderBar3( _this );
164             child_0.ref();
165             this.el.pack_start (  child_0.el , false,true,0 );
166             var child_1 = new Xcls_Table4( _this );
167             child_1.ref();
168             this.el.pack_start (  child_1.el , false,false,4 );
169             var child_2 = new Xcls_HButtonBox13( _this );
170             child_2.ref();
171             this.el.pack_end (  child_2.el , false,true,0 );
172         }
173
174         // user defined functions
175     }
176     public class Xcls_HeaderBar3 : Object
177     {
178         public Gtk.HeaderBar el;
179         private Xcls_PopoverProperty  _this;
180
181
182             // my vars (def)
183
184         // ctor
185         public Xcls_HeaderBar3(Xcls_PopoverProperty _owner )
186         {
187             _this = _owner;
188             this.el = new Gtk.HeaderBar();
189
190             // my vars (dec)
191
192             // set gobject values
193             this.el.title = "Modify / Create Property";
194         }
195
196         // user defined functions
197     }
198
199     public class Xcls_Table4 : Object
200     {
201         public Gtk.Table el;
202         private Xcls_PopoverProperty  _this;
203
204
205             // my vars (def)
206
207         // ctor
208         public Xcls_Table4(Xcls_PopoverProperty _owner )
209         {
210             _this = _owner;
211             this.el = new Gtk.Table( 3, 2, true );
212
213             // my vars (dec)
214
215             // set gobject values
216             this.el.margin_right = 4;
217             this.el.margin_left = 4;
218             this.el.row_spacing = 2;
219             var child_0 = new Xcls_Label5( _this );
220             child_0.ref();
221             this.el.attach_defaults (  child_0.el , 0,1,0,1 );
222             var child_1 = new Xcls_build_module( _this );
223             child_1.ref();
224             this.el.attach_defaults (  child_1.el , 1,2,0,1 );
225             var child_2 = new Xcls_Label9( _this );
226             child_2.ref();
227             this.el.attach_defaults (  child_2.el , 0,1,1,2 );
228             var child_3 = new Xcls_title( _this );
229             child_3.ref();
230             this.el.attach_defaults (  child_3.el , 1,2,1,2 );
231             var child_4 = new Xcls_Label11( _this );
232             child_4.ref();
233             this.el.attach_defaults (  child_4.el , 0,1,2,3 );
234             var child_5 = new Xcls_parent( _this );
235             child_5.ref();
236             this.el.attach_defaults (  child_5.el , 1,2,2,3 );
237         }
238
239         // user defined functions
240     }
241     public class Xcls_Label5 : Object
242     {
243         public Gtk.Label el;
244         private Xcls_PopoverProperty  _this;
245
246
247             // my vars (def)
248
249         // ctor
250         public Xcls_Label5(Xcls_PopoverProperty _owner )
251         {
252             _this = _owner;
253             this.el = new Gtk.Label( "Special Flags" );
254
255             // my vars (dec)
256
257             // set gobject values
258             this.el.justify = Gtk.Justification.RIGHT;
259             this.el.xalign = 0.900000f;
260         }
261
262         // user defined functions
263     }
264
265     public class Xcls_build_module : Object
266     {
267         public Gtk.ComboBox el;
268         private Xcls_PopoverProperty  _this;
269
270
271             // my vars (def)
272
273         // ctor
274         public Xcls_build_module(Xcls_PopoverProperty _owner )
275         {
276             _this = _owner;
277             _this.build_module = this;
278             this.el = new Gtk.ComboBox();
279
280             // my vars (dec)
281
282             // set gobject values
283             var child_0 = new Xcls_dbcellrenderer( _this );
284             child_0.ref();
285             this.el.pack_start (  child_0.el , true );
286             var child_1 = new Xcls_dbmodel( _this );
287             child_1.ref();
288             this.el.set_model (  child_1.el  );
289
290             // init method
291
292             this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
293         }
294
295         // user defined functions
296     }
297     public class Xcls_dbcellrenderer : Object
298     {
299         public Gtk.CellRendererText el;
300         private Xcls_PopoverProperty  _this;
301
302
303             // my vars (def)
304
305         // ctor
306         public Xcls_dbcellrenderer(Xcls_PopoverProperty _owner )
307         {
308             _this = _owner;
309             _this.dbcellrenderer = this;
310             this.el = new Gtk.CellRendererText();
311
312             // my vars (dec)
313
314             // set gobject values
315         }
316
317         // user defined functions
318     }
319
320     public class Xcls_dbmodel : Object
321     {
322         public Gtk.ListStore el;
323         private Xcls_PopoverProperty  _this;
324
325
326             // my vars (def)
327
328         // ctor
329         public Xcls_dbmodel(Xcls_PopoverProperty _owner )
330         {
331             _this = _owner;
332             _this.dbmodel = this;
333             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
334
335             // my vars (dec)
336
337             // set gobject values
338         }
339
340         // user defined functions
341         public void loadData (Gee.ArrayList<string> data, string cur) {
342             this.el.clear();                                    
343             Gtk.TreeIter iter;
344             var el = this.el;
345             
346            /// el.append(out iter);
347             
348              
349            // el.set_value(iter, 0, "");
350            // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
351         
352             el.append(out iter);
353         
354             
355             el.set_value(iter, 0, "");
356             el.set_value(iter, 1, "-- select a module --");
357             _this.build_module.el.set_active_iter(iter);
358             
359             for (var i = 0; i < data.size;i++) {
360             
361         
362                 el.append(out iter);
363                 
364                 el.set_value(iter, 0, data.get(i));
365                 el.set_value(iter, 1, data.get(i));
366                 
367                 if (data.get(i) == cur) {
368                     _this.build_module.el.set_active_iter(iter);
369                 }
370                 
371             }
372              this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
373                                              
374         }
375     }
376
377
378     public class Xcls_Label9 : Object
379     {
380         public Gtk.Label el;
381         private Xcls_PopoverProperty  _this;
382
383
384             // my vars (def)
385
386         // ctor
387         public Xcls_Label9(Xcls_PopoverProperty _owner )
388         {
389             _this = _owner;
390             this.el = new Gtk.Label( "Title" );
391
392             // my vars (dec)
393
394             // set gobject values
395             this.el.justify = Gtk.Justification.RIGHT;
396             this.el.xalign = 0.900000f;
397             this.el.visible = true;
398         }
399
400         // user defined functions
401     }
402
403     public class Xcls_title : Object
404     {
405         public Gtk.Entry el;
406         private Xcls_PopoverProperty  _this;
407
408
409             // my vars (def)
410
411         // ctor
412         public Xcls_title(Xcls_PopoverProperty _owner )
413         {
414             _this = _owner;
415             _this.title = this;
416             this.el = new Gtk.Entry();
417
418             // my vars (dec)
419
420             // set gobject values
421             this.el.visible = true;
422         }
423
424         // user defined functions
425     }
426
427     public class Xcls_Label11 : Object
428     {
429         public Gtk.Label el;
430         private Xcls_PopoverProperty  _this;
431
432
433             // my vars (def)
434
435         // ctor
436         public Xcls_Label11(Xcls_PopoverProperty _owner )
437         {
438             _this = _owner;
439             this.el = new Gtk.Label( "Name" );
440
441             // my vars (dec)
442
443             // set gobject values
444             this.el.justify = Gtk.Justification.RIGHT;
445             this.el.xalign = 0.900000f;
446             this.el.tooltip_text = "center, north, south, east, west";
447             this.el.visible = true;
448         }
449
450         // user defined functions
451     }
452
453     public class Xcls_parent : Object
454     {
455         public Gtk.Entry el;
456         private Xcls_PopoverProperty  _this;
457
458
459             // my vars (def)
460
461         // ctor
462         public Xcls_parent(Xcls_PopoverProperty _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
477
478     public class Xcls_HButtonBox13 : Object
479     {
480         public Gtk.HButtonBox el;
481         private Xcls_PopoverProperty  _this;
482
483
484             // my vars (def)
485
486         // ctor
487         public Xcls_HButtonBox13(Xcls_PopoverProperty _owner )
488         {
489             _this = _owner;
490             this.el = new Gtk.HButtonBox();
491
492             // my vars (dec)
493
494             // set gobject values
495             this.el.margin_right = 4;
496             this.el.margin_left = 4;
497             this.el.margin_bottom = 4;
498             var child_0 = new Xcls_Button14( _this );
499             child_0.ref();
500             this.el.add (  child_0.el  );
501             var child_1 = new Xcls_save_btn( _this );
502             child_1.ref();
503             this.el.add (  child_1.el  );
504         }
505
506         // user defined functions
507     }
508     public class Xcls_Button14 : Object
509     {
510         public Gtk.Button el;
511         private Xcls_PopoverProperty  _this;
512
513
514             // my vars (def)
515
516         // ctor
517         public Xcls_Button14(Xcls_PopoverProperty _owner )
518         {
519             _this = _owner;
520             this.el = new Gtk.Button();
521
522             // my vars (dec)
523
524             // set gobject values
525             this.el.label = "Cancel";
526
527             //listeners
528             this.el.clicked.connect( () => { 
529             
530               _this.done = true;
531                 _this.el.hide(); 
532             });
533         }
534
535         // user defined functions
536     }
537
538     public class Xcls_save_btn : Object
539     {
540         public Gtk.Button el;
541         private Xcls_PopoverProperty  _this;
542
543
544             // my vars (def)
545
546         // ctor
547         public Xcls_save_btn(Xcls_PopoverProperty _owner )
548         {
549             _this = _owner;
550             _this.save_btn = this;
551             this.el = new Gtk.Button();
552
553             // my vars (dec)
554
555             // set gobject values
556             this.el.label = "Save";
557
558             //listeners
559             this.el.clicked.connect( ( ) =>  { 
560             
561              
562             
563             
564                 if (_this.name.el.get_text().length  < 1) {
565                     StandardErrorDialog.show(
566                         _this.mainwindow.el,
567                         "You have to set Component name "
568                     );
569                      
570                     return;
571                 }
572                 // what does this do?
573                 
574                 var isNew = _this.file.name.length  > 0 ? false : true;
575                 /*
576                 if (!isNew && this.file.name != _this.name.el.get_text()) {
577                     Xcls_StandardErrorDialog.singleton().show(
578                         this.el,
579                         "Sorry changing names does not work yet. "
580                     );
581                      
582                     return;
583                 }
584                 */
585                  
586                 
587               
588                 // FIXME - this may be more complicated...
589                 //for (var i in this.def) {
590                 //    this.file[i] =  this.get(i).el.get_text();
591                 //}
592             
593                 if (!isNew) {
594                     try {
595                          _this.updateFileFromEntry();
596                      } catch( JsRender.Error.RENAME_FILE_EXISTS er) {
597                           Xcls_StandardErrorDialog.singleton().show(
598                             _this.mainwindow.el,
599                             "The name you used already exists "
600                         );
601                         return;
602                          
603                      }
604             
605                       _this.done = true;
606                     _this.file.save();
607                     _this.el.hide();
608                     return;
609                 }
610                 var fn = _this.name.el.get_text();
611                 var dir = _this.project.firstPath();
612                
613                 if (GLib.FileUtils.test(dir + "/" + fn + ".bjs", GLib.FileTest.EXISTS)) {
614                     Xcls_StandardErrorDialog.singleton().show(
615                         _this.mainwindow.el,
616                         "That file already exists"
617                     ); 
618                     return;
619                 }
620                
621                var f =  JsRender.JsRender.factory(
622                         _this.file.project.xtype,  
623                         _this.file.project, 
624                         dir + "/" + fn + ".bjs");
625             
626                 _this.file = f;
627                 
628             
629                 
630                 _this.updateFileFromEntry();
631                 _this.file.loaded = true;
632                 _this.file.save();
633                 _this.file.project.addFile(_this.file);
634                 
635              
636                 // what about .js ?
637                _this.done = true;
638                 _this.el.hide();
639             
640                 
641                 
642                 _this.success(_this.project, _this.file);
643                
644             });
645         }
646
647         // user defined functions
648     }
649
650
651
652 }