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