From 8f5a4f957f0d9d19fa6138da2a84d2322b140cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Huguet?= Date: Thu, 18 Jan 2024 10:16:45 +0100 Subject: [PATCH] nmtui: fix deletion confirmation with ESC key press When deleting a profile, the confirmation dialog shows "Cancel" and "Delete" buttons. ESC key should do nothing, but in some distributions like Debian and Ubuntu newt has a downstream patch that enables it (see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=584098). In that case, when pressing ESC the return value of the dialog is not "Cancel" (1) or "Delete" (2), but the "otherwise" value (0). Fix it by not checking if "Cancel" is pressed. Instead, check if "Delete" was pressed, and continue deleting only in that case. Also, fix the doc comment that incorrectly says that the dialog returns 0/1 for the buttons, it is 1/2. --- src/libnmt-newt/nmt-newt-utils.c | 2 +- src/nmtui/nmtui-edit.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libnmt-newt/nmt-newt-utils.c b/src/libnmt-newt/nmt-newt-utils.c index e021981cc2..8eeee2026b 100644 --- a/src/libnmt-newt/nmt-newt-utils.c +++ b/src/libnmt-newt/nmt-newt-utils.c @@ -282,7 +282,7 @@ nmt_newt_message_dialog(const char *message, ...) * Displays the given message in a dialog box with two buttons with * the indicated labels, and waits for the user to click one. * - * Returns: which button was clicked: 0 for @button1 or 1 for @button2 + * Returns: which button was clicked: 1 for @button1, 2 for @button2 or 0 otherwise */ int nmt_newt_choice_dialog(const char *button1, const char *button2, const char *message, ...) diff --git a/src/nmtui/nmtui-edit.c b/src/nmtui/nmtui-edit.c index 3cedf1973c..31a73fd8ad 100644 --- a/src/nmtui/nmtui-edit.c +++ b/src/nmtui/nmtui-edit.c @@ -511,7 +511,7 @@ nmt_remove_connection(NMRemoteConnection *connection) _("Delete"), _("Are you sure you want to delete the connection '%s'?"), nm_connection_get_id(NM_CONNECTION(connection))); - if (choice == 1) + if (choice != 2) return; g_object_ref(connection);