fixup confirmation dialogs for gtk4

This commit is contained in:
deltragon 2024-03-06 21:06:41 +01:00
parent 11af2113df
commit edbb7e70d5
No known key found for this signature in database
GPG Key ID: 41F552553C6D94B5
1 changed files with 29 additions and 28 deletions

View File

@ -164,56 +164,57 @@ class SettingsDialog:
def on_reset_menu_clicked(self, button): def on_reset_menu_clicked(self, button):
self.popover.hide() self.popover.hide()
def __confirmation_dialog_response(widget, response_id): def __confirmation_dialog_response(dialog, result):
if response_id == Gtk.ResponseType.OK: response_id = dialog.choose_finish(result)
if response_id == 1:
utility.reset_config() utility.reset_config()
self.config = Config() self.config = Config()
# Remove breaks from the container # Remove breaks from the container
self.box_short_breaks.foreach(lambda element: self.box_short_breaks.remove(element)) self.__clear_children(self.box_short_breaks)
self.box_long_breaks.foreach(lambda element: self.box_long_breaks.remove(element)) self.__clear_children(self.box_long_breaks)
# Remove plugins from the container self.__clear_children(self.box_plugins)
self.box_plugins.foreach(lambda element: self.box_plugins.remove(element))
# Initialize again # Initialize again
self.__initialize(self.config) self.__initialize(self.config)
widget.destroy()
messagedialog = Gtk.MessageDialog() messagedialog = Gtk.AlertDialog()
messagedialog.set_modal(True) messagedialog.set_modal(True)
messagedialog.set_transient_for(self.window) messagedialog.set_buttons(['_Cancel', _("Reset")])
messagedialog.set_property('message_type', Gtk.MessageType.WARNING) messagedialog.set_message(_("Are you sure you want to reset all settings to default?"))
messagedialog.set_property('text', _("Are you sure you want to reset all settings to default?")) messagedialog.set_detail(_("You can't undo this action."))
messagedialog.set_property('secondary-text', _("You can't undo this action."))
messagedialog.add_button('_Cancel', Gtk.ResponseType.CANCEL)
messagedialog.add_button(_("Reset"), Gtk.ResponseType.OK)
messagedialog.connect("response", __confirmation_dialog_response) messagedialog.set_cancel_button(0)
messagedialog.show() messagedialog.set_default_button(0)
messagedialog.choose(self.window, None, __confirmation_dialog_response)
def __clear_children(self, widget):
while widget.get_last_child() is not None:
widget.remove(widget.get_last_child())
def __delete_break(self, break_config, is_short, on_remove): def __delete_break(self, break_config, is_short, on_remove):
""" """
Remove the break after a confirmation. Remove the break after a confirmation.
""" """
def __confirmation_dialog_response(widget, response_id): def __confirmation_dialog_response(dialog, result):
if response_id == Gtk.ResponseType.OK: response_id = dialog.choose_finish(result)
if response_id == 1:
if is_short: if is_short:
self.config.get('short_breaks').remove(break_config) self.config.get('short_breaks').remove(break_config)
else: else:
self.config.get('long_breaks').remove(break_config) self.config.get('long_breaks').remove(break_config)
on_remove() on_remove()
widget.destroy()
messagedialog = Gtk.MessageDialog() messagedialog = Gtk.AlertDialog()
messagedialog.set_modal(True) messagedialog.set_modal(True)
messagedialog.set_transient_for(self.window) messagedialog.set_buttons(['_Cancel', _("Delete")])
messagedialog.set_property('message_type', Gtk.MessageType.WARNING) messagedialog.set_message(_("Are you sure you want to delete this break?"))
messagedialog.set_property('text', _("Are you sure you want to delete this break?")) messagedialog.set_detail(_("You can't undo this action."))
messagedialog.set_property('secondary-text', _("You can't undo this action."))
messagedialog.add_button('_Cancel', Gtk.ResponseType.CANCEL)
messagedialog.add_button(_("Delete"), Gtk.ResponseType.OK)
messagedialog.connect("response", __confirmation_dialog_response) messagedialog.set_cancel_button(0)
messagedialog.show() messagedialog.set_default_button(0)
messagedialog.choose(self.window, None, __confirmation_dialog_response)
def __create_plugin_item(self, plugin_config): def __create_plugin_item(self, plugin_config):
""" """