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