[meld] Update destructive dialog actions with appropriate styling (#660)



commit 8da440c0cc8ad64dc2016ec86392a29e8e8bbfe0
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Mar 13 09:46:04 2022 +1000

    Update destructive dialog actions with appropriate styling (#660)

 meld/dirdiff.py                          |  7 +++++--
 meld/filediff.py                         |  6 ++++--
 meld/iohelpers.py                        | 11 +++++++----
 meld/misc.py                             | 16 ++++++++++------
 meld/resources/ui/save-confirm-dialog.ui |  3 +++
 5 files changed, 29 insertions(+), 14 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 36e71606..34dffc07 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -1225,8 +1225,11 @@ class DirDiff(Gtk.VBox, tree.TreeviewCommon, MeldDoc):
                         parent_name = os.path.dirname(dst)
                         folder_name = os.path.basename(dst)
                         dialog_buttons = [
-                            (_("_Cancel"), Gtk.ResponseType.CANCEL),
-                            (_("_Replace"), Gtk.ResponseType.OK),
+                            (_("_Cancel"), Gtk.ResponseType.CANCEL, None),
+                            (
+                                _("_Replace"), Gtk.ResponseType.OK,
+                                Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION,
+                            ),
                         ]
                         replace = misc.modal_dialog(
                             primary=_("Replace folder ā€œ%sā€?") % folder_name,
diff --git a/meld/filediff.py b/meld/filediff.py
index 436fabf8..108a68b8 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1224,8 +1224,10 @@ class FileDiff(Gtk.VBox, MeldDoc):
             secondary = _(
                 "If the conflict was resolved successfully, you may mark "
                 "it as resolved now.")
-            buttons = ((_("Cancel"), Gtk.ResponseType.CANCEL),
-                       (_("Mark _Resolved"), Gtk.ResponseType.OK))
+            buttons = (
+                (_("Cancel"), Gtk.ResponseType.CANCEL, None),
+                (_("Mark _Resolved"), Gtk.ResponseType.OK, None),
+            )
             resolve_response = misc.modal_dialog(
                 primary, secondary, buttons, parent=self,
                 messagetype=Gtk.MessageType.QUESTION)
diff --git a/meld/iohelpers.py b/meld/iohelpers.py
index a7882386..d8ad74db 100644
--- a/meld/iohelpers.py
+++ b/meld/iohelpers.py
@@ -53,8 +53,11 @@ def trash_or_confirm(gfile: Gio.File) -> bool:
             "to the trash."
         ),
         buttons=[
-            (_("_Cancel"), Gtk.ResponseType.CANCEL),
-            (_("_Delete Permanently"), Gtk.ResponseType.OK),
+            (_("_Cancel"), Gtk.ResponseType.CANCEL, None),
+            (
+                _("_Delete Permanently"), Gtk.ResponseType.OK,
+                Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION,
+            ),
         ],
     )
 
@@ -110,8 +113,8 @@ def prompt_save_filename(
             "If you replace the existing file, its contents "
             "will be lost.") % parent_name,
         buttons=[
-            (_("_Cancel"), Gtk.ResponseType.CANCEL),
-            (_("_Replace"), Gtk.ResponseType.OK),
+            (_("_Cancel"), Gtk.ResponseType.CANCEL, None),
+            (_("_Replace"), Gtk.ResponseType.OK, None),
         ],
         messagetype=Gtk.MessageType.WARNING,
     )
diff --git a/meld/misc.py b/meld/misc.py
index b7f7ef4f..d7255f84 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -94,9 +94,10 @@ def error_dialog(primary: str, secondary: str) -> Gtk.ResponseType:
 def modal_dialog(
     primary: str,
     secondary: str,
-    buttons: Union[Gtk.ButtonsType, Sequence[Tuple[str, int]]],
+    buttons: Union[Gtk.ButtonsType, Sequence[Tuple[str, int, Optional[str]]]],
+    *,
     parent: Optional[Gtk.Window] = None,
-    messagetype: Gtk.MessageType = Gtk.MessageType.WARNING
+    messagetype: Gtk.MessageType = Gtk.MessageType.WARNING,
 ) -> Gtk.ResponseType:
     """A common message dialog handler for Meld
 
@@ -106,7 +107,7 @@ def modal_dialog(
     Primary must be plain text. Secondary must be valid markup.
     """
 
-    custom_buttons: Sequence[Tuple[str, int]] = []
+    custom_buttons: Sequence[Tuple[str, int, Optional[str]]] = []
     if not isinstance(buttons, Gtk.ButtonsType):
         custom_buttons, buttons = buttons, Gtk.ButtonsType.NONE
 
@@ -116,11 +117,14 @@ def modal_dialog(
         destroy_with_parent=True,
         message_type=messagetype,
         buttons=buttons,
-        text=primary)
+        text=primary,
+    )
     dialog.format_secondary_markup(secondary)
 
-    for label, response_id in custom_buttons:
-        dialog.add_button(label, response_id)
+    for label, response_id, style_class in custom_buttons:
+        button = dialog.add_button(label, response_id)
+        if style_class:
+            button.get_style_context().add_class(style_class)
 
     response = dialog.run()
     dialog.destroy()
diff --git a/meld/resources/ui/save-confirm-dialog.ui b/meld/resources/ui/save-confirm-dialog.ui
index 3b613fc1..92517d99 100644
--- a/meld/resources/ui/save-confirm-dialog.ui
+++ b/meld/resources/ui/save-confirm-dialog.ui
@@ -26,6 +26,9 @@
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_underline">True</property>
+                <style>
+                  <class name="destructive-action"/>
+                </style>
               </object>
               <packing>
                 <property name="expand">False</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]