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