2 This kind of works - however there are issues with embedding gladeui that do not seem fixable.
3 - rendering is borked for windows - they detach for some reason.
4 - selecting stuff and drag etc. would probably be complicated...
8 public class JsRender.NodeToGlade : Object {
15 public NodeToGlade( Project.Gtk project, Node node, Xml.Node* parent)
19 this.project = project;
24 public static string mungeFile(JsRender file)
26 if (file.tree == null) {
30 var n = new NodeToGlade( (Project.Gtk) file.project, file.tree, null);
32 ///n.toValaName(file.tree);
35 //GLib.debug("top cls %s / xlcs %s ",file.tree.xvala_cls,file.tree.xvala_cls);
36 //n.cls = file.tree.xvala_cls;
37 //n.xcls = file.tree.xvala_xcls;
43 public string munge ( )
50 this.doc->dump_memory_format (out ret, out len, true);
57 public Xml.Node* mungeChild( Node cnode , Xml.Node* cdom)
59 var x = new NodeToGlade(this.project, cnode, cdom);
62 public static Xml.Ns* ns = null;
65 public Xml.Node* create_element(string n)
67 if (NodeToGlade.ns == null) {
68 Xml.Ns* ns = new Xml.Ns (null, "", "");
69 ns->type = Xml.ElementType.ELEMENT_NODE;
71 Xml.Node* nn = new Xml.Node (ns, n);
76 public Xml.Node* mungeNode()
79 if (this.parent == null) {
81 this.doc = new Xml.Doc("1.0");
83 var inf = this.create_element("interface");
84 this.doc->set_root_element(inf);
85 var req = this.create_element("requires");
86 req->set_prop("lib", "gtk+");
87 req->set_prop("version", "4.1");
92 var cls = this.node.fqn().replace(".", "");
94 var gdata = Palete.Gir.factoryFqn(this.project, this.node.fqn());
95 if (gdata == null || !gdata.inherits.contains("Gtk.Buildable")) {
97 //exception to the rule.. (must be buildable to work with glade?
99 case "GtkNotebookPage":
100 if (this.node.childstore.get_n_items() < 1) {
105 case "GtkColumnViewColumn":
109 GLib.debug("Skip %s - is not buildable / no data", cls);
113 if (gdata.inherits.contains("Gtk.Native")&& !is_top) {
116 // what namespaces are supported
117 switch(this.node.NS) {
120 case "Adw": // works if you call adw.init() in main!
123 GLib.debug("Skip %s - NS is not available", cls);
129 if (gdata.fqn() == ("Gtk.ListStore")) {
133 // <object class="GtkNotebookPage">
134 // <property name="tab-expand">1</property>
135 // <property name="child">
136 // <property name="label">
137 // should really use GXml...
138 var obj = this.create_element("object");
139 //var id = this.node.uid();
140 var skip_props = false;
141 if (gdata.inherits.contains("Gtk.Native")) {
143 obj->set_prop("class", "GtkFrame");
148 obj->set_prop("class", "GtkBox");
149 this.addProperty(obj, "orientation", "horizontal");
154 obj->set_prop("class", cls);
159 obj->set_prop("id", "w" + this.node.oid.to_string());
160 this.parent->add_child(obj);
162 var props = Palete.Gir.factoryFqn(this.project, this.node.fqn()).props;
165 var pviter = props.map_iterator();
166 while (!skip_props && pviter.next()) {
168 //GLib.debug ("Check: " +cls + "::(" + pviter.get_value().propertyof + ")" + pviter.get_key() + " " );
170 // skip items we have already handled..
171 if (!this.node.has(pviter.get_key())) {
174 var k = pviter.get_key();
175 var prop = props.get(k);
176 var val = this.node.get(pviter.get_key()).strip();
177 // for Enums - we change it to lowercase, and remove all the previous bits.. hopefully might work.
178 if (prop.type.contains(".") && val.contains(".")) {
179 var typ = Palete.Gir.factoryFqn(this.project, prop.type);
180 if (typ.nodetype == "Enum") {
181 var bits = val.split(".");
182 val = bits[bits.length-1].down();
186 // value for model seems to cause problems...(it's ok as a property?)
190 this.addProperty(obj, k, val);
200 pack = this.packString();
206 var left = 0, top = 0, cols = 1;
207 if (cls == "GtkGrid") {
208 var colval = this.node.get_prop("* columns");
209 GLib.debug("Columns %s", colval == null ? "no columns" : colval.val);
210 if (colval != null) {
211 cols = int.parse(colval.val);
214 var items = this.node.readItems();
215 for (var i = 0; i < items.size; i++ ) {
216 var cn = items.get(i);
218 var childname = "child";
220 if (cn.has("* prop")) { // && cn.get_prop("* prop").val == "child") {
221 childname = "property";
222 pname = cn.get_prop("* prop").val;
225 var child = this.create_element(childname);
227 child->set_prop("name", pname);
230 if ((cls == "GtkWindow" || cls == "GtkApplicationWindow") && cn.fqn() == "Gtk.HeaderBar") {
231 child->set_prop("type", "label");
235 var sub_obj = this.mungeChild(cn, child);
236 if (sub_obj == null) {
239 if (cls == "GtkGrid") {
240 this.addGridAttach(sub_obj, left, top);
253 if (child->child_element_count() < 1) {
256 obj->add_child(child);
264 void addProperty(Xml.Node* obj, string k, string val)
266 var domprop = this.create_element("property");
267 domprop->set_prop("name", k);
268 domprop->add_child(new Xml.Node.text(val));
269 obj->add_child(domprop);
271 void addGridAttach(Xml.Node* obj, int left, int top)
273 var layout = this.create_element("layout");
274 this.addProperty(layout, "column", left.to_string());
275 this.addProperty(layout, "row", top.to_string());
276 obj->add_child(layout);