mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
lang: Allow ColumnView widgets to be built
Allow BuilderListItemFactory to contain Gtk.ColumnViewRow or Gtk.ColumnViewCell templates, in addition to Gtk.ListItem templates. This is necessary for people to use Gtk.ColumnView idiomatically in Blueprint. Fixes #157.
This commit is contained in:
parent
84e529a4a8
commit
988e69ab25
6 changed files with 85 additions and 6 deletions
|
@ -39,7 +39,10 @@ class ExtListItemFactory(AstNode):
|
|||
|
||||
@property
|
||||
def gir_class(self):
|
||||
return self.root.gir.get_type("ListItem", "Gtk")
|
||||
if self.type_name is not None:
|
||||
return self.type_name.gir_type
|
||||
else:
|
||||
return self.root.gir.get_type("ListItem", "Gtk")
|
||||
|
||||
@validate("template")
|
||||
def container_is_builder_list(self):
|
||||
|
@ -57,8 +60,14 @@ class ExtListItemFactory(AstNode):
|
|||
@validate()
|
||||
def type_is_list_item(self):
|
||||
if self.type_name is not None:
|
||||
if self.type_name.glib_type_name != "GtkListItem":
|
||||
raise CompileError(f"Only Gtk.ListItem is allowed as a type here")
|
||||
if self.type_name.glib_type_name not in (
|
||||
"GtkListItem",
|
||||
"GtkColumnViewRow",
|
||||
"GtkColumnViewCell",
|
||||
):
|
||||
raise CompileError(
|
||||
f"Only Gtk.ListItem, Gtk.ColumnViewRow, or Gtk.ColumnViewCell is allowed as a type here"
|
||||
)
|
||||
|
||||
@validate("template")
|
||||
def type_name_upgrade(self):
|
||||
|
|
|
@ -377,7 +377,7 @@ class XmlOutput(OutputFormat):
|
|||
elif isinstance(extension, ExtListItemFactory):
|
||||
child_xml = XmlEmitter()
|
||||
child_xml.start_tag("interface")
|
||||
child_xml.start_tag("template", **{"class": "GtkListItem"})
|
||||
child_xml.start_tag("template", **{"class": extension.gir_class})
|
||||
self._emit_object_or_template(extension, child_xml)
|
||||
child_xml.end_tag()
|
||||
child_xml.end_tag()
|
||||
|
|
|
@ -224,7 +224,7 @@ Valid in `Gtk.BuilderListItemFactory <https://docs.gtk.org/gtk4/class.BuilderLis
|
|||
|
||||
The ``template`` block defines the template that will be used to create list items. This block is unique within Blueprint because it defines a completely separate sub-blueprint which is used to create each list item. The sub-blueprint may not reference objects in the main blueprint or vice versa.
|
||||
|
||||
The template type must be `Gtk.ListItem <https://docs.gtk.org/gtk4/class.ListItem.html>`_. The template object can be referenced with the ``template`` keyword.
|
||||
The template type must be `Gtk.ListItem <https://docs.gtk.org/gtk4/class.ListItem.html>`_, `Gtk.ColumnViewRow <https://docs.gtk.org/gtk4/class.ColumnViewRow.html>`_, or `Gtk.ColumnViewCell <https://docs.gtk.org/gtk4/class.ColumnViewCell.html>`_ The template object can be referenced with the ``template`` keyword.
|
||||
|
||||
.. code-block:: blueprint
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
4,3,17,Only Gtk.ListItem is allowed as a type here
|
||||
4,3,17,Only Gtk.ListItem, Gtk.ColumnViewRow, or Gtk.ColumnViewCell is allowed as a type here
|
17
tests/samples/gtkcolumnview.blp
Normal file
17
tests/samples/gtkcolumnview.blp
Normal file
|
@ -0,0 +1,17 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
ColumnView {
|
||||
row-factory: BuilderListItemFactory {
|
||||
template ColumnViewRow {}
|
||||
};
|
||||
|
||||
ColumnViewColumn {
|
||||
factory: BuilderListItemFactory {
|
||||
template ColumnViewCell {
|
||||
child: Label {
|
||||
label: bind template.item as <$MyObject>.name;
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
53
tests/samples/gtkcolumnview.ui
Normal file
53
tests/samples/gtkcolumnview.ui
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?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"/>
|
||||
<object class="GtkColumnView">
|
||||
<property name="row-factory">
|
||||
<object class="GtkBuilderListItemFactory">
|
||||
<property name="bytes"><![CDATA[<?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>
|
||||
<template class="GtkColumnViewRow"></template>
|
||||
</interface>]]></property>
|
||||
</object>
|
||||
</property>
|
||||
<child>
|
||||
<object class="GtkColumnViewColumn">
|
||||
<property name="factory">
|
||||
<object class="GtkBuilderListItemFactory">
|
||||
<property name="bytes"><![CDATA[<?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>
|
||||
<template class="GtkColumnViewCell">
|
||||
<property name="child">
|
||||
<object class="GtkLabel">
|
||||
<binding name="label">
|
||||
<lookup name="name" type="MyObject">
|
||||
<lookup name="item" type="GtkColumnViewCell">
|
||||
<constant>GtkColumnViewCell</constant>
|
||||
</lookup>
|
||||
</lookup>
|
||||
</binding>
|
||||
</object>
|
||||
</property>
|
||||
</template>
|
||||
</interface>]]></property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
Loading…
Add table
Add a link
Reference in a new issue