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_header header;
16     public Xcls_kflag kflag;
17     public Xcls_dbcellrenderer dbcellrenderer;
18     public Xcls_dbmodel dbmodel;
19     public Xcls_ktype ktype;
20     public Xcls_kname kname;
21     public Xcls_save_btn save_btn;
22
23         // my vars (def)
24     public signal void success (Project.Project pr, JsRender.JsRender file);
25     public bool done;
26     public Xcls_MainWindow mainwindow;
27     public JsRender.Node node;
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.mainwindow = null;
38
39         // set gobject values
40         this.el.border_width = 0;
41         this.el.modal = true;
42         this.el.position = Gtk.PositionType.RIGHT;
43         var child_0 = new Xcls_Box2( _this );
44         child_0.ref();
45         this.el.add (  child_0.el  );
46
47         //listeners
48         this.el.closed.connect( () => {
49           if (!this.done) {
50             _this.el.show();
51           
52           }
53         });
54     }
55
56     // user defined functions
57     public void show (Gtk.Widget btn, JsRender.Node node, string type,  string key) 
58         {
59         
60         string kname = "", kflag = "", ktype = "";
61         if (key.length > 0) {
62                 node.normalize_key( key, out  kname, out  kflag, out ktype);
63         }
64     
65         _this.kname.el.set_text(kname);
66         _this.ktype.el.set_text(ktype);
67         
68         _this.dbmodel.loadData(kflag);
69         // does node have this property...
70     
71     
72         if (key.length > 0) {
73                 this.save_btn.el.set_label("Save");
74         } else {
75                 this.save_btn.el.set_label("Create");
76         }
77     
78         _this.node = node;
79         //console.log('show all');
80         this.el.set_modal(true);
81         this.el.set_relative_to(btn);
82     
83         this.el.set_position(Gtk.PositionType.TOP);
84     
85         // window + header?
86          print("SHOWALL - POPIP\n");
87         this.el.show_all();
88         this.kname.el.grab_focus();
89     
90         //this.success = c.success;
91      
92     }
93     public   void updateNodeFromValues () {
94     
95          /*   _this.file.title = _this.title.el.get_text();
96             _this.file.region = _this.region.el.get_text();            
97             _this.file.parent = _this.parent.el.get_text();                        
98             _this.file.permname = _this.permname.el.get_text();                                    
99             _this.file.modOrder = _this.modOrder.el.get_text();
100             
101             if (_this.file.name.length  > 0 && _this.file.name != _this.name.el.get_text()) {
102                 _this.file.renameTo(_this.name.el.get_text());
103             }
104             // store the module...
105             _this.file.build_module = "";        
106              Gtk.TreeIter iter; 
107             if (_this.build_module.el.get_active_iter (out iter)) {
108                  Value vfname;
109                  this.dbmodel.el.get_value (iter, 0, out vfname);
110                  if (((string)vfname).length > 0) {
111                      _this.file.build_module = (string)vfname;
112                  }
113         
114             }
115             */
116             
117             
118     
119                                                         
120     }
121     public class Xcls_Box2 : Object
122     {
123         public Gtk.Box el;
124         private Xcls_PopoverProperty  _this;
125
126
127             // my vars (def)
128
129         // ctor
130         public Xcls_Box2(Xcls_PopoverProperty _owner )
131         {
132             _this = _owner;
133             this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
134
135             // my vars (dec)
136
137             // set gobject values
138             this.el.homogeneous = false;
139             var child_0 = new Xcls_header( _this );
140             child_0.ref();
141             this.el.pack_start (  child_0.el , false,true,0 );
142             var child_1 = new Xcls_Table4( _this );
143             child_1.ref();
144             this.el.pack_start (  child_1.el , false,false,4 );
145             var child_2 = new Xcls_HButtonBox13( _this );
146             child_2.ref();
147             this.el.pack_end (  child_2.el , false,true,0 );
148         }
149
150         // user defined functions
151     }
152     public class Xcls_header : Object
153     {
154         public Gtk.HeaderBar el;
155         private Xcls_PopoverProperty  _this;
156
157
158             // my vars (def)
159
160         // ctor
161         public Xcls_header(Xcls_PopoverProperty _owner )
162         {
163             _this = _owner;
164             _this.header = this;
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_kflag( _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_kflag : Object
243     {
244         public Gtk.ComboBox el;
245         private Xcls_PopoverProperty  _this;
246
247
248             // my vars (def)
249
250         // ctor
251         public Xcls_kflag(Xcls_PopoverProperty _owner )
252         {
253             _this = _owner;
254             _this.kflag = 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 (string kflag) {
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.mainwindow.windowstate.file.xtype == "Gtk") {
342                         el.append(out iter);
343                         el.set(iter, 0, "$", 1,   "($) Raw Property (not escaped)", -1);
344                          
345                         
346                         el.append(out iter);
347                         el.set(iter, 0, "#", 1,   "(#) User defined property", -1);
348                          
349                         el.append(out iter);
350                         el.set(iter, 0, "|", 1,   "(|) User defined method", -1);
351                          
352                         el.append(out iter);
353                         el.set(iter, 0, "*", 1,   "(*) Special property (eg. prop | args | ctor | init )", -1);
354                          
355                         
356                         el.append(out iter);
357                     el.set(iter, 0, "@", 1,   "(@) Vala Signal", -1);
358                          
359                         
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                 el.foreach((tm, tp, titer) => {
374                         GLib.Value val;
375                         el.get_value(titer, 0, out val);
376                          
377                         print("check %s against %s\n", (string)val, kflag);
378                         if (((string)val) == kflag) {
379                                 _this.kflag.el.set_active_iter(titer);
380                                 return true;
381                         }
382                         return false;
383                 });
384                 
385         
386                                              
387         }
388     }
389
390
391     public class Xcls_Label9 : Object
392     {
393         public Gtk.Label el;
394         private Xcls_PopoverProperty  _this;
395
396
397             // my vars (def)
398
399         // ctor
400         public Xcls_Label9(Xcls_PopoverProperty _owner )
401         {
402             _this = _owner;
403             this.el = new Gtk.Label( "Type" );
404
405             // my vars (dec)
406
407             // set gobject values
408             this.el.justify = Gtk.Justification.RIGHT;
409             this.el.xalign = 0.900000f;
410             this.el.visible = true;
411         }
412
413         // user defined functions
414     }
415
416     public class Xcls_ktype : Object
417     {
418         public Gtk.Entry el;
419         private Xcls_PopoverProperty  _this;
420
421
422             // my vars (def)
423
424         // ctor
425         public Xcls_ktype(Xcls_PopoverProperty _owner )
426         {
427             _this = _owner;
428             _this.ktype = this;
429             this.el = new Gtk.Entry();
430
431             // my vars (dec)
432
433             // set gobject values
434             this.el.visible = true;
435         }
436
437         // user defined functions
438     }
439
440     public class Xcls_Label11 : Object
441     {
442         public Gtk.Label el;
443         private Xcls_PopoverProperty  _this;
444
445
446             // my vars (def)
447
448         // ctor
449         public Xcls_Label11(Xcls_PopoverProperty _owner )
450         {
451             _this = _owner;
452             this.el = new Gtk.Label( "Name" );
453
454             // my vars (dec)
455
456             // set gobject values
457             this.el.justify = Gtk.Justification.RIGHT;
458             this.el.xalign = 0.900000f;
459             this.el.tooltip_text = "center, north, south, east, west";
460             this.el.visible = true;
461         }
462
463         // user defined functions
464     }
465
466     public class Xcls_kname : Object
467     {
468         public Gtk.Entry el;
469         private Xcls_PopoverProperty  _this;
470
471
472             // my vars (def)
473
474         // ctor
475         public Xcls_kname(Xcls_PopoverProperty _owner )
476         {
477             _this = _owner;
478             _this.kname = this;
479             this.el = new Gtk.Entry();
480
481             // my vars (dec)
482
483             // set gobject values
484             this.el.visible = true;
485         }
486
487         // user defined functions
488     }
489
490
491     public class Xcls_HButtonBox13 : Object
492     {
493         public Gtk.HButtonBox el;
494         private Xcls_PopoverProperty  _this;
495
496
497             // my vars (def)
498
499         // ctor
500         public Xcls_HButtonBox13(Xcls_PopoverProperty _owner )
501         {
502             _this = _owner;
503             this.el = new Gtk.HButtonBox();
504
505             // my vars (dec)
506
507             // set gobject values
508             this.el.margin_right = 4;
509             this.el.margin_left = 4;
510             this.el.margin_bottom = 4;
511             var child_0 = new Xcls_Button14( _this );
512             child_0.ref();
513             this.el.add (  child_0.el  );
514             var child_1 = new Xcls_save_btn( _this );
515             child_1.ref();
516             this.el.add (  child_1.el  );
517         }
518
519         // user defined functions
520     }
521     public class Xcls_Button14 : Object
522     {
523         public Gtk.Button el;
524         private Xcls_PopoverProperty  _this;
525
526
527             // my vars (def)
528
529         // ctor
530         public Xcls_Button14(Xcls_PopoverProperty _owner )
531         {
532             _this = _owner;
533             this.el = new Gtk.Button();
534
535             // my vars (dec)
536
537             // set gobject values
538             this.el.label = "Cancel";
539
540             //listeners
541             this.el.clicked.connect( () => { 
542             
543               _this.done = true;
544                 _this.el.hide(); 
545             });
546         }
547
548         // user defined functions
549     }
550
551     public class Xcls_save_btn : Object
552     {
553         public Gtk.Button el;
554         private Xcls_PopoverProperty  _this;
555
556
557             // my vars (def)
558
559         // ctor
560         public Xcls_save_btn(Xcls_PopoverProperty _owner )
561         {
562             _this = _owner;
563             _this.save_btn = this;
564             this.el = new Gtk.Button();
565
566             // my vars (dec)
567
568             // set gobject values
569             this.el.label = "Save";
570
571             //listeners
572             this.el.clicked.connect( ( ) =>  { 
573             
574               
575             /*
576             
577                 if (_this.name.el.get_text().length  < 1) {
578                     StandardErrorDialog.show(
579                         _this.mainwindow.el,
580                         "You have to set Component name "
581                     );
582                      
583                     return;
584                 }
585                 // what does this do?
586                 
587                 var isNew = _this.file.name.length  > 0 ? false : true;
588                  
589                  
590                 
591               
592                 // FIXME - this may be more complicated...
593                 //for (var i in this.def) {
594                 //    this.file[i] =  this.get(i).el.get_text();
595                 //}
596             
597                 if (!isNew) {
598                     try {
599                          _this.updateFileFromEntry();
600                      } catch( JsRender.Error.RENAME_FILE_EXISTS er) {
601                           Xcls_StandardErrorDialog.singleton().show(
602                             _this.mainwindow.el,
603                             "The name you used already exists "
604                         );
605                         return;
606                          
607                      }
608             
609                       _this.done = true;
610                     _this.file.save();
611                     _this.el.hide();
612                     return;
613                 }
614                 var fn = _this.name.el.get_text();
615                 var dir = _this.project.firstPath();
616                
617                 if (GLib.FileUtils.test(dir + "/" + fn + ".bjs", GLib.FileTest.EXISTS)) {
618                     Xcls_StandardErrorDialog.singleton().show(
619                         _this.mainwindow.el,
620                         "That file already exists"
621                     ); 
622                     return;
623                 }
624                
625                var f =  JsRender.JsRender.factory(
626                         _this.file.project.xtype,  
627                         _this.file.project, 
628                         dir + "/" + fn + ".bjs");
629             
630                 _this.file = f;
631                 
632             
633                 
634                 _this.updateFileFromEntry();
635                 _this.file.loaded = true;
636                 _this.file.save();
637                 _this.file.project.addFile(_this.file);
638                 
639              
640                 // what about .js ?
641                _this.done = true;
642                 _this.el.hide();
643             
644                 
645                 
646                 _this.success(_this.project, _this.file);
647                 */
648                
649             });
650         }
651
652         // user defined functions
653     }
654
655
656
657 }