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_cancelbtn cancelbtn;
17 public Xcls_headertitle headertitle;
18 public Xcls_savebtn savebtn;
19 public Xcls_ptype ptype;
20 public Xcls_ktype ktype;
21 public Xcls_kname kname;
22 public Xcls_error error;
26 public Gtk.PositionType position;
27 public signal void success (Project.Project pr, JsRender.JsRender file);
28 public string key_type;
29 public Xcls_MainWindow mainwindow;
30 public JsRender.Node node;
31 public JsRender.NodeProp? original_prop;
32 public JsRender.NodeProp? prop;
34 public string old_keyname;
37 public Xcls_PopoverProperty()
40 this.el = new Gtk.Popover();
44 this.position = Gtk.PositionType.RIGHT;
45 this.mainwindow = null;
46 this.original_prop = null;
51 this.el.autohide = true;
52 var child_1 = new Xcls_Box1( _this );
54 this.el.set_child ( child_1.el );
57 this.el.closed.connect( () => {
59 GLib.debug("popover closed");
61 // dont allow hiding if we are creating a new one.
62 // on.hide will reshow it.
65 if (_this.prop == null) {
66 // hide and dont update.
69 if (this.kname.el.get_text().strip().length < 1) {
83 this.el.hide.connect( () => {
84 GLib.debug("popover hidden");
85 if (_this.is_new || this.kname.el.get_text().strip().length < 1) {
86 // dont allow hiding if we are creating a new one.
87 GLib.debug("prevent hiding as its new or text is empty");
92 if (this.original_prop != null && !this.prop.equals(this.original_prop)) {
93 // this is convoluted..
94 _this.mainwindow.windowstate.left_props.changed();
101 // user defined functions
102 public void updateProp () {
103 GLib.debug("updateProp called");
107 _this.prop.name = this.kname.el.get_text().strip();
108 _this.prop.ptype = this.ptype.getValue();
109 _this.prop.rtype = this.ktype.el.get_text().strip();
116 JsRender.NodeProp prop,
122 this.original_prop = prop.dupe();
123 this.is_new = is_new;
124 var pref = is_new ? "Add " : "Modify ";
125 if (prop.ptype == JsRender.NodePropType.LISTENER) {
126 this.headertitle.el.label = pref + "Event Listener"; // cant really happen yet?
128 this.headertitle.el.label = pref + "Property";
133 _this.kname.el.set_text(prop.name);
134 _this.ktype.el.set_text(prop.rtype);
136 _this.ptype.setValue(prop.ptype);
137 // does node have this property...
141 //console.log('show all');
143 GLib.debug("set parent = %s", btn.get_type().name());
144 var par = btn.get_parent();
147 GLib.debug("parent of that is null - not showing");
150 if (this.el.parent == null) {
151 this.el.set_parent(btn);
153 var r = Gdk.Rectangle() {
154 x = btn.get_width(), // align left...
159 //Gtk.Allocation rect;
160 //btn.get_allocation(out rect);
161 this.el.set_pointing_to(r);
167 r = Gdk.Rectangle() {
168 x = btn.get_width(), // align left...
173 this.el.set_pointing_to( r);
178 //this.el.set_position(Gtk.PositionType.TOP);
181 GLib.debug("SHOWALL - POPIP\n");
183 this.kname.el.grab_focus();
184 this.savebtn.el.set_label("Save");
185 this.cancelbtn.el.visible = false;
187 this.savebtn.el.set_label("Add Property");
188 this.cancelbtn.el.visible = true;
190 this.error.setError("");
192 //this.success = c.success;
195 public class Xcls_Box1 : Object
198 private Xcls_PopoverProperty _this;
204 public Xcls_Box1(Xcls_PopoverProperty _owner )
207 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
211 // set gobject values
212 this.el.homogeneous = false;
213 new Xcls_header( _this );
214 this.el.append( _this.header.el );
215 var child_2 = new Xcls_Label4( _this );
217 this.el.append( child_2.el );
218 new Xcls_ptype( _this );
219 this.el.append( _this.ptype.el );
220 var child_4 = new Xcls_Label7( _this );
222 this.el.append( child_4.el );
223 new Xcls_ktype( _this );
224 this.el.append( _this.ktype.el );
225 var child_6 = new Xcls_Label9( _this );
227 this.el.append( child_6.el );
228 new Xcls_kname( _this );
229 this.el.append( _this.kname.el );
230 new Xcls_error( _this );
231 this.el.append( _this.error.el );
234 // user defined functions
236 public class Xcls_header : Object
239 private Xcls_PopoverProperty _this;
245 public Xcls_header(Xcls_PopoverProperty _owner )
249 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
253 // set gobject values
254 new Xcls_cancelbtn( _this );
255 this.el.append( _this.cancelbtn.el );
256 new Xcls_headertitle( _this );
257 this.el.append( _this.headertitle.el );
258 new Xcls_savebtn( _this );
259 this.el.append( _this.savebtn.el );
262 // user defined functions
264 public class Xcls_cancelbtn : Object
266 public Gtk.Button el;
267 private Xcls_PopoverProperty _this;
271 public bool always_show_image;
274 public Xcls_cancelbtn(Xcls_PopoverProperty _owner )
277 _this.cancelbtn = this;
278 this.el = new Gtk.Button();
281 this.always_show_image = true;
283 // set gobject values
284 this.el.hexpand = true;
285 this.el.label = "Cancel";
288 this.el.clicked.connect( () => {
290 _this.is_new = false;
291 _this.kname.el.set_text("Cancel");
297 // user defined functions
300 public class Xcls_headertitle : Object
303 private Xcls_PopoverProperty _this;
309 public Xcls_headertitle(Xcls_PopoverProperty _owner )
312 _this.headertitle = this;
313 this.el = new Gtk.Label( "Add / Edit property" );
317 // set gobject values
318 this.el.hexpand = true;
321 // user defined functions
324 public class Xcls_savebtn : Object
326 public Gtk.Button el;
327 private Xcls_PopoverProperty _this;
331 public bool always_show_image;
334 public Xcls_savebtn(Xcls_PopoverProperty _owner )
337 _this.savebtn = this;
338 this.el = new Gtk.Button();
341 this.always_show_image = true;
343 // set gobject values
344 this.el.hexpand = true;
345 this.el.label = "Add Property";
348 this.el.clicked.connect( () => {
353 // check if text is not empty..
354 if ( _this.kname.el.get_text().strip().length < 1) {
356 // error should already be showing?
360 // since we can't add listeners?!?!?
362 // check if property already exists in node.
365 var prop = new JsRender.NodeProp(
366 _this.kname.el.get_text().strip(),
367 _this.ptype.getValue(),
368 _this.ktype.el.get_text().strip(),
372 if (_this.node.props.has_key(prop.to_index_key())) {
373 _this.error.setError("Property already exists");
379 _this.node.add_prop(prop);
381 _this.prop = null; // skip checks..
382 _this.is_new = false;
384 _this.mainwindow.windowstate.left_props.changed();
385 _this.mainwindow.windowstate.left_props.view.editProp(prop);
392 // user defined functions
396 public class Xcls_Label4 : Object
399 private Xcls_PopoverProperty _this;
405 public Xcls_Label4(Xcls_PopoverProperty _owner )
408 this.el = new Gtk.Label( "Property Type (eg. property or method)" );
412 // set gobject values
413 this.el.halign = Gtk.Align.START;
414 this.el.justify = Gtk.Justification.LEFT;
415 this.el.margin_top = 12;
416 this.el.visible = true;
419 // user defined functions
422 public class Xcls_ptype : Object
424 public Gtk.DropDown el;
425 private Xcls_PopoverProperty _this;
431 public Xcls_ptype(Xcls_PopoverProperty _owner )
435 var child_1 = new Xcls_StringList6( _this );
437 this.el = new Gtk.DropDown( child_1.el, null );
441 // set gobject values
442 this.el.show_arrow = true;
445 this.el.notify["selected"].connect( () => {
447 _this.el.grab_focus(); // stop prevent autohide breaking.
451 // user defined functions
452 public JsRender.NodePropType getValue () {
453 var sl = this.el.model as Gtk.StringList;
454 var str = sl.get_string(this.el.selected);
455 return JsRender.NodePropType.nameToType(str);
457 public void setValue (JsRender.NodePropType ty) {
458 var str = ty.to_name();
459 var sl = this.el.model as Gtk.StringList;
460 for(var i = 0; i < sl.get_n_items(); i++) {
461 if(sl.get_string(i) == str) {
462 this.el.set_selected(i);
469 public class Xcls_StringList6 : Object
471 public Gtk.StringList el;
472 private Xcls_PopoverProperty _this;
478 public Xcls_StringList6(Xcls_PopoverProperty _owner )
481 this.el = new Gtk.StringList( JsRender.NodePropType.get_pulldown_list() );
485 // set gobject values
488 // user defined functions
492 public class Xcls_Label7 : Object
495 private Xcls_PopoverProperty _this;
501 public Xcls_Label7(Xcls_PopoverProperty _owner )
504 this.el = new Gtk.Label( "Type or Return Type" );
508 // set gobject values
509 this.el.halign = Gtk.Align.START;
510 this.el.justify = Gtk.Justification.LEFT;
511 this.el.margin_top = 12;
512 this.el.visible = true;
515 // user defined functions
518 public class Xcls_ktype : Object
521 private Xcls_PopoverProperty _this;
527 public Xcls_ktype(Xcls_PopoverProperty _owner )
531 this.el = new Gtk.Entry();
535 // set gobject values
536 this.el.visible = true;
539 // user defined functions
542 public class Xcls_Label9 : Object
545 private Xcls_PopoverProperty _this;
551 public Xcls_Label9(Xcls_PopoverProperty _owner )
554 this.el = new Gtk.Label( "Name" );
558 // set gobject values
559 this.el.halign = Gtk.Align.START;
560 this.el.justify = Gtk.Justification.LEFT;
561 this.el.tooltip_text = "center, north, south, east, west";
562 this.el.margin_top = 12;
563 this.el.visible = true;
566 // user defined functions
569 public class Xcls_kname : Object
572 private Xcls_PopoverProperty _this;
578 public Xcls_kname(Xcls_PopoverProperty _owner )
582 this.el = new Gtk.Entry();
586 // set gobject values
587 this.el.visible = true;
588 var child_1 = new Xcls_EventControllerFocus11( _this );
590 this.el.add_controller( child_1.el );
591 var child_2 = new Xcls_EventControllerKey12( _this );
593 this.el.add_controller( child_2.el );
596 // user defined functions
598 public class Xcls_EventControllerFocus11 : Object
600 public Gtk.EventControllerFocus el;
601 private Xcls_PopoverProperty _this;
607 public Xcls_EventControllerFocus11(Xcls_PopoverProperty _owner )
610 this.el = new Gtk.EventControllerFocus();
614 // set gobject values
617 this.el.leave.connect( ( ) => {
619 _this.error.setError("");
620 var val = _this.kname.el.get_text().strip();
621 if (val.length < 1) {
622 _this.error.setError("Name can not be empty");
628 // user defined functions
631 public class Xcls_EventControllerKey12 : Object
633 public Gtk.EventControllerKey el;
634 private Xcls_PopoverProperty _this;
640 public Xcls_EventControllerKey12(Xcls_PopoverProperty _owner )
643 this.el = new Gtk.EventControllerKey();
647 // set gobject values
650 this.el.key_released.connect( (keyval, keycode, state) => {
652 _this.error.setError("");
653 var val = _this.kname.el.get_text().strip();
654 if (val.length < 1) {
655 _this.error.setError("Name can not be empty");
661 // user defined functions
665 public class Xcls_error : Object
668 private Xcls_PopoverProperty _this;
674 public Xcls_error(Xcls_PopoverProperty _owner )
678 this.el = new Gtk.Label( "<span color=\"red\">Error Message</span>" );
682 // set gobject values
683 this.el.halign = Gtk.Align.START;
684 this.el.justify = Gtk.Justification.LEFT;
685 this.el.tooltip_text = "center, north, south, east, west";
686 this.el.margin_top = 0;
687 this.el.visible = true;
688 this.el.use_markup = true;
691 // user defined functions
692 public void setError (string err) {
698 this.el.label = "<span color=\"red\">" + err + "</span>";