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         
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)", -1);
353         
354             el.append(out iter);
355             el.set(iter, 0, "@", 1,   "Vala Signal", -1);
356                                              
357         }
358     }
359
360
361     public class Xcls_Label9 : Object
362     {
363         public Gtk.Label el;
364         private Xcls_PopoverProperty  _this;
365
366
367             // my vars (def)
368
369         // ctor
370         public Xcls_Label9(Xcls_PopoverProperty _owner )
371         {
372             _this = _owner;
373             this.el = new Gtk.Label( "Type" );
374
375             // my vars (dec)
376
377             // set gobject values
378             this.el.justify = Gtk.Justification.RIGHT;
379             this.el.xalign = 0.900000f;
380             this.el.visible = true;
381         }
382
383         // user defined functions
384     }
385
386     public class Xcls_ktype : Object
387     {
388         public Gtk.Entry el;
389         private Xcls_PopoverProperty  _this;
390
391
392             // my vars (def)
393
394         // ctor
395         public Xcls_ktype(Xcls_PopoverProperty _owner )
396         {
397             _this = _owner;
398             _this.ktype = this;
399             this.el = new Gtk.Entry();
400
401             // my vars (dec)
402
403             // set gobject values
404             this.el.visible = true;
405         }
406
407         // user defined functions
408     }
409
410     public class Xcls_Label11 : Object
411     {
412         public Gtk.Label el;
413         private Xcls_PopoverProperty  _this;
414
415
416             // my vars (def)
417
418         // ctor
419         public Xcls_Label11(Xcls_PopoverProperty _owner )
420         {
421             _this = _owner;
422             this.el = new Gtk.Label( "Name" );
423
424             // my vars (dec)
425
426             // set gobject values
427             this.el.justify = Gtk.Justification.RIGHT;
428             this.el.xalign = 0.900000f;
429             this.el.tooltip_text = "center, north, south, east, west";
430             this.el.visible = true;
431         }
432
433         // user defined functions
434     }
435
436     public class Xcls_kname : Object
437     {
438         public Gtk.Entry el;
439         private Xcls_PopoverProperty  _this;
440
441
442             // my vars (def)
443
444         // ctor
445         public Xcls_kname(Xcls_PopoverProperty _owner )
446         {
447             _this = _owner;
448             _this.kname = this;
449             this.el = new Gtk.Entry();
450
451             // my vars (dec)
452
453             // set gobject values
454             this.el.visible = true;
455         }
456
457         // user defined functions
458     }
459
460
461     public class Xcls_HButtonBox13 : Object
462     {
463         public Gtk.HButtonBox el;
464         private Xcls_PopoverProperty  _this;
465
466
467             // my vars (def)
468
469         // ctor
470         public Xcls_HButtonBox13(Xcls_PopoverProperty _owner )
471         {
472             _this = _owner;
473             this.el = new Gtk.HButtonBox();
474
475             // my vars (dec)
476
477             // set gobject values
478             this.el.margin_right = 4;
479             this.el.margin_left = 4;
480             this.el.margin_bottom = 4;
481             var child_0 = new Xcls_Button14( _this );
482             child_0.ref();
483             this.el.add (  child_0.el  );
484             var child_1 = new Xcls_save_btn( _this );
485             child_1.ref();
486             this.el.add (  child_1.el  );
487         }
488
489         // user defined functions
490     }
491     public class Xcls_Button14 : Object
492     {
493         public Gtk.Button el;
494         private Xcls_PopoverProperty  _this;
495
496
497             // my vars (def)
498
499         // ctor
500         public Xcls_Button14(Xcls_PopoverProperty _owner )
501         {
502             _this = _owner;
503             this.el = new Gtk.Button();
504
505             // my vars (dec)
506
507             // set gobject values
508             this.el.label = "Cancel";
509
510             //listeners
511             this.el.clicked.connect( () => { 
512             
513               _this.done = true;
514                 _this.el.hide(); 
515             });
516         }
517
518         // user defined functions
519     }
520
521     public class Xcls_save_btn : Object
522     {
523         public Gtk.Button el;
524         private Xcls_PopoverProperty  _this;
525
526
527             // my vars (def)
528
529         // ctor
530         public Xcls_save_btn(Xcls_PopoverProperty _owner )
531         {
532             _this = _owner;
533             _this.save_btn = this;
534             this.el = new Gtk.Button();
535
536             // my vars (dec)
537
538             // set gobject values
539             this.el.label = "Save";
540
541             //listeners
542             this.el.clicked.connect( ( ) =>  { 
543             
544               
545             /*
546             
547                 if (_this.name.el.get_text().length  < 1) {
548                     StandardErrorDialog.show(
549                         _this.mainwindow.el,
550                         "You have to set Component name "
551                     );
552                      
553                     return;
554                 }
555                 // what does this do?
556                 
557                 var isNew = _this.file.name.length  > 0 ? false : true;
558                  
559                  
560                 
561               
562                 // FIXME - this may be more complicated...
563                 //for (var i in this.def) {
564                 //    this.file[i] =  this.get(i).el.get_text();
565                 //}
566             
567                 if (!isNew) {
568                     try {
569                          _this.updateFileFromEntry();
570                      } catch( JsRender.Error.RENAME_FILE_EXISTS er) {
571                           Xcls_StandardErrorDialog.singleton().show(
572                             _this.mainwindow.el,
573                             "The name you used already exists "
574                         );
575                         return;
576                          
577                      }
578             
579                       _this.done = true;
580                     _this.file.save();
581                     _this.el.hide();
582                     return;
583                 }
584                 var fn = _this.name.el.get_text();
585                 var dir = _this.project.firstPath();
586                
587                 if (GLib.FileUtils.test(dir + "/" + fn + ".bjs", GLib.FileTest.EXISTS)) {
588                     Xcls_StandardErrorDialog.singleton().show(
589                         _this.mainwindow.el,
590                         "That file already exists"
591                     ); 
592                     return;
593                 }
594                
595                var f =  JsRender.JsRender.factory(
596                         _this.file.project.xtype,  
597                         _this.file.project, 
598                         dir + "/" + fn + ".bjs");
599             
600                 _this.file = f;
601                 
602             
603                 
604                 _this.updateFileFromEntry();
605                 _this.file.loaded = true;
606                 _this.file.save();
607                 _this.file.project.addFile(_this.file);
608                 
609              
610                 // what about .js ?
611                _this.done = true;
612                 _this.el.hide();
613             
614                 
615                 
616                 _this.success(_this.project, _this.file);
617                 */
618                
619             });
620         }
621
622         // user defined functions
623     }
624
625
626
627 }