Skip to content

Commit d447365

Browse files
committed
Use add_pattern for new dialog's FileFilters
This addresses an issue originally fixed in #3221 where the GTK function `add_media_type` acted inconsistently across distributions. This was reintroduced in later releases after the UI was updated for creating bottles. As was before, the `add_media_type` function would be the ideal one to use, so this is in actuality a temporary fix.
1 parent daa3cb5 commit d447365

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

bottles/frontend/new_bottle_dialog.py

+30-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from gettext import gettext as _
1919
from typing import Any
2020
from gi.repository import Gtk, Adw, Pango, Gio, Xdp, GObject, GLib
21+
from collections.abc import Sequence
2122

2223
from bottles.backend.models.config import BottleConfig
2324
from bottles.backend.utils.threading import RunAsync
@@ -159,15 +160,37 @@ def set_path(dialog, result):
159160
self.label_choose_env.set_label(file.get_basename())
160161
self.label_choose_env.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
161162

162-
filters = Gio.ListStore.new(Gtk.FileFilter)
163+
def create_filter(name: str,
164+
patterns: Sequence[str],
165+
) -> Gtk.FileFilter:
166+
'''Creates a filter with the specified name and patterns
167+
168+
The use of patterns is particularly notable here as the other
169+
strategy for defining filters via `filter.add_mime_type` is
170+
strangely inconsistent across different distribtutions, often
171+
leaving out filters (sometimes resulting in no filters).
172+
173+
Until the reasoning for this is determined, it is safest to
174+
manually specify the patterns and name. This will ideally be
175+
replaced with the `add_mime_type` function once the root cause is
176+
discovered.
177+
'''
178+
filter = Gtk.FileFilter()
179+
filter.set_name(name)
180+
for pattern in patterns:
181+
filter.add_pattern(pattern)
163182

164-
yaml_filter = Gtk.FileFilter()
165-
yaml_filter.set_name("YAML")
166-
yaml_filter.add_mime_type("application/yaml")
183+
return filter
184+
185+
filters = Gio.ListStore.new(Gtk.FileFilter)
167186

168-
all_filter = Gtk.FileFilter()
169-
all_filter.set_name(_("All Files"))
170-
all_filter.add_pattern("*")
187+
# This filter is intended to be "application/yaml" mime type
188+
yaml_filter = create_filter(name="YAML",
189+
patterns=["*.yaml", "*.yml"],
190+
)
191+
all_filter = create_filter(name=_("All Files"),
192+
patterns=["*"],
193+
)
171194

172195
filters.append(yaml_filter)
173196
filters.append(all_filter)

0 commit comments

Comments
 (0)