mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Add support for Adw.AlertDialog
This commit is contained in:
parent
6522421251
commit
ba8b492134
13 changed files with 136 additions and 40 deletions
|
@ -79,7 +79,12 @@ def get_available_namespaces() -> T.List[T.Tuple[str, str]]:
|
|||
]
|
||||
|
||||
for search_path in search_paths:
|
||||
for filename in os.listdir(search_path):
|
||||
try:
|
||||
filenames = os.listdir(search_path)
|
||||
except FileNotFoundError:
|
||||
continue
|
||||
|
||||
for filename in filenames:
|
||||
if filename.endswith(".typelib"):
|
||||
namespace, version = filename.removesuffix(".typelib").rsplit("-", 1)
|
||||
_available_namespaces.append((namespace, version))
|
||||
|
|
|
@ -3,7 +3,7 @@ from .adw_breakpoint import (
|
|||
AdwBreakpointSetter,
|
||||
AdwBreakpointSetters,
|
||||
)
|
||||
from .adw_message_dialog import ExtAdwMessageDialog
|
||||
from .adw_response_dialog import ExtAdwResponseDialog
|
||||
from .attributes import BaseAttribute
|
||||
from .binding import Binding
|
||||
from .common import *
|
||||
|
@ -60,7 +60,7 @@ OBJECT_CONTENT_HOOKS.children = [
|
|||
AdwBreakpointCondition,
|
||||
AdwBreakpointSetters,
|
||||
ExtAccessibility,
|
||||
ExtAdwMessageDialog,
|
||||
ExtAdwResponseDialog,
|
||||
ExtComboBoxItems,
|
||||
ext_file_filter_mime_types,
|
||||
ext_file_filter_patterns,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# adw_message_dialog.py
|
||||
# adw_response_dialog.py
|
||||
#
|
||||
# Copyright 2023 James Westman <james@jwestman.net>
|
||||
#
|
||||
|
@ -25,7 +25,7 @@ from .gobject_object import ObjectContent, validate_parent_type
|
|||
from .values import StringValue
|
||||
|
||||
|
||||
class ExtAdwMessageDialogFlag(AstNode):
|
||||
class ExtAdwResponseDialogFlag(AstNode):
|
||||
grammar = AnyOf(
|
||||
UseExact("flag", "destructive"),
|
||||
UseExact("flag", "suggested"),
|
||||
|
@ -51,12 +51,12 @@ class ExtAdwMessageDialogFlag(AstNode):
|
|||
)
|
||||
|
||||
|
||||
class ExtAdwMessageDialogResponse(AstNode):
|
||||
class ExtAdwResponseDialogResponse(AstNode):
|
||||
grammar = [
|
||||
UseIdent("id"),
|
||||
Match(":").expected(),
|
||||
to_parse_node(StringValue).expected("a string or translatable string"),
|
||||
ZeroOrMore(ExtAdwMessageDialogFlag),
|
||||
ZeroOrMore(ExtAdwResponseDialogFlag),
|
||||
]
|
||||
|
||||
@property
|
||||
|
@ -64,8 +64,8 @@ class ExtAdwMessageDialogResponse(AstNode):
|
|||
return self.tokens["id"]
|
||||
|
||||
@property
|
||||
def flags(self) -> T.List[ExtAdwMessageDialogFlag]:
|
||||
return self.children[ExtAdwMessageDialogFlag]
|
||||
def flags(self) -> T.List[ExtAdwResponseDialogFlag]:
|
||||
return self.children[ExtAdwResponseDialogFlag]
|
||||
|
||||
@property
|
||||
def appearance(self) -> T.Optional[str]:
|
||||
|
@ -106,16 +106,16 @@ class ExtAdwMessageDialogResponse(AstNode):
|
|||
)
|
||||
|
||||
|
||||
class ExtAdwMessageDialog(AstNode):
|
||||
class ExtAdwResponseDialog(AstNode):
|
||||
grammar = [
|
||||
Keyword("responses"),
|
||||
Match("[").expected(),
|
||||
Delimited(ExtAdwMessageDialogResponse, ","),
|
||||
Delimited(ExtAdwResponseDialogResponse, ","),
|
||||
"]",
|
||||
]
|
||||
|
||||
@property
|
||||
def responses(self) -> T.List[ExtAdwMessageDialogResponse]:
|
||||
def responses(self) -> T.List[ExtAdwResponseDialogResponse]:
|
||||
return self.children
|
||||
|
||||
@property
|
||||
|
@ -128,8 +128,11 @@ class ExtAdwMessageDialog(AstNode):
|
|||
)
|
||||
|
||||
@validate("responses")
|
||||
def container_is_message_dialog(self):
|
||||
validate_parent_type(self, "Adw", "MessageDialog", "responses")
|
||||
def container_is_message_dialog_or_alert_dialog(self):
|
||||
try:
|
||||
validate_parent_type(self, "Adw", "MessageDialog", "responses")
|
||||
except:
|
||||
validate_parent_type(self, "Adw", "AlertDialog", "responses")
|
||||
|
||||
@validate("responses")
|
||||
def unique_in_parent(self):
|
||||
|
@ -141,7 +144,18 @@ class ExtAdwMessageDialog(AstNode):
|
|||
applies_in_subclass=("Adw", "MessageDialog"),
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def style_completer(lsp, ast_node, match_variables):
|
||||
def complete_adw_message_dialog(lsp, ast_node, match_variables):
|
||||
yield Completion(
|
||||
"responses", CompletionItemKind.Keyword, snippet="responses [\n\t$0\n]"
|
||||
)
|
||||
|
||||
|
||||
@completer(
|
||||
applies_in=[ObjectContent],
|
||||
applies_in_subclass=("Adw", "AlertDialog"),
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def complete_adw_alert_dialog(lsp, ast_node, match_variables):
|
||||
yield Completion(
|
||||
"responses", CompletionItemKind.Keyword, snippet="responses [\n\t$0\n]"
|
||||
)
|
|
@ -337,7 +337,7 @@ class XmlOutput(OutputFormat):
|
|||
self._emit_attribute("property", "name", prop.name, prop.value, xml)
|
||||
xml.end_tag()
|
||||
|
||||
elif isinstance(extension, ExtAdwMessageDialog):
|
||||
elif isinstance(extension, ExtAdwResponseDialog):
|
||||
xml.start_tag("responses")
|
||||
for response in extension.responses:
|
||||
xml.start_tag(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue