10e98cd6f47ee9228b16894fa3d6d66fc73388f4
[roobuilder] / 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_headertitle headertitle;
17         public Xcls_ptype ptype;
18         public Xcls_pselmodel pselmodel;
19         public Xcls_pmodel pmodel;
20         public Xcls_ktype ktype;
21         public Xcls_kname kname;
22         public Xcls_error error;
23         public Xcls_buttonbar buttonbar;
24
25             // my vars (def)
26         public bool is_new;
27         public signal void success (Project.Project pr, JsRender.JsRender file);
28         public string key_type;
29         public JsRender.NodeProp? prop;
30         public bool done;
31         public Xcls_MainWindow mainwindow;
32         public JsRender.Node node;
33         public string old_keyname;
34
35         // ctor
36         public Xcls_PopoverProperty()
37         {
38             _this = this;
39             this.el = new Gtk.Popover();
40
41             // my vars (dec)
42             this.is_new = false;
43             this.done = false;
44             this.mainwindow = null;
45
46             // set gobject values
47             this.el.autohide = true;
48             this.el.position = Gtk.PositionType.RIGHT;
49             var child_1 = new Xcls_Box2( _this );
50             child_1.ref();
51             this.el.set_child ( child_1.el  );
52
53             //listeners
54             this.el.closed.connect( () => {
55             
56                 GLib.debug("popover closed");
57                 if (_this.is_new) {
58                         // dont allow hiding if we are creating a new one.
59                         // on.hide will reshow it.
60                         return;
61                 }
62                 if (_this.prop == null) {
63                         // hide and dont update.
64                         return;
65                 }
66                 if (this.kname.el.get_text().strip().length < 1) {
67                         return;
68                 }
69                 
70              
71                         
72                      
73                 this.updateProp();
74                     
75                  
76             
77             
78               
79             });
80             this.el.hide.connect( () => {
81                 GLib.debug("popover hidden");
82                 if (_this.is_new || this.kname.el.get_text().strip().length < 1) {
83                         // dont allow hiding if we are creating a new one.
84                         GLib.debug("prevent hiding as its new or text is empty"); 
85                         this.el.show();
86                         return;
87             
88                 }
89                 
90             });
91         }
92
93         // user defined functions
94         public void updateProp () {
95                 GLib.debug("updateProp called");
96         
97                 
98                 
99                 _this.prop.name = this.kname.el.get_text().strip();
100                 _this.prop.ptype = this.ptype.getValue();
101                 _this.prop.rtype = this.ktype.el.get_text().strip();
102                 
103                   
104         }
105         public void show (
106                 Gtk.Widget btn, 
107                 JsRender.Node node, 
108                 JsRender.NodeProp prop, 
109                 int y,
110                 bool is_new = false
111                  ) 
112         {
113                 
114            
115                 this.is_new = is_new; 
116                 var pref = is_new ? "Add " : "Modify ";
117                 if (prop.ptype == JsRender.NodePropType.LISTENER) {
118                         this.headertitle.el.label = pref + "Event Listener"; // cant really happen yet?
119                 } else {
120                         this.headertitle.el.label = pref + "Property";
121                 }
122                 this.prop = prop;
123                 this.node = node;
124                 
125                 _this.kname.el.set_text(prop.name);
126                 _this.ktype.el.set_text(prop.rtype);
127                 
128                 _this.ptype.setValue(prop.ptype);
129                 // does node have this property...
130         
131         
132                 _this.node = node;
133                 //console.log('show all');
134                 
135                 GLib.debug("set parent = %s", btn.get_type().name());
136                 var par = btn.get_parent();
137                 
138                 if (par == null) {
139                         GLib.debug("parent of that is null - not showing");
140                         return;
141                 }
142                 if (this.el.parent == null) {
143                         this.el.set_parent(btn);
144                 }
145                 var  r = Gdk.Rectangle() {
146                                 x = btn.get_width(), // align left...
147                                 y = 0,
148                                 width = 1,
149                                 height = 1
150                         };
151                 //Gtk.Allocation rect;
152                 //btn.get_allocation(out rect);
153             this.el.set_pointing_to(r);
154             
155         
156                  
157                 if (y > -1) {
158                          
159                          r = Gdk.Rectangle() {
160                                 x = btn.get_width(), // align left...
161                                 y = y,
162                                 width = 1,
163                                 height = 1
164                         };
165                         this.el.set_pointing_to( r);
166                 }
167                 
168                 
169         
170                 //this.el.set_position(Gtk.PositionType.TOP);
171         
172                 // window + header?
173                  GLib.debug("SHOWALL - POPIP\n");
174                 
175                 this.kname.el.grab_focus();
176                 this.buttonbar.el.hide();
177                 if (this.is_new) {
178                         this.buttonbar.el.show();
179                 }
180                 this.error.setError("");
181                 this.el.show();
182                 //this.success = c.success;
183          
184         }
185         public class Xcls_Box2 : Object
186         {
187             public Gtk.Box el;
188             private Xcls_PopoverProperty  _this;
189
190
191                 // my vars (def)
192
193             // ctor
194             public Xcls_Box2(Xcls_PopoverProperty _owner )
195             {
196                 _this = _owner;
197                 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
198
199                 // my vars (dec)
200
201                 // set gobject values
202                 this.el.homogeneous = false;
203                 new Xcls_header( _this );
204                 this.el.append( _this.header.el );
205                 new Xcls_ptype( _this );
206                 this.el.append( _this.ptype.el );
207                 var child_3 = new Xcls_Label10( _this );
208                 child_3.ref();
209                 this.el.append( child_3.el );
210                 new Xcls_ktype( _this );
211                 this.el.append( _this.ktype.el );
212                 var child_5 = new Xcls_Label12( _this );
213                 child_5.ref();
214                 this.el.append( child_5.el );
215                 new Xcls_kname( _this );
216                 this.el.append( _this.kname.el );
217                 new Xcls_error( _this );
218                 this.el.append( _this.error.el );
219                 new Xcls_buttonbar( _this );
220                 this.el.append( _this.buttonbar.el );
221             }
222
223             // user defined functions
224         }
225         public class Xcls_header : Object
226         {
227             public Gtk.HeaderBar el;
228             private Xcls_PopoverProperty  _this;
229
230
231                 // my vars (def)
232
233             // ctor
234             public Xcls_header(Xcls_PopoverProperty _owner )
235             {
236                 _this = _owner;
237                 _this.header = this;
238                 this.el = new Gtk.HeaderBar();
239
240                 // my vars (dec)
241
242                 // set gobject values
243                 this.el.show_title_buttons = false;
244                 new Xcls_headertitle( _this );
245                 this.el.title_widget = _this.headertitle.el;
246             }
247
248             // user defined functions
249         }
250         public class Xcls_headertitle : Object
251         {
252             public Gtk.Label el;
253             private Xcls_PopoverProperty  _this;
254
255
256                 // my vars (def)
257
258             // ctor
259             public Xcls_headertitle(Xcls_PopoverProperty _owner )
260             {
261                 _this = _owner;
262                 _this.headertitle = this;
263                 this.el = new Gtk.Label( "Add / Edit property" );
264
265                 // my vars (dec)
266
267                 // set gobject values
268             }
269
270             // user defined functions
271         }
272
273
274         public class Xcls_ptype : Object
275         {
276             public Gtk.ColumnView el;
277             private Xcls_PopoverProperty  _this;
278
279
280                 // my vars (def)
281             public bool show_separators;
282
283             // ctor
284             public Xcls_ptype(Xcls_PopoverProperty _owner )
285             {
286                 _this = _owner;
287                 _this.ptype = this;
288                 new Xcls_pselmodel( _this );
289                 this.el = new Gtk.ColumnView( _this.pselmodel.el );
290
291                 // my vars (dec)
292                 this.show_separators = true;
293
294                 // set gobject values
295                 this.el.show_row_separators = true;
296                 var child_2 = new Xcls_ColumnViewColumn8( _this );
297                 child_2.ref();
298                 this.el.append_column ( child_2.el  );
299             }
300
301             // user defined functions
302             public JsRender.NodePropType getValue () {
303                 
304                 var li =  (JsRender.NodeProp) _this.pmodel.el.get_item(
305                         _this.pselmodel.el.get_selected()
306                         );
307                 return li.ptype;
308             
309             }
310             public void setValue (JsRender.NodePropType pt) 
311             {
312                 for (var i = 0; i < _this.pmodel.el.n_items; i++) {
313                         var li = (JsRender.NodeProp) _this.pmodel.el.get_item(i);
314                         if (li.ptype == pt) {
315                                 _this.pselmodel.el.set_selected(i);
316                                 return;
317                         }
318                 }
319                 GLib.debug("failed to set selected ptype");
320                 _this.pselmodel.el.set_selected(0);
321             }
322         }
323         public class Xcls_pselmodel : Object
324         {
325             public Gtk.SingleSelection el;
326             private Xcls_PopoverProperty  _this;
327
328
329                 // my vars (def)
330
331             // ctor
332             public Xcls_pselmodel(Xcls_PopoverProperty _owner )
333             {
334                 _this = _owner;
335                 _this.pselmodel = this;
336                 new Xcls_pmodel( _this );
337                 this.el = new Gtk.SingleSelection( _this.pmodel.el );
338
339                 // my vars (dec)
340
341                 // set gobject values
342             }
343
344             // user defined functions
345         }
346         public class Xcls_pmodel : Object
347         {
348             public GLib.ListStore el;
349             private Xcls_PopoverProperty  _this;
350
351
352                 // my vars (def)
353
354             // ctor
355             public Xcls_pmodel(Xcls_PopoverProperty _owner )
356             {
357                 _this = _owner;
358                 _this.pmodel = this;
359                 this.el = new GLib.ListStore(typeof(JsRender.NodeProp));;
360
361                 // my vars (dec)
362
363                 // set gobject values
364
365                 // init method
366
367                 {
368                 
369                 
370                         this.el.append( new JsRender.NodeProp.prop(""));
371                         this.el.append( new JsRender.NodeProp.raw(""));
372                         this.el.append( new JsRender.NodeProp.valamethod(""));
373                         this.el.append( new JsRender.NodeProp.special(""));     
374                         this.el.append( new JsRender.NodeProp.listener(""));            
375                         this.el.append( new JsRender.NodeProp.user(""));        
376                         this.el.append( new JsRender.NodeProp.sig("")); 
377                         
378                 
379                 }
380             }
381
382             // user defined functions
383         }
384
385
386         public class Xcls_ColumnViewColumn8 : Object
387         {
388             public Gtk.ColumnViewColumn el;
389             private Xcls_PopoverProperty  _this;
390
391
392                 // my vars (def)
393
394             // ctor
395             public Xcls_ColumnViewColumn8(Xcls_PopoverProperty _owner )
396             {
397                 _this = _owner;
398                 var child_1 = new Xcls_SignalListItemFactory9( _this );
399                 child_1.ref();
400                 this.el = new Gtk.ColumnViewColumn( "Property Type", child_1.el );
401
402                 // my vars (dec)
403
404                 // set gobject values
405             }
406
407             // user defined functions
408         }
409         public class Xcls_SignalListItemFactory9 : Object
410         {
411             public Gtk.SignalListItemFactory el;
412             private Xcls_PopoverProperty  _this;
413
414
415                 // my vars (def)
416
417             // ctor
418             public Xcls_SignalListItemFactory9(Xcls_PopoverProperty _owner )
419             {
420                 _this = _owner;
421                 this.el = new Gtk.SignalListItemFactory();
422
423                 // my vars (dec)
424
425                 // set gobject values
426
427                 //listeners
428                 this.el.setup.connect( (listitem) => {
429                 
430                          
431                         var label = new Gtk.Label("");
432                         label.xalign = 0;
433                          
434                         ((Gtk.ListItem)listitem).set_child(label);
435                         ((Gtk.ListItem)listitem).activatable = false;
436                         
437                 });
438                 this.el.bind.connect( (listitem) => {
439                 
440                         var lbl = (Gtk.Label) ((Gtk.ListItem)listitem).get_child(); 
441                         var np = (JsRender.NodeProp)((Gtk.ListItem)listitem).get_item();
442                  
443                         
444                   
445                         lbl.label = np.ptype.to_name();
446                          
447                 });
448             }
449
450             // user defined functions
451         }
452
453
454
455         public class Xcls_Label10 : Object
456         {
457             public Gtk.Label el;
458             private Xcls_PopoverProperty  _this;
459
460
461                 // my vars (def)
462
463             // ctor
464             public Xcls_Label10(Xcls_PopoverProperty _owner )
465             {
466                 _this = _owner;
467                 this.el = new Gtk.Label( "Type or Return Type" );
468
469                 // my vars (dec)
470
471                 // set gobject values
472                 this.el.halign = Gtk.Align.START;
473                 this.el.justify = Gtk.Justification.LEFT;
474                 this.el.margin_top = 12;
475                 this.el.visible = true;
476             }
477
478             // user defined functions
479         }
480
481         public class Xcls_ktype : Object
482         {
483             public Gtk.Entry el;
484             private Xcls_PopoverProperty  _this;
485
486
487                 // my vars (def)
488
489             // ctor
490             public Xcls_ktype(Xcls_PopoverProperty _owner )
491             {
492                 _this = _owner;
493                 _this.ktype = this;
494                 this.el = new Gtk.Entry();
495
496                 // my vars (dec)
497
498                 // set gobject values
499                 this.el.visible = true;
500             }
501
502             // user defined functions
503         }
504
505         public class Xcls_Label12 : Object
506         {
507             public Gtk.Label el;
508             private Xcls_PopoverProperty  _this;
509
510
511                 // my vars (def)
512
513             // ctor
514             public Xcls_Label12(Xcls_PopoverProperty _owner )
515             {
516                 _this = _owner;
517                 this.el = new Gtk.Label( "Name" );
518
519                 // my vars (dec)
520
521                 // set gobject values
522                 this.el.halign = Gtk.Align.START;
523                 this.el.justify = Gtk.Justification.LEFT;
524                 this.el.tooltip_text = "center, north, south, east, west";
525                 this.el.margin_top = 12;
526                 this.el.visible = true;
527             }
528
529             // user defined functions
530         }
531
532         public class Xcls_kname : Object
533         {
534             public Gtk.Entry el;
535             private Xcls_PopoverProperty  _this;
536
537
538                 // my vars (def)
539
540             // ctor
541             public Xcls_kname(Xcls_PopoverProperty _owner )
542             {
543                 _this = _owner;
544                 _this.kname = this;
545                 this.el = new Gtk.Entry();
546
547                 // my vars (dec)
548
549                 // set gobject values
550                 this.el.visible = true;
551                 var child_1 = new Xcls_EventControllerFocus14( _this );
552                 child_1.ref();
553                 this.el.add_controller(  child_1.el );
554                 var child_2 = new Xcls_EventControllerKey15( _this );
555                 child_2.ref();
556                 this.el.add_controller(  child_2.el );
557             }
558
559             // user defined functions
560         }
561         public class Xcls_EventControllerFocus14 : Object
562         {
563             public Gtk.EventControllerFocus el;
564             private Xcls_PopoverProperty  _this;
565
566
567                 // my vars (def)
568
569             // ctor
570             public Xcls_EventControllerFocus14(Xcls_PopoverProperty _owner )
571             {
572                 _this = _owner;
573                 this.el = new Gtk.EventControllerFocus();
574
575                 // my vars (dec)
576
577                 // set gobject values
578
579                 //listeners
580                 this.el.leave.connect( ( ) => {
581                 
582                     _this.error.setError("");
583                         var val = _this.kname.el.get_text().strip(); 
584                         if (val.length < 1) {
585                                 _this.error.setError("Name can not be empty");
586                         }
587                 
588                 });
589             }
590
591             // user defined functions
592         }
593
594         public class Xcls_EventControllerKey15 : Object
595         {
596             public Gtk.EventControllerKey el;
597             private Xcls_PopoverProperty  _this;
598
599
600                 // my vars (def)
601
602             // ctor
603             public Xcls_EventControllerKey15(Xcls_PopoverProperty _owner )
604             {
605                 _this = _owner;
606                 this.el = new Gtk.EventControllerKey();
607
608                 // my vars (dec)
609
610                 // set gobject values
611
612                 //listeners
613                 this.el.key_released.connect( (keyval, keycode, state) => {
614                 
615                     _this.error.setError("");
616                         var val = _this.kname.el.get_text().strip(); 
617                         if (val.length < 1) {
618                                 _this.error.setError("Name can not be empty");
619                         }
620                 
621                 });
622             }
623
624             // user defined functions
625         }
626
627
628         public class Xcls_error : Object
629         {
630             public Gtk.Label el;
631             private Xcls_PopoverProperty  _this;
632
633
634                 // my vars (def)
635
636             // ctor
637             public Xcls_error(Xcls_PopoverProperty _owner )
638             {
639                 _this = _owner;
640                 _this.error = this;
641                 this.el = new Gtk.Label( "<span color=\"red\">Error Message</span>" );
642
643                 // my vars (dec)
644
645                 // set gobject values
646                 this.el.halign = Gtk.Align.START;
647                 this.el.justify = Gtk.Justification.LEFT;
648                 this.el.tooltip_text = "center, north, south, east, west";
649                 this.el.margin_top = 0;
650                 this.el.visible = true;
651                 this.el.use_markup = true;
652             }
653
654             // user defined functions
655             public void setError (string err)   {
656                 if (err == "") {
657                         this.el.label = "";
658                 } else {
659             
660                         
661                         this.el.label = "<span color=\"red\">" + err + "</span>";
662                 }
663             }
664         }
665
666         public class Xcls_buttonbar : Object
667         {
668             public Gtk.Box el;
669             private Xcls_PopoverProperty  _this;
670
671
672                 // my vars (def)
673
674             // ctor
675             public Xcls_buttonbar(Xcls_PopoverProperty _owner )
676             {
677                 _this = _owner;
678                 _this.buttonbar = this;
679                 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
680
681                 // my vars (dec)
682
683                 // set gobject values
684                 this.el.margin_top = 20;
685                 var child_1 = new Xcls_Button18( _this );
686                 child_1.ref();
687                 this.el.append( child_1.el );
688                 var child_2 = new Xcls_Button19( _this );
689                 child_2.ref();
690                 this.el.append( child_2.el );
691             }
692
693             // user defined functions
694         }
695         public class Xcls_Button18 : Object
696         {
697             public Gtk.Button el;
698             private Xcls_PopoverProperty  _this;
699
700
701                 // my vars (def)
702             public bool always_show_image;
703
704             // ctor
705             public Xcls_Button18(Xcls_PopoverProperty _owner )
706             {
707                 _this = _owner;
708                 this.el = new Gtk.Button();
709
710                 // my vars (dec)
711                 this.always_show_image = true;
712
713                 // set gobject values
714                 this.el.hexpand = true;
715                 this.el.label = "Cancel";
716
717                 //listeners
718                 this.el.clicked.connect( () => {
719                         _this.prop = null;
720                         _this.is_new = false;
721                         _this.kname.el.set_text("Cancel");
722                         _this.el.hide();
723                         
724                 });
725             }
726
727             // user defined functions
728         }
729
730         public class Xcls_Button19 : Object
731         {
732             public Gtk.Button el;
733             private Xcls_PopoverProperty  _this;
734
735
736                 // my vars (def)
737             public bool always_show_image;
738
739             // ctor
740             public Xcls_Button19(Xcls_PopoverProperty _owner )
741             {
742                 _this = _owner;
743                 this.el = new Gtk.Button();
744
745                 // my vars (dec)
746                 this.always_show_image = true;
747
748                 // set gobject values
749                 this.el.hexpand = true;
750                 this.el.label = "Add Property";
751
752                 //listeners
753                 this.el.clicked.connect( () => {
754                         // check if text is not empty..
755                         if ( _this.kname.el.get_text().strip().length < 1) {
756                         
757                                 // error should already be showing?
758                                 return;
759                         }
760                          
761                         // since we can't add listeners?!?!?
762                         // only check props.
763                         // check if property already exists in node.    
764                 
765                 
766                         var prop = new JsRender.NodeProp(
767                                 _this.kname.el.get_text().strip(),
768                                 _this.ptype.getValue(),
769                                 _this.ktype.el.get_text().strip(),
770                                 _this.prop.val
771                         );
772                 
773                         if (_this.node.props.has_key(prop.to_index_key())) {
774                                 _this.error.setError("Property already exists");
775                                 return; 
776                         }
777                         
778                         
779                         
780                         _this.node.add_prop(prop);
781                         // hide self
782                         _this.prop = null; // skip checks..
783                         _this.is_new = false;
784                         _this.el.hide();
785                  
786                         _this.mainwindow.windowstate.left_props.view.editProp(prop);
787                 
788                         
789                         
790                 });
791             }
792
793             // user defined functions
794         }
795
796
797
798     }