| 1 |
# gtk_combo_box_text.py |
| 2 |
# |
| 3 |
# Copyright 2021 James Westman <[email protected]> |
| 4 |
# |
| 5 |
# This file is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU Lesser General Public License as |
| 7 |
# published by the Free Software Foundation; either version 3 of the |
| 8 |
# License, or (at your option) any later version. |
| 9 |
# |
| 10 |
# This file is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
# Lesser General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU Lesser General Public |
| 16 |
# License along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
# |
| 18 |
# SPDX-License-Identifier: LGPL-3.0-or-later |
| 19 |
|
| 20 |
|
| 21 |
from .common import * |
| 22 |
from .gobject_object import ObjectContent, validate_parent_type |
| 23 |
from .values import StringValue |
| 24 |
|
| 25 |
|
| 26 |
class Item(AstNode): |
| 27 |
grammar = StringValue |
| 28 |
|
| 29 |
@property |
| 30 |
def child(self) -> StringValue: |
| 31 |
return self.children[StringValue][0] |
| 32 |
|
| 33 |
@property |
| 34 |
def document_symbol(self) -> DocumentSymbol: |
| 35 |
return DocumentSymbol( |
| 36 |
self.child.range.text, |
| 37 |
SymbolKind.String, |
| 38 |
self.range, |
| 39 |
self.range, |
| 40 |
) |
| 41 |
|
| 42 |
|
| 43 |
class ExtStringListStrings(AstNode): |
| 44 |
grammar = [ |
| 45 |
Keyword("strings"), |
| 46 |
"[", |
| 47 |
Delimited(Item, ","), |
| 48 |
"]", |
| 49 |
] |
| 50 |
|
| 51 |
@property |
| 52 |
def document_symbol(self) -> DocumentSymbol: |
| 53 |
return DocumentSymbol( |
| 54 |
"strings", |
| 55 |
SymbolKind.Array, |
| 56 |
self.range, |
| 57 |
self.group.tokens["strings"].range, |
| 58 |
) |
| 59 |
|
| 60 |
@validate("strings") |
| 61 |
def container_is_string_list(self): |
| 62 |
validate_parent_type(self, "Gtk", "StringList", "StringList items") |
| 63 |
|
| 64 |
@validate("strings") |
| 65 |
def unique_in_parent(self): |
| 66 |
self.validate_unique_in_parent("Duplicate strings block") |
| 67 |
|
| 68 |
@docs("strings") |
| 69 |
def ref_docs(self): |
| 70 |
return get_docs_section("Syntax ExtStringListStrings") |
| 71 |
|
| 72 |
|
| 73 |
@completer( |
| 74 |
applies_in=[ObjectContent], |
| 75 |
applies_in_subclass=("Gtk", "StringList"), |
| 76 |
matches=new_statement_patterns, |
| 77 |
) |
| 78 |
def strings_completer(_ctx: CompletionContext): |
| 79 |
yield Completion( |
| 80 |
"strings", |
| 81 |
CompletionItemKind.Snippet, |
| 82 |
snippet="strings [$0]", |
| 83 |
sort_text=get_sort_key(CompletionPriority.OBJECT_MEMBER, "strings"), |
| 84 |
) |
| 85 |
|
| 86 |
|
| 87 |
@decompiler("items", parent_type="Gtk.StringList") |
| 88 |
def decompile_strings(ctx: DecompileCtx, gir: gir.GirContext): |
| 89 |
ctx.print("strings [") |
| 90 |
|
| 91 |
|
| 92 |
@decompiler("item", cdata=True, parent_type="Gtk.StringList") |
| 93 |
def decompile_item( |
| 94 |
ctx: DecompileCtx, |
| 95 |
gir: gir.GirContext, |
| 96 |
translatable="false", |
| 97 |
comments=None, |
| 98 |
context=None, |
| 99 |
cdata=None, |
| 100 |
): |
| 101 |
comments, translatable = decompile_translatable( |
| 102 |
cdata, translatable, context, comments |
| 103 |
) |
| 104 |
if comments is not None: |
| 105 |
ctx.print(comments) |
| 106 |
ctx.print(translatable + ",") |