diff --git a/blueprintcompiler/language/gobject_object.py b/blueprintcompiler/language/gobject_object.py index e36e4ce..e3960ab 100644 --- a/blueprintcompiler/language/gobject_object.py +++ b/blueprintcompiler/language/gobject_object.py @@ -97,13 +97,15 @@ class Object(AstNode): if child.response_id ] - def emit_xml(self, xml: XmlEmitter): - from .gtkbuilder_child import Child - + def emit_start_tag(self, xml: XmlEmitter): xml.start_tag("object", **{ "class": self.gir_class or self.tokens["class_name"], "id": self.tokens["id"], }) + + def emit_xml(self, xml: XmlEmitter): + self.emit_start_tag(xml) + for child in self.children: child.emit_xml(xml) diff --git a/blueprintcompiler/language/gtkbuilder_template.py b/blueprintcompiler/language/gtkbuilder_template.py index 0de7381..7806285 100644 --- a/blueprintcompiler/language/gtkbuilder_template.py +++ b/blueprintcompiler/language/gtkbuilder_template.py @@ -41,15 +41,12 @@ class Template(Object): def unique_in_parent(self): self.validate_unique_in_parent(f"Only one template may be defined per file, but this file contains {len(self.parent.children[Template])}",) - def emit_xml(self, xml: XmlEmitter): + def emit_start_tag(self, xml: XmlEmitter): xml.start_tag( "template", **{"class": self.tokens["name"]}, parent=self.gir_class or self.tokens["class_name"] ) - for child in self.children: - child.emit_xml(xml) - xml.end_tag() @decompiler("template") diff --git a/tests/samples/action_widgets.blp b/tests/samples/action_widgets.blp index 2d4d6ae..34293a0 100644 --- a/tests/samples/action_widgets.blp +++ b/tests/samples/action_widgets.blp @@ -1,6 +1,6 @@ using Gtk 4.0; -Dialog { +template MyDialog : Dialog { [action response=cancel] Button cancel_button { label: _("Cancel"); diff --git a/tests/samples/action_widgets.ui b/tests/samples/action_widgets.ui index 91b6e64..8c41bb2 100644 --- a/tests/samples/action_widgets.ui +++ b/tests/samples/action_widgets.ui @@ -1,7 +1,7 @@ - +