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