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