mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-05 16:09:07 -04:00
Add GtkFileFilter properties
This commit is contained in:
parent
b776163cd7
commit
ebfa72d94f
13 changed files with 141 additions and 39 deletions
|
@ -5,7 +5,8 @@ from .gtk_a11y import a11y
|
|||
from .gtk_menu import menu
|
||||
from .gtk_styles import styles
|
||||
from .gtk_layout import layout
|
||||
from .gtk_file_filter import mime_types, patterns, suffixes
|
||||
|
||||
OBJECT_HOOKS = [menu]
|
||||
|
||||
OBJECT_CONTENT_HOOKS = [a11y, styles, layout]
|
||||
OBJECT_CONTENT_HOOKS = [a11y, styles, layout, mime_types, patterns, suffixes]
|
||||
|
|
81
gtkblueprinttool/extensions/gtk_file_filter.py
Normal file
81
gtkblueprinttool/extensions/gtk_file_filter.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
# gtk_file_filter.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 .. import ast
|
||||
from ..ast_utils import AstNode
|
||||
from ..completions_utils import *
|
||||
from ..lsp_utils import Completion, CompletionItemKind
|
||||
from ..parse_tree import *
|
||||
from ..parser_utils import *
|
||||
from ..xml_emitter import XmlEmitter
|
||||
|
||||
|
||||
class Filters(AstNode):
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.start_tag(self.tokens["tag_name"])
|
||||
for child in self.children:
|
||||
child.emit_xml(xml)
|
||||
xml.end_tag()
|
||||
|
||||
|
||||
class FilterString(AstNode):
|
||||
def emit_xml(self, xml):
|
||||
xml.start_tag(self.tokens["tag_name"])
|
||||
xml.put_text(self.tokens["name"])
|
||||
xml.end_tag()
|
||||
|
||||
|
||||
def create_node(tag_name: str, singular: str):
|
||||
return Group(
|
||||
Filters,
|
||||
Statement(
|
||||
Keyword(tag_name),
|
||||
UseLiteral("tag_name", tag_name),
|
||||
Op(":"),
|
||||
Delimited(
|
||||
Group(
|
||||
FilterString,
|
||||
Sequence(
|
||||
UseQuoted("name"),
|
||||
UseLiteral("tag_name", singular),
|
||||
)
|
||||
),
|
||||
Comma(),
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
mime_types = create_node("mime-types", "mime-type")
|
||||
patterns = create_node("patterns", "pattern")
|
||||
suffixes = create_node("suffixes", "suffix")
|
||||
|
||||
|
||||
@completer(
|
||||
applies_in=[ast.ObjectContent],
|
||||
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\";")
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue