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