Fixed calculation of Copy/Move dialog width.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2009-10-11 20:18:54 +04:00
parent 42ba60cebe
commit 6cd26f8385
4 changed files with 87 additions and 61 deletions

View File

@ -1638,10 +1638,6 @@ static const char *op_names1[] = {
N_("1Delete") 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: * These are formats for building a prompt. Parts encoded as follows:
* %o - operation from op_names1 * %o - operation from op_names1
@ -1672,9 +1668,9 @@ static const char *prompt_parts[] = {
* entries. * entries.
* src_stat is only used when single_source is not NULL. * 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, panel_operate_generate_prompt (const WPanel *panel, const int operation,
const char *single_source, gboolean single_source,
const struct stat *src_stat) const struct stat *src_stat)
{ {
const char *sp, *cp; const char *sp, *cp;
@ -1716,13 +1712,11 @@ panel_operate_generate_prompt (const WPanel *panel, const int operation,
case 'f': case 'f':
if (single_source) { if (single_source) {
cp = S_ISDIR (src_stat-> cp = S_ISDIR (src_stat->
st_mode) ? prompt_parts[2] : st_mode) ? prompt_parts[2] : prompt_parts[0];
prompt_parts[0];
} else { } else {
cp = (panel->marked == panel->dirs_marked) cp = (panel->marked == panel->dirs_marked)
? prompt_parts[3] ? prompt_parts[3]
: (panel->dirs_marked ? prompt_parts[4] : (panel->dirs_marked ? prompt_parts[4] : prompt_parts[1]);
: prompt_parts[1]);
} }
break; break;
default: default:
@ -1740,18 +1734,7 @@ panel_operate_generate_prompt (const WPanel *panel, const int operation,
} }
*dp = '\0'; *dp = '\0';
if (single_source) { return g_strdup (format_string);
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;
}
}
} }
/** /**
@ -1771,12 +1754,12 @@ panel_operate (void *source_panel, FileOperation operation,
int force_single) int force_single)
{ {
WPanel *panel = source_panel; WPanel *panel = source_panel;
char *source = NULL;
#ifdef WITH_FULL_PATHS #ifdef WITH_FULL_PATHS
char *source_with_path = NULL; char *source_with_path = NULL;
#else #else
# define source_with_path source # define source_with_path source
#endif /* !WITH_FULL_PATHS */ #endif /* !WITH_FULL_PATHS */
char *source = NULL;
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;
@ -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); ctx = file_op_context_new (operation);
/* Show confirmation dialog */ /* Show confirmation dialog */
if (operation != OP_DELETE) { if (operation != OP_DELETE) {
char *dest_dir; char *dest_dir;
char *dest_dir_; char *dest_dir_;
char *format;
/* Forced single operations default to the original name */ /* Forced single operations default to the original name */
if (force_single) if (force_single)
@ -1852,8 +1833,15 @@ panel_operate (void *source_panel, FileOperation operation,
return 0; return 0;
} }
dest = file_mask_dialog (ctx, operation, fmd_buf, dest_dir_, /* Generate confirmation prompt */
single_entry, &do_bg); 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_); g_free (dest_dir_);
if (dest == NULL || dest[0] == '\0') { if (dest == NULL || dest[0] == '\0') {
@ -1862,6 +1850,24 @@ panel_operate (void *source_panel, FileOperation operation,
return 0; return 0;
} }
} else if (confirm_delete) { } 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) if (safe_delete)
query_set_sel (1); query_set_sel (1);

View File

@ -6,11 +6,12 @@
#ifndef MC_FILE_H #ifndef MC_FILE_H
#define MC_FILE_H #define MC_FILE_H
#include "global.h"
#include <sys/types.h> /* off_t */ #include <sys/types.h> /* off_t */
#include "fileopctx.h"
#include "global.h"
#include "dialog.h" /* Dlg_head */ #include "dialog.h" /* Dlg_head */
#include "widget.h" /* WLabel */ #include "widget.h" /* WLabel */
#include "fileopctx.h"
struct link; struct link;
@ -53,5 +54,4 @@ ComputeDirSizeUI *compute_dir_size_create_ui (void);
void compute_dir_size_destroy_ui (ComputeDirSizeUI *ui); void compute_dir_size_destroy_ui (ComputeDirSizeUI *ui);
FileProgressStatus compute_dir_size_update_ui (const void *ui, const char *dirname); FileProgressStatus compute_dir_size_update_ui (const void *ui, const char *dirname);
#endif /* MC_FILE_H */ #endif /* MC_FILE_H */

View File

@ -816,15 +816,23 @@ is_wildcarded (char *p)
} }
char * char *
file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text, file_mask_dialog (FileOpContext *ctx, FileOperation operation,
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)
{ {
const size_t FMDY = 13; const size_t FMDY = 13;
const size_t FMDX = 64; const size_t FMDX = 68;
size_t fmd_xlen = 0; 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; int source_easy_patterns = easy_patterns;
size_t i, len; size_t i, len;
char fmd_buf [BUF_MEDIUM];
char *source_mask, *orig_mask, *dest_dir, *tmp; char *source_mask, *orig_mask, *dest_dir, *tmp;
char *def_text_secure; char *def_text_secure;
int val; int val;
@ -861,7 +869,7 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
/* 10 - OFFSET */ /* 10 - OFFSET */
QUICK_INPUT (3, FMDX, 3, FMDY, easy_patterns ? "*" : "^\\(.*\\)$", 58, 0, "input-def", &source_mask), QUICK_INPUT (3, FMDX, 3, FMDY, easy_patterns ? "*" : "^\\(.*\\)$", 58, 0, "input-def", &source_mask),
/* 11 - OFFSET */ /* 11 - OFFSET */
QUICK_LABEL (3, FMDX, 2, FMDY, text), QUICK_LABEL (3, FMDX, 2, FMDY, fmd_buf),
QUICK_END QUICK_END
}; };
@ -894,23 +902,39 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
fmd_xlen = max (fmd_xlen, len); fmd_xlen = max (fmd_xlen, len);
/* buttons */ /* buttons */
len = str_term_width1 (fmd_widgets[2 - OFFSET].u.button.text) b2_len = str_term_width1 (fmd_widgets[2 - OFFSET].u.button.text) + 6 + gap; /* OK */
+ str_term_width1 (fmd_widgets[0].u.button.text) + 11;
#ifdef WITH_BACKGROUND #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 #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; if (only_one) {
i = len + 3; 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; 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 #ifdef WITH_BACKGROUND
/* Background button */
fmd_widgets[1].relative_x = i; fmd_widgets[1].relative_x = i;
i += str_term_width1 (fmd_widgets[1].u.button.text) + 6; i += b1_len;
#endif #endif
/* Cancel button */
fmd_widgets[0].relative_x = i; fmd_widgets[0].relative_x = i;
#define chkbox_xpos(i) \ #define chkbox_xpos(i) \
@ -920,15 +944,9 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
chkbox_xpos (9 - OFFSET); chkbox_xpos (9 - OFFSET);
#undef chkbox_xpos #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 */ /* inputs */
fmd_widgets[ 7 - OFFSET].u.input.len = fmd_widgets[ 7 - OFFSET].u.input.len =
fmd_widgets[10 - OFFSET].u.input.len = fmd_xlen - 6; fmd_widgets[10 - OFFSET].u.input.len = fmd_xlen - 6;
}
/* unselect checkbox if target filesystem don't support attributes */ /* unselect checkbox if target filesystem don't support attributes */
ctx->op_preserve = filegui__check_attrs_on_fs (def_text); 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; fmd_widgets[7 - OFFSET].u.input.text = def_text_secure;
ctx->stable_symlinks = 0; ctx->stable_symlinks = 0;
*do_background = 0; *do_background = FALSE;
{ {
struct stat buf; struct stat buf;
@ -1034,7 +1052,7 @@ file_mask_dialog (FileOpContext *ctx, FileOperation operation, const char *text,
dest_dir = g_strdup ("./"); dest_dir = g_strdup ("./");
} }
if (val == B_USER) if (val == B_USER)
*do_background = 1; *do_background = TRUE;
} }
return dest_dir; return dest_dir;

View File

@ -6,10 +6,12 @@
#ifndef MC_FILEGUI_H #ifndef MC_FILEGUI_H
#define MC_FILEGUI_H #define MC_FILEGUI_H
#include "global.h"
#include "fileopctx.h" #include "fileopctx.h"
char *file_mask_dialog (FileOpContext *ctx, FileOperation operation, char *file_mask_dialog (FileOpContext *ctx, FileOperation operation,
const char *text, const char *def_text, int only_one, gboolean only_one,
int *do_background); const char *format, const void *text,
const char *def_text, gboolean *do_background);
#endif #endif /* MC_FILEGUI_H */