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