mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
Fixed calculation of Copy/Move dialog width.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
42ba60cebe
commit
6cd26f8385
64
src/file.c
64
src/file.c
@ -1638,10 +1638,6 @@ static const char *op_names1[] = {
|
||||
N_("1Delete")
|
||||
};
|
||||
|
||||
#define FMD_XLEN 64
|
||||
int fmd_xlen = FMD_XLEN;
|
||||
char fmd_buf [BUF_MEDIUM];
|
||||
|
||||
/*
|
||||
* These are formats for building a prompt. Parts encoded as follows:
|
||||
* %o - operation from op_names1
|
||||
@ -1672,9 +1668,9 @@ static const char *prompt_parts[] = {
|
||||
* entries.
|
||||
* src_stat is only used when single_source is not NULL.
|
||||
*/
|
||||
static void
|
||||
static char *
|
||||
panel_operate_generate_prompt (const WPanel *panel, const int operation,
|
||||
const char *single_source,
|
||||
gboolean single_source,
|
||||
const struct stat *src_stat)
|
||||
{
|
||||
const char *sp, *cp;
|
||||
@ -1716,13 +1712,11 @@ panel_operate_generate_prompt (const WPanel *panel, const int operation,
|
||||
case 'f':
|
||||
if (single_source) {
|
||||
cp = S_ISDIR (src_stat->
|
||||
st_mode) ? prompt_parts[2] :
|
||||
prompt_parts[0];
|
||||
st_mode) ? prompt_parts[2] : prompt_parts[0];
|
||||
} else {
|
||||
cp = (panel->marked == panel->dirs_marked)
|
||||
? prompt_parts[3]
|
||||
: (panel->dirs_marked ? prompt_parts[4]
|
||||
: prompt_parts[1]);
|
||||
: (panel->dirs_marked ? prompt_parts[4] : prompt_parts[1]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -1740,18 +1734,7 @@ panel_operate_generate_prompt (const WPanel *panel, const int operation,
|
||||
}
|
||||
*dp = '\0';
|
||||
|
||||
if (single_source) {
|
||||
i = fmd_xlen - str_term_width1 (format_string) - 4;
|
||||
g_snprintf (fmd_buf, sizeof (fmd_buf), format_string,
|
||||
str_trunc (single_source, i));
|
||||
} else {
|
||||
g_snprintf (fmd_buf, sizeof (fmd_buf), format_string,
|
||||
panel->marked);
|
||||
i = str_term_width1 (fmd_buf) + 6 - fmd_xlen;
|
||||
if (i > 0) {
|
||||
fmd_xlen += i;
|
||||
}
|
||||
}
|
||||
return g_strdup (format_string);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1771,12 +1754,12 @@ panel_operate (void *source_panel, FileOperation operation,
|
||||
int force_single)
|
||||
{
|
||||
WPanel *panel = source_panel;
|
||||
char *source = NULL;
|
||||
#ifdef WITH_FULL_PATHS
|
||||
char *source_with_path = NULL;
|
||||
#else
|
||||
# define source_with_path source
|
||||
#endif /* !WITH_FULL_PATHS */
|
||||
char *source = NULL;
|
||||
char *dest = NULL;
|
||||
char *temp = NULL;
|
||||
char *save_cwd = NULL, *save_dest = NULL;
|
||||
@ -1816,15 +1799,13 @@ panel_operate (void *source_panel, FileOperation operation,
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate confirmation prompt */
|
||||
panel_operate_generate_prompt (panel, operation, source, &src_stat);
|
||||
|
||||
ctx = file_op_context_new (operation);
|
||||
|
||||
/* Show confirmation dialog */
|
||||
if (operation != OP_DELETE) {
|
||||
char *dest_dir;
|
||||
char *dest_dir_;
|
||||
char *format;
|
||||
|
||||
/* Forced single operations default to the original name */
|
||||
if (force_single)
|
||||
@ -1852,8 +1833,15 @@ panel_operate (void *source_panel, FileOperation operation,
|
||||
return 0;
|
||||
}
|
||||
|
||||
dest = file_mask_dialog (ctx, operation, fmd_buf, dest_dir_,
|
||||
single_entry, &do_bg);
|
||||
/* Generate confirmation prompt */
|
||||
format = panel_operate_generate_prompt (panel, operation,
|
||||
source != NULL, &src_stat);
|
||||
|
||||
dest = file_mask_dialog (ctx, operation, source != NULL,
|
||||
format, source != NULL ? source : &panel->marked,
|
||||
dest_dir_, &do_bg);
|
||||
|
||||
g_free (format);
|
||||
g_free (dest_dir_);
|
||||
|
||||
if (dest == NULL || dest[0] == '\0') {
|
||||
@ -1862,11 +1850,29 @@ panel_operate (void *source_panel, FileOperation operation,
|
||||
return 0;
|
||||
}
|
||||
} else if (confirm_delete) {
|
||||
char *format;
|
||||
char fmd_buf [BUF_MEDIUM];
|
||||
|
||||
/* Generate confirmation prompt */
|
||||
format = panel_operate_generate_prompt (panel, OP_DELETE,
|
||||
source != NULL, &src_stat);
|
||||
|
||||
if (source == NULL)
|
||||
g_snprintf (fmd_buf, sizeof (fmd_buf), format, panel->marked);
|
||||
else {
|
||||
const int fmd_xlen = 64;
|
||||
i = fmd_xlen - str_term_width1 (format) - 4;
|
||||
g_snprintf (fmd_buf, sizeof (fmd_buf),
|
||||
format, str_trunc (source, i));
|
||||
}
|
||||
|
||||
g_free (format);
|
||||
|
||||
if (safe_delete)
|
||||
query_set_sel (1);
|
||||
|
||||
i = query_dialog (_(op_names[operation]), fmd_buf, D_ERROR, 2,
|
||||
_("&Yes"), _("&No"));
|
||||
_("&Yes"), _("&No"));
|
||||
|
||||
if (i != 0) {
|
||||
file_op_context_destroy (ctx);
|
||||
|
@ -6,11 +6,12 @@
|
||||
#ifndef MC_FILE_H
|
||||
#define MC_FILE_H
|
||||
|
||||
#include "global.h"
|
||||
#include <sys/types.h> /* off_t */
|
||||
#include "fileopctx.h"
|
||||
|
||||
#include "global.h"
|
||||
#include "dialog.h" /* Dlg_head */
|
||||
#include "widget.h" /* WLabel */
|
||||
#include "fileopctx.h"
|
||||
|
||||
struct link;
|
||||
|
||||
@ -53,5 +54,4 @@ ComputeDirSizeUI *compute_dir_size_create_ui (void);
|
||||
void compute_dir_size_destroy_ui (ComputeDirSizeUI *ui);
|
||||
FileProgressStatus compute_dir_size_update_ui (const void *ui, const char *dirname);
|
||||
|
||||
|
||||
#endif /* MC_FILE_H */
|
||||
|
@ -816,15 +816,23 @@ is_wildcarded (char *p)
|
||||
}
|
||||
|
||||
char *
|
||||
file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
|
||||
const char *def_text, int only_one, int *do_background)
|
||||
file_mask_dialog (FileOpContext *ctx, FileOperation operation,
|
||||
gboolean only_one,
|
||||
const char *format, const void *text,
|
||||
const char *def_text, gboolean *do_background)
|
||||
{
|
||||
const size_t FMDY = 13;
|
||||
const size_t FMDX = 64;
|
||||
size_t fmd_xlen = 0;
|
||||
const size_t FMDX = 68;
|
||||
size_t fmd_xlen = FMDX;
|
||||
|
||||
/* buttons */
|
||||
const size_t gap = 1;
|
||||
size_t b0_len, b2_len;
|
||||
size_t b1_len = 0;
|
||||
|
||||
int source_easy_patterns = easy_patterns;
|
||||
size_t i, len;
|
||||
char fmd_buf [BUF_MEDIUM];
|
||||
char *source_mask, *orig_mask, *dest_dir, *tmp;
|
||||
char *def_text_secure;
|
||||
int val;
|
||||
@ -861,7 +869,7 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
|
||||
/* 10 - OFFSET */
|
||||
QUICK_INPUT (3, FMDX, 3, FMDY, easy_patterns ? "*" : "^\\(.*\\)$", 58, 0, "input-def", &source_mask),
|
||||
/* 11 - OFFSET */
|
||||
QUICK_LABEL (3, FMDX, 2, FMDY, text),
|
||||
QUICK_LABEL (3, FMDX, 2, FMDY, fmd_buf),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
@ -894,23 +902,39 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
|
||||
fmd_xlen = max (fmd_xlen, len);
|
||||
|
||||
/* buttons */
|
||||
len = str_term_width1 (fmd_widgets[2 - OFFSET].u.button.text)
|
||||
+ str_term_width1 (fmd_widgets[0].u.button.text) + 11;
|
||||
b2_len = str_term_width1 (fmd_widgets[2 - OFFSET].u.button.text) + 6 + gap; /* OK */
|
||||
#ifdef WITH_BACKGROUND
|
||||
len += str_term_width1 (fmd_widgets[1].u.button.text) + 6;
|
||||
b1_len = str_term_width1 (fmd_widgets[1].u.button.text) + 4 + gap; /* Background */
|
||||
#endif
|
||||
fmd_xlen = max (fmd_xlen, len + 4);
|
||||
b0_len = str_term_width1 (fmd_widgets[0].u.button.text) + 4; /* Cancel */
|
||||
len = b0_len + b1_len + b2_len;
|
||||
fmd_xlen = max (fmd_xlen, len + 6);
|
||||
|
||||
len = (fmd_xlen - (len + 6)) / 2;
|
||||
i = len + 3;
|
||||
if (only_one) {
|
||||
int flen;
|
||||
|
||||
flen = str_term_width1 (format);
|
||||
i = fmd_xlen - flen - 4; /* FIXME */
|
||||
g_snprintf (fmd_buf, sizeof (fmd_buf),
|
||||
format, str_trunc ((const char *) text, i));
|
||||
} else {
|
||||
g_snprintf (fmd_buf, sizeof (fmd_buf), format, *(const int *) text);
|
||||
fmd_xlen = max (fmd_xlen, str_term_width1 (fmd_buf) + 6);
|
||||
}
|
||||
|
||||
for (i = sizeof (fmd_widgets) / sizeof (fmd_widgets[0]); i > 0; )
|
||||
fmd_widgets[--i].x_divisions = fmd_xlen;
|
||||
|
||||
i = (fmd_xlen - len)/2;
|
||||
/* OK button */
|
||||
fmd_widgets[2 - OFFSET].relative_x = i;
|
||||
i += str_term_width1 (fmd_widgets[2 - OFFSET].u.button.text) + 8;
|
||||
|
||||
i += b2_len;
|
||||
#ifdef WITH_BACKGROUND
|
||||
/* Background button */
|
||||
fmd_widgets[1].relative_x = i;
|
||||
i += str_term_width1 (fmd_widgets[1].u.button.text) + 6;
|
||||
i += b1_len;
|
||||
#endif
|
||||
|
||||
/* Cancel button */
|
||||
fmd_widgets[0].relative_x = i;
|
||||
|
||||
#define chkbox_xpos(i) \
|
||||
@ -920,15 +944,9 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
|
||||
chkbox_xpos (9 - OFFSET);
|
||||
#undef chkbox_xpos
|
||||
|
||||
if (fmd_xlen != FMDX) {
|
||||
i = sizeof (fmd_widgets) / sizeof (fmd_widgets[0]) - 1;
|
||||
while (i--)
|
||||
fmd_widgets[i].x_divisions = fmd_xlen;
|
||||
|
||||
/* inputs */
|
||||
fmd_widgets[ 7 - OFFSET].u.input.len =
|
||||
fmd_widgets[10 - OFFSET].u.input.len = fmd_xlen - 6;
|
||||
}
|
||||
/* inputs */
|
||||
fmd_widgets[ 7 - OFFSET].u.input.len =
|
||||
fmd_widgets[10 - OFFSET].u.input.len = fmd_xlen - 6;
|
||||
|
||||
/* unselect checkbox if target filesystem don't support attributes */
|
||||
ctx->op_preserve = filegui__check_attrs_on_fs (def_text);
|
||||
@ -945,7 +963,7 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
|
||||
fmd_widgets[7 - OFFSET].u.input.text = def_text_secure;
|
||||
|
||||
ctx->stable_symlinks = 0;
|
||||
*do_background = 0;
|
||||
*do_background = FALSE;
|
||||
|
||||
{
|
||||
struct stat buf;
|
||||
@ -1034,7 +1052,7 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
|
||||
dest_dir = g_strdup ("./");
|
||||
}
|
||||
if (val == B_USER)
|
||||
*do_background = 1;
|
||||
*do_background = TRUE;
|
||||
}
|
||||
|
||||
return dest_dir;
|
||||
|
@ -6,10 +6,12 @@
|
||||
#ifndef MC_FILEGUI_H
|
||||
#define MC_FILEGUI_H
|
||||
|
||||
#include "global.h"
|
||||
#include "fileopctx.h"
|
||||
|
||||
char *file_mask_dialog (FileOpContext *ctx, FileOperation operation,
|
||||
const char *text, const char *def_text, int only_one,
|
||||
int *do_background);
|
||||
gboolean only_one,
|
||||
const char *format, const void *text,
|
||||
const char *def_text, gboolean *do_background);
|
||||
|
||||
#endif
|
||||
#endif /* MC_FILEGUI_H */
|
||||
|
Loading…
Reference in New Issue
Block a user