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