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;
25 public string old_keyname;
27 public signal void success (Project.Project pr, JsRender.JsRender file);
29 public JsRender.NodeProp? prop;
30 public Xcls_MainWindow mainwindow;
31 public string key_type;
32 public JsRender.Node node;
35 public Xcls_PopoverProperty()
38 this.el = new Gtk.Popover( null );
43 this.mainwindow = null;
46 this.el.border_width = 0;
48 this.el.position = Gtk.PositionType.LEFT;
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
109 JsRender.NodeProp prop,
116 this.is_new = is_new;
117 var pref = is_new ? "Add " : "Modify ";
118 if (prop.ptype == JsRender.NodePropType.LISTENER) {
119 this.header.el.title = pref + "Event Listener"; // cant really happen yet?
121 this.header.el.title = pref + "Property";
126 _this.kname.el.set_text(prop.name);
127 _this.ktype.el.set_text(prop.rtype);
129 _this.dbmodel.loadData(prop );
130 // does node have this property...
134 //console.log('show all');
135 this.el.set_modal(true);
136 this.el.set_relative_to(btn);
138 var r = Gdk.Rectangle() {
139 x = 0, // align left...
144 this.el.set_pointing_to( r);
149 //this.el.set_position(Gtk.PositionType.TOP);
152 print("SHOWALL - POPIP\n");
154 this.kname.el.grab_focus();
155 this.buttonbar.el.hide();
157 this.buttonbar.el.show();
159 this.error.setError("");
161 //this.success = c.success;
164 public void updateProp () {
168 this.kflag.el.get_active_iter(out citer);
169 this.dbmodel.el.get_value(citer, 0, out gval);
172 _this.prop.name = this.kname.el.get_text().strip();
173 _this.prop.rtype = this.ktype.el.get_text().strip();
174 _this.prop.ptype = (JsRender.NodePropType) gval;
177 public class Xcls_Box2 : Object
180 private Xcls_PopoverProperty _this;
186 public Xcls_Box2(Xcls_PopoverProperty _owner )
189 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
193 // set gobject values
194 this.el.homogeneous = false;
195 var child_0 = new Xcls_header( _this );
197 this.el.pack_start ( child_0.el , false,true,0 );
198 var child_1 = new Xcls_Label4( _this );
200 this.el.add ( child_1.el );
201 var child_2 = new Xcls_kflag( _this );
203 this.el.add ( child_2.el );
204 var child_3 = new Xcls_Label8( _this );
206 this.el.add ( child_3.el );
207 var child_4 = new Xcls_ktype( _this );
209 this.el.add ( child_4.el );
210 var child_5 = new Xcls_Label10( _this );
212 this.el.add ( child_5.el );
213 var child_6 = new Xcls_kname( _this );
215 this.el.add ( child_6.el );
216 var child_7 = new Xcls_error( _this );
218 this.el.add ( child_7.el );
219 var child_8 = new Xcls_buttonbar( _this );
221 this.el.add ( child_8.el );
224 // user defined functions
226 public class Xcls_header : Object
228 public Gtk.HeaderBar el;
229 private Xcls_PopoverProperty _this;
235 public Xcls_header(Xcls_PopoverProperty _owner )
239 this.el = new Gtk.HeaderBar();
243 // set gobject values
244 this.el.title = "Modify / Create Property";
247 // user defined functions
250 public class Xcls_Label4 : Object
253 private Xcls_PopoverProperty _this;
259 public Xcls_Label4(Xcls_PopoverProperty _owner )
262 this.el = new Gtk.Label( "Special Flags" );
266 // set gobject values
267 this.el.halign = Gtk.Align.START;
268 this.el.justify = Gtk.Justification.LEFT;
269 this.el.margin_top = 12;
272 // user defined functions
275 public class Xcls_kflag : Object
277 public Gtk.ComboBox el;
278 private Xcls_PopoverProperty _this;
284 public Xcls_kflag(Xcls_PopoverProperty _owner )
288 this.el = new Gtk.ComboBox();
292 // set gobject values
293 var child_0 = new Xcls_dbcellrenderer( _this );
295 this.el.pack_start ( child_0.el , true );
296 var child_1 = new Xcls_dbmodel( _this );
298 this.el.set_model ( child_1.el );
302 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
305 // user defined functions
307 public class Xcls_dbcellrenderer : Object
309 public Gtk.CellRendererText el;
310 private Xcls_PopoverProperty _this;
316 public Xcls_dbcellrenderer(Xcls_PopoverProperty _owner )
319 _this.dbcellrenderer = this;
320 this.el = new Gtk.CellRendererText();
324 // set gobject values
327 // user defined functions
330 public class Xcls_dbmodel : Object
332 public Gtk.ListStore el;
333 private Xcls_PopoverProperty _this;
339 public Xcls_dbmodel(Xcls_PopoverProperty _owner )
342 _this.dbmodel = this;
343 this.el = new Gtk.ListStore( 2, typeof(JsRender.NodePropType),typeof(string) );
347 // set gobject values
350 // user defined functions
351 public void loadData (JsRender.NodeProp prop) {
359 // user defined property '#'
360 // user defined method '|'
361 // special property '*' => prop |args|ctor|init
365 /// el.append(out iter);
368 // el.set_value(iter, 0, "");
369 // el.set_value(iter, 1, "aaa - Just add Element - aaa");
372 if (prop.ptype == JsRender.NodePropType.LISTENER) {
374 el.set(iter, 0, JsRender.NodePropType.LISTENER, 1, "Event Handler / Listener", -1);
376 else if (_this.mainwindow.windowstate.file.xtype == "Gtk") {
378 el.set(iter, 0, JsRender.NodePropType.PROP, 1, "Normal Property", -1);
382 el.set(iter, 0, JsRender.NodePropType.RAW, 1, "Raw Property (not escaped)", -1);
386 el.set(iter, 0, JsRender.NodePropType.USER, 1, "User defined property", -1);
389 el.set(iter, 0, JsRender.NodePropType.METHOD, 1, "User defined method", -1);
392 el.set(iter, 0, JsRender.NodePropType.SPECIAL, 1, "Special property (eg. prop | args | ctor | init )", -1);
396 el.set(iter, 0, JsRender.NodePropType.SIGNAL, 1, "Vala Signal", -1);
402 el.set(iter, 0, JsRender.NodePropType.PROP, 1, "Normal Property", -1);
405 el.set(iter, 0, JsRender.NodePropType.RAW, 1, "Raw Property (not escaped)", -1);
408 el.set(iter, 0, JsRender.NodePropType.METHOD, 1, "User defined method", -1);
411 el.set(iter, 0, JsRender.NodePropType.SPECIAL, 1, "(*) Special property (eg. prop )", -1);
415 // set selected, based on arg
416 el.foreach((tm, tp, titer) => {
418 el.get_value(titer, 0, out val);
420 //print("check %s against %s\n", (string)val, _this.prop.ptype);
421 if (((JsRender.NodePropType)val) == prop.ptype) {
422 _this.kflag.el.set_active_iter(titer);
434 public class Xcls_Label8 : Object
437 private Xcls_PopoverProperty _this;
443 public Xcls_Label8(Xcls_PopoverProperty _owner )
446 this.el = new Gtk.Label( "Type or Return Type" );
450 // set gobject values
451 this.el.halign = Gtk.Align.START;
452 this.el.justify = Gtk.Justification.LEFT;
453 this.el.margin_top = 12;
454 this.el.visible = true;
457 // user defined functions
460 public class Xcls_ktype : Object
463 private Xcls_PopoverProperty _this;
469 public Xcls_ktype(Xcls_PopoverProperty _owner )
473 this.el = new Gtk.Entry();
477 // set gobject values
478 this.el.visible = true;
481 // user defined functions
484 public class Xcls_Label10 : Object
487 private Xcls_PopoverProperty _this;
493 public Xcls_Label10(Xcls_PopoverProperty _owner )
496 this.el = new Gtk.Label( "Name" );
500 // set gobject values
501 this.el.halign = Gtk.Align.START;
502 this.el.justify = Gtk.Justification.LEFT;
503 this.el.tooltip_text = "center, north, south, east, west";
504 this.el.margin_top = 12;
505 this.el.visible = true;
508 // user defined functions
511 public class Xcls_kname : Object
514 private Xcls_PopoverProperty _this;
520 public Xcls_kname(Xcls_PopoverProperty _owner )
524 this.el = new Gtk.Entry();
528 // set gobject values
529 this.el.visible = true;
532 this.el.focus_out_event.connect( ()=>{
533 _this.error.setError("");
534 var val = this.el.get_text().strip();
535 if (val.length < 1) {
536 _this.error.setError("Name can not be empty");
540 this.el.key_release_event.connect( ()=>{
541 _this.error.setError("");
542 var val = this.el.get_text().strip();
543 if (val.length < 1) {
544 _this.error.setError("Name can not be empty");
550 // user defined functions
553 public class Xcls_error : Object
556 private Xcls_PopoverProperty _this;
562 public Xcls_error(Xcls_PopoverProperty _owner )
566 this.el = new Gtk.Label( "<span color=\"red\">Error Message</span>" );
570 // set gobject values
571 this.el.halign = Gtk.Align.START;
572 this.el.justify = Gtk.Justification.LEFT;
573 this.el.tooltip_text = "center, north, south, east, west";
574 this.el.margin_top = 0;
575 this.el.visible = true;
576 this.el.use_markup = true;
579 // user defined functions
580 public void setError (string err) {
586 this.el.label = "<span color=\"red\">" + err + "</span>";
591 public class Xcls_buttonbar : Object
594 private Xcls_PopoverProperty _this;
600 public Xcls_buttonbar(Xcls_PopoverProperty _owner )
603 _this.buttonbar = this;
604 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
608 // set gobject values
609 this.el.margin_top = 20;
610 var child_0 = new Xcls_Button14( _this );
612 this.el.add ( child_0.el );
613 var child_1 = new Xcls_Button16( _this );
615 this.el.add ( child_1.el );
618 // user defined functions
620 public class Xcls_Button14 : Object
622 public Gtk.Button el;
623 private Xcls_PopoverProperty _this;
629 public Xcls_Button14(Xcls_PopoverProperty _owner )
632 this.el = new Gtk.Button();
636 // set gobject values
637 this.el.hexpand = true;
638 this.el.always_show_image = true;
639 this.el.label = "Cancel";
640 var child_0 = new Xcls_Image15( _this );
642 this.el.image = child_0.el;
645 this.el.pressed.connect( () => {
648 _this.is_new = false;
649 _this.kname.el.set_text("Cancel");
655 // user defined functions
657 public class Xcls_Image15 : Object
660 private Xcls_PopoverProperty _this;
666 public Xcls_Image15(Xcls_PopoverProperty _owner )
669 this.el = new Gtk.Image();
673 // set gobject values
674 this.el.icon_name = "window-close";
677 // user defined functions
681 public class Xcls_Button16 : Object
683 public Gtk.Button el;
684 private Xcls_PopoverProperty _this;
690 public Xcls_Button16(Xcls_PopoverProperty _owner )
693 this.el = new Gtk.Button();
697 // set gobject values
698 this.el.hexpand = true;
699 this.el.always_show_image = true;
700 this.el.label = "Add Property";
701 var child_0 = new Xcls_Image17( _this );
703 this.el.image = child_0.el;
706 this.el.pressed.connect( () => {
707 // check if text is not empty..
708 if ( _this.kname.el.get_text().strip().length < 1) {
709 // error should already be showing?
714 // since we can't add listeners?!?!?
716 // check if property already exists in node.
717 var prop = _this.prop;
718 if (_this.node.props.has_key(prop.to_index_key())) {
719 _this.error.setError("Property already exists");
725 _this.is_new = false;
728 _this.prop = null; // skip checks..
732 // trigger editing of property.
733 // allow hide to work?
734 while (Gtk.events_pending()) {
735 Gtk.main_iteration();
738 _this.mainwindow.windowstate.left_props.addProp(prop);
744 // user defined functions
746 public class Xcls_Image17 : Object
749 private Xcls_PopoverProperty _this;
755 public Xcls_Image17(Xcls_PopoverProperty _owner )
758 this.el = new Gtk.Image();
762 // set gobject values
763 this.el.icon_name = "list-add";
766 // user defined functions