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