1 static Xcls_PopoverProperty _PopoverProperty;
3 public class Xcls_PopoverProperty : Object
6 private Xcls_PopoverProperty _this;
8 public static Xcls_PopoverProperty singleton()
10 if (_PopoverProperty == null) {
11 _PopoverProperty= new Xcls_PopoverProperty();
13 return _PopoverProperty;
15 public Xcls_header header;
16 public Xcls_kflag kflag;
17 public Xcls_dbcellrenderer dbcellrenderer;
18 public Xcls_dbmodel dbmodel;
19 public Xcls_ktype ktype;
20 public Xcls_kname kname;
21 public Xcls_error error;
22 public Xcls_buttonbar buttonbar;
26 public signal void success (Project.Project pr, JsRender.JsRender file);
27 public string key_type;
28 public JsRender.NodeProp? prop;
29 public JsRender.Node node;
30 public Xcls_MainWindow mainwindow;
32 public string old_keyname;
35 public Xcls_PopoverProperty()
38 this.el = new Gtk.Popover( null );
42 this.mainwindow = null;
46 this.el.border_width = 0;
48 this.el.position = Gtk.PositionType.RIGHT;
49 var child_0 = new Xcls_Box2( _this );
51 this.el.add( child_0.el );
54 this.el.closed.connect( () => {
56 GLib.debug("popover closed");
58 // dont allow hiding if we are creating a new one.
59 // on.hide will reshow it.
62 if (_this.prop == null) {
63 // hide and dont update.
66 if (this.kname.el.get_text().strip().length < 1) {
70 var oldkey = this.prop.to_index_key();
75 var newkey = this.prop.to_index_key();
76 if (oldkey != newkey) {
78 if (_this.prop.ptype == JsRender.NodePropType.LISTENER) {
79 this.node.listeners.unset(oldkey);
80 this.node.listeners.set(newkey, _this.prop);
82 this.node.props.unset(oldkey);
83 this.node.props.set(newkey, _this.prop);
87 _this.mainwindow.windowstate.left_props.reload();
92 this.el.hide.connect( () => {
93 GLib.debug("popover hidden");
94 if (_this.is_new || this.kname.el.get_text().strip().length < 1) {
95 // dont allow hiding if we are creating a new one.
96 GLib.debug("prevent hiding as its new or text is empty");
105 // user defined functions
106 public void updateProp () {
110 this.kflag.el.get_active_iter(out citer);
111 this.dbmodel.el.get_value(citer, 0, out gval);
114 _this.prop.name = this.kname.el.get_text().strip();
115 _this.prop.rtype = this.ktype.el.get_text().strip();
116 _this.prop.ptype = (JsRender.NodePropType) gval;
122 JsRender.NodeProp prop,
129 this.is_new = is_new;
130 var pref = is_new ? "Add " : "Modify ";
131 if (prop.ptype == JsRender.NodePropType.LISTENER) {
132 this.header.el.title = pref + "Event Listener"; // cant really happen yet?
134 this.header.el.title = pref + "Property";
139 _this.kname.el.set_text(prop.name);
140 _this.ktype.el.set_text(prop.rtype);
142 _this.dbmodel.loadData(prop );
143 // does node have this property...
147 //console.log('show all');
148 this.el.set_modal(true);
149 this.el.set_relative_to(btn);
153 var r = Gdk.Rectangle() {
154 x = btn.get_allocated_width(), // align left...
159 this.el.set_pointing_to( r);
164 //this.el.set_position(Gtk.PositionType.TOP);
167 print("SHOWALL - POPIP\n");
169 this.kname.el.grab_focus();
170 this.buttonbar.el.hide();
172 this.buttonbar.el.show();
174 this.error.setError("");
176 //this.success = c.success;
179 public class Xcls_Box2 : Object
182 private Xcls_PopoverProperty _this;
188 public Xcls_Box2(Xcls_PopoverProperty _owner )
191 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
195 // set gobject values
196 this.el.homogeneous = false;
197 var child_0 = new Xcls_header( _this );
199 this.el.pack_start ( child_0.el , false,true,0 );
200 var child_1 = new Xcls_Label4( _this );
202 this.el.add ( child_1.el );
203 var child_2 = new Xcls_kflag( _this );
205 this.el.add ( child_2.el );
206 var child_3 = new Xcls_Label8( _this );
208 this.el.add ( child_3.el );
209 var child_4 = new Xcls_ktype( _this );
211 this.el.add ( child_4.el );
212 var child_5 = new Xcls_Label10( _this );
214 this.el.add ( child_5.el );
215 var child_6 = new Xcls_kname( _this );
217 this.el.add ( child_6.el );
218 var child_7 = new Xcls_error( _this );
220 this.el.add ( child_7.el );
221 var child_8 = new Xcls_buttonbar( _this );
223 this.el.add ( child_8.el );
226 // user defined functions
228 public class Xcls_header : Object
230 public Gtk.HeaderBar el;
231 private Xcls_PopoverProperty _this;
237 public Xcls_header(Xcls_PopoverProperty _owner )
241 this.el = new Gtk.HeaderBar();
245 // set gobject values
246 this.el.title = "Modify / Create Property";
249 // user defined functions
252 public class Xcls_Label4 : Object
255 private Xcls_PopoverProperty _this;
261 public Xcls_Label4(Xcls_PopoverProperty _owner )
264 this.el = new Gtk.Label( "Special Flags" );
268 // set gobject values
269 this.el.halign = Gtk.Align.START;
270 this.el.justify = Gtk.Justification.LEFT;
271 this.el.margin_top = 12;
274 // user defined functions
277 public class Xcls_kflag : Object
279 public Gtk.ComboBox el;
280 private Xcls_PopoverProperty _this;
286 public Xcls_kflag(Xcls_PopoverProperty _owner )
290 this.el = new Gtk.ComboBox();
294 // set gobject values
295 var child_0 = new Xcls_dbcellrenderer( _this );
297 this.el.pack_start ( child_0.el , true );
298 var child_1 = new Xcls_dbmodel( _this );
300 this.el.set_model ( child_1.el );
304 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
307 // user defined functions
309 public class Xcls_dbcellrenderer : Object
311 public Gtk.CellRendererText el;
312 private Xcls_PopoverProperty _this;
318 public Xcls_dbcellrenderer(Xcls_PopoverProperty _owner )
321 _this.dbcellrenderer = this;
322 this.el = new Gtk.CellRendererText();
326 // set gobject values
329 // user defined functions
332 public class Xcls_dbmodel : Object
334 public Gtk.ListStore el;
335 private Xcls_PopoverProperty _this;
341 public Xcls_dbmodel(Xcls_PopoverProperty _owner )
344 _this.dbmodel = this;
345 this.el = new Gtk.ListStore.newv( { typeof(JsRender.NodePropType),typeof(string) } );
349 // set gobject values
352 // user defined functions
353 public void loadData (JsRender.NodeProp prop) {
361 // user defined property '#'
362 // user defined method '|'
363 // special property '*' => prop |args|ctor|init
367 /// el.append(out iter);
370 // el.set_value(iter, 0, "");
371 // el.set_value(iter, 1, "aaa - Just add Element - aaa");
374 if (prop.ptype == JsRender.NodePropType.LISTENER) {
376 el.set(iter, 0, JsRender.NodePropType.LISTENER, 1, "Event Handler / Listener", -1);
378 else if (_this.mainwindow.windowstate.file.xtype == "Gtk") {
380 el.set(iter, 0, JsRender.NodePropType.PROP, 1, "Normal Property", -1);
384 el.set(iter, 0, JsRender.NodePropType.RAW, 1, "Raw Property (not escaped)", -1);
388 el.set(iter, 0, JsRender.NodePropType.USER, 1, "User defined property", -1);
391 el.set(iter, 0, JsRender.NodePropType.METHOD, 1, "User defined method", -1);
394 el.set(iter, 0, JsRender.NodePropType.SPECIAL, 1, "Special property (eg. prop | args | ctor | init )", -1);
398 el.set(iter, 0, JsRender.NodePropType.SIGNAL, 1, "Vala Signal", -1);
404 el.set(iter, 0, JsRender.NodePropType.PROP, 1, "Normal Property", -1);
407 el.set(iter, 0, JsRender.NodePropType.RAW, 1, "Raw Property (not escaped)", -1);
410 el.set(iter, 0, JsRender.NodePropType.METHOD, 1, "User defined method", -1);
413 el.set(iter, 0, JsRender.NodePropType.SPECIAL, 1, "(*) Special property (eg. prop )", -1);
417 // set selected, based on arg
418 el.foreach((tm, tp, titer) => {
420 el.get_value(titer, 0, out val);
422 //print("check %s against %s\n", (string)val, _this.prop.ptype);
423 if (((JsRender.NodePropType)val) == prop.ptype) {
424 _this.kflag.el.set_active_iter(titer);
436 public class Xcls_Label8 : Object
439 private Xcls_PopoverProperty _this;
445 public Xcls_Label8(Xcls_PopoverProperty _owner )
448 this.el = new Gtk.Label( "Type or Return Type" );
452 // set gobject values
453 this.el.halign = Gtk.Align.START;
454 this.el.justify = Gtk.Justification.LEFT;
455 this.el.margin_top = 12;
456 this.el.visible = true;
459 // user defined functions
462 public class Xcls_ktype : Object
465 private Xcls_PopoverProperty _this;
471 public Xcls_ktype(Xcls_PopoverProperty _owner )
475 this.el = new Gtk.Entry();
479 // set gobject values
480 this.el.visible = true;
483 // user defined functions
486 public class Xcls_Label10 : Object
489 private Xcls_PopoverProperty _this;
495 public Xcls_Label10(Xcls_PopoverProperty _owner )
498 this.el = new Gtk.Label( "Name" );
502 // set gobject values
503 this.el.halign = Gtk.Align.START;
504 this.el.justify = Gtk.Justification.LEFT;
505 this.el.tooltip_text = "center, north, south, east, west";
506 this.el.margin_top = 12;
507 this.el.visible = true;
510 // user defined functions
513 public class Xcls_kname : Object
516 private Xcls_PopoverProperty _this;
522 public Xcls_kname(Xcls_PopoverProperty _owner )
526 this.el = new Gtk.Entry();
530 // set gobject values
531 this.el.visible = true;
534 this.el.focus_out_event.connect( ()=>{
535 _this.error.setError("");
536 var val = this.el.get_text().strip();
537 if (val.length < 1) {
538 _this.error.setError("Name can not be empty");
542 this.el.key_release_event.connect( ()=>{
543 _this.error.setError("");
544 var val = this.el.get_text().strip();
545 if (val.length < 1) {
546 _this.error.setError("Name can not be empty");
552 // user defined functions
555 public class Xcls_error : Object
558 private Xcls_PopoverProperty _this;
564 public Xcls_error(Xcls_PopoverProperty _owner )
568 this.el = new Gtk.Label( "<span color=\"red\">Error Message</span>" );
572 // set gobject values
573 this.el.halign = Gtk.Align.START;
574 this.el.justify = Gtk.Justification.LEFT;
575 this.el.tooltip_text = "center, north, south, east, west";
576 this.el.margin_top = 0;
577 this.el.visible = true;
578 this.el.use_markup = true;
581 // user defined functions
582 public void setError (string err) {
588 this.el.label = "<span color=\"red\">" + err + "</span>";
593 public class Xcls_buttonbar : Object
596 private Xcls_PopoverProperty _this;
602 public Xcls_buttonbar(Xcls_PopoverProperty _owner )
605 _this.buttonbar = this;
606 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
610 // set gobject values
611 this.el.margin_top = 20;
612 var child_0 = new Xcls_Button14( _this );
614 this.el.add ( child_0.el );
615 var child_1 = new Xcls_Button16( _this );
617 this.el.add ( child_1.el );
620 // user defined functions
622 public class Xcls_Button14 : Object
624 public Gtk.Button el;
625 private Xcls_PopoverProperty _this;
631 public Xcls_Button14(Xcls_PopoverProperty _owner )
634 this.el = new Gtk.Button();
638 // set gobject values
639 this.el.hexpand = true;
640 this.el.always_show_image = true;
641 this.el.label = "Cancel";
642 var child_0 = new Xcls_Image15( _this );
644 this.el.image = child_0.el;
647 this.el.pressed.connect( () => {
650 _this.is_new = false;
651 _this.kname.el.set_text("Cancel");
657 // user defined functions
659 public class Xcls_Image15 : Object
662 private Xcls_PopoverProperty _this;
668 public Xcls_Image15(Xcls_PopoverProperty _owner )
671 this.el = new Gtk.Image();
675 // set gobject values
676 this.el.icon_name = "window-close";
679 // user defined functions
683 public class Xcls_Button16 : Object
685 public Gtk.Button el;
686 private Xcls_PopoverProperty _this;
692 public Xcls_Button16(Xcls_PopoverProperty _owner )
695 this.el = new Gtk.Button();
699 // set gobject values
700 this.el.hexpand = true;
701 this.el.always_show_image = true;
702 this.el.label = "Add Property";
703 var child_0 = new Xcls_Image17( _this );
705 this.el.image = child_0.el;
708 this.el.pressed.connect( () => {
709 // check if text is not empty..
710 if ( _this.kname.el.get_text().strip().length < 1) {
711 // error should already be showing?
716 // since we can't add listeners?!?!?
718 // check if property already exists in node.
719 var prop = _this.prop;
720 if (_this.node.props.has_key(prop.to_index_key())) {
721 _this.error.setError("Property already exists");
727 _this.is_new = false;
730 _this.prop = null; // skip checks..
734 // trigger editing of property.
735 // allow hide to work?
736 while (Gtk.events_pending()) {
737 Gtk.main_iteration();
740 _this.mainwindow.windowstate.left_props.addProp(prop);
746 // user defined functions
748 public class Xcls_Image17 : Object
751 private Xcls_PopoverProperty _this;
757 public Xcls_Image17(Xcls_PopoverProperty _owner )
760 this.el = new Gtk.Image();
764 // set gobject values
765 this.el.icon_name = "list-add";
768 // user defined functions