Make it so only one preferences dialog can be open

This commit is contained in:
kramo
2024-04-05 11:57:22 +02:00
parent f4b44477e9
commit d9384308fe
2 changed files with 13 additions and 0 deletions

View File

@@ -285,6 +285,9 @@ class CartridgesApplication(Adw.Application):
page_name: Optional[str] = None,
expander_row: Optional[str] = None,
) -> CartridgesWindow:
if CartridgesPreferences.is_open:
return
win = CartridgesPreferences()
if page_name:
win.set_visible_page_name(page_name)

View File

@@ -118,8 +118,15 @@ class CartridgesPreferences(Adw.PreferencesDialog):
removed_games: set[Game] = set()
warning_menu_buttons: dict = {}
is_open = False
def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)
# Make it so only one dialog can be open at a time
self.__class__.is_open = True
self.connect("closed", lambda *_: self.set_is_open(False))
self.file_chooser = Gtk.FileDialog()
self.toast = Adw.Toast.new(_("All games removed"))
@@ -247,6 +254,9 @@ class CartridgesPreferences(Adw.PreferencesDialog):
self.sgdb_key_entry_row.connect("changed", set_sgdb_sensitive)
set_sgdb_sensitive(self.sgdb_key_entry_row)
def set_is_open(self, is_open: bool) -> None:
self.__class__.is_open = is_open
def get_switch(self, setting: str) -> Any:
return getattr(self, f'{setting.replace("-", "_")}_switch')