Add GtkComboBoxText items

This commit is contained in:
James Westman 2021-11-12 18:40:26 -06:00
parent f1e1811e1f
commit aa447466c0
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
12 changed files with 137 additions and 17 deletions

View file

@ -7,7 +7,8 @@ from .gtk_layout import layout
from .gtk_menu import menu
from .gtk_size_group import widgets
from .gtk_styles import styles
from .gtk_combo_box_text import items
OBJECT_HOOKS = [menu]
OBJECT_CONTENT_HOOKS = [a11y, styles, layout, mime_types, patterns, suffixes, widgets]
OBJECT_CONTENT_HOOKS = [a11y, styles, layout, mime_types, patterns, suffixes, widgets, items]

View file

@ -0,0 +1,89 @@
# gtk_combo_box_text.py
#
# Copyright 2021 James Westman <james@jwestman.net>
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This file is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: LGPL-3.0-or-later
from ..ast import BaseTypedAttribute
from ..ast_utils import AstNode, validate
from ..completions_utils import *
from ..gir import StringType
from ..lsp_utils import Completion, CompletionItemKind
from ..parse_tree import *
from ..parser_utils import *
from ..xml_emitter import XmlEmitter
class Items(AstNode):
@validate("items")
def container_is_combo_box_text(self):
self.validate_parent_type("Gtk", "ComboBoxText", "combo box items")
def emit_xml(self, xml: XmlEmitter):
xml.start_tag("items")
for child in self.children:
child.emit_xml(xml)
xml.end_tag()
class Item(BaseTypedAttribute):
tag_name = "item"
attr_name = "id"
@property
def value_type(self):
return StringType()
item = Group(
Item,
Sequence(
Optional(
Sequence(
UseIdent("name"),
Op(":"),
)
),
value,
)
)
items = Group(
Items,
Statement(
Keyword("items", True),
OpenBracket(),
Delimited(
item,
Comma()
),
CloseBracket(),
)
)
@completer(
applies_in=[ast.ObjectContent],
applies_in_subclass=("Gtk", "ComboBoxText"),
matches=new_statement_patterns,
)
def items_completer(ast_node, match_variables):
yield Completion(
"items", CompletionItemKind.Snippet,
snippet="items [$0];"
)

View file

@ -75,12 +75,11 @@ suffixes = create_node("suffixes", "suffix")
@completer(
applies_in=[ast.ObjectContent],
applies_in_subclass=("Gtk", "FileFilter"),
matches=new_statement_patterns,
)
def file_filter_completer(ast_node, match_variables):
file_filter = ast_node.root.gir.get_type("FileFilter", "Gtk")
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("patterns", CompletionItemKind.Snippet, snippet="patterns [\"$0\"];")
yield Completion("suffixes", CompletionItemKind.Snippet, snippet="suffixes [\"$0\"];")
yield Completion("mime-types", CompletionItemKind.Snippet, snippet="mime-types [\"$0\"];")
yield Completion("patterns", CompletionItemKind.Snippet, snippet="patterns [\"$0\"];")
yield Completion("suffixes", CompletionItemKind.Snippet, snippet="suffixes [\"$0\"];")

View file

@ -70,6 +70,7 @@ layout = Group(
@completer(
applies_in=[ast.ObjectContent],
applies_in_subclass=("Gtk", "Widget"),
matches=new_statement_patterns,
)
def layout_completer(ast_node, match_variables):

View file

@ -77,9 +77,8 @@ widgets = Group(
@completer(
applies_in=[ast.ObjectContent],
applies_in_subclass=("Gtk", "SizeGroup"),
matches=new_statement_patterns,
)
def file_filter_completer(ast_node, match_variables):
file_filter = ast_node.root.gir.get_type("SizeGroup", "Gtk")
if ast_node.gir_class and ast_node.gir_class.assignable_to(file_filter):
yield Completion("widgets", CompletionItemKind.Snippet, snippet="widgets [$0];")
def size_group_completer(ast_node, match_variables):
yield Completion("widgets", CompletionItemKind.Snippet, snippet="widgets [$0];")

View file

@ -63,6 +63,7 @@ styles = Group(
@completer(
applies_in=[ast.ObjectContent],
applies_in_subclass=("Gtk", "Widget"),
matches=new_statement_patterns,
)
def style_completer(ast_node, match_variables):