From a7833b5b2eda9d809d5d8d2bcb66d21576cada20 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 25 Jun 2022 21:28:58 +0300 Subject: [PATCH] (real_warn_same_file): truncate file names if required. If file name is too long, message window is wider than screen. Truncate file name to fit it in the screen. Signed-off-by: Andrew Borodin --- src/filemanager/file.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/filemanager/file.c b/src/filemanager/file.c index 956a88c16..d3271080c 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -852,10 +852,39 @@ real_warn_same_file (enum OperationMode mode, const char *fmt, const char *a, co char *msg; int result = 0; const char *head_msg; + int width_a, width_b, width; head_msg = mode == Foreground ? MSG_ERROR : _("Background process error"); - msg = g_strdup_printf (fmt, a, b); + width_a = str_term_width1 (a); + width_b = str_term_width1 (b); + width = COLS - 8; + + if (width_a > width) + { + if (width_b > width) + { + char *s; + + s = g_strndup (str_trunc (a, width), width); + b = str_trunc (b, width); + msg = g_strdup_printf (fmt, s, b); + g_free (s); + } + else + { + a = str_trunc (a, width); + msg = g_strdup_printf (fmt, a, b); + } + } + else + { + if (width_b > width) + b = str_trunc (b, width); + + msg = g_strdup_printf (fmt, a, b); + } + result = query_dialog (head_msg, msg, D_ERROR, 2, _("&Skip"), _("&Abort")); g_free (msg); do_refresh ();