{ "build_module" : "builder", "gen_extended" : false, "items" : [ { "# Gtk.PositionType position" : "Gtk.PositionType.RIGHT", "# JsRender.Node node" : "", "# JsRender.NodeProp? original_prop" : "null", "# JsRender.NodeProp? prop" : "null", "# Xcls_MainWindow mainwindow" : "null", "# string key_type" : "", "# string old_keyname" : "", "$ xns" : "Gtk", "* ctor" : "new Gtk.Popover()", "@ void success" : "(Project.Project pr, JsRender.JsRender file)", "bool autohide" : true, "bool done" : false, "bool is_new" : false, "id" : "PopoverProperty", "items" : [ { "$ xns" : "Gtk", "* pack" : "set_child", "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL", "bool homogeneous" : false, "items" : [ { "$ xns" : "Gtk", "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL", "id" : "header", "items" : [ { "$ xns" : "Gtk", "bool always_show_image" : true, "bool hexpand" : true, "id" : "cancelbtn", "listeners" : { "clicked" : [ "() => {", "\t_this.prop = null;", "\t_this.is_new = false;", "\t_this.kname.el.set_text(\"Cancel\");", "\t_this.el.hide();", "\t", "}" ] }, "string label" : "Cancel", "xtype" : "Button" }, { "$ xns" : "Gtk", "bool hexpand" : true, "id" : "headertitle", "string label" : "Add / Edit property", "xtype" : "Label" }, { "$ xns" : "Gtk", "bool always_show_image" : true, "bool hexpand" : true, "id" : "savebtn", "listeners" : { "clicked" : [ "() => {", "\tif (!_this.is_new) {", "\t\t_this.el.hide();", "\t}", "\t", "\t// check if text is not empty..", "\tif ( _this.kname.el.get_text().strip().length < 1) {", "\t", "\t\t// error should already be showing?", "\t\treturn;", "\t}", "\t ", "\t// since we can't add listeners?!?!?", "\t// only check props.", "\t// check if property already exists in node.\t", "", "", "\tvar prop = new JsRender.NodeProp(", "\t\t_this.kname.el.get_text().strip(),", "\t\t_this.ptype.getValue(),", "\t\t_this.ktype.el.get_text().strip(),", "\t\t_this.prop.val", "\t);", "", "\tif (_this.node.props.has_key(prop.to_index_key())) {", "\t\t_this.error.setError(\"Property already exists\");", "\t\treturn;\t", "\t}", "\t", "\t", "\t", "\t_this.node.add_prop(prop);", "\t// hide self", "\t_this.prop = null; // skip checks..", "\t_this.is_new = false;", "\t_this.el.hide();", " \t_this.mainwindow.windowstate.left_props.changed();", "\t_this.mainwindow.windowstate.left_props.view.editProp(prop);", "", "\t", "\t", "}" ] }, "string label" : "Add Property", "xtype" : "Button" } ], "xtype" : "Box" }, { "$ visible" : true, "$ xns" : "Gtk", "Gtk.Align halign" : "Gtk.Align.START", "Gtk.Justification justify" : "Gtk.Justification.LEFT", "int margin_top" : 12, "label" : "Property Type (eg. property or method)", "x_options" : 4, "xtype" : "Label" }, { "$ xns" : "Gtk", "bool show_arrow" : true, "id" : "ptype", "items" : [ { "$ strings" : "JsRender.NodePropType.get_pulldown_list()", "$ xns" : "Gtk", "* prop" : "model", "xtype" : "StringList" } ], "listeners" : { "notify[\"selected\"]" : [ "() => {", "", "\t_this.el.grab_focus(); // stop prevent autohide breaking.", " }" ] }, "xtype" : "DropDown", "| JsRender.NodePropType getValue" : [ "() {", "\tvar sl = this.el.model as Gtk.StringList;", "\tvar str = sl.get_string(this.el.selected);", "\treturn JsRender.NodePropType.nameToType(str);", "}" ], "| void setValue" : [ "(JsRender.NodePropType ty) {", "\tvar str = ty.to_name();", "\tvar sl = this.el.model as Gtk.StringList;", "\tfor(var i = 0; i < sl.get_n_items(); i++) {", "\t\tif(sl.get_string(i) == str) {", "\t\t\tthis.el.set_selected(i);", "\t\t\tbreak;", "\t\t}", "\t}", "\t", "}" ] }, { "$ visible" : true, "$ xns" : "Gtk", "Gtk.Align halign" : "Gtk.Align.START", "Gtk.Justification justify" : "Gtk.Justification.LEFT", "int margin_top" : 12, "label" : "Type or Return Type", "x_options" : 4, "xtype" : "Label" }, { "$ visible" : true, "$ xns" : "Gtk", "id" : "ktype", "xtype" : "Entry" }, { "$ visible" : true, "$ xns" : "Gtk", "Gtk.Align halign" : "Gtk.Align.START", "Gtk.Justification justify" : "Gtk.Justification.LEFT", "int margin_top" : 12, "label" : "Name", "tooltip_text" : "center, north, south, east, west", "x_options" : 4, "xtype" : "Label" }, { "$ visible" : true, "$ xns" : "Gtk", "id" : "kname", "items" : [ { "$ xns" : "Gtk", "listeners" : { "leave" : [ "( ) => {", "", " _this.error.setError(\"\");", "\tvar val = _this.kname.el.get_text().strip(); ", "\tif (val.length < 1) {", "\t\t_this.error.setError(\"Name can not be empty\");", "\t}", "", "}", "" ] }, "xtype" : "EventControllerFocus" }, { "$ xns" : "Gtk", "listeners" : { "key_released" : [ "(keyval, keycode, state) => {", "", " _this.error.setError(\"\");", "\tvar val = _this.kname.el.get_text().strip(); ", "\tif (val.length < 1) {", "\t\t_this.error.setError(\"Name can not be empty\");", "\t}", "", "}", "" ] }, "xtype" : "EventControllerKey" } ], "xtype" : "Entry" }, { "$ visible" : true, "$ xns" : "Gtk", "Gtk.Align halign" : "Gtk.Align.START", "Gtk.Justification justify" : "Gtk.Justification.LEFT", "bool use_markup" : true, "id" : "error", "int margin_top" : 0, "label" : "Error Message", "tooltip_text" : "center, north, south, east, west", "x_options" : 4, "xtype" : "Label", "| void setError" : [ "(string err) {", "\tif (err == \"\") {", "\t\tthis.el.label = \"\";", "\t} else {", "", "\t\t", "\t\tthis.el.label = \"\" + err + \"\";", "\t}", "}", "" ] } ], "xtype" : "Box" } ], "listeners" : { "closed" : [ "() => {", "", " \tGLib.debug(\"popover closed\");", "\tif (_this.is_new) {", "\t\t// dont allow hiding if we are creating a new one.", "\t\t// on.hide will reshow it.", "\t\treturn;", "\t}", "\tif (_this.prop == null) {", "\t\t// hide and dont update.", "\t\treturn;", "\t}", "\tif (this.kname.el.get_text().strip().length < 1) {", "\t\treturn;", "\t}", "\t", " ", " \t", " ", " \tthis.updateProp();", " ", "\t ", "", "", " ", "} " ], "hide" : [ "() => {", " \tGLib.debug(\"popover hidden\");", "\tif (_this.is_new || this.kname.el.get_text().strip().length < 1) {", "\t\t// dont allow hiding if we are creating a new one.", "\t\tGLib.debug(\"prevent hiding as its new or text is empty\"); ", "\t\tthis.el.show();", "\t\treturn;", "", "\t}", "\tif (this.original_prop != null && !this.prop.equals(this.original_prop)) {", "\t\t// this is convoluted..", "\t\t_this.mainwindow.windowstate.left_props.changed(); ", "\t}", "\t", "\t", "}" ] }, "xtype" : "Popover", "| void show" : [ "(", "\tGtk.Widget btn, ", "\tJsRender.Node node, ", "\tJsRender.NodeProp prop, ", "\tint y,", "\tbool is_new = false", "\t ) ", "{", "\t", " this.original_prop = prop.dupe();", "\tthis.is_new = is_new; ", "\tvar pref = is_new ? \"Add \" : \"Modify \";", "\tif (prop.ptype == JsRender.NodePropType.LISTENER) {", "\t\tthis.headertitle.el.label = pref + \"Event Listener\"; // cant really happen yet?", "\t} else {", "\t\tthis.headertitle.el.label = pref + \"Property\";", "\t}", "\tthis.prop = prop;", "\tthis.node = node;", "\t", "\t_this.kname.el.set_text(prop.name);", "\t_this.ktype.el.set_text(prop.rtype);", "\t", " \t_this.ptype.setValue(prop.ptype);", "\t// does node have this property...", "", "", "\t_this.node = node;", "\t//console.log('show all');", "\t", "\tGLib.debug(\"set parent = %s\", btn.get_type().name());", "\tvar par = btn.get_parent();", "\t", "\tif (par == null) {", "\t\tGLib.debug(\"parent of that is null - not showing\");", "\t\treturn;", "\t}", "\tif (this.el.parent == null) {", "\t\tthis.el.set_parent(btn);", "\t}", "\tvar r = Gdk.Rectangle() {", "\t\t\tx = btn.get_width(), // align left...", "\t\t\ty = 0,", "\t\t\twidth = 1,", "\t\t\theight = 1", "\t\t};", "\t//Gtk.Allocation rect;", "\t//btn.get_allocation(out rect);", " this.el.set_pointing_to(r);", " ", "", "\t ", "\tif (y > -1) {", "\t\t ", "\t\t r = Gdk.Rectangle() {", "\t\t\tx = btn.get_width(), // align left...", "\t\t\ty = y,", "\t\t\twidth = 1,", "\t\t\theight = 1", "\t\t};", "\t\tthis.el.set_pointing_to( r);", "\t}", "\t", "\t", "", "\t//this.el.set_position(Gtk.PositionType.TOP);", "", "\t// window + header?", "\t GLib.debug(\"SHOWALL - POPIP\\n\");", "\t", "\tthis.kname.el.grab_focus();", "\tthis.savebtn.el.set_label(\"Save\");", "\tthis.cancelbtn.el.visible = false;", "\tif (this.is_new) {", "\t\tthis.savebtn.el.set_label(\"Add Property\");", "\t\tthis.cancelbtn.el.visible = true;", "\t}", "\tthis.error.setError(\"\");", "\tthis.el.show();", "\t//this.success = c.success;", " ", "}" ], "| void updateProp" : [ "() {", " \tGLib.debug(\"updateProp called\");", "", "\t", "\t", "\t_this.prop.name = this.kname.el.get_text().strip();", "\t_this.prop.ptype = this.ptype.getValue();", "\t_this.prop.rtype = this.ktype.el.get_text().strip();", "\t", "\t ", "}", "" ] } ], "name" : "PopoverProperty" }