Refactoring of file operations.

(copy_cmd, copy_cmd_local, rename_cmd, rename_cmd_local, delete_cmd,
delete_cmd_local): move same code to panel_operate(), make inline.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2021-09-05 13:04:55 +03:00
parent d410af27c0
commit 022c3d2f94
3 changed files with 76 additions and 97 deletions

View File

@ -80,10 +80,8 @@
#endif
#include "fileopctx.h"
#include "file.h" /* file operation routines */
#include "filenot.h"
#include "hotlist.h" /* hotlist_show() */
#include "panel.h" /* WPanel */
#include "tree.h" /* tree_chdir() */
#include "filemanager.h" /* change_panel() */
#include "command.h" /* cmdline */
@ -769,66 +767,6 @@ edit_cmd_new (void)
vfs_path_free (fname_vpath, TRUE);
}
/* --------------------------------------------------------------------------------------------- */
/** Invoked by F5. Copy, default to the other panel. */
void
copy_cmd (WPanel * panel)
{
save_cwds_stat ();
if (panel_operate (panel, OP_COPY, FALSE))
{
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen ();
}
}
/* --------------------------------------------------------------------------------------------- */
/** Invoked by F6. Move/rename, default to the other panel, ignore marks. */
void
rename_cmd (WPanel * panel)
{
save_cwds_stat ();
if (panel_operate (panel, OP_MOVE, FALSE))
{
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen ();
}
}
/* --------------------------------------------------------------------------------------------- */
/** Invoked by F15. Copy, default to the same panel, ignore marks. */
void
copy_cmd_local (WPanel * panel)
{
save_cwds_stat ();
if (panel_operate (panel, OP_COPY, TRUE))
{
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen ();
}
}
/* --------------------------------------------------------------------------------------------- */
/** Invoked by F16. Move/rename, default to the same panel. */
void
rename_cmd_local (WPanel * panel)
{
save_cwds_stat ();
if (panel_operate (panel, OP_MOVE, TRUE))
{
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen ();
}
}
/* --------------------------------------------------------------------------------------------- */
void
@ -880,35 +818,6 @@ mkdir_cmd (WPanel * panel)
g_free (dir);
}
/* --------------------------------------------------------------------------------------------- */
void
delete_cmd (WPanel * panel)
{
save_cwds_stat ();
if (panel_operate (panel, OP_DELETE, FALSE))
{
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen ();
}
}
/* --------------------------------------------------------------------------------------------- */
/** Invoked by F18. Remove selected file, regardless of marked files. */
void
delete_cmd_local (WPanel * panel)
{
save_cwds_stat ();
if (panel_operate (panel, OP_DELETE, TRUE))
{
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen ();
}
}
/* --------------------------------------------------------------------------------------------- */
/** Invoked from the left/right menus */

View File

@ -9,6 +9,7 @@
#include "lib/global.h"
#include "file.h" /* panel_operate() */
#include "panel.h"
/*** typedefs(not structures) and defined constants **********************************************/
@ -56,13 +57,7 @@ void edit_cmd_new (void);
#ifdef USE_INTERNAL_EDIT
void edit_cmd_force_internal (const WPanel * panel);
#endif
void copy_cmd (WPanel * panel);
void copy_cmd_local (WPanel * panel);
void rename_cmd (WPanel * panel);
void rename_cmd_local (WPanel * panel);
void mkdir_cmd (WPanel * panel);
void delete_cmd (WPanel * panel);
void delete_cmd_local (WPanel * panel);
void filter_cmd (void);
void reread_cmd (void);
void vfs_list (WPanel * panel);
@ -104,5 +99,75 @@ const char *chattr_get_as_str (unsigned long attr);
/* find.c */
void find_cmd (WPanel * panel);
/* --------------------------------------------------------------------------------------------- */
/*** inline functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/**
* Copy, default to the other panel.
*/
static inline void
copy_cmd (WPanel * panel)
{
panel_operate (panel, OP_COPY, FALSE);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Copy, default to the same panel, ignore marks.
*/
static inline void
copy_cmd_local (WPanel * panel)
{
panel_operate (panel, OP_COPY, TRUE);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Move/rename, default to the other panel.
*/
static inline void
rename_cmd (WPanel * panel)
{
panel_operate (panel, OP_MOVE, FALSE);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Move/rename, default to the same panel, ignore marks.
*/
static inline void
rename_cmd_local (WPanel * panel)
{
panel_operate (panel, OP_MOVE, TRUE);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Remove.
*/
static inline void
delete_cmd (WPanel * panel)
{
panel_operate (panel, OP_DELETE, FALSE);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Remove, ignore marks.
*/
static inline void
delete_cmd_local (WPanel * panel)
{
panel_operate (panel, OP_DELETE, TRUE);
}
/* --------------------------------------------------------------------------------------------- */
#endif /* MC__CMD_H */

View File

@ -3240,6 +3240,8 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
linklist = free_linklist (linklist);
dest_dirs = free_linklist (dest_dirs);
save_cwds_stat ();
if (single_entry)
{
source = check_single_entry (panel, force_single, &src_stat);
@ -3459,6 +3461,9 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
ret_fast:
file_op_context_destroy (ctx);
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen ();
return ret_val;
}