Browse Source

(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 <aborodin@vmail.ru>
Andrew Borodin 2 years ago
parent
commit
a7833b5b2e
1 changed files with 30 additions and 1 deletions
  1. 30 1
      src/filemanager/file.c

+ 30 - 1
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 ();