Skip to content

Commit 8da440c

Browse files
committed
Update destructive dialog actions with appropriate styling (#660)
1 parent a633838 commit 8da440c

5 files changed

Lines changed: 29 additions & 14 deletions

File tree

meld/dirdiff.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,8 +1225,11 @@ def copy_selected(self, direction):
12251225
parent_name = os.path.dirname(dst)
12261226
folder_name = os.path.basename(dst)
12271227
dialog_buttons = [
1228-
(_("_Cancel"), Gtk.ResponseType.CANCEL),
1229-
(_("_Replace"), Gtk.ResponseType.OK),
1228+
(_("_Cancel"), Gtk.ResponseType.CANCEL, None),
1229+
(
1230+
_("_Replace"), Gtk.ResponseType.OK,
1231+
Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION,
1232+
),
12301233
]
12311234
replace = misc.modal_dialog(
12321235
primary=_("Replace folder “%s”?") % folder_name,

meld/filediff.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,10 @@ def prompt_resolve_conflict(self):
12241224
secondary = _(
12251225
"If the conflict was resolved successfully, you may mark "
12261226
"it as resolved now.")
1227-
buttons = ((_("Cancel"), Gtk.ResponseType.CANCEL),
1228-
(_("Mark _Resolved"), Gtk.ResponseType.OK))
1227+
buttons = (
1228+
(_("Cancel"), Gtk.ResponseType.CANCEL, None),
1229+
(_("Mark _Resolved"), Gtk.ResponseType.OK, None),
1230+
)
12291231
resolve_response = misc.modal_dialog(
12301232
primary, secondary, buttons, parent=self,
12311233
messagetype=Gtk.MessageType.QUESTION)

meld/iohelpers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ def trash_or_confirm(gfile: Gio.File) -> bool:
5353
"to the trash."
5454
),
5555
buttons=[
56-
(_("_Cancel"), Gtk.ResponseType.CANCEL),
57-
(_("_Delete Permanently"), Gtk.ResponseType.OK),
56+
(_("_Cancel"), Gtk.ResponseType.CANCEL, None),
57+
(
58+
_("_Delete Permanently"), Gtk.ResponseType.OK,
59+
Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION,
60+
),
5861
],
5962
)
6063

@@ -110,8 +113,8 @@ def prompt_save_filename(
110113
"If you replace the existing file, its contents "
111114
"will be lost.") % parent_name,
112115
buttons=[
113-
(_("_Cancel"), Gtk.ResponseType.CANCEL),
114-
(_("_Replace"), Gtk.ResponseType.OK),
116+
(_("_Cancel"), Gtk.ResponseType.CANCEL, None),
117+
(_("_Replace"), Gtk.ResponseType.OK, None),
115118
],
116119
messagetype=Gtk.MessageType.WARNING,
117120
)

meld/misc.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ def error_dialog(primary: str, secondary: str) -> Gtk.ResponseType:
9494
def modal_dialog(
9595
primary: str,
9696
secondary: str,
97-
buttons: Union[Gtk.ButtonsType, Sequence[Tuple[str, int]]],
97+
buttons: Union[Gtk.ButtonsType, Sequence[Tuple[str, int, Optional[str]]]],
98+
*,
9899
parent: Optional[Gtk.Window] = None,
99-
messagetype: Gtk.MessageType = Gtk.MessageType.WARNING
100+
messagetype: Gtk.MessageType = Gtk.MessageType.WARNING,
100101
) -> Gtk.ResponseType:
101102
"""A common message dialog handler for Meld
102103
@@ -106,7 +107,7 @@ def modal_dialog(
106107
Primary must be plain text. Secondary must be valid markup.
107108
"""
108109

109-
custom_buttons: Sequence[Tuple[str, int]] = []
110+
custom_buttons: Sequence[Tuple[str, int, Optional[str]]] = []
110111
if not isinstance(buttons, Gtk.ButtonsType):
111112
custom_buttons, buttons = buttons, Gtk.ButtonsType.NONE
112113

@@ -116,11 +117,14 @@ def modal_dialog(
116117
destroy_with_parent=True,
117118
message_type=messagetype,
118119
buttons=buttons,
119-
text=primary)
120+
text=primary,
121+
)
120122
dialog.format_secondary_markup(secondary)
121123

122-
for label, response_id in custom_buttons:
123-
dialog.add_button(label, response_id)
124+
for label, response_id, style_class in custom_buttons:
125+
button = dialog.add_button(label, response_id)
126+
if style_class:
127+
button.get_style_context().add_class(style_class)
124128

125129
response = dialog.run()
126130
dialog.destroy()

meld/resources/ui/save-confirm-dialog.ui

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<property name="can_focus">True</property>
2727
<property name="receives_default">True</property>
2828
<property name="use_underline">True</property>
29+
<style>
30+
<class name="destructive-action"/>
31+
</style>
2932
</object>
3033
<packing>
3134
<property name="expand">False</property>

0 commit comments

Comments
 (0)