mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
language: Fix some issues with menus
Blueprint's handling of menus didn't line up with how GtkBuilder handles them. The root <menu> element must have an ID and may not have attributes, and menus may not be used inline in a property.
This commit is contained in:
parent
93f2a27e35
commit
bbad6988fa
18 changed files with 52 additions and 53 deletions
|
@ -20,7 +20,6 @@
|
|||
|
||||
from .attributes import BaseAttribute
|
||||
from .gobject_object import Object, ObjectContent
|
||||
from .ui import UI
|
||||
from .common import *
|
||||
|
||||
|
||||
|
@ -31,6 +30,11 @@ class Menu(Object):
|
|||
child.emit_xml(xml)
|
||||
xml.end_tag()
|
||||
|
||||
@validate("menu")
|
||||
def has_id(self):
|
||||
if self.tokens["tag"] == "menu" and self.tokens["id"] is None:
|
||||
raise CompileError("Menu requires an ID")
|
||||
|
||||
@property
|
||||
def gir_class(self):
|
||||
return self.root.gir.namespaces["Gtk"].lookup_type("Gio.MenuModel")
|
||||
|
@ -39,6 +43,11 @@ class Menu(Object):
|
|||
class MenuAttribute(BaseAttribute):
|
||||
tag_name = "attribute"
|
||||
|
||||
@validate()
|
||||
def not_in_menu(self):
|
||||
if self.parent.tokens["tag"] == "menu":
|
||||
raise CompileError("Menu root may not have attributes")
|
||||
|
||||
@property
|
||||
def value_type(self):
|
||||
return None
|
||||
|
@ -128,16 +137,17 @@ menu_contents.children = [
|
|||
), "}"),
|
||||
]
|
||||
|
||||
menu = Group(
|
||||
menu: Group = Group(
|
||||
Menu,
|
||||
[
|
||||
"menu",
|
||||
Keyword("menu"),
|
||||
UseLiteral("tag", "menu"),
|
||||
Optional(UseIdent("id")),
|
||||
menu_contents
|
||||
],
|
||||
)
|
||||
|
||||
from .ui import UI
|
||||
|
||||
@completer(
|
||||
applies_in=[UI],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue