Use array-like syntax for styles, file filters

These are now pseudo-properties with brackets around the array items,
for consistency with more familiar languages.
This commit is contained in:
James Westman 2021-11-12 09:26:41 -06:00
parent ebfa72d94f
commit f8478adf3a
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
5 changed files with 15 additions and 10 deletions

View file

@ -199,7 +199,7 @@ Basic Usage
.. code-block:: .. code-block::
Gtk.Label { Gtk.Label {
style "dim-label", "title"; styles: ["dim-label", "title"];
} }

View file

@ -49,6 +49,7 @@ def create_node(tag_name: str, singular: str):
Keyword(tag_name), Keyword(tag_name),
UseLiteral("tag_name", tag_name), UseLiteral("tag_name", tag_name),
Op(":"), Op(":"),
OpenBracket(),
Delimited( Delimited(
Group( Group(
FilterString, FilterString,
@ -59,6 +60,7 @@ def create_node(tag_name: str, singular: str):
), ),
Comma(), Comma(),
), ),
CloseBracket(),
) )
) )
@ -75,7 +77,7 @@ suffixes = create_node("suffixes", "suffix")
def file_filter_completer(ast_node, match_variables): def file_filter_completer(ast_node, match_variables):
file_filter = ast_node.root.gir.get_type("FileFilter", "Gtk") file_filter = ast_node.root.gir.get_type("FileFilter", "Gtk")
if ast_node.gir_class and ast_node.gir_class.assignable_to(file_filter): if ast_node.gir_class and ast_node.gir_class.assignable_to(file_filter):
yield Completion("mime-types", CompletionItemKind.Snippet, snippet="mime-types \"$0\";") yield Completion("mime-types", CompletionItemKind.Snippet, snippet="mime-types: [\"$0\"];")
yield Completion("patterns", CompletionItemKind.Snippet, snippet="patterns \"$0\";") yield Completion("patterns", CompletionItemKind.Snippet, snippet="patterns: [\"$0\"];")
yield Completion("suffixes", CompletionItemKind.Snippet, snippet="suffixes \"$0\";") yield Completion("suffixes", CompletionItemKind.Snippet, snippet="suffixes: [\"$0\"];")

View file

@ -43,7 +43,9 @@ class StyleClass(AstNode):
styles = Group( styles = Group(
Styles, Styles,
Statement( Statement(
Keyword("style"), Keyword("styles"),
Op(":"),
OpenBracket(),
Delimited( Delimited(
Group( Group(
StyleClass, StyleClass,
@ -51,6 +53,7 @@ styles = Group(
), ),
Comma(), Comma(),
), ),
CloseBracket(),
) )
) )
@ -60,5 +63,5 @@ styles = Group(
matches=new_statement_patterns, matches=new_statement_patterns,
) )
def style_completer(ast_node, match_variables): def style_completer(ast_node, match_variables):
yield Completion("style", CompletionItemKind.Keyword, snippet="style \"$0\";") yield Completion("styles", CompletionItemKind.Keyword, snippet="styles: [\"$0\"];")

View file

@ -2,7 +2,7 @@ using Gtk 4.0;
FileFilter { FileFilter {
name: "File Filter Name"; name: "File Filter Name";
mime-types: "text/plain", "image/ *"; mime-types: ["text/plain", "image/ *"];
patterns: "*.txt"; patterns: ["*.txt"];
suffixes: "png"; suffixes: ["png"];
} }

View file

@ -1,5 +1,5 @@
using Gtk 4.0; using Gtk 4.0;
Label { Label {
style "class-1", "class-2"; styles: ["class-1", "class-2"];
} }