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