From f4ac2bb01fbd9b6bb447075f7823b2fd2fb5e6f7 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 9 May 2023 09:04:44 +0300 Subject: [PATCH] (cd_error_msg): new function to show the change directory error message. Use it where needed. Signed-off-by: Andrew Borodin --- src/filemanager/cd.c | 13 +++++++++++-- src/filemanager/cd.h | 1 + src/filemanager/cmd.c | 8 ++++---- src/filemanager/panel.c | 12 +++++------- src/filemanager/tree.c | 4 ++-- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/filemanager/cd.c b/src/filemanager/cd.c index c2f025b0f..564a60576 100644 --- a/src/filemanager/cd.c +++ b/src/filemanager/cd.c @@ -38,6 +38,7 @@ #include "lib/vfs/vfs.h" #include "lib/strescape.h" /* strutils_shell_unescape() */ #include "lib/util.h" /* whitespace() */ +#include "lib/widget.h" /* message() */ #include "filemanager.h" /* current_panel, panel.h, layout.h */ #include "tree.h" /* sync_tree() */ @@ -286,8 +287,7 @@ cd_to (const char *path) char *d; d = vfs_path_to_str_flags (q_vpath, 0, VPF_STRIP_PASSWORD); - message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), d, - unix_error_string (errno)); + cd_error_message (d); g_free (d); } @@ -299,3 +299,12 @@ cd_to (const char *path) } /* --------------------------------------------------------------------------------------------- */ + +void +cd_error_message (const char *path) +{ + message (D_ERROR, MSG_ERROR, _("Cannot change directory to\n%s\n%s"), path, + unix_error_string (errno)); +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/cd.h b/src/filemanager/cd.h index a63278a32..13e77187d 100644 --- a/src/filemanager/cd.h +++ b/src/filemanager/cd.h @@ -16,6 +16,7 @@ /*** declarations of public functions ************************************************************/ void cd_to (const char *path); +void cd_error_message (const char *path); /*** inline functions ****************************************************************************/ diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index 216079968..8c33fd89d 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -90,7 +90,7 @@ #include "ext.h" /* regex_command() */ #include "boxes.h" /* cd_box() */ #include "dir.h" -#include "cd.h" /* cd_to() */ +#include "cd.h" #include "cmd.h" /* Our definitions */ @@ -147,7 +147,7 @@ do_view_cmd (WPanel * panel, gboolean plain_view) fname_vpath = vfs_path_from_str (fe->fname->str); if (!panel_cd (panel, fname_vpath, cd_exact)) - message (D_ERROR, MSG_ERROR, _("Cannot change directory")); + cd_error_message (fe->fname->str); vfs_path_free (fname_vpath, TRUE); } else @@ -446,7 +446,7 @@ nice_cd (const char *text, const char *xtext, const char *help, cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON); if (!panel_do_cd (MENU_PANEL, cd_vpath, cd_parse_command)) { - message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path); + cd_error_message (cd_path); if (save_type != view_listing) create_panel (MENU_PANEL_IDX, save_type); @@ -1009,7 +1009,7 @@ vfs_list (WPanel * panel) target_vpath = vfs_path_from_str (target); if (!panel_cd (current_panel, target_vpath, cd_exact)) - message (D_ERROR, MSG_ERROR, _("Cannot change directory")); + cd_error_message (target); vfs_path_free (target_vpath, TRUE); g_free (target); } diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index e778e579e..ec1dbc3dd 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -32,7 +32,6 @@ #include -#include #include #include #include @@ -77,6 +76,7 @@ #include "command.h" /* cmdline */ #include "filemanager.h" #include "mountlist.h" /* my_statfs */ +#include "cd.h" /* cd_error_message() */ #include "panel.h" @@ -2936,7 +2936,7 @@ do_enter_on_file_entry (WPanel * panel, file_entry_t * fe) fname_vpath = vfs_path_from_str (fname); if (!panel_cd (panel, fname_vpath, cd_exact)) - message (D_ERROR, MSG_ERROR, _("Cannot change directory")); + cd_error_message (fname); vfs_path_free (fname_vpath, TRUE); return TRUE; } @@ -3519,7 +3519,7 @@ directory_history_list (WPanel * panel) if (ok) directory_history_add (panel, panel->cwd_vpath); else - message (D_ERROR, MSG_ERROR, _("Cannot change directory")); + cd_error_message (hd.text); vfs_path_free (s_vpath, TRUE); g_free (hd.text); } @@ -3814,8 +3814,7 @@ panel_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d char *cwd; cwd = vfs_path_to_str_flags (panel->cwd_vpath, 0, VPF_STRIP_PASSWORD); - message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), - cwd, unix_error_string (errno)); + cd_error_message (cwd); g_free (cwd); } else @@ -4971,8 +4970,7 @@ panel_change_encoding (WPanel * panel) vfs_path_change_encoding (panel->cwd_vpath, encoding); if (!panel_do_cd (panel, panel->cwd_vpath, cd_parse_command)) - message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), - vfs_path_as_str (panel->cwd_vpath)); + cd_error_message (vfs_path_as_str (panel->cwd_vpath)); } } diff --git a/src/filemanager/tree.c b/src/filemanager/tree.c index 1a0196ea9..cbdb52919 100644 --- a/src/filemanager/tree.c +++ b/src/filemanager/tree.c @@ -66,6 +66,7 @@ #include "treestore.h" #include "cmd.h" #include "filegui.h" +#include "cd.h" /* cd_error_message() */ #include "tree.h" @@ -593,8 +594,7 @@ tree_chdir_sel (WTree * tree) if (panel_cd (p, tree->selected_ptr->name, cd_exact)) select_item (p); else - message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), - vfs_path_as_str (tree->selected_ptr->name), unix_error_string (errno)); + cd_error_message (vfs_path_as_str (tree->selected_ptr->name)); widget_draw (WIDGET (p)); (void) change_panel ();