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( () => {
55 GLib.debug("popover closed");
57 // dont allow hiding if we are creating a new one.
58 // 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) {
72 _this.mainwindow.windowstate.left_props.reload();
77 this.el.hide.connect( () => {
78 GLib.debug("popover hidden");
79 if (_this.is_new || this.kname.el.get_text().strip().length < 1) {
80 // dont allow hiding if we are creating a new one.
81 GLib.debug("prevent hiding as its new or text is empty");
90 // user defined functions
94 JsRender.NodeProp prop,
101 this.is_new = is_new;
102 var pref = is_new ? "Add " : "Modify ";
103 if (prop.ptype == JsRender.NodePropType.LISTENER) {
104 this.header.el.title = pref + "Event Listener"; // cant really happen yet?
106 this.header.el.title = pref + "Property";
111 _this.kname.el.set_text(prop.name);
112 _this.ktype.el.set_text(prop.rtype);
114 _this.dbmodel.loadData(prop );
115 // does node have this property...
119 //console.log('show all');
120 this.el.set_modal(true);
121 this.el.set_relative_to(btn);
123 var r = Gdk.Rectangle() {
124 x = 0, // align left...
129 this.el.set_pointing_to( r);
134 //this.el.set_position(Gtk.PositionType.TOP);
137 print("SHOWALL - POPIP\n");
139 this.kname.el.grab_focus();
140 this.buttonbar.el.hide();
142 this.buttonbar.el.show();
144 this.error.setError("");
146 //this.success = c.success;
149 public void updateProp () {
153 this.kflag.el.get_active_iter(out citer);
154 this.dbmodel.el.get_value(citer, 0, out gval);
157 _this.prop.name = this.kname.el.get_text().strip();
158 _this.prop.rtype = this.ktype.el.get_text().strip();
159 _this.prop.ptype = (JsRender.NodePropType) gval;
162 public class Xcls_Box2 : Object
165 private Xcls_PopoverProperty _this;
171 public Xcls_Box2(Xcls_PopoverProperty _owner )
174 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
178 // set gobject values
179 this.el.homogeneous = false;
180 var child_0 = new Xcls_header( _this );
182 this.el.pack_start ( child_0.el , false,true,0 );
183 var child_1 = new Xcls_Label4( _this );
185 this.el.add ( child_1.el );
186 var child_2 = new Xcls_kflag( _this );
188 this.el.add ( child_2.el );
189 var child_3 = new Xcls_Label8( _this );
191 this.el.add ( child_3.el );
192 var child_4 = new Xcls_ktype( _this );
194 this.el.add ( child_4.el );
195 var child_5 = new Xcls_Label10( _this );
197 this.el.add ( child_5.el );
198 var child_6 = new Xcls_kname( _this );
200 this.el.add ( child_6.el );
201 var child_7 = new Xcls_error( _this );
203 this.el.add ( child_7.el );
204 var child_8 = new Xcls_buttonbar( _this );
206 this.el.add ( child_8.el );
209 // user defined functions
211 public class Xcls_header : Object
213 public Gtk.HeaderBar el;
214 private Xcls_PopoverProperty _this;
220 public Xcls_header(Xcls_PopoverProperty _owner )
224 this.el = new Gtk.HeaderBar();
228 // set gobject values
229 this.el.title = "Modify / Create Property";
232 // user defined functions
235 public class Xcls_Label4 : Object
238 private Xcls_PopoverProperty _this;
244 public Xcls_Label4(Xcls_PopoverProperty _owner )
247 this.el = new Gtk.Label( "Special Flags" );
251 // set gobject values
252 this.el.halign = Gtk.Align.START;
253 this.el.justify = Gtk.Justification.LEFT;
254 this.el.margin_top = 12;
257 // user defined functions
260 public class Xcls_kflag : Object
262 public Gtk.ComboBox el;
263 private Xcls_PopoverProperty _this;
269 public Xcls_kflag(Xcls_PopoverProperty _owner )
273 this.el = new Gtk.ComboBox();
277 // set gobject values
278 var child_0 = new Xcls_dbcellrenderer( _this );
280 this.el.pack_start ( child_0.el , true );
281 var child_1 = new Xcls_dbmodel( _this );
283 this.el.set_model ( child_1.el );
287 this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
290 // user defined functions
292 public class Xcls_dbcellrenderer : Object
294 public Gtk.CellRendererText el;
295 private Xcls_PopoverProperty _this;
301 public Xcls_dbcellrenderer(Xcls_PopoverProperty _owner )
304 _this.dbcellrenderer = this;
305 this.el = new Gtk.CellRendererText();
309 // set gobject values
312 // user defined functions
315 public class Xcls_dbmodel : Object
317 public Gtk.ListStore el;
318 private Xcls_PopoverProperty _this;
324 public Xcls_dbmodel(Xcls_PopoverProperty _owner )
327 _this.dbmodel = this;
328 this.el = new Gtk.ListStore( 2, typeof(JsRender.NodePropType),typeof(string) );
332 // set gobject values
335 // user defined functions
336 public void loadData (JsRender.NodeProp prop) {
344 // user defined property '#'
345 // user defined method '|'
346 // special property '*' => prop |args|ctor|init
350 /// el.append(out iter);
353 // el.set_value(iter, 0, "");
354 // el.set_value(iter, 1, "aaa - Just add Element - aaa");
357 if (prop.ptype == JsRender.NodePropType.LISTENER) {
359 el.set(iter, 0, JsRender.NodePropType.LISTENER, 1, "Event Handler / Listener", -1);
361 else if (_this.mainwindow.windowstate.file.xtype == "Gtk") {
363 el.set(iter, 0, JsRender.NodePropType.PROP, 1, "Normal Property", -1);
367 el.set(iter, 0, JsRender.NodePropType.RAW, 1, "Raw Property (not escaped)", -1);
371 el.set(iter, 0, JsRender.NodePropType.USER, 1, "User defined property", -1);
374 el.set(iter, 0, JsRender.NodePropType.METHOD, 1, "User defined method", -1);
377 el.set(iter, 0, JsRender.NodePropType.SPECIAL, 1, "Special property (eg. prop | args | ctor | init )", -1);
381 el.set(iter, 0, JsRender.NodePropType.SIGNAL, 1, "Vala Signal", -1);
387 el.set(iter, 0, JsRender.NodePropType.PROP, 1, "Normal Property", -1);
390 el.set(iter, 0, JsRender.NodePropType.RAW, 1, "Raw Property (not escaped)", -1);
393 el.set(iter, 0, JsRender.NodePropType.METHOD, 1, "User defined method", -1);
396 el.set(iter, 0, JsRender.NodePropType.SPECIAL, 1, "(*) Special property (eg. prop )", -1);
400 // set selected, based on arg
401 el.foreach((tm, tp, titer) => {
403 el.get_value(titer, 0, out val);
405 //print("check %s against %s\n", (string)val, _this.prop.ptype);
406 if (((JsRender.NodePropType)val) == prop.ptype) {
407 _this.kflag.el.set_active_iter(titer);
419 public class Xcls_Label8 : Object
422 private Xcls_PopoverProperty _this;
428 public Xcls_Label8(Xcls_PopoverProperty _owner )
431 this.el = new Gtk.Label( "Type or Return Type" );
435 // set gobject values
436 this.el.halign = Gtk.Align.START;
437 this.el.justify = Gtk.Justification.LEFT;
438 this.el.margin_top = 12;
439 this.el.visible = true;
442 // user defined functions
445 public class Xcls_ktype : Object
448 private Xcls_PopoverProperty _this;
454 public Xcls_ktype(Xcls_PopoverProperty _owner )
458 this.el = new Gtk.Entry();
462 // set gobject values
463 this.el.visible = true;
466 // user defined functions
469 public class Xcls_Label10 : Object
472 private Xcls_PopoverProperty _this;
478 public Xcls_Label10(Xcls_PopoverProperty _owner )
481 this.el = new Gtk.Label( "Name" );
485 // set gobject values
486 this.el.halign = Gtk.Align.START;
487 this.el.justify = Gtk.Justification.LEFT;
488 this.el.tooltip_text = "center, north, south, east, west";
489 this.el.margin_top = 12;
490 this.el.visible = true;
493 // user defined functions
496 public class Xcls_kname : Object
499 private Xcls_PopoverProperty _this;
505 public Xcls_kname(Xcls_PopoverProperty _owner )
509 this.el = new Gtk.Entry();
513 // set gobject values
514 this.el.visible = true;
517 this.el.focus_out_event.connect( ()=>{
518 _this.error.setError("");
519 var val = this.el.get_text().strip();
520 if (val.length < 1) {
521 _this.error.setError("Name can not be empty");
525 this.el.key_release_event.connect( ()=>{
526 _this.error.setError("");
527 var val = this.el.get_text().strip();
528 if (val.length < 1) {
529 _this.error.setError("Name can not be empty");
535 // user defined functions
538 public class Xcls_error : Object
541 private Xcls_PopoverProperty _this;
547 public Xcls_error(Xcls_PopoverProperty _owner )
551 this.el = new Gtk.Label( "<span color=\"red\">Error Message</span>" );
555 // set gobject values
556 this.el.halign = Gtk.Align.START;
557 this.el.justify = Gtk.Justification.LEFT;
558 this.el.tooltip_text = "center, north, south, east, west";
559 this.el.margin_top = 0;
560 this.el.visible = true;
561 this.el.use_markup = true;
564 // user defined functions
565 public void setError (string err) {
571 this.el.label = "<span color=\"red\">" + err + "</span>";
576 public class Xcls_buttonbar : Object
579 private Xcls_PopoverProperty _this;
585 public Xcls_buttonbar(Xcls_PopoverProperty _owner )
588 _this.buttonbar = this;
589 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
593 // set gobject values
594 this.el.margin_top = 20;
595 var child_0 = new Xcls_Button14( _this );
597 this.el.add ( child_0.el );
598 var child_1 = new Xcls_Button16( _this );
600 this.el.add ( child_1.el );
603 // user defined functions
605 public class Xcls_Button14 : Object
607 public Gtk.Button el;
608 private Xcls_PopoverProperty _this;
614 public Xcls_Button14(Xcls_PopoverProperty _owner )
617 this.el = new Gtk.Button();
621 // set gobject values
622 this.el.hexpand = true;
623 this.el.always_show_image = true;
624 this.el.label = "Cancel";
625 var child_0 = new Xcls_Image15( _this );
627 this.el.image = child_0.el;
630 this.el.pressed.connect( () => {
633 _this.is_new = false;
634 _this.kname.el.set_text("Cancel");
640 // user defined functions
642 public class Xcls_Image15 : Object
645 private Xcls_PopoverProperty _this;
651 public Xcls_Image15(Xcls_PopoverProperty _owner )
654 this.el = new Gtk.Image();
658 // set gobject values
659 this.el.icon_name = "window-close";
662 // user defined functions
666 public class Xcls_Button16 : Object
668 public Gtk.Button el;
669 private Xcls_PopoverProperty _this;
675 public Xcls_Button16(Xcls_PopoverProperty _owner )
678 this.el = new Gtk.Button();
682 // set gobject values
683 this.el.hexpand = true;
684 this.el.always_show_image = true;
685 this.el.label = "Add Property";
686 var child_0 = new Xcls_Image17( _this );
688 this.el.image = child_0.el;
691 this.el.pressed.connect( () => {
692 // check if text is not empty..
693 if ( _this.kname.el.get_text().strip().length < 1) {
694 // error should already be showing?
699 // since we can't add listeners?!?!?
701 // check if property already exists in node.
702 var prop = _this.prop;
703 if (_this.node.props.has_key(prop.to_index_key())) {
704 _this.error.setError("Property already exists");
710 _this.is_new = false;
713 _this.prop = null; // skip checks..
717 // trigger editing of property.
718 // allow hide to work?
719 while (Gtk.events_pending()) {
720 Gtk.main_iteration();
723 _this.mainwindow.windowstate.left_props.addProp(prop);
729 // user defined functions
731 public class Xcls_Image17 : Object
734 private Xcls_PopoverProperty _this;
740 public Xcls_Image17(Xcls_PopoverProperty _owner )
743 this.el = new Gtk.Image();
747 // set gobject values
748 this.el.icon_name = "list-add";
751 // user defined functions