mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Support template without parent
This commit is contained in:
parent
896dd7f824
commit
adc2be1454
5 changed files with 28 additions and 2 deletions
|
@ -905,7 +905,11 @@ class Namespace(GirNode):
|
|||
def get_type_by_cname(self, cname: str) -> T.Optional[GirType]:
|
||||
"""Gets a type from this namespace by its C name."""
|
||||
for item in self.entries.values():
|
||||
if hasattr(item, "cname") and item.cname == cname:
|
||||
if (
|
||||
hasattr(item, "cname")
|
||||
and item.cname is not None
|
||||
and item.cname == cname
|
||||
):
|
||||
return item
|
||||
return None
|
||||
|
||||
|
|
|
@ -97,6 +97,9 @@ def decompile_template(ctx: DecompileCtx, gir, klass, parent=None):
|
|||
else:
|
||||
return "$" + cname
|
||||
|
||||
if parent is None:
|
||||
ctx.print(f"template {class_name(klass)} {{")
|
||||
else:
|
||||
ctx.print(f"template {class_name(klass)} : {class_name(parent)} {{")
|
||||
|
||||
ctx.template_class = klass
|
||||
|
|
5
tests/samples/template_orphan.blp
Normal file
5
tests/samples/template_orphan.blp
Normal file
|
@ -0,0 +1,5 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template $TestTemplate {
|
||||
test-property: 'Hello, world';
|
||||
}
|
12
tests/samples/template_orphan.ui
Normal file
12
tests/samples/template_orphan.ui
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
DO NOT EDIT!
|
||||
This file was @generated by blueprint-compiler. Instead, edit the
|
||||
corresponding .blp file and regenerate this file with blueprint-compiler.
|
||||
-->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<template class="TestTemplate">
|
||||
<property name="test-property">Hello, world</property>
|
||||
</template>
|
||||
</interface>
|
|
@ -186,6 +186,7 @@ class TestSamples(unittest.TestCase):
|
|||
"template_bind_property",
|
||||
"template_id",
|
||||
"template_no_parent",
|
||||
"template_orphan",
|
||||
"template_simple_binding",
|
||||
"typeof",
|
||||
"unchecked_class",
|
||||
|
@ -235,6 +236,7 @@ class TestSamples(unittest.TestCase):
|
|||
self.assert_decompile("strings_dec")
|
||||
self.assert_decompile("style_dec")
|
||||
self.assert_decompile("template")
|
||||
self.assert_decompile("template_orphan")
|
||||
self.assert_decompile("translated")
|
||||
self.assert_decompile("using")
|
||||
self.assert_decompile("unchecked_class_dec")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue