(do_cd): get rid of global variable current_panel usage...

...and related changes.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2020-10-25 14:29:46 +03:00
parent 952933d0a7
commit 0e272b9e90
12 changed files with 57 additions and 54 deletions

View File

@ -131,7 +131,7 @@ edition_pre_exec (void)
static void
do_possible_cd (const vfs_path_t * new_dir_vpath)
{
if (!do_cd (new_dir_vpath, cd_exact))
if (!do_cd (current_panel, new_dir_vpath, cd_exact))
message (D_ERROR, _("Warning"), "%s",
_("The Commander can't change to the directory that\n"
"the subshell claims you are in. Perhaps you have\n"

View File

@ -127,7 +127,7 @@ static const char *machine_str = N_("Enter machine name (F1 for details):");
* If @plain_view is TRUE, force internal viewer and raw mode (used for F13).
*/
static void
do_view_cmd (const WPanel * panel, gboolean plain_view)
do_view_cmd (WPanel * panel, gboolean plain_view)
{
/* Directories are viewed by changing to them */
if (S_ISDIR (selection (panel)->st.st_mode) || link_isdir (selection (panel)))
@ -140,7 +140,7 @@ do_view_cmd (const WPanel * panel, gboolean plain_view)
return;
fname_vpath = vfs_path_from_str (selection (panel)->fname);
if (!do_cd (fname_vpath, cd_exact))
if (!do_cd (panel, fname_vpath, cd_exact))
message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
vfs_path_free (fname_vpath);
}
@ -609,7 +609,7 @@ view_file (const vfs_path_t * filename_vpath, gboolean plain_view, gboolean inte
/** Run user's preferred viewer on the currently selected file */
void
view_cmd (const WPanel * panel)
view_cmd (WPanel * panel)
{
do_view_cmd (panel, FALSE);
}
@ -639,7 +639,7 @@ view_file_cmd (const WPanel * panel)
/* --------------------------------------------------------------------------------------------- */
/** Run plain internal viewer on the currently selected file */
void
view_raw_cmd (const WPanel * panel)
view_raw_cmd (WPanel * panel)
{
do_view_cmd (panel, TRUE);
}
@ -1126,7 +1126,7 @@ vfs_list (void)
return;
target_vpath = vfs_path_from_str (target);
if (!do_cd (target_vpath, cd_exact))
if (!do_cd (current_panel, target_vpath, cd_exact))
message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
vfs_path_free (target_vpath);
g_free (target);

View File

@ -49,9 +49,9 @@ gboolean view_file_at_line (const vfs_path_t * filename_vpath, gboolean plain_vi
gboolean internal, long start_line, off_t search_start,
off_t search_end);
gboolean view_file (const vfs_path_t * filename_vpath, gboolean plain_view, gboolean internal);
void view_cmd (const WPanel * panel);
void view_cmd (WPanel * panel);
void view_file_cmd (const WPanel * panel);
void view_raw_cmd (const WPanel * panel);
void view_raw_cmd (WPanel * panel);
void view_filtered_cmd (const WPanel * panel);
void edit_file_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_line);
void edit_cmd (const WPanel * panel);

View File

@ -216,7 +216,7 @@ handle_cdpath (const char *path)
vfs_path_t *r_vpath;
r_vpath = vfs_path_build_filename (p, path, (char *) NULL);
result = do_cd (r_vpath, cd_parse_command);
result = do_cd (current_panel, r_vpath, cd_parse_command);
vfs_path_free (r_vpath);
}
*s = c;
@ -435,7 +435,7 @@ do_cd_command (char *orig_cmd)
else
q_vpath = vfs_path_from_str_flags (path, VPF_NO_CANON);
ok = do_cd (q_vpath, cd_parse_command);
ok = do_cd (current_panel, q_vpath, cd_parse_command);
if (!ok)
ok = handle_cdpath (path);

View File

@ -62,6 +62,7 @@
#include "src/selcodepage.h" /* do_set_codepage */
#endif
#include "filemanager.h" /* current_panel */
#include "panel.h" /* do_cd */
#include "ext.h"
@ -388,7 +389,7 @@ exec_extension_view (void *target, char *cmd, const vfs_path_t * filename_vpath,
/* --------------------------------------------------------------------------------------------- */
static void
exec_extension_cd (void)
exec_extension_cd (WPanel * panel)
{
char *q;
vfs_path_t *p_vpath;
@ -403,7 +404,7 @@ exec_extension_cd (void)
q[1] = 0;
p_vpath = vfs_path_from_str_flags (pbuffer, VPF_NO_CANON);
do_cd (p_vpath, cd_parse_command);
do_cd (panel, p_vpath, cd_parse_command);
vfs_path_free (p_vpath);
}
@ -411,8 +412,8 @@ exec_extension_cd (void)
/* --------------------------------------------------------------------------------------------- */
static vfs_path_t *
exec_extension (void *target, const vfs_path_t * filename_vpath, const char *lc_data,
int start_line)
exec_extension (WPanel * panel, void *target, const vfs_path_t * filename_vpath,
const char *lc_data, int start_line)
{
char *shell_string, *export_variables;
vfs_path_t *script_vpath = NULL;
@ -439,7 +440,7 @@ exec_extension (void *target, const vfs_path_t * filename_vpath, const char *lc_
if (is_cd)
{
exec_extension_cd ();
exec_extension_cd (panel);
g_free (shell_string);
goto ret;
}
@ -1025,7 +1026,7 @@ regex_command_for (void *target, const vfs_path_t * filename_vpath, const char *
{
vfs_path_t *sv;
sv = exec_extension (target, filename_vpath, r + 1,
sv = exec_extension (current_panel, target, filename_vpath, r + 1,
view_at_line_number);
if (script_vpath != NULL)
*script_vpath = sv;

View File

@ -154,7 +154,7 @@ treebox_cmd (void)
vfs_path_t *sel_vdir;
sel_vdir = vfs_path_from_str (sel_dir);
do_cd (sel_vdir, cd_exact);
do_cd (current_panel, sel_vdir, cd_exact);
vfs_path_free (sel_vdir);
g_free (sel_dir);
}
@ -1031,7 +1031,7 @@ show_editor_viewer_history (void)
d = g_path_get_dirname (s);
s_vpath = vfs_path_from_str (d);
do_cd (s_vpath, cd_exact);
do_cd (current_panel, s_vpath, cd_exact);
try_to_select (current_panel, s);
g_free (d);
}

View File

@ -1904,7 +1904,7 @@ find_cmd (void)
vfs_path_t *dirname_vpath;
dirname_vpath = vfs_path_from_str (dirname);
do_cd (dirname_vpath, cd_exact);
do_cd (current_panel, dirname_vpath, cd_exact);
vfs_path_free (dirname_vpath);
if (filename != NULL)
try_to_select (current_panel,
@ -1916,7 +1916,7 @@ find_cmd (void)
vfs_path_t *filename_vpath;
filename_vpath = vfs_path_from_str (filename);
do_cd (filename_vpath, cd_exact);
do_cd (current_panel, filename_vpath, cd_exact);
vfs_path_free (filename_vpath);
}
}

View File

@ -1979,12 +1979,12 @@ mini_status_format (WPanel * panel)
/* --------------------------------------------------------------------------------------------- */
static void
cd_up_dir (void)
cd_up_dir (WPanel * panel)
{
vfs_path_t *up_dir;
up_dir = vfs_path_from_str ("..");
do_cd (up_dir, cd_exact);
do_cd (panel, up_dir, cd_exact);
vfs_path_free (up_dir);
}
@ -1992,23 +1992,22 @@ cd_up_dir (void)
/** Used to emulate Lynx's entering leaving a directory with the arrow keys */
static cb_ret_t
maybe_cd (gboolean move_up_dir)
maybe_cd (WPanel * panel, gboolean move_up_dir)
{
if (panels_options.navigate_with_arrows && input_is_empty (cmdline))
{
if (move_up_dir)
{
cd_up_dir ();
cd_up_dir (panel);
return MSG_HANDLED;
}
if (S_ISDIR (selection (current_panel)->st.st_mode)
|| link_isdir (selection (current_panel)))
if (S_ISDIR (selection (panel)->st.st_mode) || link_isdir (selection (panel)))
{
vfs_path_t *vpath;
vpath = vfs_path_from_str (selection (current_panel)->fname);
do_cd (vpath, cd_exact);
vpath = vfs_path_from_str (selection (panel)->fname);
do_cd (panel, vpath, cd_exact);
vfs_path_free (vpath);
return MSG_HANDLED;
}
@ -2021,11 +2020,11 @@ maybe_cd (gboolean move_up_dir)
/* if command line is empty then do 'cd ..' */
static cb_ret_t
force_maybe_cd (void)
force_maybe_cd (WPanel * panel)
{
if (input_is_empty (cmdline))
{
cd_up_dir ();
cd_up_dir (panel);
return MSG_HANDLED;
}
@ -2219,7 +2218,7 @@ move_left (WPanel * panel)
return MSG_HANDLED;
}
return maybe_cd (TRUE); /* cd .. */
return maybe_cd (panel, TRUE); /* cd .. */
}
/* --------------------------------------------------------------------------------------------- */
@ -2233,7 +2232,7 @@ move_right (WPanel * panel)
return MSG_HANDLED;
}
return maybe_cd (FALSE); /* cd (selection) */
return maybe_cd (panel, FALSE); /* cd (selection) */
}
/* --------------------------------------------------------------------------------------------- */
@ -2266,7 +2265,7 @@ static void
goto_parent_dir (WPanel * panel)
{
if (!panel->is_panelized)
cd_up_dir ();
cd_up_dir (panel);
else
{
char *fname = panel->dir.list[panel->selected].fname;
@ -2293,7 +2292,7 @@ goto_parent_dir (WPanel * panel)
g_free (dname);
}
do_cd (dname_vpath, cd_exact);
do_cd (panel, dname_vpath, cd_exact);
try_to_select (panel, bname);
vfs_path_free (dname_vpath);
@ -2337,7 +2336,7 @@ goto_child_dir (WPanel * panel)
vfs_path_t *vpath;
vpath = vfs_path_from_str (selection (panel)->fname);
do_cd (vpath, cd_exact);
do_cd (panel, vpath, cd_exact);
vfs_path_free (vpath);
}
}
@ -2780,7 +2779,7 @@ stop_search (WPanel * panel)
/** Return TRUE if the Enter key has been processed, FALSE otherwise */
static gboolean
do_enter_on_file_entry (file_entry_t * fe)
do_enter_on_file_entry (WPanel * panel, file_entry_t * fe)
{
vfs_path_t *full_name_vpath;
gboolean ok;
@ -2794,13 +2793,13 @@ do_enter_on_file_entry (file_entry_t * fe)
vfs_path_t *fname_vpath;
fname_vpath = vfs_path_from_str (fe->fname);
if (!do_cd (fname_vpath, cd_exact))
if (!do_cd (panel, fname_vpath, cd_exact))
message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
vfs_path_free (fname_vpath);
return TRUE;
}
full_name_vpath = vfs_path_append_new (current_panel->cwd_vpath, fe->fname, (char *) NULL);
full_name_vpath = vfs_path_append_new (panel->cwd_vpath, fe->fname, (char *) NULL);
/* Try associated command */
ok = regex_command (full_name_vpath, "Open") != 0;
@ -2809,7 +2808,7 @@ do_enter_on_file_entry (file_entry_t * fe)
return TRUE;
/* Check if the file is executable */
full_name_vpath = vfs_path_append_new (current_panel->cwd_vpath, fe->fname, (char *) NULL);
full_name_vpath = vfs_path_append_new (panel->cwd_vpath, fe->fname, (char *) NULL);
ok = (is_exe (fe->st.st_mode) && if_link_is_exe (full_name_vpath, fe));
vfs_path_free (full_name_vpath);
if (!ok)
@ -2854,7 +2853,7 @@ do_enter_on_file_entry (file_entry_t * fe)
static inline gboolean
do_enter (WPanel * panel)
{
return do_enter_on_file_entry (selection (panel));
return do_enter_on_file_entry (panel, selection (panel));
}
@ -2890,7 +2889,7 @@ chdir_other_panel (WPanel * panel)
}
change_panel ();
do_cd (new_dir_vpath, cd_exact);
do_cd (current_panel, new_dir_vpath, cd_exact);
vfs_path_free (new_dir_vpath);
if (sel_entry)
@ -2971,7 +2970,7 @@ chdir_to_readlink (WPanel * panel)
new_dir_vpath = vfs_path_append_new (panel->cwd_vpath, buffer, (char *) NULL);
change_panel ();
do_cd (new_dir_vpath, cd_exact);
do_cd (current_panel, new_dir_vpath, cd_exact);
vfs_path_free (new_dir_vpath);
change_panel ();
@ -3513,7 +3512,7 @@ panel_execute_cmd (WPanel * panel, long command)
mark_file_right (panel);
break;
case CK_CdParentSmart:
res = force_maybe_cd ();
res = force_maybe_cd (panel);
break;
case CK_Up:
move_up (panel);
@ -5018,12 +5017,12 @@ panel_deinit (void)
/* --------------------------------------------------------------------------------------------- */
gboolean
do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum exact)
do_cd (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum exact)
{
gboolean res;
const vfs_path_t *_new_dir_vpath = new_dir_vpath;
if (current_panel->is_panelized)
if (panel->is_panelized)
{
size_t new_vpath_len;
@ -5032,18 +5031,18 @@ do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum exact)
_new_dir_vpath = panelized_panel.root_vpath;
}
res = do_panel_cd (current_panel, _new_dir_vpath, exact);
res = do_panel_cd (panel, _new_dir_vpath, exact);
#ifdef HAVE_CHARSET
if (res)
{
const vfs_path_element_t *path_element;
path_element = vfs_path_get_by_index (current_panel->cwd_vpath, -1);
path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
if (path_element->encoding != NULL)
current_panel->codepage = get_codepage_index (path_element->encoding);
panel->codepage = get_codepage_index (path_element->encoding);
else
current_panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
}
#endif /* HAVE_CHARSET */

View File

@ -202,7 +202,7 @@ void panel_set_lwd (WPanel * panel, const vfs_path_t * vpath);
void panel_init (void);
void panel_deinit (void);
gboolean do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
gboolean do_cd (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
/* --------------------------------------------------------------------------------------------- */
/*** inline functions ****************************************************************************/

View File

@ -588,7 +588,7 @@ tree_chdir_sel (WTree * tree)
{
change_panel ();
if (do_cd (tree->selected_ptr->name, cd_exact))
if (do_cd (current_panel, tree->selected_ptr->name, cd_exact))
select_item (current_panel);
else
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"),

View File

@ -30,7 +30,7 @@
#include "src/vfs/local/local.c"
#include "src/filemanager/command.c"
#include "src/filemanager/panel.h"
/* --------------------------------------------------------------------------------------------- */
@ -55,8 +55,10 @@ static gboolean do_cd__return_value;
/* @Mock */
gboolean
do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum cd_type)
do_cd (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum cd_type)
{
(void) panel;
do_cd__new_dir_vpath__captured = vfs_path_clone (new_dir_vpath);
do_cd__cd_type__captured = cd_type;
return do_cd__return_value;

View File

@ -56,8 +56,9 @@ get_current_type (void)
}
gboolean
do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum cd_type)
do_cd (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum cd_type)
{
(void) panel;
(void) new_dir_vpath;
(void) cd_type;