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