mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Make builder template factories use a subscope
This commit is contained in:
parent
a2eaaa26fe
commit
9dcd06de51
6 changed files with 46 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
||||||
from .gobject_object import ObjectContent, validate_parent_type
|
from .gobject_object import ObjectContent, validate_parent_type
|
||||||
from ..parse_tree import Keyword
|
from ..parse_tree import Keyword
|
||||||
from ..ast_utils import AstNode, validate
|
from ..ast_utils import AstNode, validate
|
||||||
|
from .common import *
|
||||||
|
from .contexts import ScopeCtx
|
||||||
|
|
||||||
|
|
||||||
class ListItemFactory(AstNode):
|
class ListItemFactory(AstNode):
|
||||||
|
@ -19,6 +21,14 @@ class ListItemFactory(AstNode):
|
||||||
"sub-templates",
|
"sub-templates",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@context(ScopeCtx)
|
||||||
|
def scope_ctx(self) -> ScopeCtx:
|
||||||
|
return ScopeCtx(node=self)
|
||||||
|
|
||||||
|
@validate()
|
||||||
|
def unique_ids(self):
|
||||||
|
self.context[ScopeCtx].validate_unique_ids()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def content(self) -> ObjectContent:
|
def content(self) -> ObjectContent:
|
||||||
return self.children[ObjectContent][0]
|
return self.children[ObjectContent][0]
|
||||||
|
|
9
tests/sample_errors/subscope.blp
Normal file
9
tests/sample_errors/subscope.blp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
using Gtk 4.0;
|
||||||
|
|
||||||
|
BuilderListItemFactory {
|
||||||
|
template {
|
||||||
|
child: label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Label label {}
|
1
tests/sample_errors/subscope.err
Normal file
1
tests/sample_errors/subscope.err
Normal file
|
@ -0,0 +1 @@
|
||||||
|
5,12,5,Could not find object with ID label
|
9
tests/samples/subscope.blp
Normal file
9
tests/samples/subscope.blp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
using Gtk 4.0;
|
||||||
|
|
||||||
|
Gtk.BuilderListItemFactory {
|
||||||
|
template {
|
||||||
|
child: Gtk.Label label {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Gtk.Label label {}
|
15
tests/samples/subscope.ui
Normal file
15
tests/samples/subscope.ui
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk" version="4.0"/>
|
||||||
|
<object class="GtkBuilderListItemFactory">
|
||||||
|
<property name="bytes"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<interface>
|
||||||
|
<template class="GtkListItem">
|
||||||
|
<property name="child">
|
||||||
|
<object class="GtkLabel" id="label"></object>
|
||||||
|
</property>
|
||||||
|
</template>
|
||||||
|
</interface>]]></property>
|
||||||
|
</object>
|
||||||
|
<object class="GtkLabel" id="label"></object>
|
||||||
|
</interface>
|
|
@ -184,6 +184,7 @@ class TestSamples(unittest.TestCase):
|
||||||
self.assert_sample("string_list")
|
self.assert_sample("string_list")
|
||||||
self.assert_sample("strings")
|
self.assert_sample("strings")
|
||||||
self.assert_sample("style")
|
self.assert_sample("style")
|
||||||
|
self.assert_sample("subscope")
|
||||||
self.assert_sample(
|
self.assert_sample(
|
||||||
"template", skip_run=True
|
"template", skip_run=True
|
||||||
) # The template class doesn't exist
|
) # The template class doesn't exist
|
||||||
|
@ -258,6 +259,7 @@ class TestSamples(unittest.TestCase):
|
||||||
self.assert_sample_error("size_group_obj_dne")
|
self.assert_sample_error("size_group_obj_dne")
|
||||||
self.assert_sample_error("strv")
|
self.assert_sample_error("strv")
|
||||||
self.assert_sample_error("styles_in_non_widget")
|
self.assert_sample_error("styles_in_non_widget")
|
||||||
|
self.assert_sample_error("subscope")
|
||||||
self.assert_sample_error("two_templates")
|
self.assert_sample_error("two_templates")
|
||||||
self.assert_sample_error("uint")
|
self.assert_sample_error("uint")
|
||||||
self.assert_sample_error("using_invalid_namespace")
|
self.assert_sample_error("using_invalid_namespace")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue