1
1

* file.c (panel_operate_generate_prompt): Remove source

calculation, it doesn't belong here.
(panel_operate): Change arguments: drop ask_user and thedefault,
introduce force_single.  force_single changes default to the
current file and ignores selection.  Adjust all dependencies.
Этот коммит содержится в:
Pavel Roskin 2003-08-18 04:35:28 +00:00
родитель 4dd13a09ba
Коммит df6365e737
4 изменённых файлов: 105 добавлений и 90 удалений

Просмотреть файл

@ -1,3 +1,11 @@
2003-08-18 Pavel Roskin <proski@gnu.org>
* file.c (panel_operate_generate_prompt): Remove source
calculation, it doesn't belong here.
(panel_operate): Change arguments: drop ask_user and thedefault,
introduce force_single. force_single changes default to the
current file and ignores selection. Adjust all dependencies.
2003-08-17 Pavel Roskin <proski@gnu.org> 2003-08-17 Pavel Roskin <proski@gnu.org>
* dir.h (file_entry): Rename "buf" to "st". Adjust all * dir.h (file_entry): Rename "buf" to "st". Adjust all

Просмотреть файл

@ -313,7 +313,7 @@ void
copy_cmd (void) copy_cmd (void)
{ {
save_cwds_stat (); save_cwds_stat ();
if (panel_operate (cpanel, OP_COPY, NULL, TRUE)) { if (panel_operate (cpanel, OP_COPY, 0)) {
update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen (); repaint_screen ();
} }
@ -323,7 +323,7 @@ copy_cmd (void)
void ren_cmd (void) void ren_cmd (void)
{ {
save_cwds_stat (); save_cwds_stat ();
if (panel_operate (cpanel, OP_MOVE, NULL, TRUE)){ if (panel_operate (cpanel, OP_MOVE, 0)){
update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen (); repaint_screen ();
} }
@ -333,7 +333,7 @@ void ren_cmd (void)
void copy_cmd_local (void) void copy_cmd_local (void)
{ {
save_cwds_stat (); save_cwds_stat ();
if (panel_operate (cpanel, OP_COPY, selection (cpanel)->fname, TRUE)){ if (panel_operate (cpanel, OP_COPY, 1)){
update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen (); repaint_screen ();
} }
@ -343,7 +343,7 @@ void copy_cmd_local (void)
void ren_cmd_local (void) void ren_cmd_local (void)
{ {
save_cwds_stat (); save_cwds_stat ();
if (panel_operate (cpanel, OP_MOVE, selection (cpanel)->fname, TRUE)){ if (panel_operate (cpanel, OP_MOVE, 1)){
update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen (); repaint_screen ();
} }
@ -384,7 +384,7 @@ void delete_cmd (void)
{ {
save_cwds_stat (); save_cwds_stat ();
if (panel_operate (cpanel, OP_DELETE, NULL, TRUE)){ if (panel_operate (cpanel, OP_DELETE, 0)){
update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen (); repaint_screen ();
} }

Просмотреть файл

@ -1531,7 +1531,10 @@ erase_dir_iff_empty (FileOpContext *ctx, char *s)
/* {{{ Panel operate routines */ /* {{{ Panel operate routines */
/* Returns currently selected file or the first marked file if there is one */ /*
* Return currently selected entry name or the name of the first marked
* entry if there is one.
*/
static char * static char *
panel_get_file (WPanel *panel, struct stat *stat_buf) panel_get_file (WPanel *panel, struct stat *stat_buf)
{ {
@ -1687,15 +1690,21 @@ static char *prompt_parts[] = {
N_("files/directories"), N_(" with source mask:"), N_(" to:") N_("files/directories"), N_(" with source mask:"), N_(" to:")
}; };
static char * /*
panel_operate_generate_prompt (WPanel *panel, int operation, int only_one, * Generate user prompt for panel operation.
struct stat *src_stat) * single_source is the name if the source entry or NULL for multiple
* entries.
* src_stat is only used when single_source is not NULL.
*/
static void
panel_operate_generate_prompt (const WPanel *panel, const int operation,
const char *single_source,
const struct stat *src_stat)
{ {
register char *sp, *cp; register char *sp, *cp;
register int i; register int i;
char format_string[BUF_MEDIUM]; char format_string[BUF_MEDIUM];
char *dp = format_string; char *dp = format_string;
char *source = NULL;
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
static int i18n_flag = 0; static int i18n_flag = 0;
@ -1714,10 +1723,7 @@ panel_operate_generate_prompt (WPanel *panel, int operation, int only_one,
} }
#endif /* ENABLE_NLS */ #endif /* ENABLE_NLS */
sp = only_one ? one_format : many_format; sp = single_source ? one_format : many_format;
if (only_one)
source = panel_get_file (panel, src_stat);
while (*sp) { while (*sp) {
switch (*sp) { switch (*sp) {
@ -1734,9 +1740,10 @@ panel_operate_generate_prompt (WPanel *panel, int operation, int only_one,
cp = operation == OP_DELETE ? "?" : prompt_parts[6]; cp = operation == OP_DELETE ? "?" : prompt_parts[6];
break; break;
case 'f': case 'f':
if (only_one) { if (single_source) {
cp = S_ISDIR (src_stat->st_mode) ? cp = S_ISDIR (src_stat->
prompt_parts[2] : prompt_parts[0]; st_mode) ? prompt_parts[2] :
prompt_parts[0];
} else { } else {
cp = (panel->marked == panel->dirs_marked) cp = (panel->marked == panel->dirs_marked)
? prompt_parts[3] ? prompt_parts[3]
@ -1759,10 +1766,10 @@ panel_operate_generate_prompt (WPanel *panel, int operation, int only_one,
} }
*dp = '\0'; *dp = '\0';
if (only_one) { if (single_source) {
i = fmd_xlen - strlen (format_string) - 4; i = fmd_xlen - strlen (format_string) - 4;
g_snprintf (cmd_buf, sizeof (cmd_buf), format_string, g_snprintf (cmd_buf, sizeof (cmd_buf), format_string,
name_trunc (source, i)); name_trunc (single_source, i));
} else { } else {
g_snprintf (cmd_buf, sizeof (cmd_buf), format_string, g_snprintf (cmd_buf, sizeof (cmd_buf), format_string,
panel->marked); panel->marked);
@ -1772,8 +1779,6 @@ panel_operate_generate_prompt (WPanel *panel, int operation, int only_one,
fmd_init_i18n (TRUE); /* to recalculate positions of child widgets */ fmd_init_i18n (TRUE); /* to recalculate positions of child widgets */
} }
} }
return source;
} }
/** /**
@ -1784,10 +1789,13 @@ panel_operate_generate_prompt (WPanel *panel, int operation, int only_one,
* *
* Returns 1 if did change the directory * Returns 1 if did change the directory
* structure, Returns 0 if user aborted * structure, Returns 0 if user aborted
*
* force_single forces operation on the current entry and affects
* default destination. Current filename is used as default.
*/ */
int int
panel_operate (void *source_panel, FileOperation operation, panel_operate (void *source_panel, FileOperation operation,
char *thedefault, int ask_user) int force_single)
{ {
WPanel *panel = source_panel; WPanel *panel = source_panel;
#ifdef WITH_FULL_PATHS #ifdef WITH_FULL_PATHS
@ -1799,8 +1807,8 @@ panel_operate (void *source_panel, FileOperation operation,
char *dest = NULL; char *dest = NULL;
char *temp = NULL; char *temp = NULL;
char *save_cwd = NULL, *save_dest = NULL; char *save_cwd = NULL, *save_dest = NULL;
int only_one = (get_current_type () == view_tree) int single_entry = (get_current_type () == view_tree)
|| (panel->marked <= 1); || (panel->marked <= 1) || force_single;
struct stat src_stat, dst_stat; struct stat src_stat, dst_stat;
int i, value; int i, value;
FileOpContext *ctx; FileOpContext *ctx;
@ -1809,67 +1817,64 @@ panel_operate (void *source_panel, FileOperation operation,
double bytes = 0; double bytes = 0;
int dst_result; int dst_result;
int do_bg; /* do background operation? */ int do_bg = 0; /* do background operation? */
ctx = file_op_context_new ();
do_bg = 0;
free_linklist (&linklist); free_linklist (&linklist);
free_linklist (&dest_dirs); free_linklist (&dest_dirs);
if (get_current_type () == view_listing)
if (!panel->marked && !strcmp (selection (panel)->fname, "..")) { if (single_entry) {
message (1, MSG_ERROR, _(" Cannot operate on \"..\"! ")); if (force_single) {
file_op_context_destroy (ctx); source = selection (panel)->fname;
return 0; src_stat = selection (panel)->st;
} else {
source = panel_get_file (panel, &src_stat);
} }
if (!strcmp (source, "..")) {
message (1, MSG_ERROR, _(" Cannot operate on \"..\"! "));
return 0;
}
}
/* Generate confirmation prompt */ /* Generate confirmation prompt */
source = panel_operate_generate_prompt (panel, operation, source, &src_stat);
panel_operate_generate_prompt (panel, operation, only_one,
&src_stat); ctx = file_op_context_new ();
/* Show confirmation dialog */ /* Show confirmation dialog */
if (operation == OP_DELETE && confirm_delete) { if (operation == OP_DELETE && confirm_delete) {
if (safe_delete) if (safe_delete)
query_set_sel (1); query_set_sel (1);
i = query_dialog (_(op_names[operation]), cmd_buf, i = query_dialog (_(op_names[operation]), cmd_buf, D_ERROR, 2,
D_ERROR, 2, _("&Yes"), _("&No")); _("&Yes"), _("&No"));
if (i != 0) { if (i != 0) {
file_op_context_destroy (ctx); file_op_context_destroy (ctx);
return 0; return 0;
} }
} else if (operation != OP_DELETE) { } else if (operation != OP_DELETE) {
if (ask_user) { char *dest_dir;
char *dest_dir;
if (thedefault != NULL) /* Forced single operations default to the original name */
dest_dir = thedefault; if (force_single)
else if (get_other_type () == view_listing) dest_dir = source;
dest_dir = opanel->cwd; else if (get_other_type () == view_listing)
else dest_dir = opanel->cwd;
dest_dir = panel->cwd; else
dest_dir = panel->cwd;
dest = dest =
file_mask_dialog (ctx, operation, cmd_buf, dest_dir, file_mask_dialog (ctx, operation, cmd_buf, dest_dir,
only_one, &do_bg); single_entry, &do_bg);
if (!dest) { if (!dest) {
file_op_context_destroy (ctx); file_op_context_destroy (ctx);
return 0; return 0;
} }
if (!*dest) { if (!*dest) {
file_op_context_destroy (ctx); file_op_context_destroy (ctx);
g_free (dest); g_free (dest);
return 0; return 0;
}
} else {
char *all = "^\\(.*\\)$";
re_compile_pattern (all, strlen (all), &ctx->rx);
ctx->dest_mask = g_strdup ("*");
do_bg = FALSE;
dest = g_strdup (thedefault);
} }
} }
#ifdef WITH_BACKGROUND #ifdef WITH_BACKGROUND
@ -1916,7 +1921,7 @@ panel_operate (void *source_panel, FileOperation operation,
file_op_context_create_ui (ctx, operation, 1); file_op_context_create_ui (ctx, operation, 1);
/* This code is only called by the tree and panel code */ /* This code is only called by the tree and panel code */
if (only_one) { if (single_entry) {
/* We now have ETA in all cases */ /* We now have ETA in all cases */
/* One file: FIXME mc_chdir will take user out of any vfs */ /* One file: FIXME mc_chdir will take user out of any vfs */
@ -1980,7 +1985,7 @@ panel_operate (void *source_panel, FileOperation operation,
} }
} /* Copy or move operation */ } /* Copy or move operation */
if (value == FILE_CONT) if ((value == FILE_CONT) && !force_single)
unmark_files (panel); unmark_files (panel);
} else { } else {
/* Many files */ /* Many files */
@ -2043,7 +2048,7 @@ panel_operate (void *source_panel, FileOperation operation,
switch (operation) { switch (operation) {
case OP_COPY: case OP_COPY:
/* /*
* we use file_mask_op_follow_links only with OP_COPY, * we use file_mask_op_follow_links only with OP_COPY
*/ */
(*ctx->stat_func) (source_with_path, &src_stat); (*ctx->stat_func) (source_with_path, &src_stat);
if (S_ISDIR (src_stat.st_mode)) if (S_ISDIR (src_stat.st_mode))
@ -2098,7 +2103,7 @@ panel_operate (void *source_panel, FileOperation operation,
mc_refresh (); mc_refresh ();
} /* Loop for every file */ } /* Loop for every file */
} /* Many files */ } /* Many entries */
clean_up: clean_up:
/* Clean up */ /* Clean up */

Просмотреть файл

@ -8,35 +8,37 @@ extern int safe_delete;
struct link; struct link;
int copy_file_file (FileOpContext *ctx, char *s, char *d, int ask_overwrite, int copy_file_file (FileOpContext *ctx, char *s, char *d,
off_t *progress_count, double *progress_bytes, int ask_overwrite, off_t *progress_count,
int is_toplevel_file); double *progress_bytes, int is_toplevel_file);
int move_file_file (FileOpContext *ctx, char *s, char *d, int move_file_file (FileOpContext *ctx, char *s, char *d,
off_t *progress_count, double *progress_bytes); off_t *progress_count, double *progress_bytes);
int move_dir_dir (FileOpContext *ctx, char *s, char *d, int move_dir_dir (FileOpContext *ctx, char *s, char *d,
off_t *progress_count, double *progress_bytes); off_t *progress_count, double *progress_bytes);
int copy_dir_dir (FileOpContext *ctx, char *s, char *d, int toplevel, int move_over, int copy_dir_dir (FileOpContext *ctx, char *s, char *d, int toplevel,
int delete, struct link *parent_dirs, int move_over, int delete, struct link *parent_dirs,
off_t *progress_count, double *progress_bytes); off_t *progress_count, double *progress_bytes);
int erase_dir (FileOpContext *ctx, char *s, off_t *progress_count, double *progress_bytes); int erase_dir (FileOpContext *ctx, char *s, off_t *progress_count,
int erase_file (FileOpContext *ctx, char *s, off_t *progress_count, double *progress_bytes, double *progress_bytes);
int is_toplevel_file); int erase_file (FileOpContext *ctx, char *s, off_t *progress_count,
double *progress_bytes, int is_toplevel_file);
int erase_dir_iff_empty (FileOpContext *ctx, char *s); int erase_dir_iff_empty (FileOpContext *ctx, char *s);
int panel_operate (void *source_panel, FileOperation op, int panel_operate (void *source_panel, FileOperation op, int force_single);
char *thedefault, int ask_user);
extern int file_op_compute_totals; extern int file_op_compute_totals;
/* Error reporting routines */ /* Error reporting routines */
/* Report error with one file */
int file_error (char *format, char *file);
/* Report error with two files */ /* Report error with one file */
int files_error (char *format, char *file1, char *file2); int file_error (char *format, char *file);
/* Report error with two files */
int files_error (char *format, char *file1, char *file2);
/* Query routines */ /* Query routines */
void compute_dir_size (char *dirname, off_t *ret_marked, double *ret_total); void compute_dir_size (char *dirname, off_t *ret_marked,
double *ret_total);
#endif /* !__FILE_H */ #endif /* !__FILE_H */