mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
decompiler: Support action widgets
This commit is contained in:
parent
21d5ce86e9
commit
65d4612b51
3 changed files with 39 additions and 7 deletions
|
@ -22,7 +22,7 @@ from functools import cached_property
|
||||||
|
|
||||||
from .common import *
|
from .common import *
|
||||||
from .gobject_object import Object
|
from .gobject_object import Object
|
||||||
from .response_id import ExtResponse
|
from .response_id import ExtResponse, decompile_response_type
|
||||||
|
|
||||||
ALLOWED_PARENTS: T.List[T.Tuple[str, str]] = [
|
ALLOWED_PARENTS: T.List[T.Tuple[str, str]] = [
|
||||||
("Gtk", "Buildable"),
|
("Gtk", "Buildable"),
|
||||||
|
@ -127,10 +127,15 @@ class Child(AstNode):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@decompiler("child")
|
@decompiler("child", element=True)
|
||||||
def decompile_child(ctx, gir, type=None, internal_child=None):
|
def decompile_child(ctx, gir, element):
|
||||||
if type is not None:
|
if type := element["type"]:
|
||||||
|
if type == "action":
|
||||||
|
if decompiled := decompile_response_type(ctx.parent_node, element):
|
||||||
|
ctx.print(decompiled)
|
||||||
|
return
|
||||||
|
|
||||||
ctx.print(f"[{type}]")
|
ctx.print(f"[{type}]")
|
||||||
elif internal_child is not None:
|
elif internal_child := element["internal-child"]:
|
||||||
ctx.print(f"[internal-child {internal_child}]")
|
ctx.print(f"[internal-child {internal_child}]")
|
||||||
return gir
|
return gir
|
||||||
|
|
|
@ -123,3 +123,32 @@ class ExtResponse(AstNode):
|
||||||
|
|
||||||
object = self.parent_by_type(Child).object
|
object = self.parent_by_type(Child).object
|
||||||
return object.id
|
return object.id
|
||||||
|
|
||||||
|
|
||||||
|
def decompile_response_type(parent_element, child_element):
|
||||||
|
obj_id = None
|
||||||
|
for obj in child_element.children:
|
||||||
|
if obj.tag == "object":
|
||||||
|
obj_id = obj["id"]
|
||||||
|
break
|
||||||
|
|
||||||
|
if obj_id is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
for child in parent_element.children:
|
||||||
|
if child.tag == "action-widgets":
|
||||||
|
for action_widget in child.children:
|
||||||
|
if action_widget.cdata == obj_id:
|
||||||
|
response_id = action_widget["response"]
|
||||||
|
is_default = (
|
||||||
|
" default" if decompile.truthy(action_widget["default"]) else ""
|
||||||
|
)
|
||||||
|
return f"[action response={response_id}{is_default}]"
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@decompiler("action-widgets", skip_children=True)
|
||||||
|
def decompile_action_widgets(ctx, gir):
|
||||||
|
# This is handled in the <child> decompiler and decompile_response_type above
|
||||||
|
pass
|
||||||
|
|
|
@ -210,8 +210,6 @@ class TestSamples(unittest.TestCase):
|
||||||
SKIP_COMPILE = ["translator_comments"]
|
SKIP_COMPILE = ["translator_comments"]
|
||||||
|
|
||||||
SKIP_DECOMPILE = [
|
SKIP_DECOMPILE = [
|
||||||
# Not implemented yet
|
|
||||||
"action_widgets",
|
|
||||||
# Comments are not preserved in either direction
|
# Comments are not preserved in either direction
|
||||||
"comments",
|
"comments",
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue