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