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