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