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