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_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;
27 public signal void success (Project.Project pr, JsRender.JsRender file);
28 public string key_type;
29 public JsRender.NodeProp? prop;
31 public Xcls_MainWindow mainwindow;
32 public JsRender.Node node;
33 public string old_keyname;
36 public Xcls_PopoverProperty()
39 this.el = new Gtk.Popover();
44 this.mainwindow = null;
47 this.el.autohide = true;
48 this.el.position = Gtk.PositionType.RIGHT;
49 var child_1 = new Xcls_Box2( _this );
51 this.el.set_child ( child_1.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) {
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");
93 // user defined functions
94 public void updateProp () {
95 GLib.debug("updateProp called");
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();
108 JsRender.NodeProp prop,
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?
120 this.headertitle.el.label = pref + "Property";
125 _this.kname.el.set_text(prop.name);
126 _this.ktype.el.set_text(prop.rtype);
128 _this.ptype.setValue(prop.ptype);
129 // does node have this property...
133 //console.log('show all');
135 GLib.debug("set parent = %s", btn.get_type().name());
136 var par = btn.get_parent();
139 GLib.debug("parent of that is null - not showing");
142 if (this.el.parent == null) {
143 this.el.set_parent(btn);
145 var r = Gdk.Rectangle() {
146 x = btn.get_width(), // align left...
151 //Gtk.Allocation rect;
152 //btn.get_allocation(out rect);
153 this.el.set_pointing_to(r);
159 r = Gdk.Rectangle() {
160 x = btn.get_width(), // align left...
165 this.el.set_pointing_to( r);
170 //this.el.set_position(Gtk.PositionType.TOP);
173 GLib.debug("SHOWALL - POPIP\n");
175 this.kname.el.grab_focus();
176 this.buttonbar.el.hide();
178 this.buttonbar.el.show();
180 this.error.setError("");
182 //this.success = c.success;
185 public class Xcls_Box2 : Object
188 private Xcls_PopoverProperty _this;
194 public Xcls_Box2(Xcls_PopoverProperty _owner )
197 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
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 );
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 );
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 );
223 // user defined functions
225 public class Xcls_header : Object
227 public Gtk.HeaderBar el;
228 private Xcls_PopoverProperty _this;
234 public Xcls_header(Xcls_PopoverProperty _owner )
238 this.el = new Gtk.HeaderBar();
242 // set gobject values
243 this.el.show_title_buttons = false;
244 new Xcls_headertitle( _this );
245 this.el.title_widget = _this.headertitle.el;
248 // user defined functions
250 public class Xcls_headertitle : Object
253 private Xcls_PopoverProperty _this;
259 public Xcls_headertitle(Xcls_PopoverProperty _owner )
262 _this.headertitle = this;
263 this.el = new Gtk.Label( "Add / Edit property" );
267 // set gobject values
270 // user defined functions
274 public class Xcls_ptype : Object
276 public Gtk.ColumnView el;
277 private Xcls_PopoverProperty _this;
281 public bool show_separators;
284 public Xcls_ptype(Xcls_PopoverProperty _owner )
288 new Xcls_pselmodel( _this );
289 this.el = new Gtk.ColumnView( _this.pselmodel.el );
292 this.show_separators = true;
294 // set gobject values
295 this.el.show_row_separators = true;
296 var child_2 = new Xcls_ColumnViewColumn8( _this );
298 this.el.append_column ( child_2.el );
301 // user defined functions
302 public JsRender.NodePropType getValue () {
304 var li = (JsRender.NodeProp) _this.pmodel.el.get_item(
305 _this.pselmodel.el.get_selected()
310 public void setValue (JsRender.NodePropType pt)
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);
319 GLib.debug("failed to set selected ptype");
320 _this.pselmodel.el.set_selected(0);
323 public class Xcls_pselmodel : Object
325 public Gtk.SingleSelection el;
326 private Xcls_PopoverProperty _this;
332 public Xcls_pselmodel(Xcls_PopoverProperty _owner )
335 _this.pselmodel = this;
336 new Xcls_pmodel( _this );
337 this.el = new Gtk.SingleSelection( _this.pmodel.el );
341 // set gobject values
344 // user defined functions
346 public class Xcls_pmodel : Object
348 public GLib.ListStore el;
349 private Xcls_PopoverProperty _this;
355 public Xcls_pmodel(Xcls_PopoverProperty _owner )
359 this.el = new GLib.ListStore(typeof(JsRender.NodeProp));;
363 // set gobject values
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(""));
382 // user defined functions
386 public class Xcls_ColumnViewColumn8 : Object
388 public Gtk.ColumnViewColumn el;
389 private Xcls_PopoverProperty _this;
395 public Xcls_ColumnViewColumn8(Xcls_PopoverProperty _owner )
398 var child_1 = new Xcls_SignalListItemFactory9( _this );
400 this.el = new Gtk.ColumnViewColumn( "Property Type", child_1.el );
404 // set gobject values
407 // user defined functions
409 public class Xcls_SignalListItemFactory9 : Object
411 public Gtk.SignalListItemFactory el;
412 private Xcls_PopoverProperty _this;
418 public Xcls_SignalListItemFactory9(Xcls_PopoverProperty _owner )
421 this.el = new Gtk.SignalListItemFactory();
425 // set gobject values
428 this.el.setup.connect( (listitem) => {
431 var label = new Gtk.Label("");
434 ((Gtk.ListItem)listitem).set_child(label);
435 ((Gtk.ListItem)listitem).activatable = false;
438 this.el.bind.connect( (listitem) => {
440 var lbl = (Gtk.Label) ((Gtk.ListItem)listitem).get_child();
441 var np = (JsRender.NodeProp)((Gtk.ListItem)listitem).get_item();
445 lbl.label = np.ptype.to_name();
450 // user defined functions
455 public class Xcls_Label10 : Object
458 private Xcls_PopoverProperty _this;
464 public Xcls_Label10(Xcls_PopoverProperty _owner )
467 this.el = new Gtk.Label( "Type or Return Type" );
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;
478 // user defined functions
481 public class Xcls_ktype : Object
484 private Xcls_PopoverProperty _this;
490 public Xcls_ktype(Xcls_PopoverProperty _owner )
494 this.el = new Gtk.Entry();
498 // set gobject values
499 this.el.visible = true;
502 // user defined functions
505 public class Xcls_Label12 : Object
508 private Xcls_PopoverProperty _this;
514 public Xcls_Label12(Xcls_PopoverProperty _owner )
517 this.el = new Gtk.Label( "Name" );
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;
529 // user defined functions
532 public class Xcls_kname : Object
535 private Xcls_PopoverProperty _this;
541 public Xcls_kname(Xcls_PopoverProperty _owner )
545 this.el = new Gtk.Entry();
549 // set gobject values
550 this.el.visible = true;
551 var child_1 = new Xcls_EventControllerFocus14( _this );
553 this.el.add_controller( child_1.el );
554 var child_2 = new Xcls_EventControllerKey15( _this );
556 this.el.add_controller( child_2.el );
559 // user defined functions
561 public class Xcls_EventControllerFocus14 : Object
563 public Gtk.EventControllerFocus el;
564 private Xcls_PopoverProperty _this;
570 public Xcls_EventControllerFocus14(Xcls_PopoverProperty _owner )
573 this.el = new Gtk.EventControllerFocus();
577 // set gobject values
580 this.el.leave.connect( ( ) => {
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");
591 // user defined functions
594 public class Xcls_EventControllerKey15 : Object
596 public Gtk.EventControllerKey el;
597 private Xcls_PopoverProperty _this;
603 public Xcls_EventControllerKey15(Xcls_PopoverProperty _owner )
606 this.el = new Gtk.EventControllerKey();
610 // set gobject values
613 this.el.key_released.connect( (keyval, keycode, state) => {
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");
624 // user defined functions
628 public class Xcls_error : Object
631 private Xcls_PopoverProperty _this;
637 public Xcls_error(Xcls_PopoverProperty _owner )
641 this.el = new Gtk.Label( "<span color=\"red\">Error Message</span>" );
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;
654 // user defined functions
655 public void setError (string err) {
661 this.el.label = "<span color=\"red\">" + err + "</span>";
666 public class Xcls_buttonbar : Object
669 private Xcls_PopoverProperty _this;
675 public Xcls_buttonbar(Xcls_PopoverProperty _owner )
678 _this.buttonbar = this;
679 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
683 // set gobject values
684 this.el.margin_top = 20;
685 var child_1 = new Xcls_Button18( _this );
687 this.el.append( child_1.el );
688 var child_2 = new Xcls_Button19( _this );
690 this.el.append( child_2.el );
693 // user defined functions
695 public class Xcls_Button18 : Object
697 public Gtk.Button el;
698 private Xcls_PopoverProperty _this;
702 public bool always_show_image;
705 public Xcls_Button18(Xcls_PopoverProperty _owner )
708 this.el = new Gtk.Button();
711 this.always_show_image = true;
713 // set gobject values
714 this.el.hexpand = true;
715 this.el.label = "Cancel";
718 this.el.clicked.connect( () => {
720 _this.is_new = false;
721 _this.kname.el.set_text("Cancel");
727 // user defined functions
730 public class Xcls_Button19 : Object
732 public Gtk.Button el;
733 private Xcls_PopoverProperty _this;
737 public bool always_show_image;
740 public Xcls_Button19(Xcls_PopoverProperty _owner )
743 this.el = new Gtk.Button();
746 this.always_show_image = true;
748 // set gobject values
749 this.el.hexpand = true;
750 this.el.label = "Add Property";
753 this.el.clicked.connect( () => {
754 // check if text is not empty..
755 if ( _this.kname.el.get_text().strip().length < 1) {
757 // error should already be showing?
761 // since we can't add listeners?!?!?
763 // check if property already exists in node.
766 var prop = new JsRender.NodeProp(
767 _this.kname.el.get_text().strip(),
768 _this.ptype.getValue(),
769 _this.ktype.el.get_text().strip(),
773 if (_this.node.props.has_key(prop.to_index_key())) {
774 _this.error.setError("Property already exists");
780 _this.node.add_prop(prop);
782 _this.prop = null; // skip checks..
783 _this.is_new = false;
786 _this.mainwindow.windowstate.left_props.view.editProp(prop);
793 // user defined functions