diff --git a/blueprintcompiler/language/gobject_property.py b/blueprintcompiler/language/gobject_property.py index 50a7512..c782d2e 100644 --- a/blueprintcompiler/language/gobject_property.py +++ b/blueprintcompiler/language/gobject_property.py @@ -21,12 +21,15 @@ from .binding import Binding from .common import * from .contexts import ValueTypeCtx +from .gtk_menu import menu from .values import ArrayValue, ExprValue, ObjectValue, Value class Property(AstNode): grammar = Statement( - UseIdent("name"), ":", AnyOf(Binding, ExprValue, ObjectValue, Value, ArrayValue) + UseIdent("name"), + ":", + AnyOf(Binding, ExprValue, menu, ObjectValue, Value, ArrayValue), ) @property diff --git a/blueprintcompiler/language/gtk_menu.py b/blueprintcompiler/language/gtk_menu.py index c7ef5f2..bc38f37 100644 --- a/blueprintcompiler/language/gtk_menu.py +++ b/blueprintcompiler/language/gtk_menu.py @@ -60,11 +60,6 @@ class Menu(AstNode): def items(self) -> T.List[T.Union["Menu", "MenuAttribute"]]: return self.children - @validate("menu") - def has_id(self): - if self.tokens["tag"] == "menu" and self.tokens["id"] is None: - raise CompileError("Menu requires an ID") - @validate("id") def object_id_not_reserved(self): if self.id in RESERVED_IDS: diff --git a/blueprintcompiler/outputs/xml/__init__.py b/blueprintcompiler/outputs/xml/__init__.py index 15850f7..32291ee 100644 --- a/blueprintcompiler/outputs/xml/__init__.py +++ b/blueprintcompiler/outputs/xml/__init__.py @@ -139,6 +139,11 @@ class XmlOutput(OutputFormat): self._emit_expression(value.expression, xml) xml.end_tag() + elif isinstance(value, Menu): + xml.start_tag("property", **props) + self._emit_menu(value, xml) + xml.end_tag() + elif isinstance(value, ObjectValue): xml.start_tag("property", **props) self._emit_object(value.object, xml) diff --git a/docs/reference/objects.rst b/docs/reference/objects.rst index 6f76da6..d759abe 100644 --- a/docs/reference/objects.rst +++ b/docs/reference/objects.rst @@ -58,7 +58,7 @@ Properties .. rst-class:: grammar-block - Property = `> ':' ( :ref:`Binding` | :ref:`ExprValue` | :ref:`ObjectValue` | :ref:`Value` ) ';' + Property = `> ':' ( :ref:`Binding` | :ref:`ExprValue` | :ref:`Menu` | :ref:`ObjectValue` | :ref:`Value` ) ';' Properties specify the details of each object, like a label's text, an image's icon name, or the margins on a container. diff --git a/tests/sample_errors/inline_menu.err b/tests/sample_errors/inline_menu.err deleted file mode 100644 index 3115750..0000000 --- a/tests/sample_errors/inline_menu.err +++ /dev/null @@ -1 +0,0 @@ -4,15,4,Namespace Gtk does not contain a type called menu \ No newline at end of file diff --git a/tests/sample_errors/menu_no_id.err b/tests/sample_errors/menu_no_id.err deleted file mode 100644 index e97f033..0000000 --- a/tests/sample_errors/menu_no_id.err +++ /dev/null @@ -1 +0,0 @@ -3,1,4,Menu requires an ID \ No newline at end of file diff --git a/tests/sample_errors/inline_menu.blp b/tests/samples/inline_menu.blp similarity index 100% rename from tests/sample_errors/inline_menu.blp rename to tests/samples/inline_menu.blp diff --git a/tests/samples/inline_menu.ui b/tests/samples/inline_menu.ui new file mode 100644 index 0000000..2910b14 --- /dev/null +++ b/tests/samples/inline_menu.ui @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/tests/sample_errors/menu_no_id.blp b/tests/samples/menu_no_id.blp similarity index 100% rename from tests/sample_errors/menu_no_id.blp rename to tests/samples/menu_no_id.blp diff --git a/tests/samples/menu_no_id.ui b/tests/samples/menu_no_id.ui new file mode 100644 index 0000000..934f6da --- /dev/null +++ b/tests/samples/menu_no_id.ui @@ -0,0 +1,10 @@ + + + + + +