Merge pull request #1330 from auouymous/inject-extension-preferences

Add/remove extension preferences buttons when loaded/unloaded.
This commit is contained in:
auouymous 2022-07-13 11:50:32 -07:00 committed by GitHub
commit cf24177462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 12 deletions

View File

@ -321,21 +321,35 @@ class gPodderPreferences(BuilderWidget):
gpodder.user_extensions.on_ui_object_available('preferences-gtk', self)
self.inject_extensions_preferences(init=True)
self.prefs_stack.foreach(self._wrap_checkbox_labels)
def _wrap_checkbox_labels(self, w, *args):
if w.get_name().startswith("no_label_wrap"):
return
elif isinstance(w, Gtk.CheckButton):
label = w.get_child()
label.set_line_wrap(True)
elif isinstance(w, Gtk.Container):
w.foreach(self._wrap_checkbox_labels)
def inject_extensions_preferences(self, init=False):
if not init:
# remove preferences buttons for all extensions
for child in self.prefs_stack.get_children():
if child.get_name().startswith("extension."):
self.prefs_stack.remove(child)
# add preferences buttons for all extensions
result = gpodder.user_extensions.on_preferences()
if result:
for label, callback in result:
self.prefs_stack.add_titled(callback(), label, label)
def _wrap_checkbox_labels(w, *args):
if w.get_name().startswith("no_label_wrap"):
return
elif isinstance(w, Gtk.CheckButton):
label = w.get_child()
label.set_line_wrap(True)
elif isinstance(w, Gtk.Container):
w.foreach(_wrap_checkbox_labels)
self.prefs_stack.foreach(_wrap_checkbox_labels)
page = callback()
name = "extension." + label
page.set_name(name)
page.foreach(self._wrap_checkbox_labels)
self.prefs_stack.add_titled(page, name, label)
def _extensions_select_function(self, selection, model, path, path_currently_selected):
return model.get_value(model.get_iter(path), self.C_SHOW_TOGGLE)
@ -464,6 +478,7 @@ class gPodderPreferences(BuilderWidget):
self.on_extension_enabled(container.module)
else:
self.on_extension_disabled(container.module)
self.inject_extensions_preferences()
elif container.error is not None:
if hasattr(container.error, 'message'):
error_msg = container.error.message