mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
ExtAdwMessageDialog: Duplicate flag errors
This commit is contained in:
parent
c95195197d
commit
64da41b268
3 changed files with 50 additions and 10 deletions
|
@ -25,31 +25,60 @@ from .gobject_object import ObjectContent, validate_parent_type
|
||||||
from .values import StringValue
|
from .values import StringValue
|
||||||
|
|
||||||
|
|
||||||
class Response(AstNode):
|
class ExtAdwMessageDialogFlag(AstNode):
|
||||||
|
grammar = AnyOf(
|
||||||
|
UseExact("flag", "destructive"),
|
||||||
|
UseExact("flag", "suggested"),
|
||||||
|
UseExact("flag", "disabled"),
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def flag(self) -> str:
|
||||||
|
return self.tokens["flag"]
|
||||||
|
|
||||||
|
@validate()
|
||||||
|
def unique(self):
|
||||||
|
self.validate_unique_in_parent(
|
||||||
|
f"Duplicate '{self.flag}' flag", check=lambda child: child.flag == self.flag
|
||||||
|
)
|
||||||
|
|
||||||
|
@validate()
|
||||||
|
def exclusive(self):
|
||||||
|
if self.flag in ["destructive", "suggested"]:
|
||||||
|
self.validate_unique_in_parent(
|
||||||
|
"'suggested' and 'destructive' are exclusive",
|
||||||
|
check=lambda child: child.flag in ["destructive", "suggested"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ExtAdwMessageDialogResponse(AstNode):
|
||||||
grammar = [
|
grammar = [
|
||||||
UseIdent("id"),
|
UseIdent("id"),
|
||||||
Match(":").expected(),
|
Match(":").expected(),
|
||||||
to_parse_node(StringValue).expected("a string or translatable string"),
|
to_parse_node(StringValue).expected("a string or translatable string"),
|
||||||
ZeroOrMore(
|
ZeroOrMore(ExtAdwMessageDialogFlag),
|
||||||
AnyOf(Keyword("destructive"), Keyword("suggested"), Keyword("disabled"))
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def id(self) -> str:
|
def id(self) -> str:
|
||||||
return self.tokens["id"]
|
return self.tokens["id"]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def flags(self) -> T.List[ExtAdwMessageDialogFlag]:
|
||||||
|
return self.children[ExtAdwMessageDialogFlag]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def appearance(self) -> T.Optional[str]:
|
def appearance(self) -> T.Optional[str]:
|
||||||
if "destructive" in self.tokens:
|
if any(flag.flag == "destructive" for flag in self.flags):
|
||||||
return "destructive"
|
return "destructive"
|
||||||
if "suggested" in self.tokens:
|
elif any(flag.flag == "suggested" for flag in self.flags):
|
||||||
return "suggested"
|
return "suggested"
|
||||||
return None
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def enabled(self) -> bool:
|
def enabled(self) -> bool:
|
||||||
return "disabled" not in self.tokens
|
return not any(flag.flag == "disabled" for flag in self.flags)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def value(self) -> StringValue:
|
def value(self) -> StringValue:
|
||||||
|
@ -71,12 +100,12 @@ class ExtAdwMessageDialog(AstNode):
|
||||||
grammar = [
|
grammar = [
|
||||||
Keyword("responses"),
|
Keyword("responses"),
|
||||||
Match("[").expected(),
|
Match("[").expected(),
|
||||||
Delimited(Response, ","),
|
Delimited(ExtAdwMessageDialogResponse, ","),
|
||||||
"]",
|
"]",
|
||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def responses(self) -> T.List[Response]:
|
def responses(self) -> T.List[ExtAdwMessageDialogResponse]:
|
||||||
return self.children
|
return self.children
|
||||||
|
|
||||||
@validate("responses")
|
@validate("responses")
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
using Gtk 4.0;
|
||||||
|
using Adw 1;
|
||||||
|
|
||||||
|
Adw.MessageDialog {
|
||||||
|
responses [
|
||||||
|
cancel: _("Cancel") disabled disabled,
|
||||||
|
ok: _("Ok") destructive suggested,
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
6,34,8,Duplicate 'disabled' flag
|
||||||
|
7,29,9,'suggested' and 'destructive' are exclusive
|
Loading…
Add table
Add a link
Reference in a new issue