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