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