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 Gtk.PositionType position;
28 public signal void success (Project.Project pr, JsRender.JsRender file);
29 public string key_type;
30 public JsRender.NodeProp? prop;
32 public Xcls_MainWindow mainwindow;
33 public JsRender.Node node;
34 public JsRender.NodeProp? original_prop;
35 public string old_keyname;
38 public Xcls_PopoverProperty()
41 this.el = new Gtk.Popover();
45 this.position = Gtk.PositionType.RIGHT;
48 this.mainwindow = null;
49 this.original_prop = null;
52 this.el.autohide = true;
53 var child_1 = new Xcls_Box2( _this );
55 this.el.set_child ( child_1.el );
58 this.el.closed.connect( () => {
60 GLib.debug("popover closed");
62 // dont allow hiding if we are creating a new one.
63 // on.hide will reshow it.
66 if (_this.prop == null) {
67 // hide and dont update.
70 if (this.kname.el.get_text().strip().length < 1) {
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");
93 if (this.original_prop != null && !this.prop.equals(this.original_prop)) {
94 // this is convoluted..
95 _this.mainwindow.windowstate.left_props.changed();
102 // user defined functions
103 public void updateProp () {
104 GLib.debug("updateProp called");
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();
117 JsRender.NodeProp prop,
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?
129 this.headertitle.el.label = pref + "Property";
134 _this.kname.el.set_text(prop.name);
135 _this.ktype.el.set_text(prop.rtype);
137 _this.ptype.setValue(prop.ptype);
138 // does node have this property...
142 //console.log('show all');
144 GLib.debug("set parent = %s", btn.get_type().name());
145 var par = btn.get_parent();
148 GLib.debug("parent of that is null - not showing");
151 if (this.el.parent == null) {
152 this.el.set_parent(btn);
154 var r = Gdk.Rectangle() {
155 x = btn.get_width(), // align left...
160 //Gtk.Allocation rect;
161 //btn.get_allocation(out rect);
162 this.el.set_pointing_to(r);
168 r = Gdk.Rectangle() {
169 x = btn.get_width(), // align left...
174 this.el.set_pointing_to( r);
179 //this.el.set_position(Gtk.PositionType.TOP);
182 GLib.debug("SHOWALL - POPIP\n");
184 this.kname.el.grab_focus();
185 this.buttonbar.el.hide();
187 this.buttonbar.el.show();
189 this.error.setError("");
191 //this.success = c.success;
194 public class Xcls_Box2 : Object
197 private Xcls_PopoverProperty _this;
203 public Xcls_Box2(Xcls_PopoverProperty _owner )
206 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
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 );
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 );
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 );
232 // user defined functions
234 public class Xcls_header : Object
236 public Gtk.HeaderBar el;
237 private Xcls_PopoverProperty _this;
243 public Xcls_header(Xcls_PopoverProperty _owner )
247 this.el = new Gtk.HeaderBar();
251 // set gobject values
252 this.el.show_title_buttons = false;
253 new Xcls_headertitle( _this );
254 this.el.title_widget = _this.headertitle.el;
257 // user defined functions
259 public class Xcls_headertitle : Object
262 private Xcls_PopoverProperty _this;
268 public Xcls_headertitle(Xcls_PopoverProperty _owner )
271 _this.headertitle = this;
272 this.el = new Gtk.Label( "Add / Edit property" );
276 // set gobject values
279 // user defined functions
283 public class Xcls_ptype : Object
285 public Gtk.ColumnView el;
286 private Xcls_PopoverProperty _this;
290 public bool show_separators;
293 public Xcls_ptype(Xcls_PopoverProperty _owner )
297 new Xcls_pselmodel( _this );
298 this.el = new Gtk.ColumnView( _this.pselmodel.el );
301 this.show_separators = true;
303 // set gobject values
304 this.el.show_row_separators = true;
305 var child_2 = new Xcls_ColumnViewColumn8( _this );
307 this.el.append_column ( child_2.el );
310 // user defined functions
311 public JsRender.NodePropType getValue () {
313 var li = (JsRender.NodeProp) _this.pmodel.el.get_item(
314 _this.pselmodel.el.get_selected()
319 public void setValue (JsRender.NodePropType pt)
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);
328 GLib.debug("failed to set selected ptype");
329 _this.pselmodel.el.set_selected(0);
332 public class Xcls_pselmodel : Object
334 public Gtk.SingleSelection el;
335 private Xcls_PopoverProperty _this;
341 public Xcls_pselmodel(Xcls_PopoverProperty _owner )
344 _this.pselmodel = this;
345 new Xcls_pmodel( _this );
346 this.el = new Gtk.SingleSelection( _this.pmodel.el );
350 // set gobject values
353 // user defined functions
355 public class Xcls_pmodel : Object
357 public GLib.ListStore el;
358 private Xcls_PopoverProperty _this;
364 public Xcls_pmodel(Xcls_PopoverProperty _owner )
368 this.el = new GLib.ListStore(typeof(JsRender.NodeProp));;
372 // set gobject values
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(""));
391 // user defined functions
395 public class Xcls_ColumnViewColumn8 : Object
397 public Gtk.ColumnViewColumn el;
398 private Xcls_PopoverProperty _this;
404 public Xcls_ColumnViewColumn8(Xcls_PopoverProperty _owner )
407 var child_1 = new Xcls_SignalListItemFactory9( _this );
409 this.el = new Gtk.ColumnViewColumn( "Property Type", child_1.el );
413 // set gobject values
416 // user defined functions
418 public class Xcls_SignalListItemFactory9 : Object
420 public Gtk.SignalListItemFactory el;
421 private Xcls_PopoverProperty _this;
427 public Xcls_SignalListItemFactory9(Xcls_PopoverProperty _owner )
430 this.el = new Gtk.SignalListItemFactory();
434 // set gobject values
437 this.el.setup.connect( (listitem) => {
440 var label = new Gtk.Label("");
443 ((Gtk.ListItem)listitem).set_child(label);
444 ((Gtk.ListItem)listitem).activatable = false;
447 this.el.bind.connect( (listitem) => {
449 var lbl = (Gtk.Label) ((Gtk.ListItem)listitem).get_child();
450 var np = (JsRender.NodeProp)((Gtk.ListItem)listitem).get_item();
454 lbl.label = np.ptype.to_name();
459 // user defined functions
464 public class Xcls_Label10 : Object
467 private Xcls_PopoverProperty _this;
473 public Xcls_Label10(Xcls_PopoverProperty _owner )
476 this.el = new Gtk.Label( "Type or Return Type" );
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;
487 // user defined functions
490 public class Xcls_ktype : Object
493 private Xcls_PopoverProperty _this;
499 public Xcls_ktype(Xcls_PopoverProperty _owner )
503 this.el = new Gtk.Entry();
507 // set gobject values
508 this.el.visible = true;
511 // user defined functions
514 public class Xcls_Label12 : Object
517 private Xcls_PopoverProperty _this;
523 public Xcls_Label12(Xcls_PopoverProperty _owner )
526 this.el = new Gtk.Label( "Name" );
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;
538 // user defined functions
541 public class Xcls_kname : Object
544 private Xcls_PopoverProperty _this;
550 public Xcls_kname(Xcls_PopoverProperty _owner )
554 this.el = new Gtk.Entry();
558 // set gobject values
559 this.el.visible = true;
560 var child_1 = new Xcls_EventControllerFocus14( _this );
562 this.el.add_controller( child_1.el );
563 var child_2 = new Xcls_EventControllerKey15( _this );
565 this.el.add_controller( child_2.el );
568 // user defined functions
570 public class Xcls_EventControllerFocus14 : Object
572 public Gtk.EventControllerFocus el;
573 private Xcls_PopoverProperty _this;
579 public Xcls_EventControllerFocus14(Xcls_PopoverProperty _owner )
582 this.el = new Gtk.EventControllerFocus();
586 // set gobject values
589 this.el.leave.connect( ( ) => {
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");
600 // user defined functions
603 public class Xcls_EventControllerKey15 : Object
605 public Gtk.EventControllerKey el;
606 private Xcls_PopoverProperty _this;
612 public Xcls_EventControllerKey15(Xcls_PopoverProperty _owner )
615 this.el = new Gtk.EventControllerKey();
619 // set gobject values
622 this.el.key_released.connect( (keyval, keycode, state) => {
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");
633 // user defined functions
637 public class Xcls_error : Object
640 private Xcls_PopoverProperty _this;
646 public Xcls_error(Xcls_PopoverProperty _owner )
650 this.el = new Gtk.Label( "<span color=\"red\">Error Message</span>" );
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;
663 // user defined functions
664 public void setError (string err) {
670 this.el.label = "<span color=\"red\">" + err + "</span>";
675 public class Xcls_buttonbar : Object
678 private Xcls_PopoverProperty _this;
684 public Xcls_buttonbar(Xcls_PopoverProperty _owner )
687 _this.buttonbar = this;
688 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
692 // set gobject values
693 this.el.margin_top = 20;
694 var child_1 = new Xcls_Button18( _this );
696 this.el.append( child_1.el );
697 var child_2 = new Xcls_Button19( _this );
699 this.el.append( child_2.el );
702 // user defined functions
704 public class Xcls_Button18 : Object
706 public Gtk.Button el;
707 private Xcls_PopoverProperty _this;
711 public bool always_show_image;
714 public Xcls_Button18(Xcls_PopoverProperty _owner )
717 this.el = new Gtk.Button();
720 this.always_show_image = true;
722 // set gobject values
723 this.el.hexpand = true;
724 this.el.label = "Cancel";
727 this.el.clicked.connect( () => {
729 _this.is_new = false;
730 _this.kname.el.set_text("Cancel");
736 // user defined functions
739 public class Xcls_Button19 : Object
741 public Gtk.Button el;
742 private Xcls_PopoverProperty _this;
746 public bool always_show_image;
749 public Xcls_Button19(Xcls_PopoverProperty _owner )
752 this.el = new Gtk.Button();
755 this.always_show_image = true;
757 // set gobject values
758 this.el.hexpand = true;
759 this.el.label = "Add Property";
762 this.el.clicked.connect( () => {
763 // check if text is not empty..
764 if ( _this.kname.el.get_text().strip().length < 1) {
766 // error should already be showing?
770 // since we can't add listeners?!?!?
772 // check if property already exists in node.
775 var prop = new JsRender.NodeProp(
776 _this.kname.el.get_text().strip(),
777 _this.ptype.getValue(),
778 _this.ktype.el.get_text().strip(),
782 if (_this.node.props.has_key(prop.to_index_key())) {
783 _this.error.setError("Property already exists");
789 _this.node.add_prop(prop);
791 _this.prop = null; // skip checks..
792 _this.is_new = false;
794 _this.mainwindow.windowstate.left_props.changed();
795 _this.mainwindow.windowstate.left_props.view.editProp(prop);
802 // user defined functions