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