mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +03:00
Applied MC indentation policy.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
b0be11acd5
commit
a708b5c514
@ -54,8 +54,10 @@ mc_skin_lines_load_frm (mc_skin_t * mc_skin, const char *name)
|
|||||||
ret = mc_tty_normalize_lines_char (frm_val);
|
ret = mc_tty_normalize_lines_char (frm_val);
|
||||||
|
|
||||||
g_free (frm_val);
|
g_free (frm_val);
|
||||||
/*
|
|
||||||
switch (ret) {
|
#if 0
|
||||||
|
switch (ret)
|
||||||
|
{
|
||||||
case 0x80:
|
case 0x80:
|
||||||
ret = ACS_HLINE;
|
ret = ACS_HLINE;
|
||||||
break;
|
break;
|
||||||
@ -86,7 +88,8 @@ mc_skin_lines_load_frm (mc_skin_t * mc_skin, const char *name)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*/
|
#endif
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,8 @@ mc_tty_normalize_lines_char (const char *ch)
|
|||||||
char *str2;
|
char *str2;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
struct mc_tty_lines_struct {
|
struct mc_tty_lines_struct
|
||||||
|
{
|
||||||
const char *line;
|
const char *line;
|
||||||
int line_code;
|
int line_code;
|
||||||
} const lines_codes[] = {
|
} const lines_codes[] = {
|
||||||
@ -118,7 +119,8 @@ mc_tty_normalize_lines_char (const char *ch)
|
|||||||
if (ch == NULL)
|
if (ch == NULL)
|
||||||
return (int) ' ';
|
return (int) ' ';
|
||||||
|
|
||||||
for (res = 0; lines_codes[res].line; res++) {
|
for (res = 0; lines_codes[res].line; res++)
|
||||||
|
{
|
||||||
if (strcmp (ch, lines_codes[res].line) == 0)
|
if (strcmp (ch, lines_codes[res].line) == 0)
|
||||||
return lines_codes[res].line_code;
|
return lines_codes[res].line_code;
|
||||||
}
|
}
|
||||||
@ -293,7 +295,8 @@ tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < rows; i++) {
|
for (i = 0; i < rows; i++)
|
||||||
|
{
|
||||||
move (y + i, x);
|
move (y + i, x);
|
||||||
hline (ch, cols);
|
hline (ch, cols);
|
||||||
}
|
}
|
||||||
@ -324,18 +327,20 @@ tty_print_anychar (int c)
|
|||||||
{
|
{
|
||||||
unsigned char str[6 + 1];
|
unsigned char str[6 + 1];
|
||||||
|
|
||||||
if (utf8_display || c > 255) {
|
if (utf8_display || c > 255)
|
||||||
|
{
|
||||||
int res = g_unichar_to_utf8 (c, (char *) str);
|
int res = g_unichar_to_utf8 (c, (char *) str);
|
||||||
if (res == 0) {
|
if (res == 0)
|
||||||
|
{
|
||||||
str[0] = '.';
|
str[0] = '.';
|
||||||
str[1] = '\0';
|
str[1] = '\0';
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
str[res] = '\0';
|
str[res] = '\0';
|
||||||
}
|
|
||||||
addstr (str_term_form ((char *) str));
|
addstr (str_term_form ((char *) str));
|
||||||
} else {
|
|
||||||
addch (c);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
addch (c);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,44 +83,47 @@ static gboolean no_slang_delay;
|
|||||||
/* This table describes which capabilities we want and which values we
|
/* This table describes which capabilities we want and which values we
|
||||||
* assign to them.
|
* assign to them.
|
||||||
*/
|
*/
|
||||||
static const struct {
|
static const struct
|
||||||
|
{
|
||||||
int key_code;
|
int key_code;
|
||||||
const char *key_name;
|
const char *key_name;
|
||||||
} key_table[] = {
|
} key_table[] =
|
||||||
{
|
{
|
||||||
KEY_F (0), "k0"}, {
|
/* *INDENT-OFF* */
|
||||||
KEY_F (1), "k1"}, {
|
{ KEY_F (0), "k0" },
|
||||||
KEY_F (2), "k2"}, {
|
{ KEY_F (1), "k1" },
|
||||||
KEY_F (3), "k3"}, {
|
{ KEY_F (2), "k2" },
|
||||||
KEY_F (4), "k4"}, {
|
{ KEY_F (3), "k3" },
|
||||||
KEY_F (5), "k5"}, {
|
{ KEY_F (4), "k4" },
|
||||||
KEY_F (6), "k6"}, {
|
{ KEY_F (5), "k5" },
|
||||||
KEY_F (7), "k7"}, {
|
{ KEY_F (6), "k6" },
|
||||||
KEY_F (8), "k8"}, {
|
{ KEY_F (7), "k7" },
|
||||||
KEY_F (9), "k9"}, {
|
{ KEY_F (8), "k8" },
|
||||||
KEY_F (10), "k;"}, {
|
{ KEY_F (9), "k9" },
|
||||||
KEY_F (11), "F1"}, {
|
{ KEY_F (10), "k;" },
|
||||||
KEY_F (12), "F2"}, {
|
{ KEY_F (11), "F1" },
|
||||||
KEY_F (13), "F3"}, {
|
{ KEY_F (12), "F2" },
|
||||||
KEY_F (14), "F4"}, {
|
{ KEY_F (13), "F3" },
|
||||||
KEY_F (15), "F5"}, {
|
{ KEY_F (14), "F4" },
|
||||||
KEY_F (16), "F6"}, {
|
{ KEY_F (15), "F5" },
|
||||||
KEY_F (17), "F7"}, {
|
{ KEY_F (16), "F6" },
|
||||||
KEY_F (18), "F8"}, {
|
{ KEY_F (17), "F7" },
|
||||||
KEY_F (19), "F9"}, {
|
{ KEY_F (18), "F8" },
|
||||||
KEY_F (20), "FA"}, {
|
{ KEY_F (19), "F9" },
|
||||||
KEY_IC, "kI"}, {
|
{ KEY_F (20), "FA" },
|
||||||
KEY_NPAGE, "kN"}, {
|
{ KEY_IC, "kI" },
|
||||||
KEY_PPAGE, "kP"}, {
|
{ KEY_NPAGE, "kN" },
|
||||||
KEY_LEFT, "kl"}, {
|
{ KEY_PPAGE, "kP" },
|
||||||
KEY_RIGHT, "kr"}, {
|
{ KEY_LEFT, "kl" },
|
||||||
KEY_UP, "ku"}, {
|
{ KEY_RIGHT, "kr" },
|
||||||
KEY_DOWN, "kd"}, {
|
{ KEY_UP, "ku" },
|
||||||
KEY_DC, "kD"}, {
|
{ KEY_DOWN, "kd" },
|
||||||
KEY_BACKSPACE, "kb"}, {
|
{ KEY_DC, "kD" },
|
||||||
KEY_HOME, "kh"}, {
|
{ KEY_BACKSPACE, "kb" },
|
||||||
KEY_END, "@7"}, {
|
{ KEY_HOME, "kh" },
|
||||||
0, NULL}
|
{ KEY_END, "@7" },
|
||||||
|
{ 0, NULL }
|
||||||
|
/* *INDENT-ON* */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*** file scope functions **********************************************/
|
/*** file scope functions **********************************************/
|
||||||
@ -148,10 +151,12 @@ slang_reset_softkeys (void)
|
|||||||
static const char display[] = " ";
|
static const char display[] = " ";
|
||||||
char tmp[BUF_SMALL];
|
char tmp[BUF_SMALL];
|
||||||
|
|
||||||
for (key = 1; key < 9; key++) {
|
for (key = 1; key < 9; key++)
|
||||||
|
{
|
||||||
g_snprintf (tmp, sizeof (tmp), "k%d", key);
|
g_snprintf (tmp, sizeof (tmp), "k%d", key);
|
||||||
send = (char *) SLtt_tgetstr (tmp);
|
send = (char *) SLtt_tgetstr (tmp);
|
||||||
if (send != NULL) {
|
if (send != NULL)
|
||||||
|
{
|
||||||
g_snprintf (tmp, sizeof (tmp), "\033&f%dk%dd%dL%s%s", key,
|
g_snprintf (tmp, sizeof (tmp), "\033&f%dk%dd%dL%s%s", key,
|
||||||
(int) (sizeof (display) - 1), (int) strlen (send), display, send);
|
(int) (sizeof (display) - 1), (int) strlen (send), display, send);
|
||||||
SLtt_write_string (tmp);
|
SLtt_write_string (tmp);
|
||||||
@ -188,7 +193,8 @@ mc_tty_normalize_lines_char (const char *str)
|
|||||||
char *str2;
|
char *str2;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
struct mc_tty_lines_struct {
|
struct mc_tty_lines_struct
|
||||||
|
{
|
||||||
const char *line;
|
const char *line;
|
||||||
int line_code;
|
int line_code;
|
||||||
} const lines_codes[] = {
|
} const lines_codes[] = {
|
||||||
@ -210,7 +216,8 @@ mc_tty_normalize_lines_char (const char *str)
|
|||||||
if (!str)
|
if (!str)
|
||||||
return (int) ' ';
|
return (int) ' ';
|
||||||
|
|
||||||
for (res = 0; lines_codes[res].line; res++) {
|
for (res = 0; lines_codes[res].line; res++)
|
||||||
|
{
|
||||||
if (strcmp (str, lines_codes[res].line) == 0)
|
if (strcmp (str, lines_codes[res].line) == 0)
|
||||||
return lines_codes[res].line_code;
|
return lines_codes[res].line_code;
|
||||||
}
|
}
|
||||||
@ -242,7 +249,8 @@ tty_init (gboolean slow, gboolean ugly_lines)
|
|||||||
* small, large and negative screen dimensions.
|
* small, large and negative screen dimensions.
|
||||||
*/
|
*/
|
||||||
if ((COLS < 10) || (LINES < 5)
|
if ((COLS < 10) || (LINES < 5)
|
||||||
|| (COLS > SLTT_MAX_SCREEN_COLS) || (LINES > SLTT_MAX_SCREEN_ROWS)) {
|
|| (COLS > SLTT_MAX_SCREEN_COLS) || (LINES > SLTT_MAX_SCREEN_ROWS))
|
||||||
|
{
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("Screen size %dx%d is not supported.\n"
|
_("Screen size %dx%d is not supported.\n"
|
||||||
"Check the TERM environment variable.\n"), COLS, LINES);
|
"Check the TERM environment variable.\n"), COLS, LINES);
|
||||||
@ -263,7 +271,8 @@ tty_init (gboolean slow, gboolean ugly_lines)
|
|||||||
if (SLang_TT_Read_FD == fileno (stderr))
|
if (SLang_TT_Read_FD == fileno (stderr))
|
||||||
SLang_TT_Read_FD = fileno (stdin);
|
SLang_TT_Read_FD = fileno (stdin);
|
||||||
|
|
||||||
if (tcgetattr (SLang_TT_Read_FD, &new_mode) == 0) {
|
if (tcgetattr (SLang_TT_Read_FD, &new_mode) == 0)
|
||||||
|
{
|
||||||
#ifdef VDSUSP
|
#ifdef VDSUSP
|
||||||
new_mode.c_cc[VDSUSP] = NULL_VALUE; /* to ignore ^Y */
|
new_mode.c_cc[VDSUSP] = NULL_VALUE; /* to ignore ^Y */
|
||||||
#endif
|
#endif
|
||||||
@ -302,7 +311,8 @@ tty_shutdown (void)
|
|||||||
* active when the program was started up
|
* active when the program was started up
|
||||||
*/
|
*/
|
||||||
op_cap = SLtt_tgetstr ((char *) "op");
|
op_cap = SLtt_tgetstr ((char *) "op");
|
||||||
if (op_cap != NULL) {
|
if (op_cap != NULL)
|
||||||
|
{
|
||||||
fputs (op_cap, stdout);
|
fputs (op_cap, stdout);
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
}
|
}
|
||||||
@ -379,7 +389,8 @@ tty_lowlevel_getch (void)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
c = SLang_getkey ();
|
c = SLang_getkey ();
|
||||||
if (c == SLANG_GETKEY_ERROR) {
|
if (c == SLANG_GETKEY_ERROR)
|
||||||
|
{
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"SLang_getkey returned SLANG_GETKEY_ERROR\n"
|
"SLang_getkey returned SLANG_GETKEY_ERROR\n"
|
||||||
"Assuming EOF on stdin and exiting\n");
|
"Assuming EOF on stdin and exiting\n");
|
||||||
@ -422,10 +433,12 @@ tty_draw_hline (int y, int x, int ch, int len)
|
|||||||
if (ch == ACS_HLINE)
|
if (ch == ACS_HLINE)
|
||||||
ch = mc_tty_frm[MC_TTY_FRM_HORIZ];
|
ch = mc_tty_frm[MC_TTY_FRM_HORIZ];
|
||||||
|
|
||||||
if ((y < 0) || (x < 0)) {
|
if ((y < 0) || (x < 0))
|
||||||
|
{
|
||||||
y = SLsmg_get_row ();
|
y = SLsmg_get_row ();
|
||||||
x = SLsmg_get_column ();
|
x = SLsmg_get_column ();
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
SLsmg_gotorc (y, x);
|
SLsmg_gotorc (y, x);
|
||||||
|
|
||||||
if (ch == 0)
|
if (ch == 0)
|
||||||
@ -447,10 +460,12 @@ tty_draw_vline (int y, int x, int ch, int len)
|
|||||||
if (ch == ACS_VLINE)
|
if (ch == ACS_VLINE)
|
||||||
ch = mc_tty_frm[MC_TTY_FRM_VERT];
|
ch = mc_tty_frm[MC_TTY_FRM_VERT];
|
||||||
|
|
||||||
if ((y < 0) || (x < 0)) {
|
if ((y < 0) || (x < 0))
|
||||||
|
{
|
||||||
y = SLsmg_get_row ();
|
y = SLsmg_get_row ();
|
||||||
x = SLsmg_get_column ();
|
x = SLsmg_get_column ();
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
SLsmg_gotorc (y, x);
|
SLsmg_gotorc (y, x);
|
||||||
|
|
||||||
if (ch == 0)
|
if (ch == 0)
|
||||||
@ -458,10 +473,12 @@ tty_draw_vline (int y, int x, int ch, int len)
|
|||||||
|
|
||||||
if (ch == ACS_VLINE)
|
if (ch == ACS_VLINE)
|
||||||
SLsmg_draw_vline (len);
|
SLsmg_draw_vline (len);
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
while (len-- != 0) {
|
while (len-- != 0)
|
||||||
|
{
|
||||||
SLsmg_gotorc (y + pos, x);
|
SLsmg_gotorc (y + pos, x);
|
||||||
tty_print_char (ch);
|
tty_print_char (ch);
|
||||||
pos++;
|
pos++;
|
||||||
@ -501,7 +518,8 @@ tty_print_alt_char (int c, gboolean single)
|
|||||||
#define DRAW(x, y) (x == y) \
|
#define DRAW(x, y) (x == y) \
|
||||||
? SLsmg_draw_object (SLsmg_get_row(), SLsmg_get_column(), x) \
|
? SLsmg_draw_object (SLsmg_get_row(), SLsmg_get_column(), x) \
|
||||||
: SLsmg_write_char ((unsigned int) y)
|
: SLsmg_write_char ((unsigned int) y)
|
||||||
switch (c) {
|
switch (c)
|
||||||
|
{
|
||||||
case ACS_VLINE:
|
case ACS_VLINE:
|
||||||
DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT]);
|
DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT]);
|
||||||
break;
|
break;
|
||||||
@ -540,16 +558,22 @@ tty_print_anychar (int c)
|
|||||||
{
|
{
|
||||||
char str[6 + 1];
|
char str[6 + 1];
|
||||||
|
|
||||||
if (c > 255) {
|
if (c > 255)
|
||||||
|
{
|
||||||
int res = g_unichar_to_utf8 (c, str);
|
int res = g_unichar_to_utf8 (c, str);
|
||||||
if (res == 0) {
|
if (res == 0)
|
||||||
|
{
|
||||||
str[0] = '.';
|
str[0] = '.';
|
||||||
str[1] = '\0';
|
str[1] = '\0';
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
str[res] = '\0';
|
str[res] = '\0';
|
||||||
}
|
}
|
||||||
SLsmg_write_string ((char *) str_term_form (str));
|
SLsmg_write_string ((char *) str_term_form (str));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
SLsmg_write_char ((SLwchar_Type) ((unsigned int) c));
|
SLsmg_write_char ((SLwchar_Type) ((unsigned int) c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,8 @@ mc_tty_normalize_from_utf8 (const char *str)
|
|||||||
|
|
||||||
buffer = g_string_new ("");
|
buffer = g_string_new ("");
|
||||||
|
|
||||||
if (str_convert (conv, str, buffer) == ESTR_FAILURE) {
|
if (str_convert (conv, str, buffer) == ESTR_FAILURE)
|
||||||
|
{
|
||||||
g_string_free (buffer, TRUE);
|
g_string_free (buffer, TRUE);
|
||||||
str_close_conv (conv);
|
str_close_conv (conv);
|
||||||
return g_strdup (str);
|
return g_strdup (str);
|
||||||
|
@ -80,7 +80,8 @@ extern void tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
|
|||||||
|
|
||||||
extern int mc_tty_frm[];
|
extern int mc_tty_frm[];
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
/* single lines */
|
/* single lines */
|
||||||
MC_TTY_FRM_VERT,
|
MC_TTY_FRM_VERT,
|
||||||
MC_TTY_FRM_HORIZ,
|
MC_TTY_FRM_HORIZ,
|
||||||
|
136
src/chmod.c
136
src/chmod.c
@ -81,41 +81,48 @@ static const char *c_fname, *c_fown, *c_fgrp;
|
|||||||
|
|
||||||
static WLabel *statl;
|
static WLabel *statl;
|
||||||
|
|
||||||
static struct {
|
static struct
|
||||||
|
{
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
const char *text;
|
const char *text;
|
||||||
int selected;
|
int selected;
|
||||||
WCheck *check;
|
WCheck *check;
|
||||||
} check_perm[PERMISSIONS] =
|
} check_perm[PERMISSIONS] =
|
||||||
{
|
{
|
||||||
{ S_IXOTH, N_("execute/search by others"), 0, 0, },
|
/* *INDENT-OFF* */
|
||||||
{ S_IWOTH, N_("write by others"), 0, 0, },
|
{ S_IXOTH, N_("execute/search by others"), 0, 0 },
|
||||||
{ S_IROTH, N_("read by others"), 0, 0, },
|
{ S_IWOTH, N_("write by others"), 0, 0 },
|
||||||
{ S_IXGRP, N_("execute/search by group"), 0, 0, },
|
{ S_IROTH, N_("read by others"), 0, 0 },
|
||||||
{ S_IWGRP, N_("write by group"), 0, 0, },
|
{ S_IXGRP, N_("execute/search by group"), 0, 0 },
|
||||||
{ S_IRGRP, N_("read by group"), 0, 0, },
|
{ S_IWGRP, N_("write by group"), 0, 0 },
|
||||||
{ S_IXUSR, N_("execute/search by owner"), 0, 0, },
|
{ S_IRGRP, N_("read by group"), 0, 0 },
|
||||||
{ S_IWUSR, N_("write by owner"), 0, 0, },
|
{ S_IXUSR, N_("execute/search by owner"), 0, 0 },
|
||||||
{ S_IRUSR, N_("read by owner"), 0, 0, },
|
{ S_IWUSR, N_("write by owner"), 0, 0 },
|
||||||
{ S_ISVTX, N_("sticky bit"), 0, 0, },
|
{ S_IRUSR, N_("read by owner"), 0, 0 },
|
||||||
{ S_ISGID, N_("set group ID on execution"), 0, 0, },
|
{ S_ISVTX, N_("sticky bit"), 0, 0 },
|
||||||
{ S_ISUID, N_("set user ID on execution"), 0, 0, },
|
{ S_ISGID, N_("set group ID on execution"), 0, 0 },
|
||||||
|
{ S_ISUID, N_("set user ID on execution"), 0, 0 }
|
||||||
|
/* *INDENT-ON* */
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct {
|
static struct
|
||||||
|
{
|
||||||
int ret_cmd, flags, y, x;
|
int ret_cmd, flags, y, x;
|
||||||
const char *text;
|
const char *text;
|
||||||
} chmod_but[BUTTONS] =
|
} chmod_but[BUTTONS] =
|
||||||
{
|
{
|
||||||
|
/* *INDENT-OFF* */
|
||||||
{ B_CANCEL, NORMAL_BUTTON, 2, 33, N_("&Cancel") },
|
{ B_CANCEL, NORMAL_BUTTON, 2, 33, N_("&Cancel") },
|
||||||
{ B_ENTER, DEFPUSH_BUTTON, 2, 17, N_("&Set") },
|
{ B_ENTER, DEFPUSH_BUTTON, 2, 17, N_("&Set") },
|
||||||
{ B_CLRMRK, NORMAL_BUTTON, 0, 42, N_("C&lear marked") },
|
{ B_CLRMRK, NORMAL_BUTTON, 0, 42, N_("C&lear marked") },
|
||||||
{ B_SETMRK, NORMAL_BUTTON, 0, 27, N_("S&et marked") },
|
{ B_SETMRK, NORMAL_BUTTON, 0, 27, N_("S&et marked") },
|
||||||
{ B_MARKED, NORMAL_BUTTON, 0, 12, N_("&Marked all") },
|
{ B_MARKED, NORMAL_BUTTON, 0, 12, N_("&Marked all") },
|
||||||
{ B_ALL, NORMAL_BUTTON, 0, 0, N_("Set &all") },
|
{ B_ALL, NORMAL_BUTTON, 0, 0, N_("Set &all") }
|
||||||
|
/* *INDENT-ON* */
|
||||||
};
|
};
|
||||||
|
|
||||||
static void chmod_toggle_select (Dlg_head *h, int Id)
|
static void
|
||||||
|
chmod_toggle_select (Dlg_head * h, int Id)
|
||||||
{
|
{
|
||||||
tty_setcolor (COLOR_NORMAL);
|
tty_setcolor (COLOR_NORMAL);
|
||||||
check_perm[Id].selected ^= 1;
|
check_perm[Id].selected ^= 1;
|
||||||
@ -125,7 +132,8 @@ static void chmod_toggle_select (Dlg_head *h, int Id)
|
|||||||
dlg_move (h, PY + PERMISSIONS - Id, PX + 3);
|
dlg_move (h, PY + PERMISSIONS - Id, PX + 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void chmod_refresh (Dlg_head *h)
|
static void
|
||||||
|
chmod_refresh (Dlg_head * h)
|
||||||
{
|
{
|
||||||
common_dialog_repaint (h);
|
common_dialog_repaint (h);
|
||||||
|
|
||||||
@ -161,15 +169,16 @@ static void chmod_refresh (Dlg_head *h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
chmod_callback (Dlg_head *h, Widget *sender,
|
chmod_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||||
dlg_msg_t msg, int parm, void *data)
|
|
||||||
{
|
{
|
||||||
char buffer[BUF_TINY];
|
char buffer[BUF_TINY];
|
||||||
int id = h->current->dlg_id - BUTTONS + single_set * 2;
|
int id = h->current->dlg_id - BUTTONS + single_set * 2;
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg)
|
||||||
|
{
|
||||||
case DLG_ACTION:
|
case DLG_ACTION:
|
||||||
if (id >= 0) {
|
if (id >= 0)
|
||||||
|
{
|
||||||
c_stat ^= check_perm[id].mode;
|
c_stat ^= check_perm[id].mode;
|
||||||
g_snprintf (buffer, sizeof (buffer), "%o", c_stat);
|
g_snprintf (buffer, sizeof (buffer), "%o", c_stat);
|
||||||
label_set_text (statl, buffer);
|
label_set_text (statl, buffer);
|
||||||
@ -179,7 +188,8 @@ chmod_callback (Dlg_head *h, Widget *sender,
|
|||||||
return MSG_HANDLED;
|
return MSG_HANDLED;
|
||||||
|
|
||||||
case DLG_KEY:
|
case DLG_KEY:
|
||||||
if ((parm == 'T' || parm == 't' || parm == KEY_IC) && id > 0) {
|
if ((parm == 'T' || parm == 't' || parm == KEY_IC) && id > 0)
|
||||||
|
{
|
||||||
chmod_toggle_select (h, id);
|
chmod_toggle_select (h, id);
|
||||||
if (parm == KEY_IC)
|
if (parm == KEY_IC)
|
||||||
dlg_one_down (h);
|
dlg_one_down (h);
|
||||||
@ -208,10 +218,10 @@ init_chmod (void)
|
|||||||
|
|
||||||
ch_dlg =
|
ch_dlg =
|
||||||
create_dlg (0, 0, 22 - single_set, 70, dialog_colors,
|
create_dlg (0, 0, 22 - single_set, 70, dialog_colors,
|
||||||
chmod_callback, "[Chmod]", _("Chmod command"),
|
chmod_callback, "[Chmod]", _("Chmod command"), DLG_CENTER | DLG_REVERSE);
|
||||||
DLG_CENTER | DLG_REVERSE);
|
|
||||||
|
|
||||||
for (i = 0; i < BUTTONS; i++) {
|
for (i = 0; i < BUTTONS; i++)
|
||||||
|
{
|
||||||
if (i == 2 && single_set)
|
if (i == 2 && single_set)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
@ -219,28 +229,28 @@ init_chmod (void)
|
|||||||
button_new (BY + chmod_but[i].y - single_set,
|
button_new (BY + chmod_but[i].y - single_set,
|
||||||
BX + chmod_but[i].x,
|
BX + chmod_but[i].x,
|
||||||
chmod_but[i].ret_cmd,
|
chmod_but[i].ret_cmd,
|
||||||
chmod_but[i].flags,
|
chmod_but[i].flags, _(chmod_but[i].text), 0));
|
||||||
_(chmod_but[i].text), 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < PERMISSIONS; i++) {
|
for (i = 0; i < PERMISSIONS; i++)
|
||||||
check_perm[i].check =
|
{
|
||||||
check_new (PY + (PERMISSIONS - i), PX + 2, 0,
|
check_perm[i].check = check_new (PY + (PERMISSIONS - i), PX + 2, 0, _(check_perm[i].text));
|
||||||
_(check_perm[i].text));
|
|
||||||
add_widget (ch_dlg, check_perm[i].check);
|
add_widget (ch_dlg, check_perm[i].check);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ch_dlg;
|
return ch_dlg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void chmod_done (void)
|
static void
|
||||||
|
chmod_done (void)
|
||||||
{
|
{
|
||||||
if (need_update)
|
if (need_update)
|
||||||
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
|
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
|
||||||
repaint_screen ();
|
repaint_screen ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *next_file (void)
|
static char *
|
||||||
|
next_file (void)
|
||||||
{
|
{
|
||||||
while (!current_panel->dir.list[c_file].f.marked)
|
while (!current_panel->dir.list[c_file].f.marked)
|
||||||
c_file++;
|
c_file++;
|
||||||
@ -248,50 +258,57 @@ static char *next_file (void)
|
|||||||
return current_panel->dir.list[c_file].fname;
|
return current_panel->dir.list[c_file].fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_chmod (struct stat *sf)
|
static void
|
||||||
|
do_chmod (struct stat *sf)
|
||||||
{
|
{
|
||||||
sf->st_mode &= and_mask;
|
sf->st_mode &= and_mask;
|
||||||
sf->st_mode |= or_mask;
|
sf->st_mode |= or_mask;
|
||||||
if (mc_chmod (current_panel->dir.list [c_file].fname, sf->st_mode) == -1)
|
if (mc_chmod (current_panel->dir.list[c_file].fname, sf->st_mode) == -1)
|
||||||
message (D_ERROR, MSG_ERROR, _(" Cannot chmod \"%s\" \n %s "),
|
message (D_ERROR, MSG_ERROR, _(" Cannot chmod \"%s\" \n %s "),
|
||||||
current_panel->dir.list [c_file].fname, unix_error_string (errno));
|
current_panel->dir.list[c_file].fname, unix_error_string (errno));
|
||||||
|
|
||||||
do_file_mark (current_panel, c_file, 0);
|
do_file_mark (current_panel, c_file, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void apply_mask (struct stat *sf)
|
static void
|
||||||
|
apply_mask (struct stat *sf)
|
||||||
{
|
{
|
||||||
char *fname;
|
char *fname;
|
||||||
|
|
||||||
need_update = end_chmod = 1;
|
need_update = end_chmod = 1;
|
||||||
do_chmod (sf);
|
do_chmod (sf);
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
fname = next_file ();
|
fname = next_file ();
|
||||||
if (mc_stat (fname, sf) != 0)
|
if (mc_stat (fname, sf) != 0)
|
||||||
return;
|
return;
|
||||||
c_stat = sf->st_mode;
|
c_stat = sf->st_mode;
|
||||||
|
|
||||||
do_chmod (sf);
|
do_chmod (sf);
|
||||||
} while (current_panel->marked);
|
}
|
||||||
|
while (current_panel->marked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void chmod_cmd (void)
|
void
|
||||||
|
chmod_cmd (void)
|
||||||
{
|
{
|
||||||
char buffer [BUF_TINY];
|
char buffer[BUF_TINY];
|
||||||
char *fname;
|
char *fname;
|
||||||
int i;
|
int i;
|
||||||
struct stat sf_stat;
|
struct stat sf_stat;
|
||||||
Dlg_head *ch_dlg;
|
Dlg_head *ch_dlg;
|
||||||
|
|
||||||
do { /* do while any files remaining */
|
do
|
||||||
|
{ /* do while any files remaining */
|
||||||
ch_dlg = init_chmod ();
|
ch_dlg = init_chmod ();
|
||||||
if (current_panel->marked)
|
if (current_panel->marked)
|
||||||
fname = next_file (); /* next marked file */
|
fname = next_file (); /* next marked file */
|
||||||
else
|
else
|
||||||
fname = selection (current_panel)->fname; /* single file */
|
fname = selection (current_panel)->fname; /* single file */
|
||||||
|
|
||||||
if (mc_stat (fname, &sf_stat) != 0) { /* get status of file */
|
if (mc_stat (fname, &sf_stat) != 0)
|
||||||
|
{ /* get status of file */
|
||||||
destroy_dlg (ch_dlg);
|
destroy_dlg (ch_dlg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -300,26 +317,28 @@ void chmod_cmd (void)
|
|||||||
mode_change = 0; /* clear changes flag */
|
mode_change = 0; /* clear changes flag */
|
||||||
|
|
||||||
/* set check buttons */
|
/* set check buttons */
|
||||||
for (i = 0; i < PERMISSIONS; i++){
|
for (i = 0; i < PERMISSIONS; i++)
|
||||||
|
{
|
||||||
check_perm[i].check->state = (c_stat & check_perm[i].mode) ? 1 : 0;
|
check_perm[i].check->state = (c_stat & check_perm[i].mode) ? 1 : 0;
|
||||||
check_perm[i].selected = 0;
|
check_perm[i].selected = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the labels */
|
/* Set the labels */
|
||||||
c_fname = str_trunc (fname, 21);
|
c_fname = str_trunc (fname, 21);
|
||||||
add_widget (ch_dlg, label_new (FY+2, FX+2, c_fname));
|
add_widget (ch_dlg, label_new (FY + 2, FX + 2, c_fname));
|
||||||
c_fown = str_trunc (get_owner (sf_stat.st_uid), 21);
|
c_fown = str_trunc (get_owner (sf_stat.st_uid), 21);
|
||||||
add_widget (ch_dlg, label_new (FY+6, FX+2, c_fown));
|
add_widget (ch_dlg, label_new (FY + 6, FX + 2, c_fown));
|
||||||
c_fgrp = str_trunc (get_group (sf_stat.st_gid), 21);
|
c_fgrp = str_trunc (get_group (sf_stat.st_gid), 21);
|
||||||
add_widget (ch_dlg, label_new (FY+8, FX+2, c_fgrp));
|
add_widget (ch_dlg, label_new (FY + 8, FX + 2, c_fgrp));
|
||||||
g_snprintf (buffer, sizeof (buffer), "%o", c_stat);
|
g_snprintf (buffer, sizeof (buffer), "%o", c_stat);
|
||||||
statl = label_new (FY+4, FX+2, buffer);
|
statl = label_new (FY + 4, FX + 2, buffer);
|
||||||
add_widget (ch_dlg, statl);
|
add_widget (ch_dlg, statl);
|
||||||
|
|
||||||
run_dlg (ch_dlg); /* retrieve an action */
|
run_dlg (ch_dlg); /* retrieve an action */
|
||||||
|
|
||||||
/* do action */
|
/* do action */
|
||||||
switch (ch_dlg->ret_value){
|
switch (ch_dlg->ret_value)
|
||||||
|
{
|
||||||
case B_ENTER:
|
case B_ENTER:
|
||||||
if (mode_change)
|
if (mode_change)
|
||||||
if (mc_chmod (fname, c_stat) == -1)
|
if (mc_chmod (fname, c_stat) == -1)
|
||||||
@ -337,8 +356,10 @@ void chmod_cmd (void)
|
|||||||
and_mask = or_mask = 0;
|
and_mask = or_mask = 0;
|
||||||
and_mask = ~and_mask;
|
and_mask = ~and_mask;
|
||||||
|
|
||||||
for (i = 0; i < PERMISSIONS; i++) {
|
for (i = 0; i < PERMISSIONS; i++)
|
||||||
if (check_perm[i].selected || ch_dlg->ret_value == B_ALL) {
|
{
|
||||||
|
if (check_perm[i].selected || ch_dlg->ret_value == B_ALL)
|
||||||
|
{
|
||||||
if (check_perm[i].check->state & C_BOOL)
|
if (check_perm[i].check->state & C_BOOL)
|
||||||
or_mask |= check_perm[i].mode;
|
or_mask |= check_perm[i].mode;
|
||||||
else
|
else
|
||||||
@ -353,7 +374,8 @@ void chmod_cmd (void)
|
|||||||
and_mask = or_mask = 0;
|
and_mask = or_mask = 0;
|
||||||
and_mask = ~and_mask;
|
and_mask = ~and_mask;
|
||||||
|
|
||||||
for (i = 0; i < PERMISSIONS; i++) {
|
for (i = 0; i < PERMISSIONS; i++)
|
||||||
|
{
|
||||||
if (check_perm[i].selected)
|
if (check_perm[i].selected)
|
||||||
or_mask |= check_perm[i].mode;
|
or_mask |= check_perm[i].mode;
|
||||||
}
|
}
|
||||||
@ -364,7 +386,8 @@ void chmod_cmd (void)
|
|||||||
and_mask = or_mask = 0;
|
and_mask = or_mask = 0;
|
||||||
and_mask = ~and_mask;
|
and_mask = ~and_mask;
|
||||||
|
|
||||||
for (i = 0; i < PERMISSIONS; i++) {
|
for (i = 0; i < PERMISSIONS; i++)
|
||||||
|
{
|
||||||
if (check_perm[i].selected)
|
if (check_perm[i].selected)
|
||||||
and_mask &= ~check_perm[i].mode;
|
and_mask &= ~check_perm[i].mode;
|
||||||
}
|
}
|
||||||
@ -373,12 +396,13 @@ void chmod_cmd (void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_panel->marked && ch_dlg->ret_value!=B_CANCEL) {
|
if (current_panel->marked && ch_dlg->ret_value != B_CANCEL)
|
||||||
|
{
|
||||||
do_file_mark (current_panel, c_file, 0);
|
do_file_mark (current_panel, c_file, 0);
|
||||||
need_update = 1;
|
need_update = 1;
|
||||||
}
|
}
|
||||||
destroy_dlg (ch_dlg);
|
destroy_dlg (ch_dlg);
|
||||||
} while (current_panel->marked && !end_chmod);
|
}
|
||||||
|
while (current_panel->marked && !end_chmod);
|
||||||
chmod_done ();
|
chmod_done ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
src/chown.c
10
src/chown.c
@ -91,11 +91,11 @@ static struct {
|
|||||||
int y, x;
|
int y, x;
|
||||||
WLabel *l;
|
WLabel *l;
|
||||||
} chown_label [LABELS] = {
|
} chown_label [LABELS] = {
|
||||||
{ TY+2, TX+2, NULL },
|
{ TY + 2, TX + 2, NULL },
|
||||||
{ TY+4, TX+2, NULL },
|
{ TY + 4, TX + 2, NULL },
|
||||||
{ TY+6, TX+2, NULL },
|
{ TY + 6, TX + 2, NULL },
|
||||||
{ TY+8, TX+2, NULL },
|
{ TY + 8, TX + 2, NULL },
|
||||||
{ TY+10,TX+2, NULL }
|
{ TY + 10,TX + 2, NULL }
|
||||||
};
|
};
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
|
|
||||||
|
273
src/dialog.c
273
src/dialog.c
@ -45,8 +45,8 @@
|
|||||||
#include "setup.h" /* mouse_close_dialog */
|
#include "setup.h" /* mouse_close_dialog */
|
||||||
|
|
||||||
/* Color styles for normal and error dialogs */
|
/* Color styles for normal and error dialogs */
|
||||||
int dialog_colors [4];
|
int dialog_colors[4];
|
||||||
int alarm_colors [4];
|
int alarm_colors[4];
|
||||||
|
|
||||||
/* Primitive way to check if the the current dialog is our dialog */
|
/* Primitive way to check if the the current dialog is our dialog */
|
||||||
/* This is needed by async routines like load_prompt */
|
/* This is needed by async routines like load_prompt */
|
||||||
@ -58,31 +58,30 @@ Hook *idle_hook = 0;
|
|||||||
/* left click outside of dialog closes it */
|
/* left click outside of dialog closes it */
|
||||||
int mouse_close_dialog = 0;
|
int mouse_close_dialog = 0;
|
||||||
|
|
||||||
static void dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t message,
|
static void dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t message, int reverse, int flags);
|
||||||
int reverse, int flags);
|
|
||||||
|
|
||||||
/* draw box in window */
|
/* draw box in window */
|
||||||
void
|
void
|
||||||
draw_box (Dlg_head *h, int y, int x, int ys, int xs, gboolean single)
|
draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single)
|
||||||
{
|
{
|
||||||
tty_draw_box (h->y + y, h->x + x, ys, xs, single);
|
tty_draw_box (h->y + y, h->x + x, ys, xs, single);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
widget_erase (Widget *w)
|
widget_erase (Widget * w)
|
||||||
{
|
{
|
||||||
tty_fill_region (w->y, w->x, w->lines, w->cols, ' ');
|
tty_fill_region (w->y, w->x, w->lines, w->cols, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dlg_erase (Dlg_head *h)
|
dlg_erase (Dlg_head * h)
|
||||||
{
|
{
|
||||||
if (h != NULL)
|
if (h != NULL)
|
||||||
tty_fill_region (h->y, h->x, h->lines, h->cols, ' ');
|
tty_fill_region (h->y, h->x, h->lines, h->cols, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init_widget (Widget *w, int y, int x, int lines, int cols,
|
init_widget (Widget * w, int y, int x, int lines, int cols,
|
||||||
callback_fn callback, mouse_h mouse_handler)
|
callback_fn callback, mouse_h mouse_handler)
|
||||||
{
|
{
|
||||||
w->x = x;
|
w->x = x;
|
||||||
@ -109,7 +108,8 @@ common_dialog_repaint (struct Dlg_head *h)
|
|||||||
dlg_erase (h);
|
dlg_erase (h);
|
||||||
draw_box (h, space, space, h->lines - 2 * space, h->cols - 2 * space, FALSE);
|
draw_box (h, space, space, h->lines - 2 * space, h->cols - 2 * space, FALSE);
|
||||||
|
|
||||||
if (h->title) {
|
if (h->title)
|
||||||
|
{
|
||||||
tty_setcolor (DLG_HOT_NORMALC (h));
|
tty_setcolor (DLG_HOT_NORMALC (h));
|
||||||
dlg_move (h, space, (h->cols - str_term_width1 (h->title)) / 2);
|
dlg_move (h, space, (h->cols - str_term_width1 (h->title)) / 2);
|
||||||
tty_print_string (h->title);
|
tty_print_string (h->title);
|
||||||
@ -118,7 +118,7 @@ common_dialog_repaint (struct Dlg_head *h)
|
|||||||
|
|
||||||
/* this function allows to set dialog position */
|
/* this function allows to set dialog position */
|
||||||
void
|
void
|
||||||
dlg_set_position (Dlg_head *h, int y1, int x1, int y2, int x2)
|
dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2)
|
||||||
{
|
{
|
||||||
/* save old positions, will be used to reposition childs */
|
/* save old positions, will be used to reposition childs */
|
||||||
int ox, oy, oc, ol;
|
int ox, oy, oc, ol;
|
||||||
@ -144,10 +144,12 @@ dlg_set_position (Dlg_head *h, int y1, int x1, int y2, int x2)
|
|||||||
if (h->current == NULL)
|
if (h->current == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((shift_x != 0) || (shift_y != 0) || (scale_x != 0) || (scale_y != 0)) {
|
if ((shift_x != 0) || (shift_y != 0) || (scale_x != 0) || (scale_y != 0))
|
||||||
|
{
|
||||||
Widget *c = h->current;
|
Widget *c = h->current;
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
/* there are, mainly, 2 generally possible
|
/* there are, mainly, 2 generally possible
|
||||||
situations:
|
situations:
|
||||||
|
|
||||||
@ -162,18 +164,22 @@ dlg_set_position (Dlg_head *h, int y1, int x1, int y2, int x2)
|
|||||||
int cols = c->cols;
|
int cols = c->cols;
|
||||||
int lines = c->lines;
|
int lines = c->lines;
|
||||||
|
|
||||||
if ((c->pos_flags & WPOS_KEEP_LEFT) && (c->pos_flags & WPOS_KEEP_RIGHT)) {
|
if ((c->pos_flags & WPOS_KEEP_LEFT) && (c->pos_flags & WPOS_KEEP_RIGHT))
|
||||||
|
{
|
||||||
x += shift_x;
|
x += shift_x;
|
||||||
cols += scale_x;
|
cols += scale_x;
|
||||||
} else if (c->pos_flags & WPOS_KEEP_LEFT)
|
}
|
||||||
|
else if (c->pos_flags & WPOS_KEEP_LEFT)
|
||||||
x += shift_x;
|
x += shift_x;
|
||||||
else if (c->pos_flags & WPOS_KEEP_RIGHT)
|
else if (c->pos_flags & WPOS_KEEP_RIGHT)
|
||||||
x += shift_x + scale_x;
|
x += shift_x + scale_x;
|
||||||
|
|
||||||
if ((c->pos_flags & WPOS_KEEP_TOP) && (c->pos_flags & WPOS_KEEP_BOTTOM)) {
|
if ((c->pos_flags & WPOS_KEEP_TOP) && (c->pos_flags & WPOS_KEEP_BOTTOM))
|
||||||
|
{
|
||||||
y += shift_y;
|
y += shift_y;
|
||||||
lines += scale_y;
|
lines += scale_y;
|
||||||
} else if (c->pos_flags & WPOS_KEEP_TOP)
|
}
|
||||||
|
else if (c->pos_flags & WPOS_KEEP_TOP)
|
||||||
y += shift_y;
|
y += shift_y;
|
||||||
else if (c->pos_flags & WPOS_KEEP_BOTTOM)
|
else if (c->pos_flags & WPOS_KEEP_BOTTOM)
|
||||||
y += shift_y + scale_y;
|
y += shift_y + scale_y;
|
||||||
@ -181,18 +187,20 @@ dlg_set_position (Dlg_head *h, int y1, int x1, int y2, int x2)
|
|||||||
widget_set_size (c, y, x, lines, cols);
|
widget_set_size (c, y, x, lines, cols);
|
||||||
|
|
||||||
c = c->next;
|
c = c->next;
|
||||||
} while (h->current != c);
|
}
|
||||||
|
while (h->current != c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this function sets only size, leaving positioning to automatic methods */
|
/* this function sets only size, leaving positioning to automatic methods */
|
||||||
void
|
void
|
||||||
dlg_set_size (Dlg_head *h, int lines, int cols)
|
dlg_set_size (Dlg_head * h, int lines, int cols)
|
||||||
{
|
{
|
||||||
int x = h->x;
|
int x = h->x;
|
||||||
int y = h->y;
|
int y = h->y;
|
||||||
|
|
||||||
if (h->flags & DLG_CENTER) {
|
if (h->flags & DLG_CENTER)
|
||||||
|
{
|
||||||
y = (LINES - lines) / 2;
|
y = (LINES - lines) / 2;
|
||||||
x = (COLS - cols) / 2;
|
x = (COLS - cols) / 2;
|
||||||
}
|
}
|
||||||
@ -205,16 +213,17 @@ dlg_set_size (Dlg_head *h, int lines, int cols)
|
|||||||
|
|
||||||
/* Default dialog callback */
|
/* Default dialog callback */
|
||||||
cb_ret_t
|
cb_ret_t
|
||||||
default_dlg_callback (Dlg_head *h, Widget *sender,
|
default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||||
dlg_msg_t msg, int parm, void *data)
|
|
||||||
{
|
{
|
||||||
(void) sender;
|
(void) sender;
|
||||||
(void) parm;
|
(void) parm;
|
||||||
(void) data;
|
(void) data;
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg)
|
||||||
|
{
|
||||||
case DLG_DRAW:
|
case DLG_DRAW:
|
||||||
if (h->color != NULL) {
|
if (h->color != NULL)
|
||||||
|
{
|
||||||
common_dialog_repaint (h);
|
common_dialog_repaint (h);
|
||||||
return MSG_HANDLED;
|
return MSG_HANDLED;
|
||||||
}
|
}
|
||||||
@ -242,13 +251,13 @@ default_dlg_callback (Dlg_head *h, Widget *sender,
|
|||||||
|
|
||||||
Dlg_head *
|
Dlg_head *
|
||||||
create_dlg (int y1, int x1, int lines, int cols, const int *colors,
|
create_dlg (int y1, int x1, int lines, int cols, const int *colors,
|
||||||
dlg_cb_fn callback, const char *help_ctx, const char *title,
|
dlg_cb_fn callback, const char *help_ctx, const char *title, int flags)
|
||||||
int flags)
|
|
||||||
{
|
{
|
||||||
Dlg_head *new_d;
|
Dlg_head *new_d;
|
||||||
|
|
||||||
new_d = g_new0 (Dlg_head, 1);
|
new_d = g_new0 (Dlg_head, 1);
|
||||||
if (colors != NULL) {
|
if (colors != NULL)
|
||||||
|
{
|
||||||
new_d->color = g_new (int, DLG_COLOR_NUM);
|
new_d->color = g_new (int, DLG_COLOR_NUM);
|
||||||
memmove (new_d->color, colors, sizeof (int) * DLG_COLOR_NUM);
|
memmove (new_d->color, colors, sizeof (int) * DLG_COLOR_NUM);
|
||||||
}
|
}
|
||||||
@ -262,7 +271,8 @@ create_dlg (int y1, int x1, int lines, int cols, const int *colors,
|
|||||||
dlg_set_size (new_d, lines, cols);
|
dlg_set_size (new_d, lines, cols);
|
||||||
|
|
||||||
/* Strip existing spaces, add one space before and after the title */
|
/* Strip existing spaces, add one space before and after the title */
|
||||||
if (title) {
|
if (title)
|
||||||
|
{
|
||||||
char *t;
|
char *t;
|
||||||
|
|
||||||
t = g_strstrip (g_strdup (title));
|
t = g_strstrip (g_strdup (title));
|
||||||
@ -277,19 +287,19 @@ create_dlg (int y1, int x1, int lines, int cols, const int *colors,
|
|||||||
void
|
void
|
||||||
dlg_set_default_colors (void)
|
dlg_set_default_colors (void)
|
||||||
{
|
{
|
||||||
dialog_colors [0] = COLOR_NORMAL;
|
dialog_colors[0] = COLOR_NORMAL;
|
||||||
dialog_colors [1] = COLOR_FOCUS;
|
dialog_colors[1] = COLOR_FOCUS;
|
||||||
dialog_colors [2] = COLOR_HOT_NORMAL;
|
dialog_colors[2] = COLOR_HOT_NORMAL;
|
||||||
dialog_colors [3] = COLOR_HOT_FOCUS;
|
dialog_colors[3] = COLOR_HOT_FOCUS;
|
||||||
|
|
||||||
alarm_colors [0] = ERROR_COLOR;
|
alarm_colors[0] = ERROR_COLOR;
|
||||||
alarm_colors [1] = REVERSE_COLOR;
|
alarm_colors[1] = REVERSE_COLOR;
|
||||||
alarm_colors [2] = ERROR_HOT_NORMAL;
|
alarm_colors[2] = ERROR_HOT_NORMAL;
|
||||||
alarm_colors [3] = ERROR_HOT_FOCUS;
|
alarm_colors[3] = ERROR_HOT_FOCUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
set_idle_proc (Dlg_head *d, int enable)
|
set_idle_proc (Dlg_head * d, int enable)
|
||||||
{
|
{
|
||||||
if (enable)
|
if (enable)
|
||||||
d->flags |= DLG_WANT_IDLE;
|
d->flags |= DLG_WANT_IDLE;
|
||||||
@ -302,7 +312,7 @@ set_idle_proc (Dlg_head *d, int enable)
|
|||||||
* from the bottom, make the widget current. Return widget number.
|
* from the bottom, make the widget current. Return widget number.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
add_widget_autopos (Dlg_head *h, void *w, widget_pos_flags_t pos_flags)
|
add_widget_autopos (Dlg_head * h, void *w, widget_pos_flags_t pos_flags)
|
||||||
{
|
{
|
||||||
Widget *widget = (Widget *) w;
|
Widget *widget = (Widget *) w;
|
||||||
|
|
||||||
@ -316,12 +326,15 @@ add_widget_autopos (Dlg_head *h, void *w, widget_pos_flags_t pos_flags)
|
|||||||
widget->dlg_id = h->count++;
|
widget->dlg_id = h->count++;
|
||||||
widget->pos_flags = pos_flags;
|
widget->pos_flags = pos_flags;
|
||||||
|
|
||||||
if (h->current) {
|
if (h->current)
|
||||||
|
{
|
||||||
widget->next = h->current;
|
widget->next = h->current;
|
||||||
widget->prev = h->current->prev;
|
widget->prev = h->current->prev;
|
||||||
h->current->prev->next = widget;
|
h->current->prev->next = widget;
|
||||||
h->current->prev = widget;
|
h->current->prev = widget;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
widget->prev = widget;
|
widget->prev = widget;
|
||||||
widget->next = widget;
|
widget->next = widget;
|
||||||
}
|
}
|
||||||
@ -334,13 +347,13 @@ add_widget_autopos (Dlg_head *h, void *w, widget_pos_flags_t pos_flags)
|
|||||||
|
|
||||||
/* wrapper to simply add lefttop positioned controls */
|
/* wrapper to simply add lefttop positioned controls */
|
||||||
int
|
int
|
||||||
add_widget (Dlg_head *h, void *w)
|
add_widget (Dlg_head * h, void *w)
|
||||||
{
|
{
|
||||||
return add_widget_autopos (h, w, WPOS_KEEP_LEFT | WPOS_KEEP_TOP);
|
return add_widget_autopos (h, w, WPOS_KEEP_LEFT | WPOS_KEEP_TOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_complete_refresh (Dlg_head *dlg)
|
do_complete_refresh (Dlg_head * dlg)
|
||||||
{
|
{
|
||||||
if (!dlg->fullscreen && dlg->parent)
|
if (!dlg->fullscreen && dlg->parent)
|
||||||
do_complete_refresh (dlg->parent);
|
do_complete_refresh (dlg->parent);
|
||||||
@ -356,9 +369,8 @@ do_refresh (void)
|
|||||||
|
|
||||||
if (fast_refresh)
|
if (fast_refresh)
|
||||||
dlg_redraw (current_dlg);
|
dlg_redraw (current_dlg);
|
||||||
else {
|
else
|
||||||
do_complete_refresh (current_dlg);
|
do_complete_refresh (current_dlg);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* broadcast a message to all the widgets in a dialog that have
|
/* broadcast a message to all the widgets in a dialog that have
|
||||||
@ -366,8 +378,7 @@ do_refresh (void)
|
|||||||
* to all widgets.
|
* to all widgets.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
dlg_broadcast_msg_to (Dlg_head *h, widget_msg_t message, int reverse,
|
dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t message, int reverse, int flags)
|
||||||
int flags)
|
|
||||||
{
|
{
|
||||||
Widget *p, *first, *wi;
|
Widget *p, *first, *wi;
|
||||||
|
|
||||||
@ -379,7 +390,8 @@ dlg_broadcast_msg_to (Dlg_head *h, widget_msg_t message, int reverse,
|
|||||||
else
|
else
|
||||||
first = p = h->current->next;
|
first = p = h->current->next;
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
wi = p;
|
wi = p;
|
||||||
if (reverse)
|
if (reverse)
|
||||||
p = p->prev;
|
p = p->prev;
|
||||||
@ -387,21 +399,22 @@ dlg_broadcast_msg_to (Dlg_head *h, widget_msg_t message, int reverse,
|
|||||||
p = p->next;
|
p = p->next;
|
||||||
if (flags == 0 || (flags & wi->options))
|
if (flags == 0 || (flags & wi->options))
|
||||||
send_message (wi, message, 0);
|
send_message (wi, message, 0);
|
||||||
} while (first != p);
|
}
|
||||||
|
while (first != p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* broadcast a message to all the widgets in a dialog */
|
/* broadcast a message to all the widgets in a dialog */
|
||||||
void
|
void
|
||||||
dlg_broadcast_msg (Dlg_head *h, widget_msg_t message, int reverse)
|
dlg_broadcast_msg (Dlg_head * h, widget_msg_t message, int reverse)
|
||||||
{
|
{
|
||||||
dlg_broadcast_msg_to (h, message, reverse, 0);
|
dlg_broadcast_msg_to (h, message, reverse, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
dlg_focus (Dlg_head *h)
|
dlg_focus (Dlg_head * h)
|
||||||
{
|
{
|
||||||
if ((h->current != NULL)
|
if ((h->current != NULL) && (send_message (h->current, WIDGET_FOCUS, 0) == MSG_HANDLED))
|
||||||
&& (send_message (h->current, WIDGET_FOCUS, 0) == MSG_HANDLED)) {
|
{
|
||||||
h->callback (h, h->current, DLG_FOCUS, 0, NULL);
|
h->callback (h, h->current, DLG_FOCUS, 0, NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -409,10 +422,10 @@ dlg_focus (Dlg_head *h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dlg_unfocus (Dlg_head *h)
|
dlg_unfocus (Dlg_head * h)
|
||||||
{
|
{
|
||||||
if ((h->current != NULL)
|
if ((h->current != NULL) && (send_message (h->current, WIDGET_UNFOCUS, 0) == MSG_HANDLED))
|
||||||
&& (send_message (h->current, WIDGET_UNFOCUS, 0) == MSG_HANDLED)) {
|
{
|
||||||
h->callback (h, h->current, DLG_UNFOCUS, 0, NULL);
|
h->callback (h, h->current, DLG_UNFOCUS, 0, NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -421,12 +434,11 @@ dlg_unfocus (Dlg_head *h)
|
|||||||
|
|
||||||
|
|
||||||
/* Return true if the windows overlap */
|
/* Return true if the windows overlap */
|
||||||
int dlg_overlap (Widget *a, Widget *b)
|
int
|
||||||
|
dlg_overlap (Widget * a, Widget * b)
|
||||||
{
|
{
|
||||||
if ((b->x >= a->x + a->cols)
|
if ((b->x >= a->x + a->cols)
|
||||||
|| (a->x >= b->x + b->cols)
|
|| (a->x >= b->x + b->cols) || (b->y >= a->y + a->lines) || (a->y >= b->y + b->lines))
|
||||||
|| (b->y >= a->y + a->lines)
|
|
||||||
|| (a->y >= b->y + b->lines))
|
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -434,16 +446,19 @@ int dlg_overlap (Widget *a, Widget *b)
|
|||||||
|
|
||||||
/* Find the widget with the given callback in the dialog h */
|
/* Find the widget with the given callback in the dialog h */
|
||||||
Widget *
|
Widget *
|
||||||
find_widget_type (const Dlg_head *h, callback_fn callback)
|
find_widget_type (const Dlg_head * h, callback_fn callback)
|
||||||
{
|
{
|
||||||
Widget *w = NULL;
|
Widget *w = NULL;
|
||||||
|
|
||||||
if ((h != NULL) && (h->current != NULL)) {
|
if ((h != NULL) && (h->current != NULL))
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
Widget *item;
|
Widget *item;
|
||||||
|
|
||||||
for (i = 0, item = h->current; i < h->count; i++, item = item->next) {
|
for (i = 0, item = h->current; i < h->count; i++, item = item->next)
|
||||||
if (item->callback == callback) {
|
{
|
||||||
|
if (item->callback == callback)
|
||||||
|
{
|
||||||
w = item;
|
w = item;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -455,7 +470,7 @@ find_widget_type (const Dlg_head *h, callback_fn callback)
|
|||||||
|
|
||||||
/* Find the widget with the given dialog id in the dialog h and select it */
|
/* Find the widget with the given dialog id in the dialog h and select it */
|
||||||
void
|
void
|
||||||
dlg_select_by_id (const Dlg_head *h, int id)
|
dlg_select_by_id (const Dlg_head * h, int id)
|
||||||
{
|
{
|
||||||
Widget *w, *w_found;
|
Widget *w, *w_found;
|
||||||
|
|
||||||
@ -465,21 +480,25 @@ dlg_select_by_id (const Dlg_head *h, int id)
|
|||||||
w = h->current;
|
w = h->current;
|
||||||
w_found = NULL;
|
w_found = NULL;
|
||||||
|
|
||||||
do {
|
do
|
||||||
if (w->dlg_id == id) {
|
{
|
||||||
|
if (w->dlg_id == id)
|
||||||
|
{
|
||||||
w_found = w;
|
w_found = w;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
w = w->next;
|
w = w->next;
|
||||||
} while (w != h->current);
|
}
|
||||||
|
while (w != h->current);
|
||||||
|
|
||||||
if (w_found)
|
if (w_found)
|
||||||
dlg_select_widget(w_found);
|
dlg_select_widget (w_found);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* What to do if the requested widget doesn't take focus */
|
/* What to do if the requested widget doesn't take focus */
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
SELECT_NEXT, /* go the the next widget */
|
SELECT_NEXT, /* go the the next widget */
|
||||||
SELECT_PREV, /* go the the previous widget */
|
SELECT_PREV, /* go the the previous widget */
|
||||||
SELECT_EXACT /* use current widget */
|
SELECT_EXACT /* use current widget */
|
||||||
@ -490,7 +509,7 @@ typedef enum {
|
|||||||
* Otherwise go to the previous widget.
|
* Otherwise go to the previous widget.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
do_select_widget (Dlg_head *h, Widget *w, select_dir_t dir)
|
do_select_widget (Dlg_head * h, Widget * w, select_dir_t dir)
|
||||||
{
|
{
|
||||||
Widget *w0 = h->current;
|
Widget *w0 = h->current;
|
||||||
|
|
||||||
@ -498,11 +517,13 @@ do_select_widget (Dlg_head *h, Widget *w, select_dir_t dir)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
h->current = w;
|
h->current = w;
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
if (dlg_focus (h))
|
if (dlg_focus (h))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch (dir) {
|
switch (dir)
|
||||||
|
{
|
||||||
case SELECT_NEXT:
|
case SELECT_NEXT:
|
||||||
h->current = h->current->next;
|
h->current = h->current->next;
|
||||||
break;
|
break;
|
||||||
@ -514,9 +535,11 @@ do_select_widget (Dlg_head *h, Widget *w, select_dir_t dir)
|
|||||||
dlg_focus (h);
|
dlg_focus (h);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} while (h->current != w);
|
}
|
||||||
|
while (h->current != w);
|
||||||
|
|
||||||
if (dlg_overlap (w0, h->current)) {
|
if (dlg_overlap (w0, h->current))
|
||||||
|
{
|
||||||
send_message (h->current, WIDGET_DRAW, 0);
|
send_message (h->current, WIDGET_DRAW, 0);
|
||||||
send_message (h->current, WIDGET_FOCUS, 0);
|
send_message (h->current, WIDGET_FOCUS, 0);
|
||||||
}
|
}
|
||||||
@ -535,7 +558,7 @@ dlg_select_widget (void *w)
|
|||||||
|
|
||||||
/* Try to select previous widget in the tab order */
|
/* Try to select previous widget in the tab order */
|
||||||
void
|
void
|
||||||
dlg_one_up (Dlg_head *h)
|
dlg_one_up (Dlg_head * h)
|
||||||
{
|
{
|
||||||
if (h->current)
|
if (h->current)
|
||||||
do_select_widget (h, h->current->prev, SELECT_PREV);
|
do_select_widget (h, h->current->prev, SELECT_PREV);
|
||||||
@ -544,18 +567,20 @@ dlg_one_up (Dlg_head *h)
|
|||||||
|
|
||||||
/* Try to select next widget in the tab order */
|
/* Try to select next widget in the tab order */
|
||||||
void
|
void
|
||||||
dlg_one_down (Dlg_head *h)
|
dlg_one_down (Dlg_head * h)
|
||||||
{
|
{
|
||||||
if (h->current)
|
if (h->current)
|
||||||
do_select_widget (h, h->current->next, SELECT_NEXT);
|
do_select_widget (h, h->current->next, SELECT_NEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void update_cursor (Dlg_head *h)
|
void
|
||||||
|
update_cursor (Dlg_head * h)
|
||||||
{
|
{
|
||||||
Widget *p = h->current;
|
Widget *p = h->current;
|
||||||
|
|
||||||
if (p != NULL) {
|
if (p != NULL)
|
||||||
|
{
|
||||||
if (p->options & W_WANT_CURSOR)
|
if (p->options & W_WANT_CURSOR)
|
||||||
send_message (p, WIDGET_CURSOR, 0);
|
send_message (p, WIDGET_CURSOR, 0);
|
||||||
else
|
else
|
||||||
@ -570,7 +595,7 @@ void update_cursor (Dlg_head *h)
|
|||||||
* as the last one
|
* as the last one
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
dlg_redraw (Dlg_head *h)
|
dlg_redraw (Dlg_head * h)
|
||||||
{
|
{
|
||||||
h->callback (h, NULL, DLG_DRAW, 0, NULL);
|
h->callback (h, NULL, DLG_DRAW, 0, NULL);
|
||||||
dlg_broadcast_msg (h, WIDGET_DRAW, 1);
|
dlg_broadcast_msg (h, WIDGET_DRAW, 1);
|
||||||
@ -578,21 +603,23 @@ dlg_redraw (Dlg_head *h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dlg_stop (Dlg_head *h)
|
dlg_stop (Dlg_head * h)
|
||||||
{
|
{
|
||||||
h->running = 0;
|
h->running = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dialog_handle_key (Dlg_head *h, int d_key)
|
dialog_handle_key (Dlg_head * h, int d_key)
|
||||||
{
|
{
|
||||||
if (is_abort_char (d_key)) {
|
if (is_abort_char (d_key))
|
||||||
|
{
|
||||||
h->ret_value = B_CANCEL;
|
h->ret_value = B_CANCEL;
|
||||||
dlg_stop (h);
|
dlg_stop (h);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (d_key) {
|
switch (d_key)
|
||||||
|
{
|
||||||
case '\n':
|
case '\n':
|
||||||
case KEY_ENTER:
|
case KEY_ENTER:
|
||||||
h->ret_value = B_ENTER;
|
h->ret_value = B_ENTER;
|
||||||
@ -609,16 +636,16 @@ dialog_handle_key (Dlg_head *h, int d_key)
|
|||||||
dlg_one_down (h);
|
dlg_one_down (h);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_F(1):
|
case KEY_F (1):
|
||||||
interactive_display (NULL, h->help_ctx);
|
interactive_display (NULL, h->help_ctx);
|
||||||
do_refresh ();
|
do_refresh ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XCTRL('z'):
|
case XCTRL ('z'):
|
||||||
suspend_cmd ();
|
suspend_cmd ();
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
|
|
||||||
case XCTRL('l'):
|
case XCTRL ('l'):
|
||||||
#ifdef HAVE_SLANG
|
#ifdef HAVE_SLANG
|
||||||
tty_touch_screen ();
|
tty_touch_screen ();
|
||||||
mc_refresh ();
|
mc_refresh ();
|
||||||
@ -635,7 +662,7 @@ dialog_handle_key (Dlg_head *h, int d_key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
dlg_try_hotkey (Dlg_head *h, int d_key)
|
dlg_try_hotkey (Dlg_head * h, int d_key)
|
||||||
{
|
{
|
||||||
Widget *hot_cur;
|
Widget *hot_cur;
|
||||||
cb_ret_t handled;
|
cb_ret_t handled;
|
||||||
@ -649,7 +676,8 @@ dlg_try_hotkey (Dlg_head *h, int d_key)
|
|||||||
* the currently selected widget is an input line
|
* the currently selected widget is an input line
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (h->current->options & W_IS_INPUT) {
|
if (h->current->options & W_IS_INPUT)
|
||||||
|
{
|
||||||
/* skip ascii control characters, anything else can valid character in
|
/* skip ascii control characters, anything else can valid character in
|
||||||
* some encoding */
|
* some encoding */
|
||||||
if (d_key >= 32 && d_key < 256)
|
if (d_key >= 32 && d_key < 256)
|
||||||
@ -672,7 +700,8 @@ dlg_try_hotkey (Dlg_head *h, int d_key)
|
|||||||
hot_cur = h->current->next;
|
hot_cur = h->current->next;
|
||||||
|
|
||||||
/* send it to all widgets */
|
/* send it to all widgets */
|
||||||
while (h->current != hot_cur && handled == MSG_NOT_HANDLED) {
|
while (h->current != hot_cur && handled == MSG_NOT_HANDLED)
|
||||||
|
{
|
||||||
if (hot_cur->options & W_WANT_HOTKEY)
|
if (hot_cur->options & W_WANT_HOTKEY)
|
||||||
handled = send_message (hot_cur, WIDGET_HOTKEY, d_key);
|
handled = send_message (hot_cur, WIDGET_HOTKEY, d_key);
|
||||||
|
|
||||||
@ -687,7 +716,7 @@ dlg_try_hotkey (Dlg_head *h, int d_key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dlg_key_event (Dlg_head *h, int d_key)
|
dlg_key_event (Dlg_head * h, int d_key)
|
||||||
{
|
{
|
||||||
cb_ret_t handled;
|
cb_ret_t handled;
|
||||||
|
|
||||||
@ -695,11 +724,15 @@ dlg_key_event (Dlg_head *h, int d_key)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* TAB used to cycle */
|
/* TAB used to cycle */
|
||||||
if (!(h->flags & DLG_WANT_TAB)) {
|
if (!(h->flags & DLG_WANT_TAB))
|
||||||
if (d_key == '\t') {
|
{
|
||||||
|
if (d_key == '\t')
|
||||||
|
{
|
||||||
dlg_one_down (h);
|
dlg_one_down (h);
|
||||||
return;
|
return;
|
||||||
} else if (d_key == KEY_BTAB) {
|
}
|
||||||
|
else if (d_key == KEY_BTAB)
|
||||||
|
{
|
||||||
dlg_one_up (h);
|
dlg_one_up (h);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -738,23 +771,25 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
|
|||||||
int y = event->y;
|
int y = event->y;
|
||||||
|
|
||||||
/* close the dialog by mouse click out of dialog area */
|
/* close the dialog by mouse click out of dialog area */
|
||||||
if (mouse_close_dialog && !h->fullscreen
|
if (mouse_close_dialog && !h->fullscreen && ((event->buttons & GPM_B_LEFT) != 0) && ((event->type & GPM_DOWN) != 0) /* left click */
|
||||||
&& ((event->buttons & GPM_B_LEFT) != 0) && ((event->type & GPM_DOWN) != 0) /* left click */
|
&& !((x > h->x) && (x <= h->x + h->cols) && (y > h->y) && (y <= h->y + h->lines)))
|
||||||
&& !((x > h->x) && (x <= h->x + h->cols) && (y > h->y) && (y <= h->y + h->lines))) {
|
{
|
||||||
h->ret_value = B_CANCEL;
|
h->ret_value = B_CANCEL;
|
||||||
dlg_stop (h);
|
dlg_stop (h);
|
||||||
return MOU_NORMAL;
|
return MOU_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = starting_widget;
|
item = starting_widget;
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
Widget *widget;
|
Widget *widget;
|
||||||
|
|
||||||
widget = item;
|
widget = item;
|
||||||
item = item->next;
|
item = item->next;
|
||||||
|
|
||||||
if ((x > widget->x) && (x <= widget->x + widget->cols)
|
if ((x > widget->x) && (x <= widget->x + widget->cols)
|
||||||
&& (y > widget->y) && (y <= widget->y + widget->lines)) {
|
&& (y > widget->y) && (y <= widget->y + widget->lines))
|
||||||
|
{
|
||||||
new_event = *event;
|
new_event = *event;
|
||||||
new_event.x -= widget->x;
|
new_event.x -= widget->x;
|
||||||
new_event.y -= widget->y;
|
new_event.y -= widget->y;
|
||||||
@ -762,7 +797,8 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
|
|||||||
if (widget->mouse != NULL)
|
if (widget->mouse != NULL)
|
||||||
return widget->mouse (&new_event, widget);
|
return widget->mouse (&new_event, widget);
|
||||||
}
|
}
|
||||||
} while (item != starting_widget);
|
}
|
||||||
|
while (item != starting_widget);
|
||||||
|
|
||||||
return MOU_NORMAL;
|
return MOU_NORMAL;
|
||||||
}
|
}
|
||||||
@ -771,7 +807,7 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
|
|||||||
|
|
||||||
/* Init the process */
|
/* Init the process */
|
||||||
void
|
void
|
||||||
init_dlg (Dlg_head *h)
|
init_dlg (Dlg_head * h)
|
||||||
{
|
{
|
||||||
/* Initialize dialog manager and widgets */
|
/* Initialize dialog manager and widgets */
|
||||||
h->callback (h, NULL, DLG_INIT, 0, NULL);
|
h->callback (h, NULL, DLG_INIT, 0, NULL);
|
||||||
@ -799,7 +835,7 @@ init_dlg (Dlg_head *h)
|
|||||||
|
|
||||||
/* Shutdown the run_dlg */
|
/* Shutdown the run_dlg */
|
||||||
void
|
void
|
||||||
dlg_run_done (Dlg_head *h)
|
dlg_run_done (Dlg_head * h)
|
||||||
{
|
{
|
||||||
if (h->current != NULL)
|
if (h->current != NULL)
|
||||||
h->callback (h, h->current, DLG_END, 0, NULL);
|
h->callback (h, h->current, DLG_END, 0, NULL);
|
||||||
@ -808,11 +844,12 @@ dlg_run_done (Dlg_head *h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dlg_process_event (Dlg_head *h, int key, Gpm_Event *event)
|
dlg_process_event (Dlg_head * h, int key, Gpm_Event * event)
|
||||||
{
|
{
|
||||||
if (key == EV_NONE){
|
if (key == EV_NONE)
|
||||||
|
{
|
||||||
if (tty_got_interrupt ())
|
if (tty_got_interrupt ())
|
||||||
key = XCTRL('g');
|
key = XCTRL ('g');
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -824,17 +861,19 @@ dlg_process_event (Dlg_head *h, int key, Gpm_Event *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
frontend_run_dlg (Dlg_head *h)
|
frontend_run_dlg (Dlg_head * h)
|
||||||
{
|
{
|
||||||
int d_key;
|
int d_key;
|
||||||
Gpm_Event event;
|
Gpm_Event event;
|
||||||
|
|
||||||
event.x = -1;
|
event.x = -1;
|
||||||
while (h->running) {
|
while (h->running)
|
||||||
|
{
|
||||||
if (winch_flag)
|
if (winch_flag)
|
||||||
change_screen_size ();
|
change_screen_size ();
|
||||||
|
|
||||||
if (is_idle ()) {
|
if (is_idle ())
|
||||||
|
{
|
||||||
if (idle_hook)
|
if (idle_hook)
|
||||||
execute_hooks (idle_hook);
|
execute_hooks (idle_hook);
|
||||||
|
|
||||||
@ -864,7 +903,8 @@ frontend_run_dlg (Dlg_head *h)
|
|||||||
* behavior on complex routines like the file routines, this way,
|
* behavior on complex routines like the file routines, this way,
|
||||||
* they can call the dlg_process_event without rewriting all the code
|
* they can call the dlg_process_event without rewriting all the code
|
||||||
*/
|
*/
|
||||||
int run_dlg (Dlg_head *h)
|
int
|
||||||
|
run_dlg (Dlg_head * h)
|
||||||
{
|
{
|
||||||
init_dlg (h);
|
init_dlg (h);
|
||||||
frontend_run_dlg (h);
|
frontend_run_dlg (h);
|
||||||
@ -873,14 +913,15 @@ int run_dlg (Dlg_head *h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
destroy_dlg (Dlg_head *h)
|
destroy_dlg (Dlg_head * h)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
Widget *c;
|
Widget *c;
|
||||||
|
|
||||||
dlg_broadcast_msg (h, WIDGET_DESTROY, 0);
|
dlg_broadcast_msg (h, WIDGET_DESTROY, 0);
|
||||||
c = h->current;
|
c = h->current;
|
||||||
for (i = 0; i < h->count; i++) {
|
for (i = 0; i < h->count; i++)
|
||||||
|
{
|
||||||
c = c->next;
|
c = c->next;
|
||||||
g_free (h->current);
|
g_free (h->current);
|
||||||
h->current = c;
|
h->current = c;
|
||||||
@ -892,18 +933,19 @@ destroy_dlg (Dlg_head *h)
|
|||||||
do_refresh ();
|
do_refresh ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void widget_set_size (Widget *widget, int y, int x, int lines, int cols)
|
void
|
||||||
|
widget_set_size (Widget * widget, int y, int x, int lines, int cols)
|
||||||
{
|
{
|
||||||
widget->x = x;
|
widget->x = x;
|
||||||
widget->y = y;
|
widget->y = y;
|
||||||
widget->cols = cols;
|
widget->cols = cols;
|
||||||
widget->lines = lines;
|
widget->lines = lines;
|
||||||
send_message (widget, WIDGET_RESIZED, 0 /* unused */);
|
send_message (widget, WIDGET_RESIZED, 0 /* unused */ );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Replace widget old_w for widget new_w in the dialog */
|
/* Replace widget old_w for widget new_w in the dialog */
|
||||||
void
|
void
|
||||||
dlg_replace_widget (Widget *old_w, Widget *new_w)
|
dlg_replace_widget (Widget * old_w, Widget * new_w)
|
||||||
{
|
{
|
||||||
Dlg_head *h = old_w->parent;
|
Dlg_head *h = old_w->parent;
|
||||||
int should_focus = 0;
|
int should_focus = 0;
|
||||||
@ -917,11 +959,14 @@ dlg_replace_widget (Widget *old_w, Widget *new_w)
|
|||||||
new_w->parent = h;
|
new_w->parent = h;
|
||||||
new_w->dlg_id = old_w->dlg_id;
|
new_w->dlg_id = old_w->dlg_id;
|
||||||
|
|
||||||
if (old_w == old_w->next) {
|
if (old_w == old_w->next)
|
||||||
|
{
|
||||||
/* just one widget */
|
/* just one widget */
|
||||||
new_w->prev = new_w;
|
new_w->prev = new_w;
|
||||||
new_w->next = new_w;
|
new_w->next = new_w;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
new_w->prev = old_w->prev;
|
new_w->prev = old_w->prev;
|
||||||
new_w->next = old_w->next;
|
new_w->next = old_w->next;
|
||||||
old_w->prev->next = new_w;
|
old_w->prev->next = new_w;
|
||||||
|
89
src/dialog.h
89
src/dialog.h
@ -35,7 +35,8 @@
|
|||||||
typedef struct Widget Widget;
|
typedef struct Widget Widget;
|
||||||
|
|
||||||
/* Widget messages */
|
/* Widget messages */
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
WIDGET_INIT, /* Initialize widget */
|
WIDGET_INIT, /* Initialize widget */
|
||||||
WIDGET_FOCUS, /* Draw widget in focused state */
|
WIDGET_FOCUS, /* Draw widget in focused state */
|
||||||
WIDGET_UNFOCUS, /* Draw widget in unfocused state */
|
WIDGET_UNFOCUS, /* Draw widget in unfocused state */
|
||||||
@ -45,11 +46,12 @@ typedef enum {
|
|||||||
WIDGET_COMMAND, /* Send to widget to handle command */
|
WIDGET_COMMAND, /* Send to widget to handle command */
|
||||||
WIDGET_DESTROY, /* Sent to widget at destruction time */
|
WIDGET_DESTROY, /* Sent to widget at destruction time */
|
||||||
WIDGET_CURSOR, /* Sent to widget to position the cursor */
|
WIDGET_CURSOR, /* Sent to widget to position the cursor */
|
||||||
WIDGET_IDLE, /* Sent to widgets with options & W_WANT_IDLE*/
|
WIDGET_IDLE, /* Sent to widgets with options & W_WANT_IDLE */
|
||||||
WIDGET_RESIZED /* Sent after a widget has been resized */
|
WIDGET_RESIZED /* Sent after a widget has been resized */
|
||||||
} widget_msg_t;
|
} widget_msg_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
MSG_NOT_HANDLED = 0,
|
MSG_NOT_HANDLED = 0,
|
||||||
MSG_HANDLED = 1
|
MSG_HANDLED = 1
|
||||||
} cb_ret_t;
|
} cb_ret_t;
|
||||||
@ -60,10 +62,11 @@ typedef enum {
|
|||||||
WIDGET_UNFOCUS: 1 if they accept to release the focus, 0 if they don't.
|
WIDGET_UNFOCUS: 1 if they accept to release the focus, 0 if they don't.
|
||||||
WIDGET_KEY: 1 if they actually used the key, 0 if not.
|
WIDGET_KEY: 1 if they actually used the key, 0 if not.
|
||||||
WIDGET_HOTKEY: 1 if they actually used the key, 0 if not.
|
WIDGET_HOTKEY: 1 if they actually used the key, 0 if not.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Dialog messages */
|
/* Dialog messages */
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
DLG_INIT = 0, /* Initialize dialog */
|
DLG_INIT = 0, /* Initialize dialog */
|
||||||
DLG_IDLE = 1, /* The idle state is active */
|
DLG_IDLE = 1, /* The idle state is active */
|
||||||
DLG_DRAW = 2, /* Draw dialog on screen */
|
DLG_DRAW = 2, /* Draw dialog on screen */
|
||||||
@ -83,12 +86,12 @@ typedef enum {
|
|||||||
|
|
||||||
/* Dialog callback */
|
/* Dialog callback */
|
||||||
typedef struct Dlg_head Dlg_head;
|
typedef struct Dlg_head Dlg_head;
|
||||||
typedef cb_ret_t (*dlg_cb_fn)(struct Dlg_head *h, Widget *sender,
|
typedef cb_ret_t (*dlg_cb_fn) (struct Dlg_head * h, Widget * sender,
|
||||||
dlg_msg_t msg, int parm, void *data);
|
dlg_msg_t msg, int parm, void *data);
|
||||||
|
|
||||||
/* get string representation of shortcut assigned with command */
|
/* get string representation of shortcut assigned with command */
|
||||||
/* as menu is a widget of dialog, ask dialog about shortcut string */
|
/* as menu is a widget of dialog, ask dialog about shortcut string */
|
||||||
typedef char * (*dlg_shortcut_str) (unsigned long command);
|
typedef char *(*dlg_shortcut_str) (unsigned long command);
|
||||||
|
|
||||||
/* Dialog color constants */
|
/* Dialog color constants */
|
||||||
#define DLG_COLOR_NUM 4
|
#define DLG_COLOR_NUM 4
|
||||||
@ -97,12 +100,14 @@ typedef char * (*dlg_shortcut_str) (unsigned long command);
|
|||||||
#define DLG_HOT_NORMALC(h) ((h)->color[2])
|
#define DLG_HOT_NORMALC(h) ((h)->color[2])
|
||||||
#define DLG_HOT_FOCUSC(h) ((h)->color[3])
|
#define DLG_HOT_FOCUSC(h) ((h)->color[3])
|
||||||
|
|
||||||
struct Dlg_head {
|
struct Dlg_head
|
||||||
|
{
|
||||||
/* Set by the user */
|
/* Set by the user */
|
||||||
int flags; /* User flags */
|
int flags; /* User flags */
|
||||||
const char *help_ctx; /* Name of the help entry */
|
const char *help_ctx; /* Name of the help entry */
|
||||||
int *color; /* Color set. Unused in viewer and editor */
|
int *color; /* Color set. Unused in viewer and editor */
|
||||||
/*notconst*/ char *title; /* Title of the dialog */
|
/*notconst */ char *title;
|
||||||
|
/* Title of the dialog */
|
||||||
|
|
||||||
/* Set and received by the user */
|
/* Set and received by the user */
|
||||||
int ret_value; /* Result of run_dlg() */
|
int ret_value; /* Result of run_dlg() */
|
||||||
@ -131,10 +136,11 @@ extern int alarm_colors[4];
|
|||||||
|
|
||||||
|
|
||||||
/* Widget callback */
|
/* Widget callback */
|
||||||
typedef cb_ret_t (*callback_fn) (Widget *widget, widget_msg_t msg, int parm);
|
typedef cb_ret_t (*callback_fn) (Widget * widget, widget_msg_t msg, int parm);
|
||||||
|
|
||||||
/* widget options */
|
/* widget options */
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
W_WANT_HOTKEY = (1 << 1),
|
W_WANT_HOTKEY = (1 << 1),
|
||||||
W_WANT_CURSOR = (1 << 2),
|
W_WANT_CURSOR = (1 << 2),
|
||||||
W_WANT_IDLE = (1 << 3),
|
W_WANT_IDLE = (1 << 3),
|
||||||
@ -142,7 +148,8 @@ typedef enum {
|
|||||||
} widget_options_t;
|
} widget_options_t;
|
||||||
|
|
||||||
/* Flags for widget repositioning on dialog resize */
|
/* Flags for widget repositioning on dialog resize */
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
WPOS_KEEP_LEFT = (1 << 0), /* keep widget distance to left border of dialog */
|
WPOS_KEEP_LEFT = (1 << 0), /* keep widget distance to left border of dialog */
|
||||||
WPOS_KEEP_RIGHT = (1 << 1), /* keep widget distance to right border of dialog */
|
WPOS_KEEP_RIGHT = (1 << 1), /* keep widget distance to right border of dialog */
|
||||||
WPOS_KEEP_TOP = (1 << 2), /* keep widget distance to top border of dialog */
|
WPOS_KEEP_TOP = (1 << 2), /* keep widget distance to top border of dialog */
|
||||||
@ -153,7 +160,8 @@ typedef enum {
|
|||||||
} widget_pos_flags_t;
|
} widget_pos_flags_t;
|
||||||
|
|
||||||
/* Every Widget must have this as its first element */
|
/* Every Widget must have this as its first element */
|
||||||
struct Widget {
|
struct Widget
|
||||||
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
int cols, lines;
|
int cols, lines;
|
||||||
widget_options_t options;
|
widget_options_t options;
|
||||||
@ -167,7 +175,7 @@ struct Widget {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* draw box in window */
|
/* draw box in window */
|
||||||
void draw_box (Dlg_head *h, int y, int x, int ys, int xs, gboolean single);
|
void draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single);
|
||||||
|
|
||||||
/* Flags for create_dlg: */
|
/* Flags for create_dlg: */
|
||||||
#define DLG_REVERSE (1 << 5) /* Tab order is opposite to the add order */
|
#define DLG_REVERSE (1 << 5) /* Tab order is opposite to the add order */
|
||||||
@ -185,38 +193,37 @@ Dlg_head *create_dlg (int y1, int x1, int lines, int cols,
|
|||||||
|
|
||||||
void dlg_set_default_colors (void);
|
void dlg_set_default_colors (void);
|
||||||
|
|
||||||
int add_widget_autopos (Dlg_head *dest, void *w, widget_pos_flags_t pos_flags);
|
int add_widget_autopos (Dlg_head * dest, void *w, widget_pos_flags_t pos_flags);
|
||||||
int add_widget (Dlg_head *dest, void *w);
|
int add_widget (Dlg_head * dest, void *w);
|
||||||
|
|
||||||
/* sets size of dialog, leaving positioning to automatic mehtods
|
/* sets size of dialog, leaving positioning to automatic mehtods
|
||||||
according to dialog flags */
|
according to dialog flags */
|
||||||
void dlg_set_size (Dlg_head *h, int lines, int cols);
|
void dlg_set_size (Dlg_head * h, int lines, int cols);
|
||||||
/* this function allows to set dialog position */
|
/* this function allows to set dialog position */
|
||||||
void dlg_set_position (Dlg_head *h, int y1, int x1, int y2, int x2);
|
void dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2);
|
||||||
|
|
||||||
/* Runs dialog d */
|
/* Runs dialog d */
|
||||||
int run_dlg (Dlg_head *d);
|
int run_dlg (Dlg_head * d);
|
||||||
|
|
||||||
void dlg_run_done (Dlg_head *h);
|
void dlg_run_done (Dlg_head * h);
|
||||||
void dlg_process_event (Dlg_head *h, int key, Gpm_Event *event);
|
void dlg_process_event (Dlg_head * h, int key, Gpm_Event * event);
|
||||||
void init_dlg (Dlg_head *h);
|
void init_dlg (Dlg_head * h);
|
||||||
|
|
||||||
/* To activate/deactivate the idle message generation */
|
/* To activate/deactivate the idle message generation */
|
||||||
void set_idle_proc (Dlg_head *d, int enable);
|
void set_idle_proc (Dlg_head * d, int enable);
|
||||||
|
|
||||||
void dlg_redraw (Dlg_head *h);
|
void dlg_redraw (Dlg_head * h);
|
||||||
void destroy_dlg (Dlg_head *h);
|
void destroy_dlg (Dlg_head * h);
|
||||||
|
|
||||||
void widget_set_size (Widget *widget, int y, int x, int lines, int cols);
|
void widget_set_size (Widget * widget, int y, int x, int lines, int cols);
|
||||||
|
|
||||||
void dlg_broadcast_msg (Dlg_head *h, widget_msg_t message, int reverse);
|
void dlg_broadcast_msg (Dlg_head * h, widget_msg_t message, int reverse);
|
||||||
|
|
||||||
void init_widget (Widget *w, int y, int x, int lines, int cols,
|
void init_widget (Widget * w, int y, int x, int lines, int cols,
|
||||||
callback_fn callback, mouse_h mouse_handler);
|
callback_fn callback, mouse_h mouse_handler);
|
||||||
|
|
||||||
/* Default callback for dialogs */
|
/* Default callback for dialogs */
|
||||||
cb_ret_t default_dlg_callback (Dlg_head *h, Widget *sender,
|
cb_ret_t default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
|
||||||
dlg_msg_t msg, int parm, void *data);
|
|
||||||
|
|
||||||
/* Default paint routine for dialogs */
|
/* Default paint routine for dialogs */
|
||||||
void common_dialog_repaint (struct Dlg_head *h);
|
void common_dialog_repaint (struct Dlg_head *h);
|
||||||
@ -230,7 +237,7 @@ extern Dlg_head *current_dlg;
|
|||||||
extern Hook *idle_hook;
|
extern Hook *idle_hook;
|
||||||
|
|
||||||
static inline cb_ret_t
|
static inline cb_ret_t
|
||||||
send_message (Widget *w, widget_msg_t msg, int parm)
|
send_message (Widget * w, widget_msg_t msg, int parm)
|
||||||
{
|
{
|
||||||
return (*(w->callback)) (w, msg, parm);
|
return (*(w->callback)) (w, msg, parm);
|
||||||
}
|
}
|
||||||
@ -243,19 +250,19 @@ dlg_widget_active (void *w)
|
|||||||
return (w1->parent->current == w1);
|
return (w1->parent->current == w1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dlg_replace_widget (Widget *old, Widget *new);
|
void dlg_replace_widget (Widget * old, Widget * new);
|
||||||
int dlg_overlap (Widget *a, Widget *b);
|
int dlg_overlap (Widget * a, Widget * b);
|
||||||
void widget_erase (Widget *);
|
void widget_erase (Widget *);
|
||||||
void dlg_erase (Dlg_head *h);
|
void dlg_erase (Dlg_head * h);
|
||||||
void dlg_stop (Dlg_head *h);
|
void dlg_stop (Dlg_head * h);
|
||||||
|
|
||||||
/* Widget selection */
|
/* Widget selection */
|
||||||
void dlg_select_widget (void *widget);
|
void dlg_select_widget (void *widget);
|
||||||
void dlg_one_up (Dlg_head *h);
|
void dlg_one_up (Dlg_head * h);
|
||||||
void dlg_one_down (Dlg_head *h);
|
void dlg_one_down (Dlg_head * h);
|
||||||
int dlg_focus (Dlg_head *h);
|
int dlg_focus (Dlg_head * h);
|
||||||
Widget *find_widget_type (const Dlg_head *h, callback_fn callback);
|
Widget *find_widget_type (const Dlg_head * h, callback_fn callback);
|
||||||
void dlg_select_by_id (const Dlg_head *h, int id);
|
void dlg_select_by_id (const Dlg_head * h, int id);
|
||||||
|
|
||||||
/* Redraw all dialogs */
|
/* Redraw all dialogs */
|
||||||
void do_refresh (void);
|
void do_refresh (void);
|
||||||
@ -268,6 +275,6 @@ void do_refresh (void);
|
|||||||
#define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i)
|
#define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i)
|
||||||
|
|
||||||
/* Used in load_prompt() */
|
/* Used in load_prompt() */
|
||||||
void update_cursor (Dlg_head *h);
|
void update_cursor (Dlg_head * h);
|
||||||
|
|
||||||
#endif /* MC_DIALOG_H */
|
#endif /* MC_DIALOG_H */
|
||||||
|
528
src/hotlist.c
528
src/hotlist.c
File diff suppressed because it is too large
Load Diff
89
src/info.c
89
src/info.c
@ -34,8 +34,8 @@
|
|||||||
#include "lib/strutil.h"
|
#include "lib/strutil.h"
|
||||||
|
|
||||||
#include "dialog.h"
|
#include "dialog.h"
|
||||||
#include "widget.h" /* default_proc*/
|
#include "widget.h" /* default_proc */
|
||||||
#include "main-widgets.h" /* the_menubar*/
|
#include "main-widgets.h" /* the_menubar */
|
||||||
#include "dir.h" /* required by panel */
|
#include "dir.h" /* required by panel */
|
||||||
#include "panel.h" /* for the panel structure */
|
#include "panel.h" /* for the panel structure */
|
||||||
#include "main.h" /* other_panel, current_panel definitions */
|
#include "main.h" /* other_panel, current_panel definitions */
|
||||||
@ -48,7 +48,8 @@
|
|||||||
# define VERSION "undefined"
|
# define VERSION "undefined"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct WInfo {
|
struct WInfo
|
||||||
|
{
|
||||||
Widget widget;
|
Widget widget;
|
||||||
int ready;
|
int ready;
|
||||||
};
|
};
|
||||||
@ -57,13 +58,13 @@ struct WInfo {
|
|||||||
static gboolean initialized = FALSE;
|
static gboolean initialized = FALSE;
|
||||||
static struct my_statfs myfs_stats;
|
static struct my_statfs myfs_stats;
|
||||||
|
|
||||||
static void info_box (Dlg_head *h, struct WInfo *info)
|
static void
|
||||||
|
info_box (Dlg_head * h, struct WInfo *info)
|
||||||
{
|
{
|
||||||
tty_set_normal_attrs ();
|
tty_set_normal_attrs ();
|
||||||
tty_setcolor (NORMAL_COLOR);
|
tty_setcolor (NORMAL_COLOR);
|
||||||
widget_erase (&info->widget);
|
widget_erase (&info->widget);
|
||||||
draw_box (h, info->widget.y, info->widget.x,
|
draw_box (h, info->widget.y, info->widget.x, info->widget.lines, info->widget.cols, FALSE);
|
||||||
info->widget.lines, info->widget.cols, FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -82,8 +83,7 @@ info_show_info (struct WInfo *info)
|
|||||||
widget_move (&info->widget, 1, 3);
|
widget_move (&info->widget, 1, 3);
|
||||||
tty_printf (_("Midnight Commander %s"), VERSION);
|
tty_printf (_("Midnight Commander %s"), VERSION);
|
||||||
tty_setcolor (NORMAL_COLOR);
|
tty_setcolor (NORMAL_COLOR);
|
||||||
tty_draw_hline (info->widget.y + 2, info->widget.x + 1,
|
tty_draw_hline (info->widget.y + 2, info->widget.x + 1, ACS_HLINE, info->widget.cols - 2);
|
||||||
ACS_HLINE, info->widget.cols - 2);
|
|
||||||
if (get_current_type () != view_listing)
|
if (get_current_type () != view_listing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -91,11 +91,12 @@ info_show_info (struct WInfo *info)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
my_statfs (&myfs_stats, current_panel->cwd);
|
my_statfs (&myfs_stats, current_panel->cwd);
|
||||||
st = current_panel->dir.list [current_panel->selected].st;
|
st = current_panel->dir.list[current_panel->selected].st;
|
||||||
|
|
||||||
/* Print only lines which fit */
|
/* Print only lines which fit */
|
||||||
|
|
||||||
if (i18n_adjust == 0) {
|
if (i18n_adjust == 0)
|
||||||
|
{
|
||||||
/* This printf pattern string is used as a reference for size */
|
/* This printf pattern string is used as a reference for size */
|
||||||
file_label = _("File: %s");
|
file_label = _("File: %s");
|
||||||
i18n_adjust = str_term_width1 (file_label) + 2;
|
i18n_adjust = str_term_width1 (file_label) + 2;
|
||||||
@ -103,32 +104,33 @@ info_show_info (struct WInfo *info)
|
|||||||
|
|
||||||
buff = g_string_new ("");
|
buff = g_string_new ("");
|
||||||
|
|
||||||
switch (info->widget.lines-2){
|
switch (info->widget.lines - 2)
|
||||||
|
{
|
||||||
/* Note: all cases are fall-throughs */
|
/* Note: all cases are fall-throughs */
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
case 16:
|
case 16:
|
||||||
widget_move (&info->widget, 16, 3);
|
widget_move (&info->widget, 16, 3);
|
||||||
if (myfs_stats.nfree >0 || myfs_stats.nodes > 0)
|
if (myfs_stats.nfree > 0 || myfs_stats.nodes > 0)
|
||||||
tty_printf (_("Free nodes: %d (%d%%) of %d"),
|
tty_printf (_("Free nodes: %d (%d%%) of %d"),
|
||||||
myfs_stats.nfree,
|
myfs_stats.nfree,
|
||||||
myfs_stats.total
|
myfs_stats.total
|
||||||
? 100 * myfs_stats.nfree / myfs_stats.nodes : 0,
|
? 100 * myfs_stats.nfree / myfs_stats.nodes : 0, myfs_stats.nodes);
|
||||||
myfs_stats.nodes);
|
|
||||||
else
|
else
|
||||||
tty_print_string (_("No node information"));
|
tty_print_string (_("No node information"));
|
||||||
|
|
||||||
case 15:
|
case 15:
|
||||||
widget_move (&info->widget, 15, 3);
|
widget_move (&info->widget, 15, 3);
|
||||||
if (myfs_stats.avail > 0 || myfs_stats.total > 0){
|
if (myfs_stats.avail > 0 || myfs_stats.total > 0)
|
||||||
char buffer1 [6], buffer2[6];
|
{
|
||||||
|
char buffer1[6], buffer2[6];
|
||||||
size_trunc_len (buffer1, 5, myfs_stats.avail, 1);
|
size_trunc_len (buffer1, 5, myfs_stats.avail, 1);
|
||||||
size_trunc_len (buffer2, 5, myfs_stats.total, 1);
|
size_trunc_len (buffer2, 5, myfs_stats.total, 1);
|
||||||
tty_printf (_("Free space: %s (%d%%) of %s"), buffer1, myfs_stats.total ?
|
tty_printf (_("Free space: %s (%d%%) of %s"), buffer1, myfs_stats.total ?
|
||||||
(int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0,
|
(int) (100 * (double) myfs_stats.avail / myfs_stats.total) : 0, buffer2);
|
||||||
buffer2);
|
}
|
||||||
} else
|
else
|
||||||
tty_print_string (_("No space information"));
|
tty_print_string (_("No space information"));
|
||||||
|
|
||||||
case 14:
|
case 14:
|
||||||
@ -143,55 +145,51 @@ info_show_info (struct WInfo *info)
|
|||||||
str_printf (buff, _("Device: %s"),
|
str_printf (buff, _("Device: %s"),
|
||||||
str_trunc (myfs_stats.device, info->widget.cols - i18n_adjust));
|
str_trunc (myfs_stats.device, info->widget.cols - i18n_adjust));
|
||||||
tty_print_string (buff->str);
|
tty_print_string (buff->str);
|
||||||
g_string_set_size(buff, 0);
|
g_string_set_size (buff, 0);
|
||||||
case 12:
|
case 12:
|
||||||
widget_move (&info->widget, 12, 3);
|
widget_move (&info->widget, 12, 3);
|
||||||
str_printf (buff, _("Filesystem: %s"),
|
str_printf (buff, _("Filesystem: %s"),
|
||||||
str_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust));
|
str_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust));
|
||||||
tty_print_string (buff->str);
|
tty_print_string (buff->str);
|
||||||
g_string_set_size(buff, 0);
|
g_string_set_size (buff, 0);
|
||||||
case 11:
|
case 11:
|
||||||
widget_move (&info->widget, 11, 3);
|
widget_move (&info->widget, 11, 3);
|
||||||
str_printf (buff, _("Accessed: %s"), file_date (st.st_atime));
|
str_printf (buff, _("Accessed: %s"), file_date (st.st_atime));
|
||||||
tty_print_string (buff->str);
|
tty_print_string (buff->str);
|
||||||
g_string_set_size(buff, 0);
|
g_string_set_size (buff, 0);
|
||||||
case 10:
|
case 10:
|
||||||
widget_move (&info->widget, 10, 3);
|
widget_move (&info->widget, 10, 3);
|
||||||
str_printf (buff, _("Modified: %s"), file_date (st.st_mtime));
|
str_printf (buff, _("Modified: %s"), file_date (st.st_mtime));
|
||||||
tty_print_string (buff->str);
|
tty_print_string (buff->str);
|
||||||
g_string_set_size(buff, 0);
|
g_string_set_size (buff, 0);
|
||||||
case 9:
|
case 9:
|
||||||
widget_move (&info->widget, 9, 3);
|
widget_move (&info->widget, 9, 3);
|
||||||
/* TRANSLATORS: "Status changed", like in the stat(2) man page */
|
/* TRANSLATORS: "Status changed", like in the stat(2) man page */
|
||||||
str_printf (buff, _("Status: %s"), file_date (st.st_ctime));
|
str_printf (buff, _("Status: %s"), file_date (st.st_ctime));
|
||||||
tty_print_string (buff->str);
|
tty_print_string (buff->str);
|
||||||
g_string_set_size(buff, 0);
|
g_string_set_size (buff, 0);
|
||||||
|
|
||||||
case 8:
|
case 8:
|
||||||
widget_move (&info->widget, 8, 3);
|
widget_move (&info->widget, 8, 3);
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_RDEV
|
#ifdef HAVE_STRUCT_STAT_ST_RDEV
|
||||||
if (S_ISCHR (st.st_mode) || S_ISBLK(st.st_mode))
|
if (S_ISCHR (st.st_mode) || S_ISBLK (st.st_mode))
|
||||||
tty_printf (_("Dev. type: major %lu, minor %lu"),
|
tty_printf (_("Dev. type: major %lu, minor %lu"),
|
||||||
(unsigned long) major (st.st_rdev),
|
(unsigned long) major (st.st_rdev), (unsigned long) minor (st.st_rdev));
|
||||||
(unsigned long) minor (st.st_rdev));
|
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
char buffer[10];
|
char buffer[10];
|
||||||
size_trunc_len(buffer, 9, st.st_size, 0);
|
size_trunc_len (buffer, 9, st.st_size, 0);
|
||||||
tty_printf (_("Size: %s"), buffer);
|
tty_printf (_("Size: %s"), buffer);
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
|
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
|
||||||
tty_printf (ngettext(" (%ld block)", " (%ld blocks)",
|
tty_printf (ngettext (" (%ld block)", " (%ld blocks)",
|
||||||
(unsigned long int) st.st_blocks),
|
(unsigned long int) st.st_blocks), (long int) st.st_blocks);
|
||||||
(long int) st.st_blocks);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
case 7:
|
case 7:
|
||||||
widget_move (&info->widget, 7, 3);
|
widget_move (&info->widget, 7, 3);
|
||||||
tty_printf (_("Owner: %s/%s"),
|
tty_printf (_("Owner: %s/%s"), get_owner (st.st_uid), get_group (st.st_gid));
|
||||||
get_owner (st.st_uid),
|
|
||||||
get_group (st.st_gid));
|
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
widget_move (&info->widget, 6, 3);
|
widget_move (&info->widget, 6, 3);
|
||||||
@ -204,16 +202,15 @@ info_show_info (struct WInfo *info)
|
|||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
widget_move (&info->widget, 4, 3);
|
widget_move (&info->widget, 4, 3);
|
||||||
tty_printf (_("Location: %Xh:%Xh"), (int)st.st_dev, (int)st.st_ino);
|
tty_printf (_("Location: %Xh:%Xh"), (int) st.st_dev, (int) st.st_ino);
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
{
|
{
|
||||||
const char *fname;
|
const char *fname;
|
||||||
|
|
||||||
widget_move (&info->widget, 3, 2);
|
widget_move (&info->widget, 3, 2);
|
||||||
fname = current_panel->dir.list [current_panel->selected].fname;
|
fname = current_panel->dir.list[current_panel->selected].fname;
|
||||||
str_printf (buff, file_label,
|
str_printf (buff, file_label, str_trunc (fname, info->widget.cols - i18n_adjust));
|
||||||
str_trunc (fname, info->widget.cols - i18n_adjust));
|
|
||||||
tty_print_string (buff->str);
|
tty_print_string (buff->str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +222,8 @@ info_show_info (struct WInfo *info)
|
|||||||
g_string_free (buff, TRUE);
|
g_string_free (buff, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void info_hook (void *data)
|
static void
|
||||||
|
info_hook (void *data)
|
||||||
{
|
{
|
||||||
struct WInfo *info = (struct WInfo *) data;
|
struct WInfo *info = (struct WInfo *) data;
|
||||||
Widget *other_widget;
|
Widget *other_widget;
|
||||||
@ -241,11 +239,12 @@ static void info_hook (void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
info_callback (Widget *w, widget_msg_t msg, int parm)
|
info_callback (Widget * w, widget_msg_t msg, int parm)
|
||||||
{
|
{
|
||||||
struct WInfo *info = (struct WInfo *) w;
|
struct WInfo *info = (struct WInfo *) w;
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg)
|
||||||
|
{
|
||||||
|
|
||||||
case WIDGET_INIT:
|
case WIDGET_INIT:
|
||||||
add_hook (&select_file_hook, info_hook, info);
|
add_hook (&select_file_hook, info_hook, info);
|
||||||
@ -270,12 +269,13 @@ info_callback (Widget *w, widget_msg_t msg, int parm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
info_event (Gpm_Event *event, void *data)
|
info_event (Gpm_Event * event, void *data)
|
||||||
{
|
{
|
||||||
Widget *w = &((WInfo *) data)->widget;
|
Widget *w = &((WInfo *) data)->widget;
|
||||||
|
|
||||||
/* rest of the upper frame, the menu is invisible - call menu */
|
/* rest of the upper frame, the menu is invisible - call menu */
|
||||||
if (event->type & GPM_DOWN && event->y == 1 && !menubar_visible) {
|
if (event->type & GPM_DOWN && event->y == 1 && !menubar_visible)
|
||||||
|
{
|
||||||
event->x += w->x;
|
event->x += w->x;
|
||||||
return the_menubar->widget.mouse (event, the_menubar);
|
return the_menubar->widget.mouse (event, the_menubar);
|
||||||
}
|
}
|
||||||
@ -293,7 +293,8 @@ info_new (void)
|
|||||||
/* We do not want the cursor */
|
/* We do not want the cursor */
|
||||||
widget_want_cursor (info->widget, 0);
|
widget_want_cursor (info->widget, 0);
|
||||||
|
|
||||||
if (!initialized) {
|
if (!initialized)
|
||||||
|
{
|
||||||
initialized = TRUE;
|
initialized = TRUE;
|
||||||
init_my_statfs ();
|
init_my_statfs ();
|
||||||
}
|
}
|
||||||
|
228
src/menu.c
228
src/menu.c
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
int menubar_visible = 1; /* This is the new default */
|
int menubar_visible = 1; /* This is the new default */
|
||||||
|
|
||||||
static cb_ret_t menubar_callback (Widget *w, widget_msg_t msg, int parm);
|
static cb_ret_t menubar_callback (Widget * w, widget_msg_t msg, int parm);
|
||||||
|
|
||||||
menu_entry_t *
|
menu_entry_t *
|
||||||
menu_entry_create (const char *name, unsigned long command)
|
menu_entry_create (const char *name, unsigned long command)
|
||||||
@ -60,9 +60,10 @@ menu_entry_create (const char *name, unsigned long command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
menu_entry_free (menu_entry_t *entry)
|
menu_entry_free (menu_entry_t * entry)
|
||||||
{
|
{
|
||||||
if (entry != NULL) {
|
if (entry != NULL)
|
||||||
|
{
|
||||||
release_hotkey (entry->text);
|
release_hotkey (entry->text);
|
||||||
g_free (entry->shortcut);
|
g_free (entry->shortcut);
|
||||||
g_free (entry);
|
g_free (entry);
|
||||||
@ -70,19 +71,22 @@ menu_entry_free (menu_entry_t *entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menu_arrange (Menu *menu, dlg_shortcut_str get_shortcut)
|
menu_arrange (Menu * menu, dlg_shortcut_str get_shortcut)
|
||||||
{
|
{
|
||||||
if (menu != NULL) {
|
if (menu != NULL)
|
||||||
|
{
|
||||||
GList *i;
|
GList *i;
|
||||||
size_t max_shortcut_len = 0;
|
size_t max_shortcut_len = 0;
|
||||||
|
|
||||||
menu->max_entry_len = 1;
|
menu->max_entry_len = 1;
|
||||||
menu->max_hotkey_len = 1;
|
menu->max_hotkey_len = 1;
|
||||||
|
|
||||||
for (i = menu->entries; i != NULL; i = g_list_next (i)) {
|
for (i = menu->entries; i != NULL; i = g_list_next (i))
|
||||||
|
{
|
||||||
menu_entry_t *entry = i->data;
|
menu_entry_t *entry = i->data;
|
||||||
|
|
||||||
if (entry != NULL) {
|
if (entry != NULL)
|
||||||
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
len = (size_t) hotkey_width (entry->text);
|
len = (size_t) hotkey_width (entry->text);
|
||||||
@ -91,7 +95,8 @@ menu_arrange (Menu *menu, dlg_shortcut_str get_shortcut)
|
|||||||
if (get_shortcut != NULL)
|
if (get_shortcut != NULL)
|
||||||
entry->shortcut = get_shortcut (entry->command);
|
entry->shortcut = get_shortcut (entry->command);
|
||||||
|
|
||||||
if (entry->shortcut != NULL) {
|
if (entry->shortcut != NULL)
|
||||||
|
{
|
||||||
len = (size_t) str_term_width1 (entry->shortcut);
|
len = (size_t) str_term_width1 (entry->shortcut);
|
||||||
max_shortcut_len = max (max_shortcut_len, len);
|
max_shortcut_len = max (max_shortcut_len, len);
|
||||||
}
|
}
|
||||||
@ -103,7 +108,7 @@ menu_arrange (Menu *menu, dlg_shortcut_str get_shortcut)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Menu *
|
Menu *
|
||||||
create_menu (const char *name, GList *entries, const char *help_node)
|
create_menu (const char *name, GList * entries, const char *help_node)
|
||||||
{
|
{
|
||||||
Menu *menu;
|
Menu *menu;
|
||||||
|
|
||||||
@ -120,7 +125,7 @@ create_menu (const char *name, GList *entries, const char *help_node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
destroy_menu (Menu *menu)
|
destroy_menu (Menu * menu)
|
||||||
{
|
{
|
||||||
release_hotkey (menu->text);
|
release_hotkey (menu->text);
|
||||||
g_list_foreach (menu->entries, (GFunc) menu_entry_free, NULL);
|
g_list_foreach (menu->entries, (GFunc) menu_entry_free, NULL);
|
||||||
@ -130,7 +135,7 @@ destroy_menu (Menu *menu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_paint_idx (WMenuBar *menubar, unsigned int idx, int color)
|
menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color)
|
||||||
{
|
{
|
||||||
const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||||
const menu_entry_t *entry = g_list_nth_data (menu->entries, idx);
|
const menu_entry_t *entry = g_list_nth_data (menu->entries, idx);
|
||||||
@ -140,7 +145,8 @@ menubar_paint_idx (WMenuBar *menubar, unsigned int idx, int color)
|
|||||||
if (x + menu->max_entry_len + 4 > (gsize) menubar->widget.cols)
|
if (x + menu->max_entry_len + 4 > (gsize) menubar->widget.cols)
|
||||||
x = menubar->widget.cols - menu->max_entry_len - 4;
|
x = menubar->widget.cols - menu->max_entry_len - 4;
|
||||||
|
|
||||||
if (entry == NULL) {
|
if (entry == NULL)
|
||||||
|
{
|
||||||
/* menu separator */
|
/* menu separator */
|
||||||
tty_setcolor (MENU_ENTRY_COLOR);
|
tty_setcolor (MENU_ENTRY_COLOR);
|
||||||
|
|
||||||
@ -152,7 +158,9 @@ menubar_paint_idx (WMenuBar *menubar, unsigned int idx, int color)
|
|||||||
|
|
||||||
widget_move (&menubar->widget, y, x + menu->max_entry_len + 3);
|
widget_move (&menubar->widget, y, x + menu->max_entry_len + 3);
|
||||||
tty_print_alt_char (ACS_RTEE, FALSE);
|
tty_print_alt_char (ACS_RTEE, FALSE);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* menu text */
|
/* menu text */
|
||||||
tty_setcolor (color);
|
tty_setcolor (color);
|
||||||
widget_move (&menubar->widget, y, x);
|
widget_move (&menubar->widget, y, x);
|
||||||
@ -160,9 +168,9 @@ menubar_paint_idx (WMenuBar *menubar, unsigned int idx, int color)
|
|||||||
tty_draw_hline (-1, -1, ' ', menu->max_entry_len + 2); /* clear line */
|
tty_draw_hline (-1, -1, ' ', menu->max_entry_len + 2); /* clear line */
|
||||||
tty_print_string (entry->text.start);
|
tty_print_string (entry->text.start);
|
||||||
|
|
||||||
if (entry->text.hotkey != NULL) {
|
if (entry->text.hotkey != NULL)
|
||||||
tty_setcolor (color == MENU_SELECTED_COLOR ?
|
{
|
||||||
MENU_HOTSEL_COLOR : MENU_HOT_COLOR);
|
tty_setcolor (color == MENU_SELECTED_COLOR ? MENU_HOTSEL_COLOR : MENU_HOT_COLOR);
|
||||||
tty_print_string (entry->text.hotkey);
|
tty_print_string (entry->text.hotkey);
|
||||||
tty_setcolor (color);
|
tty_setcolor (color);
|
||||||
}
|
}
|
||||||
@ -170,7 +178,8 @@ menubar_paint_idx (WMenuBar *menubar, unsigned int idx, int color)
|
|||||||
if (entry->text.end != NULL)
|
if (entry->text.end != NULL)
|
||||||
tty_print_string (entry->text.end);
|
tty_print_string (entry->text.end);
|
||||||
|
|
||||||
if (entry->shortcut != NULL) {
|
if (entry->shortcut != NULL)
|
||||||
|
{
|
||||||
widget_move (&menubar->widget, y, x + menu->max_hotkey_len + 3);
|
widget_move (&menubar->widget, y, x + menu->max_hotkey_len + 3);
|
||||||
tty_print_string (entry->shortcut);
|
tty_print_string (entry->shortcut);
|
||||||
}
|
}
|
||||||
@ -181,7 +190,7 @@ menubar_paint_idx (WMenuBar *menubar, unsigned int idx, int color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_draw_drop (WMenuBar *menubar)
|
menubar_draw_drop (WMenuBar * menubar)
|
||||||
{
|
{
|
||||||
const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||||
const unsigned int count = g_list_length (menu->entries);
|
const unsigned int count = g_list_length (menu->entries);
|
||||||
@ -206,7 +215,7 @@ menubar_draw_drop (WMenuBar *menubar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_set_color (WMenuBar *menubar, gboolean current, gboolean hotkey)
|
menubar_set_color (WMenuBar * menubar, gboolean current, gboolean hotkey)
|
||||||
{
|
{
|
||||||
if (!menubar->is_active)
|
if (!menubar->is_active)
|
||||||
tty_setcolor (MENU_INACTIVE_COLOR);
|
tty_setcolor (MENU_INACTIVE_COLOR);
|
||||||
@ -217,7 +226,7 @@ menubar_set_color (WMenuBar *menubar, gboolean current, gboolean hotkey)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_draw (WMenuBar *menubar)
|
menubar_draw (WMenuBar * menubar)
|
||||||
{
|
{
|
||||||
GList *i;
|
GList *i;
|
||||||
|
|
||||||
@ -226,7 +235,8 @@ menubar_draw (WMenuBar *menubar)
|
|||||||
tty_draw_hline (menubar->widget.y, menubar->widget.x, ' ', menubar->widget.cols);
|
tty_draw_hline (menubar->widget.y, menubar->widget.x, ' ', menubar->widget.cols);
|
||||||
|
|
||||||
/* Now each one of the entries */
|
/* Now each one of the entries */
|
||||||
for (i = menubar->menu; i != NULL; i = g_list_next (i)) {
|
for (i = menubar->menu; i != NULL; i = g_list_next (i))
|
||||||
|
{
|
||||||
Menu *menu = i->data;
|
Menu *menu = i->data;
|
||||||
gboolean is_selected = (menubar->selected == (gsize) g_list_position (menubar->menu, i));
|
gboolean is_selected = (menubar->selected == (gsize) g_list_position (menubar->menu, i));
|
||||||
|
|
||||||
@ -236,7 +246,8 @@ menubar_draw (WMenuBar *menubar)
|
|||||||
tty_print_char (' ');
|
tty_print_char (' ');
|
||||||
tty_print_string (menu->text.start);
|
tty_print_string (menu->text.start);
|
||||||
|
|
||||||
if (menu->text.hotkey != NULL) {
|
if (menu->text.hotkey != NULL)
|
||||||
|
{
|
||||||
menubar_set_color (menubar, is_selected, TRUE);
|
menubar_set_color (menubar, is_selected, TRUE);
|
||||||
tty_print_string (menu->text.hotkey);
|
tty_print_string (menu->text.hotkey);
|
||||||
menubar_set_color (menubar, is_selected, FALSE);
|
menubar_set_color (menubar, is_selected, FALSE);
|
||||||
@ -252,14 +263,14 @@ menubar_draw (WMenuBar *menubar)
|
|||||||
menubar_draw_drop (menubar);
|
menubar_draw_drop (menubar);
|
||||||
else
|
else
|
||||||
widget_move (&menubar->widget, 0,
|
widget_move (&menubar->widget, 0,
|
||||||
((Menu *) g_list_nth_data (menubar->menu,
|
((Menu *) g_list_nth_data (menubar->menu, menubar->selected))->start_x);
|
||||||
menubar->selected))->start_x);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_remove (WMenuBar *menubar)
|
menubar_remove (WMenuBar * menubar)
|
||||||
{
|
{
|
||||||
if (menubar->is_dropped) {
|
if (menubar->is_dropped)
|
||||||
|
{
|
||||||
menubar->is_dropped = FALSE;
|
menubar->is_dropped = FALSE;
|
||||||
do_refresh ();
|
do_refresh ();
|
||||||
menubar->is_dropped = TRUE;
|
menubar->is_dropped = TRUE;
|
||||||
@ -267,7 +278,7 @@ menubar_remove (WMenuBar *menubar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_left (WMenuBar *menubar)
|
menubar_left (WMenuBar * menubar)
|
||||||
{
|
{
|
||||||
menubar_remove (menubar);
|
menubar_remove (menubar);
|
||||||
if (menubar->selected == 0)
|
if (menubar->selected == 0)
|
||||||
@ -278,7 +289,7 @@ menubar_left (WMenuBar *menubar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_right (WMenuBar *menubar)
|
menubar_right (WMenuBar * menubar)
|
||||||
{
|
{
|
||||||
menubar_remove (menubar);
|
menubar_remove (menubar);
|
||||||
menubar->selected = (menubar->selected + 1) % g_list_length (menubar->menu);
|
menubar->selected = (menubar->selected + 1) % g_list_length (menubar->menu);
|
||||||
@ -286,7 +297,7 @@ menubar_right (WMenuBar *menubar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_finish (WMenuBar *menubar)
|
menubar_finish (WMenuBar * menubar)
|
||||||
{
|
{
|
||||||
menubar->is_dropped = FALSE;
|
menubar->is_dropped = FALSE;
|
||||||
menubar->is_active = FALSE;
|
menubar->is_active = FALSE;
|
||||||
@ -298,7 +309,7 @@ menubar_finish (WMenuBar *menubar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_drop (WMenuBar *menubar, unsigned int selected)
|
menubar_drop (WMenuBar * menubar, unsigned int selected)
|
||||||
{
|
{
|
||||||
menubar->is_dropped = TRUE;
|
menubar->is_dropped = TRUE;
|
||||||
menubar->selected = selected;
|
menubar->selected = selected;
|
||||||
@ -306,12 +317,13 @@ menubar_drop (WMenuBar *menubar, unsigned int selected)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_execute (WMenuBar *menubar)
|
menubar_execute (WMenuBar * menubar)
|
||||||
{
|
{
|
||||||
const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||||
const menu_entry_t *entry = g_list_nth_data (menu->entries, menu->selected);
|
const menu_entry_t *entry = g_list_nth_data (menu->entries, menu->selected);
|
||||||
|
|
||||||
if ((entry != NULL) && (entry->command != CK_Ignore_Key)) {
|
if ((entry != NULL) && (entry->command != CK_Ignore_Key))
|
||||||
|
{
|
||||||
is_right = (menubar->selected != 0);
|
is_right = (menubar->selected != 0);
|
||||||
menubar_finish (menubar);
|
menubar_finish (menubar);
|
||||||
menubar->widget.parent->callback (menubar->widget.parent, &menubar->widget,
|
menubar->widget.parent->callback (menubar->widget.parent, &menubar->widget,
|
||||||
@ -321,7 +333,7 @@ menubar_execute (WMenuBar *menubar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_down (WMenuBar *menubar)
|
menubar_down (WMenuBar * menubar)
|
||||||
{
|
{
|
||||||
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||||
const unsigned int len = g_list_length (menu->entries);
|
const unsigned int len = g_list_length (menu->entries);
|
||||||
@ -329,16 +341,18 @@ menubar_down (WMenuBar *menubar)
|
|||||||
|
|
||||||
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
|
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
menu->selected = (menu->selected + 1) % len;
|
menu->selected = (menu->selected + 1) % len;
|
||||||
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
||||||
} while ((entry == NULL) || (entry->command == CK_Ignore_Key));
|
}
|
||||||
|
while ((entry == NULL) || (entry->command == CK_Ignore_Key));
|
||||||
|
|
||||||
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_up (WMenuBar *menubar)
|
menubar_up (WMenuBar * menubar)
|
||||||
{
|
{
|
||||||
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||||
const unsigned int len = g_list_length (menu->entries);
|
const unsigned int len = g_list_length (menu->entries);
|
||||||
@ -346,19 +360,21 @@ menubar_up (WMenuBar *menubar)
|
|||||||
|
|
||||||
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
|
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
if (menu->selected == 0)
|
if (menu->selected == 0)
|
||||||
menu->selected = len - 1;
|
menu->selected = len - 1;
|
||||||
else
|
else
|
||||||
menu->selected--;
|
menu->selected--;
|
||||||
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
||||||
} while ((entry == NULL) || (entry->command == CK_Ignore_Key));
|
}
|
||||||
|
while ((entry == NULL) || (entry->command == CK_Ignore_Key));
|
||||||
|
|
||||||
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_first (WMenuBar *menubar)
|
menubar_first (WMenuBar * menubar)
|
||||||
{
|
{
|
||||||
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||||
menu_entry_t *entry;
|
menu_entry_t *entry;
|
||||||
@ -370,7 +386,8 @@ menubar_first (WMenuBar *menubar)
|
|||||||
|
|
||||||
menu->selected = 0;
|
menu->selected = 0;
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE)
|
||||||
|
{
|
||||||
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
||||||
|
|
||||||
if ((entry == NULL) || (entry->command == CK_Ignore_Key))
|
if ((entry == NULL) || (entry->command == CK_Ignore_Key))
|
||||||
@ -383,7 +400,7 @@ menubar_first (WMenuBar *menubar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menubar_last (WMenuBar *menubar)
|
menubar_last (WMenuBar * menubar)
|
||||||
{
|
{
|
||||||
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||||
const unsigned int len = g_list_length (menu->entries);
|
const unsigned int len = g_list_length (menu->entries);
|
||||||
@ -396,29 +413,33 @@ menubar_last (WMenuBar *menubar)
|
|||||||
|
|
||||||
menu->selected = len;
|
menu->selected = len;
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
menu->selected--;
|
menu->selected--;
|
||||||
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
||||||
} while ((entry == NULL) || (entry->command == CK_Ignore_Key));
|
}
|
||||||
|
while ((entry == NULL) || (entry->command == CK_Ignore_Key));
|
||||||
|
|
||||||
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
menubar_handle_key (WMenuBar *menubar, int key)
|
menubar_handle_key (WMenuBar * menubar, int key)
|
||||||
{
|
{
|
||||||
/* Lowercase */
|
/* Lowercase */
|
||||||
if (isascii (key))
|
if (isascii (key))
|
||||||
key = g_ascii_tolower (key);
|
key = g_ascii_tolower (key);
|
||||||
|
|
||||||
if (is_abort_char (key)) {
|
if (is_abort_char (key))
|
||||||
|
{
|
||||||
menubar_finish (menubar);
|
menubar_finish (menubar);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* menubar help or menubar navigation */
|
/* menubar help or menubar navigation */
|
||||||
switch (key) {
|
switch (key)
|
||||||
case KEY_F(1):
|
{
|
||||||
|
case KEY_F (1):
|
||||||
if (menubar->is_dropped)
|
if (menubar->is_dropped)
|
||||||
interactive_display (NULL,
|
interactive_display (NULL,
|
||||||
((Menu *) g_list_nth_data (menubar->menu,
|
((Menu *) g_list_nth_data (menubar->menu,
|
||||||
@ -429,7 +450,7 @@ menubar_handle_key (WMenuBar *menubar, int key)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case KEY_LEFT:
|
case KEY_LEFT:
|
||||||
case XCTRL('b'):
|
case XCTRL ('b'):
|
||||||
menubar_left (menubar);
|
menubar_left (menubar);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -439,23 +460,24 @@ menubar_handle_key (WMenuBar *menubar, int key)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!menubar->is_dropped) {
|
if (!menubar->is_dropped)
|
||||||
|
{
|
||||||
GList *i;
|
GList *i;
|
||||||
|
|
||||||
/* drop menu by hotkey */
|
/* drop menu by hotkey */
|
||||||
for (i = menubar->menu; i != NULL; i = g_list_next (i)) {
|
for (i = menubar->menu; i != NULL; i = g_list_next (i))
|
||||||
|
{
|
||||||
Menu *menu = i->data;
|
Menu *menu = i->data;
|
||||||
|
|
||||||
if ((menu->text.hotkey != NULL)
|
if ((menu->text.hotkey != NULL) && (key == g_ascii_tolower (menu->text.hotkey[0])))
|
||||||
&& (key == g_ascii_tolower (menu->text.hotkey[0]))) {
|
{
|
||||||
menubar_drop (menubar, g_list_position (menubar->menu, i));
|
menubar_drop (menubar, g_list_position (menubar->menu, i));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* drop menu by Enter or Dowwn key */
|
/* drop menu by Enter or Dowwn key */
|
||||||
if (key == KEY_ENTER || key == XCTRL ('n')
|
if (key == KEY_ENTER || key == XCTRL ('n') || key == KEY_DOWN || key == '\n')
|
||||||
|| key == KEY_DOWN || key == '\n')
|
|
||||||
menubar_drop (menubar, menubar->selected);
|
menubar_drop (menubar, menubar->selected);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -466,12 +488,13 @@ menubar_handle_key (WMenuBar *menubar, int key)
|
|||||||
GList *i;
|
GList *i;
|
||||||
|
|
||||||
/* execute menu command by hotkey */
|
/* execute menu command by hotkey */
|
||||||
for (i = menu->entries; i != NULL; i = g_list_next (i)) {
|
for (i = menu->entries; i != NULL; i = g_list_next (i))
|
||||||
|
{
|
||||||
const menu_entry_t *entry = i->data;
|
const menu_entry_t *entry = i->data;
|
||||||
|
|
||||||
if ((entry != NULL) && (entry->command != CK_Ignore_Key)
|
if ((entry != NULL) && (entry->command != CK_Ignore_Key)
|
||||||
&& (entry->text.hotkey != NULL)
|
&& (entry->text.hotkey != NULL) && (key == g_ascii_tolower (entry->text.hotkey[0])))
|
||||||
&& (key == g_ascii_tolower (entry->text.hotkey[0]))) {
|
{
|
||||||
menu->selected = g_list_position (menu->entries, i);
|
menu->selected = g_list_position (menu->entries, i);
|
||||||
menubar_execute (menubar);
|
menubar_execute (menubar);
|
||||||
return 1;
|
return 1;
|
||||||
@ -479,7 +502,8 @@ menubar_handle_key (WMenuBar *menubar, int key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* menu execute by Enter or menu navigation */
|
/* menu execute by Enter or menu navigation */
|
||||||
switch (key) {
|
switch (key)
|
||||||
|
{
|
||||||
case KEY_ENTER:
|
case KEY_ENTER:
|
||||||
case '\n':
|
case '\n':
|
||||||
menubar_execute (menubar);
|
menubar_execute (menubar);
|
||||||
@ -511,11 +535,12 @@ menubar_handle_key (WMenuBar *menubar, int key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
menubar_callback (Widget *w, widget_msg_t msg, int parm)
|
menubar_callback (Widget * w, widget_msg_t msg, int parm)
|
||||||
{
|
{
|
||||||
WMenuBar *menubar = (WMenuBar *) w;
|
WMenuBar *menubar = (WMenuBar *) w;
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg)
|
||||||
|
{
|
||||||
/* We do not want the focus unless we have been activated */
|
/* We do not want the focus unless we have been activated */
|
||||||
case WIDGET_FOCUS:
|
case WIDGET_FOCUS:
|
||||||
if (!menubar->is_active)
|
if (!menubar->is_active)
|
||||||
@ -534,7 +559,8 @@ menubar_callback (Widget *w, widget_msg_t msg, int parm)
|
|||||||
/* We don't want the buttonbar to activate while using the menubar */
|
/* We don't want the buttonbar to activate while using the menubar */
|
||||||
case WIDGET_HOTKEY:
|
case WIDGET_HOTKEY:
|
||||||
case WIDGET_KEY:
|
case WIDGET_KEY:
|
||||||
if (menubar->is_active) {
|
if (menubar->is_active)
|
||||||
|
{
|
||||||
menubar_handle_key (menubar, parm);
|
menubar_handle_key (menubar, parm);
|
||||||
return MSG_HANDLED;
|
return MSG_HANDLED;
|
||||||
}
|
}
|
||||||
@ -552,7 +578,8 @@ menubar_callback (Widget *w, widget_msg_t msg, int parm)
|
|||||||
return MSG_HANDLED;
|
return MSG_HANDLED;
|
||||||
|
|
||||||
case WIDGET_DRAW:
|
case WIDGET_DRAW:
|
||||||
if (menubar_visible) {
|
if (menubar_visible)
|
||||||
|
{
|
||||||
menubar_draw (menubar);
|
menubar_draw (menubar);
|
||||||
return MSG_HANDLED;
|
return MSG_HANDLED;
|
||||||
}
|
}
|
||||||
@ -574,7 +601,7 @@ menubar_callback (Widget *w, widget_msg_t msg, int parm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
menubar_event (Gpm_Event *event, void *data)
|
menubar_event (Gpm_Event * event, void *data)
|
||||||
{
|
{
|
||||||
WMenuBar *menubar = data;
|
WMenuBar *menubar = data;
|
||||||
gboolean was_active = TRUE;
|
gboolean was_active = TRUE;
|
||||||
@ -586,11 +613,11 @@ menubar_event (Gpm_Event *event, void *data)
|
|||||||
return MOU_NORMAL;
|
return MOU_NORMAL;
|
||||||
|
|
||||||
/* ignore wheel events if menu is inactive */
|
/* ignore wheel events if menu is inactive */
|
||||||
if (!menubar->is_active
|
if (!menubar->is_active && ((event->buttons & (GPM_B_MIDDLE | GPM_B_UP | GPM_B_DOWN)) != 0))
|
||||||
&& ((event->buttons & (GPM_B_MIDDLE | GPM_B_UP | GPM_B_DOWN)) != 0))
|
|
||||||
return MOU_NORMAL;
|
return MOU_NORMAL;
|
||||||
|
|
||||||
if (!menubar->is_dropped) {
|
if (!menubar->is_dropped)
|
||||||
|
{
|
||||||
menubar->previous_widget = menubar->widget.parent->current->dlg_id;
|
menubar->previous_widget = menubar->widget.parent->current->dlg_id;
|
||||||
menubar->is_active = TRUE;
|
menubar->is_active = TRUE;
|
||||||
menubar->is_dropped = TRUE;
|
menubar->is_dropped = TRUE;
|
||||||
@ -598,7 +625,8 @@ menubar_event (Gpm_Event *event, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Mouse operations on the menubar */
|
/* Mouse operations on the menubar */
|
||||||
if (event->y == 1 || !was_active) {
|
if (event->y == 1 || !was_active)
|
||||||
|
{
|
||||||
if ((event->type & GPM_UP) != 0)
|
if ((event->type & GPM_UP) != 0)
|
||||||
return MOU_NORMAL;
|
return MOU_NORMAL;
|
||||||
|
|
||||||
@ -607,7 +635,8 @@ menubar_event (Gpm_Event *event, void *data)
|
|||||||
menubar_left (menubar);
|
menubar_left (menubar);
|
||||||
else if (event->buttons & GPM_B_DOWN)
|
else if (event->buttons & GPM_B_DOWN)
|
||||||
menubar_right (menubar);
|
menubar_right (menubar);
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
const unsigned int len = g_list_length (menubar->menu);
|
const unsigned int len = g_list_length (menubar->menu);
|
||||||
unsigned int new_selection = 0;
|
unsigned int new_selection = 0;
|
||||||
|
|
||||||
@ -619,10 +648,13 @@ menubar_event (Gpm_Event *event, void *data)
|
|||||||
if (new_selection != 0) /* Don't set the invalid value -1 */
|
if (new_selection != 0) /* Don't set the invalid value -1 */
|
||||||
new_selection--;
|
new_selection--;
|
||||||
|
|
||||||
if (!was_active) {
|
if (!was_active)
|
||||||
|
{
|
||||||
menubar->selected = new_selection;
|
menubar->selected = new_selection;
|
||||||
dlg_select_widget (menubar);
|
dlg_select_widget (menubar);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
menubar_remove (menubar);
|
menubar_remove (menubar);
|
||||||
menubar->selected = new_selection;
|
menubar->selected = new_selection;
|
||||||
}
|
}
|
||||||
@ -635,8 +667,8 @@ menubar_event (Gpm_Event *event, void *data)
|
|||||||
return MOU_NORMAL;
|
return MOU_NORMAL;
|
||||||
|
|
||||||
/* middle click -- everywhere */
|
/* middle click -- everywhere */
|
||||||
if (((event->buttons & GPM_B_MIDDLE) != 0)
|
if (((event->buttons & GPM_B_MIDDLE) != 0) && ((event->type & GPM_DOWN) != 0))
|
||||||
&& ((event->type & GPM_DOWN) != 0)) {
|
{
|
||||||
menubar_execute (menubar);
|
menubar_execute (menubar);
|
||||||
return MOU_NORMAL;
|
return MOU_NORMAL;
|
||||||
}
|
}
|
||||||
@ -645,23 +677,27 @@ menubar_event (Gpm_Event *event, void *data)
|
|||||||
menu = (Menu *) g_list_nth_data (menubar->menu, menubar->selected);
|
menu = (Menu *) g_list_nth_data (menubar->menu, menubar->selected);
|
||||||
left_x = menu->start_x;
|
left_x = menu->start_x;
|
||||||
right_x = left_x + menu->max_entry_len + 3;
|
right_x = left_x + menu->max_entry_len + 3;
|
||||||
if (right_x > menubar->widget.cols) {
|
if (right_x > menubar->widget.cols)
|
||||||
|
{
|
||||||
left_x = menubar->widget.cols - menu->max_entry_len - 3;
|
left_x = menubar->widget.cols - menu->max_entry_len - 3;
|
||||||
right_x = menubar->widget.cols;
|
right_x = menubar->widget.cols;
|
||||||
}
|
}
|
||||||
|
|
||||||
bottom_y = g_list_length (menu->entries) + 3;
|
bottom_y = g_list_length (menu->entries) + 3;
|
||||||
|
|
||||||
if ((event->x >= left_x) && (event->x <= right_x) && (event->y <= bottom_y)){
|
if ((event->x >= left_x) && (event->x <= right_x) && (event->y <= bottom_y))
|
||||||
|
{
|
||||||
int pos = event->y - 3;
|
int pos = event->y - 3;
|
||||||
const menu_entry_t *entry = g_list_nth_data (menu->entries, pos);
|
const menu_entry_t *entry = g_list_nth_data (menu->entries, pos);
|
||||||
|
|
||||||
/* mouse wheel */
|
/* mouse wheel */
|
||||||
if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN)) {
|
if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN))
|
||||||
|
{
|
||||||
menubar_up (menubar);
|
menubar_up (menubar);
|
||||||
return MOU_NORMAL;
|
return MOU_NORMAL;
|
||||||
}
|
}
|
||||||
if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN)) {
|
if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN))
|
||||||
|
{
|
||||||
menubar_down (menubar);
|
menubar_down (menubar);
|
||||||
return MOU_NORMAL;
|
return MOU_NORMAL;
|
||||||
}
|
}
|
||||||
@ -670,7 +706,8 @@ menubar_event (Gpm_Event *event, void *data)
|
|||||||
if ((pos < 0) || (pos >= bottom_y - 3))
|
if ((pos < 0) || (pos >= bottom_y - 3))
|
||||||
return MOU_NORMAL;
|
return MOU_NORMAL;
|
||||||
|
|
||||||
if ((entry != NULL) && (entry->command != CK_Ignore_Key)) {
|
if ((entry != NULL) && (entry->command != CK_Ignore_Key))
|
||||||
|
{
|
||||||
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
|
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
|
||||||
menu->selected = pos;
|
menu->selected = pos;
|
||||||
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
||||||
@ -678,32 +715,32 @@ menubar_event (Gpm_Event *event, void *data)
|
|||||||
if ((event->type & GPM_UP) != 0)
|
if ((event->type & GPM_UP) != 0)
|
||||||
menubar_execute (menubar);
|
menubar_execute (menubar);
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
/* use click not wheel to close menu */
|
/* use click not wheel to close menu */
|
||||||
if (((event->type & GPM_DOWN) != 0)
|
if (((event->type & GPM_DOWN) != 0) && ((event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0))
|
||||||
&& ((event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0))
|
|
||||||
menubar_finish (menubar);
|
menubar_finish (menubar);
|
||||||
|
|
||||||
return MOU_NORMAL;
|
return MOU_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
WMenuBar *
|
WMenuBar *
|
||||||
menubar_new (int y, int x, int cols, GList *menu)
|
menubar_new (int y, int x, int cols, GList * menu)
|
||||||
{
|
{
|
||||||
WMenuBar *menubar = g_new0 (WMenuBar, 1);
|
WMenuBar *menubar = g_new0 (WMenuBar, 1);
|
||||||
|
|
||||||
init_widget (&menubar->widget, y, x, 1, cols,
|
init_widget (&menubar->widget, y, x, 1, cols, menubar_callback, menubar_event);
|
||||||
menubar_callback, menubar_event);
|
|
||||||
widget_want_cursor (menubar->widget, 0);
|
widget_want_cursor (menubar->widget, 0);
|
||||||
menubar_set_menu (menubar, menu);
|
menubar_set_menu (menubar, menu);
|
||||||
return menubar;
|
return menubar;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
menubar_set_menu (WMenuBar *menubar, GList *menu)
|
menubar_set_menu (WMenuBar * menubar, GList * menu)
|
||||||
{
|
{
|
||||||
/* delete previous menu */
|
/* delete previous menu */
|
||||||
if (menubar->menu != NULL) {
|
if (menubar->menu != NULL)
|
||||||
|
{
|
||||||
g_list_foreach (menubar->menu, (GFunc) destroy_menu, NULL);
|
g_list_foreach (menubar->menu, (GFunc) destroy_menu, NULL);
|
||||||
g_list_free (menubar->menu);
|
g_list_free (menubar->menu);
|
||||||
}
|
}
|
||||||
@ -716,9 +753,10 @@ menubar_set_menu (WMenuBar *menubar, GList *menu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
menubar_add_menu (WMenuBar *menubar, Menu *menu)
|
menubar_add_menu (WMenuBar * menubar, Menu * menu)
|
||||||
{
|
{
|
||||||
if (menu != NULL) {
|
if (menu != NULL)
|
||||||
|
{
|
||||||
menu_arrange (menu, menubar->widget.parent->get_shortcut);
|
menu_arrange (menu, menubar->widget.parent->get_shortcut);
|
||||||
menubar->menu = g_list_append (menubar->menu, menu);
|
menubar->menu = g_list_append (menubar->menu, menu);
|
||||||
}
|
}
|
||||||
@ -731,7 +769,7 @@ menubar_add_menu (WMenuBar *menubar, Menu *menu)
|
|||||||
* and also when widget width is changed (i.e. upon xterm resize).
|
* and also when widget width is changed (i.e. upon xterm resize).
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
menubar_arrange (WMenuBar* menubar)
|
menubar_arrange (WMenuBar * menubar)
|
||||||
{
|
{
|
||||||
int start_x = 1;
|
int start_x = 1;
|
||||||
GList *i;
|
GList *i;
|
||||||
@ -743,7 +781,8 @@ menubar_arrange (WMenuBar* menubar)
|
|||||||
#ifndef RESIZABLE_MENUBAR
|
#ifndef RESIZABLE_MENUBAR
|
||||||
gap = 3;
|
gap = 3;
|
||||||
|
|
||||||
for (i = menubar->menu; i != NULL; i = g_list_next (i)) {
|
for (i = menubar->menu; i != NULL; i = g_list_next (i))
|
||||||
|
{
|
||||||
Menu *menu = i->data;
|
Menu *menu = i->data;
|
||||||
int len = hotkey_width (menu->text) + 2;
|
int len = hotkey_width (menu->text) + 2;
|
||||||
|
|
||||||
@ -754,7 +793,8 @@ menubar_arrange (WMenuBar* menubar)
|
|||||||
gap = menubar->widget.cols - 2;
|
gap = menubar->widget.cols - 2;
|
||||||
|
|
||||||
/* First, calculate gap between items... */
|
/* First, calculate gap between items... */
|
||||||
for (i = menubar->menu; i != NULL; i = g_list_nwxt (i)) {
|
for (i = menubar->menu; i != NULL; i = g_list_nwxt (i))
|
||||||
|
{
|
||||||
Menu *menu = i->data;
|
Menu *menu = i->data;
|
||||||
/* preserve length here, to be used below */
|
/* preserve length here, to be used below */
|
||||||
menu->start_x = hotkey_width (menu->text) + 2;
|
menu->start_x = hotkey_width (menu->text) + 2;
|
||||||
@ -763,13 +803,15 @@ menubar_arrange (WMenuBar* menubar)
|
|||||||
|
|
||||||
gap /= (menubar->menu->len - 1);
|
gap /= (menubar->menu->len - 1);
|
||||||
|
|
||||||
if (gap <= 0) {
|
if (gap <= 0)
|
||||||
|
{
|
||||||
/* We are out of luck - window is too narrow... */
|
/* We are out of luck - window is too narrow... */
|
||||||
gap = 1;
|
gap = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ...and now fix start positions of menubar items */
|
/* ...and now fix start positions of menubar items */
|
||||||
for (i = menubar->menu; i != NULL; i = g_list_nwxt (i)) {
|
for (i = menubar->menu; i != NULL; i = g_list_nwxt (i))
|
||||||
|
{
|
||||||
Menu *menu = i->data;
|
Menu *menu = i->data;
|
||||||
int len = menu->start_x;
|
int len = menu->start_x;
|
||||||
|
|
||||||
@ -781,7 +823,7 @@ menubar_arrange (WMenuBar* menubar)
|
|||||||
|
|
||||||
/* Find MenuBar widget in the dialog */
|
/* Find MenuBar widget in the dialog */
|
||||||
WMenuBar *
|
WMenuBar *
|
||||||
find_menubar (const Dlg_head *h)
|
find_menubar (const Dlg_head * h)
|
||||||
{
|
{
|
||||||
return (WMenuBar *) find_widget_type (h, menubar_callback);
|
return (WMenuBar *) find_widget_type (h, menubar_callback);
|
||||||
}
|
}
|
||||||
|
211
src/panelize.c
211
src/panelize.c
@ -67,21 +67,26 @@ static Dlg_head *panelize_dlg;
|
|||||||
static int last_listitem;
|
static int last_listitem;
|
||||||
static WInput *pname;
|
static WInput *pname;
|
||||||
|
|
||||||
static struct {
|
static struct
|
||||||
|
{
|
||||||
int ret_cmd, flags, y, x;
|
int ret_cmd, flags, y, x;
|
||||||
const char *text;
|
const char *text;
|
||||||
} panelize_but [BUTTONS] = {
|
} panelize_but[BUTTONS] =
|
||||||
|
{
|
||||||
|
/* *INDENT-OFF* */
|
||||||
{ B_CANCEL, NORMAL_BUTTON, 0, 53, N_("&Cancel") },
|
{ B_CANCEL, NORMAL_BUTTON, 0, 53, N_("&Cancel") },
|
||||||
{ B_ADD, NORMAL_BUTTON, 0, 28, N_("&Add new") },
|
{ B_ADD, NORMAL_BUTTON, 0, 28, N_("&Add new") },
|
||||||
{ B_REMOVE, NORMAL_BUTTON, 0, 16, N_("&Remove") },
|
{ B_REMOVE, NORMAL_BUTTON, 0, 16, N_("&Remove") },
|
||||||
{ B_ENTER, DEFPUSH_BUTTON, 0, 0, N_("Pane&lize") },
|
{ B_ENTER, DEFPUSH_BUTTON, 0, 0, N_("Pane&lize") }
|
||||||
|
/* *INDENT-ON* */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *panelize_section = "Panelize";
|
static const char *panelize_section = "Panelize";
|
||||||
static void do_external_panelize (char *command);
|
static void do_external_panelize (char *command);
|
||||||
|
|
||||||
/* Directory panelize */
|
/* Directory panelize */
|
||||||
static struct panelize {
|
static struct panelize
|
||||||
|
{
|
||||||
char *command;
|
char *command;
|
||||||
char *label;
|
char *label;
|
||||||
struct panelize *next;
|
struct panelize *next;
|
||||||
@ -90,7 +95,8 @@ static struct panelize {
|
|||||||
static void
|
static void
|
||||||
update_command (void)
|
update_command (void)
|
||||||
{
|
{
|
||||||
if (l_panelize->pos != last_listitem) {
|
if (l_panelize->pos != last_listitem)
|
||||||
|
{
|
||||||
struct panelize *data = NULL;
|
struct panelize *data = NULL;
|
||||||
|
|
||||||
last_listitem = l_panelize->pos;
|
last_listitem = l_panelize->pos;
|
||||||
@ -102,10 +108,10 @@ update_command (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
panelize_callback (Dlg_head *h, Widget *sender,
|
panelize_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||||
dlg_msg_t msg, int parm, void *data)
|
|
||||||
{
|
{
|
||||||
switch (msg) {
|
switch (msg)
|
||||||
|
{
|
||||||
case DLG_INIT:
|
case DLG_INIT:
|
||||||
case DLG_POST_KEY:
|
case DLG_POST_KEY:
|
||||||
tty_setcolor (MENU_ENTRY_COLOR);
|
tty_setcolor (MENU_ENTRY_COLOR);
|
||||||
@ -133,9 +139,11 @@ init_panelize (void)
|
|||||||
static int i18n_flag = 0;
|
static int i18n_flag = 0;
|
||||||
static int maxlen = 0;
|
static int maxlen = 0;
|
||||||
|
|
||||||
if (!i18n_flag) {
|
if (!i18n_flag)
|
||||||
|
{
|
||||||
i = sizeof (panelize_but) / sizeof (panelize_but[0]);
|
i = sizeof (panelize_but) / sizeof (panelize_but[0]);
|
||||||
while (i--) {
|
while (i--)
|
||||||
|
{
|
||||||
panelize_but[i].text = _(panelize_but[i].text);
|
panelize_but[i].text = _(panelize_but[i].text);
|
||||||
maxlen += str_term_width1 (panelize_but[i].text) + 5;
|
maxlen += str_term_width1 (panelize_but[i].text) + 5;
|
||||||
}
|
}
|
||||||
@ -145,12 +153,9 @@ init_panelize (void)
|
|||||||
}
|
}
|
||||||
panelize_cols = max (panelize_cols, maxlen);
|
panelize_cols = max (panelize_cols, maxlen);
|
||||||
|
|
||||||
panelize_but[2].x =
|
panelize_but[2].x = panelize_but[3].x + str_term_width1 (panelize_but[3].text) + 7;
|
||||||
panelize_but[3].x + str_term_width1 (panelize_but[3].text) + 7;
|
panelize_but[1].x = panelize_but[2].x + str_term_width1 (panelize_but[2].text) + 5;
|
||||||
panelize_but[1].x =
|
panelize_but[0].x = panelize_cols - str_term_width1 (panelize_but[0].text) - 8 - BX;
|
||||||
panelize_but[2].x + str_term_width1 (panelize_but[2].text) + 5;
|
|
||||||
panelize_but[0].x =
|
|
||||||
panelize_cols - str_term_width1 (panelize_but[0].text) - 8 - BX;
|
|
||||||
|
|
||||||
#endif /* ENABLE_NLS */
|
#endif /* ENABLE_NLS */
|
||||||
|
|
||||||
@ -168,8 +173,7 @@ init_panelize (void)
|
|||||||
button_new (BY + panelize_but[i].y,
|
button_new (BY + panelize_but[i].y,
|
||||||
BX + panelize_but[i].x,
|
BX + panelize_but[i].x,
|
||||||
panelize_but[i].ret_cmd,
|
panelize_but[i].ret_cmd,
|
||||||
panelize_but[i].flags,
|
panelize_but[i].flags, panelize_but[i].text, 0));
|
||||||
panelize_but[i].text, 0));
|
|
||||||
|
|
||||||
pname =
|
pname =
|
||||||
input_new (UY + 14, UX, INPUT_COLOR, panelize_dlg->cols - 10, "",
|
input_new (UY + 14, UX, INPUT_COLOR, panelize_dlg->cols - 10, "",
|
||||||
@ -179,10 +183,10 @@ init_panelize (void)
|
|||||||
add_widget (panelize_dlg, label_new (UY + 13, UX, _("Command")));
|
add_widget (panelize_dlg, label_new (UY + 13, UX, _("Command")));
|
||||||
|
|
||||||
/* get new listbox */
|
/* get new listbox */
|
||||||
l_panelize =
|
l_panelize = listbox_new (UY + 1, UX + 1, 10, panelize_dlg->cols - 12, FALSE, NULL);
|
||||||
listbox_new (UY + 1, UX + 1, 10, panelize_dlg->cols - 12, FALSE, NULL);
|
|
||||||
|
|
||||||
while (current) {
|
while (current)
|
||||||
|
{
|
||||||
listbox_add_item (l_panelize, LISTBOX_APPEND_AT_END, 0, current->label, current);
|
listbox_add_item (l_panelize, LISTBOX_APPEND_AT_END, 0, current->label, current);
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
@ -190,34 +194,38 @@ init_panelize (void)
|
|||||||
/* add listbox to the dialogs */
|
/* add listbox to the dialogs */
|
||||||
add_widget (panelize_dlg, l_panelize);
|
add_widget (panelize_dlg, l_panelize);
|
||||||
|
|
||||||
listbox_select_entry (l_panelize,
|
listbox_select_entry (l_panelize, listbox_search_text (l_panelize, _("Other command")));
|
||||||
listbox_search_text (l_panelize,
|
|
||||||
_("Other command")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void panelize_done (void)
|
static void
|
||||||
|
panelize_done (void)
|
||||||
{
|
{
|
||||||
destroy_dlg (panelize_dlg);
|
destroy_dlg (panelize_dlg);
|
||||||
repaint_screen ();
|
repaint_screen ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add2panelize (char *label, char *command)
|
static void
|
||||||
|
add2panelize (char *label, char *command)
|
||||||
{
|
{
|
||||||
struct panelize *current, *old;
|
struct panelize *current, *old;
|
||||||
|
|
||||||
old = NULL;
|
old = NULL;
|
||||||
current = panelize;
|
current = panelize;
|
||||||
while (current && strcmp (current->label, label) <= 0){
|
while (current && strcmp (current->label, label) <= 0)
|
||||||
|
{
|
||||||
old = current;
|
old = current;
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (old == NULL){
|
if (old == NULL)
|
||||||
|
{
|
||||||
panelize = g_new (struct panelize, 1);
|
panelize = g_new (struct panelize, 1);
|
||||||
panelize->label = label;
|
panelize->label = label;
|
||||||
panelize->command = command;
|
panelize->command = command;
|
||||||
panelize->next = current;
|
panelize->next = current;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
struct panelize *new;
|
struct panelize *new;
|
||||||
new = g_new (struct panelize, 1);
|
new = g_new (struct panelize, 1);
|
||||||
new->label = label;
|
new->label = label;
|
||||||
@ -232,14 +240,14 @@ add2panelize_cmd (void)
|
|||||||
{
|
{
|
||||||
char *label;
|
char *label;
|
||||||
|
|
||||||
if (pname->buffer && (*pname->buffer)) {
|
if (pname->buffer && (*pname->buffer))
|
||||||
|
{
|
||||||
label = input_dialog (_(" Add to external panelize "),
|
label = input_dialog (_(" Add to external panelize "),
|
||||||
_(" Enter command label: "),
|
_(" Enter command label: "), MC_HISTORY_FM_PANELIZE_ADD, "");
|
||||||
MC_HISTORY_FM_PANELIZE_ADD,
|
|
||||||
"");
|
|
||||||
if (!label)
|
if (!label)
|
||||||
return;
|
return;
|
||||||
if (!*label) {
|
if (!*label)
|
||||||
|
{
|
||||||
g_free (label);
|
g_free (label);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -248,16 +256,22 @@ add2panelize_cmd (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void remove_from_panelize (struct panelize *entry)
|
static void
|
||||||
|
remove_from_panelize (struct panelize *entry)
|
||||||
{
|
{
|
||||||
if (strcmp (entry->label, _("Other command")) != 0) {
|
if (strcmp (entry->label, _("Other command")) != 0)
|
||||||
if (entry == panelize) {
|
{
|
||||||
|
if (entry == panelize)
|
||||||
|
{
|
||||||
panelize = panelize->next;
|
panelize = panelize->next;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
struct panelize *current = panelize;
|
struct panelize *current = panelize;
|
||||||
while (current && current->next != entry)
|
while (current && current->next != entry)
|
||||||
current = current->next;
|
current = current->next;
|
||||||
if (current) {
|
if (current)
|
||||||
|
{
|
||||||
current->next = entry->next;
|
current->next = entry->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,9 +287,9 @@ external_panelize (void)
|
|||||||
{
|
{
|
||||||
char *target = NULL;
|
char *target = NULL;
|
||||||
|
|
||||||
if (!vfs_current_is_local ()){
|
if (!vfs_current_is_local ())
|
||||||
message (D_ERROR, MSG_ERROR,
|
{
|
||||||
_(" Cannot run external panelize in a non-local directory "));
|
message (D_ERROR, MSG_ERROR, _(" Cannot run external panelize in a non-local directory "));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +300,8 @@ external_panelize (void)
|
|||||||
|
|
||||||
run_dlg (panelize_dlg);
|
run_dlg (panelize_dlg);
|
||||||
|
|
||||||
switch (panelize_dlg->ret_value) {
|
switch (panelize_dlg->ret_value)
|
||||||
|
{
|
||||||
case B_CANCEL:
|
case B_CANCEL:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -305,7 +320,8 @@ external_panelize (void)
|
|||||||
|
|
||||||
case B_ENTER:
|
case B_ENTER:
|
||||||
target = pname->buffer;
|
target = pname->buffer;
|
||||||
if (target != NULL && *target) {
|
if (target != NULL && *target)
|
||||||
|
{
|
||||||
char *cmd = g_strdup (target);
|
char *cmd = g_strdup (target);
|
||||||
destroy_dlg (panelize_dlg);
|
destroy_dlg (panelize_dlg);
|
||||||
do_external_panelize (cmd);
|
do_external_panelize (cmd);
|
||||||
@ -319,7 +335,8 @@ external_panelize (void)
|
|||||||
panelize_done ();
|
panelize_done ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_panelize (void)
|
void
|
||||||
|
load_panelize (void)
|
||||||
{
|
{
|
||||||
gchar **profile_keys, **keys;
|
gchar **profile_keys, **keys;
|
||||||
gsize len;
|
gsize len;
|
||||||
@ -328,61 +345,70 @@ void load_panelize (void)
|
|||||||
|
|
||||||
conv = str_crt_conv_from ("UTF-8");
|
conv = str_crt_conv_from ("UTF-8");
|
||||||
|
|
||||||
profile_keys = keys = mc_config_get_keys (mc_main_config, panelize_section,&len);
|
profile_keys = keys = mc_config_get_keys (mc_main_config, panelize_section, &len);
|
||||||
|
|
||||||
add2panelize (g_strdup (_("Other command")), g_strdup (""));
|
add2panelize (g_strdup (_("Other command")), g_strdup (""));
|
||||||
|
|
||||||
if (!profile_keys || *profile_keys == NULL){
|
if (!profile_keys || *profile_keys == NULL)
|
||||||
add2panelize (g_strdup (_("Find rejects after patching")), g_strdup ("find . -name \\*.rej -print"));
|
{
|
||||||
add2panelize (g_strdup (_("Find *.orig after patching")), g_strdup ("find . -name \\*.orig -print"));
|
add2panelize (g_strdup (_("Find rejects after patching")),
|
||||||
add2panelize (g_strdup (_("Find SUID and SGID programs")), g_strdup ("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print"));
|
g_strdup ("find . -name \\*.rej -print"));
|
||||||
|
add2panelize (g_strdup (_("Find *.orig after patching")),
|
||||||
|
g_strdup ("find . -name \\*.orig -print"));
|
||||||
|
add2panelize (g_strdup (_("Find SUID and SGID programs")),
|
||||||
|
g_strdup
|
||||||
|
("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*profile_keys){
|
while (*profile_keys)
|
||||||
|
{
|
||||||
|
|
||||||
if (utf8_display || conv == INVALID_CONV){
|
if (utf8_display || conv == INVALID_CONV)
|
||||||
|
{
|
||||||
buffer = g_string_new (*profile_keys);
|
buffer = g_string_new (*profile_keys);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
buffer = g_string_new ("");
|
buffer = g_string_new ("");
|
||||||
if (str_convert (conv, *profile_keys, buffer) == ESTR_FAILURE)
|
if (str_convert (conv, *profile_keys, buffer) == ESTR_FAILURE)
|
||||||
{
|
{
|
||||||
g_string_free(buffer, TRUE);
|
g_string_free (buffer, TRUE);
|
||||||
buffer = g_string_new (*profile_keys);
|
buffer = g_string_new (*profile_keys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add2panelize (
|
add2panelize (g_string_free (buffer, FALSE),
|
||||||
g_string_free(buffer, FALSE),
|
mc_config_get_string (mc_main_config, panelize_section, *profile_keys, ""));
|
||||||
mc_config_get_string(mc_main_config,panelize_section,*profile_keys,"")
|
|
||||||
);
|
|
||||||
profile_keys++;
|
profile_keys++;
|
||||||
}
|
}
|
||||||
g_strfreev(keys);
|
g_strfreev (keys);
|
||||||
str_close_conv (conv);
|
str_close_conv (conv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_panelize (void)
|
void
|
||||||
|
save_panelize (void)
|
||||||
{
|
{
|
||||||
struct panelize *current = panelize;
|
struct panelize *current = panelize;
|
||||||
|
|
||||||
mc_config_del_group (mc_main_config, panelize_section);
|
mc_config_del_group (mc_main_config, panelize_section);
|
||||||
for (;current; current = current->next){
|
for (; current; current = current->next)
|
||||||
|
{
|
||||||
if (strcmp (current->label, _("Other command")))
|
if (strcmp (current->label, _("Other command")))
|
||||||
mc_config_set_string(mc_main_config,
|
mc_config_set_string (mc_main_config,
|
||||||
panelize_section,
|
panelize_section, current->label, current->command);
|
||||||
current->label,
|
|
||||||
current->command);
|
|
||||||
}
|
}
|
||||||
mc_config_save_file (mc_main_config, NULL);
|
mc_config_save_file (mc_main_config, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void done_panelize (void)
|
void
|
||||||
|
done_panelize (void)
|
||||||
{
|
{
|
||||||
struct panelize *current = panelize;
|
struct panelize *current = panelize;
|
||||||
struct panelize *next;
|
struct panelize *next;
|
||||||
|
|
||||||
for (; current; current = next){
|
for (; current; current = next)
|
||||||
|
{
|
||||||
next = current->next;
|
next = current->next;
|
||||||
g_free (current->label);
|
g_free (current->label);
|
||||||
g_free (current->command);
|
g_free (current->command);
|
||||||
@ -390,54 +416,57 @@ void done_panelize (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_external_panelize (char *command)
|
static void
|
||||||
|
do_external_panelize (char *command)
|
||||||
{
|
{
|
||||||
int status, link_to_dir, stale_link;
|
int status, link_to_dir, stale_link;
|
||||||
int next_free = 0;
|
int next_free = 0;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
dir_list *list = ¤t_panel->dir;
|
dir_list *list = ¤t_panel->dir;
|
||||||
char line [MC_MAXPATHLEN];
|
char line[MC_MAXPATHLEN];
|
||||||
char *name;
|
char *name;
|
||||||
FILE *external;
|
FILE *external;
|
||||||
|
|
||||||
open_error_pipe ();
|
open_error_pipe ();
|
||||||
external = popen (command, "r");
|
external = popen (command, "r");
|
||||||
if (!external){
|
if (!external)
|
||||||
|
{
|
||||||
close_error_pipe (D_ERROR, _("Cannot invoke command."));
|
close_error_pipe (D_ERROR, _("Cannot invoke command."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Clear the counters and the directory list */
|
/* Clear the counters and the directory list */
|
||||||
panel_clean_dir (current_panel);
|
panel_clean_dir (current_panel);
|
||||||
|
|
||||||
while (1) {
|
while (1)
|
||||||
clearerr(external);
|
{
|
||||||
if (fgets (line, MC_MAXPATHLEN, external) == NULL) {
|
clearerr (external);
|
||||||
if (ferror(external) && errno == EINTR)
|
if (fgets (line, MC_MAXPATHLEN, external) == NULL)
|
||||||
|
{
|
||||||
|
if (ferror (external) && errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (line[strlen(line)-1] == '\n')
|
if (line[strlen (line) - 1] == '\n')
|
||||||
line[strlen(line)-1] = 0;
|
line[strlen (line) - 1] = 0;
|
||||||
if (strlen(line) < 1)
|
if (strlen (line) < 1)
|
||||||
continue;
|
continue;
|
||||||
if (line [0] == '.' && line[1] == PATH_SEP)
|
if (line[0] == '.' && line[1] == PATH_SEP)
|
||||||
name = line + 2;
|
name = line + 2;
|
||||||
else
|
else
|
||||||
name = line;
|
name = line;
|
||||||
status = handle_path (list, name, &st, next_free, &link_to_dir,
|
status = handle_path (list, name, &st, next_free, &link_to_dir, &stale_link);
|
||||||
&stale_link);
|
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
continue;
|
continue;
|
||||||
if (status == -1)
|
if (status == -1)
|
||||||
break;
|
break;
|
||||||
list->list [next_free].fnamelen = strlen (name);
|
list->list[next_free].fnamelen = strlen (name);
|
||||||
list->list [next_free].fname = g_strdup (name);
|
list->list[next_free].fname = g_strdup (name);
|
||||||
file_mark (current_panel, next_free, 0);
|
file_mark (current_panel, next_free, 0);
|
||||||
list->list [next_free].f.link_to_dir = link_to_dir;
|
list->list[next_free].f.link_to_dir = link_to_dir;
|
||||||
list->list [next_free].f.stale_link = stale_link;
|
list->list[next_free].f.stale_link = stale_link;
|
||||||
list->list [next_free].f.dir_size_computed = 0;
|
list->list[next_free].f.dir_size_computed = 0;
|
||||||
list->list [next_free].st = st;
|
list->list[next_free].st = st;
|
||||||
list->list[next_free].sort_key = NULL;
|
list->list[next_free].sort_key = NULL;
|
||||||
list->list[next_free].second_sort_key = NULL;
|
list->list[next_free].second_sort_key = NULL;
|
||||||
next_free++;
|
next_free++;
|
||||||
@ -446,13 +475,17 @@ static void do_external_panelize (char *command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
current_panel->is_panelized = 1;
|
current_panel->is_panelized = 1;
|
||||||
if (next_free){
|
if (next_free)
|
||||||
|
{
|
||||||
current_panel->count = next_free;
|
current_panel->count = next_free;
|
||||||
if (list->list [0].fname [0] == PATH_SEP){
|
if (list->list[0].fname[0] == PATH_SEP)
|
||||||
|
{
|
||||||
strcpy (current_panel->cwd, PATH_SEP_STR);
|
strcpy (current_panel->cwd, PATH_SEP_STR);
|
||||||
chdir (PATH_SEP_STR);
|
chdir (PATH_SEP_STR);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
current_panel->count = set_zero_dir (list) ? 1 : 0;
|
current_panel->count = set_zero_dir (list) ? 1 : 0;
|
||||||
}
|
}
|
||||||
if (pclose (external) < 0)
|
if (pclose (external) < 0)
|
||||||
|
@ -89,7 +89,8 @@ typedef struct format_e
|
|||||||
const char *id;
|
const char *id;
|
||||||
} format_e;
|
} format_e;
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
QSEARCH_CASE_INSENSITIVE = 0, /* quick search in case insensitive mode */
|
QSEARCH_CASE_INSENSITIVE = 0, /* quick search in case insensitive mode */
|
||||||
QSEARCH_CASE_SENSITIVE = 1, /* quick search in case sensitive mode */
|
QSEARCH_CASE_SENSITIVE = 1, /* quick search in case sensitive mode */
|
||||||
QSEARCH_PANEL_CASE = 2 /* quick search get value from panel case_sensitive */
|
QSEARCH_PANEL_CASE = 2 /* quick search get value from panel case_sensitive */
|
||||||
@ -3214,7 +3215,7 @@ mouse_sort_col (Gpm_Event * event, WPanel * panel)
|
|||||||
* If the event is redirected to the menu, *redir is set to TRUE.
|
* If the event is redirected to the menu, *redir is set to TRUE.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
do_panel_event (Gpm_Event * event, WPanel * panel, gboolean *redir)
|
do_panel_event (Gpm_Event * event, WPanel * panel, gboolean * redir)
|
||||||
{
|
{
|
||||||
const int lines = llines (panel);
|
const int lines = llines (panel);
|
||||||
const gboolean is_active = dlg_widget_active (panel);
|
const gboolean is_active = dlg_widget_active (panel);
|
||||||
|
409
src/tree.c
409
src/tree.c
@ -78,7 +78,8 @@ const global_keymap_t *tree_map;
|
|||||||
/* Specifies the display mode: 1d or 2d */
|
/* Specifies the display mode: 1d or 2d */
|
||||||
static gboolean tree_navigation_flag = FALSE;
|
static gboolean tree_navigation_flag = FALSE;
|
||||||
|
|
||||||
struct WTree {
|
struct WTree
|
||||||
|
{
|
||||||
Widget widget;
|
Widget widget;
|
||||||
struct TreeStore *store;
|
struct TreeStore *store;
|
||||||
tree_entry *selected_ptr; /* The selected directory */
|
tree_entry *selected_ptr; /* The selected directory */
|
||||||
@ -95,37 +96,40 @@ struct WTree {
|
|||||||
static void tree_rescan (void *data);
|
static void tree_rescan (void *data);
|
||||||
|
|
||||||
static tree_entry *
|
static tree_entry *
|
||||||
back_ptr (tree_entry *ptr, int *count)
|
back_ptr (tree_entry * ptr, int *count)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (ptr && ptr->prev && i < *count){
|
while (ptr && ptr->prev && i < *count)
|
||||||
|
{
|
||||||
ptr = ptr->prev;
|
ptr = ptr->prev;
|
||||||
i ++;
|
i++;
|
||||||
}
|
}
|
||||||
*count = i;
|
*count = i;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static tree_entry *
|
static tree_entry *
|
||||||
forw_ptr (tree_entry *ptr, int *count)
|
forw_ptr (tree_entry * ptr, int *count)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (ptr && ptr->next && i < *count){
|
while (ptr && ptr->next && i < *count)
|
||||||
|
{
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
i ++;
|
i++;
|
||||||
}
|
}
|
||||||
*count = i;
|
*count = i;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
remove_callback (tree_entry *entry, void *data)
|
remove_callback (tree_entry * entry, void *data)
|
||||||
{
|
{
|
||||||
WTree *tree = data;
|
WTree *tree = data;
|
||||||
|
|
||||||
if (tree->selected_ptr == entry){
|
if (tree->selected_ptr == entry)
|
||||||
|
{
|
||||||
if (tree->selected_ptr->next)
|
if (tree->selected_ptr->next)
|
||||||
tree->selected_ptr = tree->selected_ptr->next;
|
tree->selected_ptr = tree->selected_ptr->next;
|
||||||
else
|
else
|
||||||
@ -135,7 +139,7 @@ remove_callback (tree_entry *entry, void *data)
|
|||||||
|
|
||||||
/* Save the ~/.mc/Tree file */
|
/* Save the ~/.mc/Tree file */
|
||||||
static void
|
static void
|
||||||
save_tree (WTree *tree)
|
save_tree (WTree * tree)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
char *tree_name;
|
char *tree_name;
|
||||||
@ -144,9 +148,9 @@ save_tree (WTree *tree)
|
|||||||
error = tree_store_save ();
|
error = tree_store_save ();
|
||||||
|
|
||||||
|
|
||||||
if (error){
|
if (error)
|
||||||
tree_name = g_build_filename (home_dir, MC_USERCONF_DIR,
|
{
|
||||||
MC_TREESTORE_FILE, (char *) NULL);
|
tree_name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, (char *) NULL);
|
||||||
fprintf (stderr, _("Cannot open the %s file for writing:\n%s\n"), tree_name,
|
fprintf (stderr, _("Cannot open the %s file for writing:\n%s\n"), tree_name,
|
||||||
unix_error_string (error));
|
unix_error_string (error));
|
||||||
g_free (tree_name);
|
g_free (tree_name);
|
||||||
@ -154,14 +158,14 @@ save_tree (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_remove_entry (WTree *tree, char *name)
|
tree_remove_entry (WTree * tree, char *name)
|
||||||
{
|
{
|
||||||
(void) tree;
|
(void) tree;
|
||||||
tree_store_remove_entry (name);
|
tree_store_remove_entry (name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_destroy (WTree *tree)
|
tree_destroy (WTree * tree)
|
||||||
{
|
{
|
||||||
tree_store_remove_entry_remove_hook (remove_callback);
|
tree_store_remove_entry_remove_hook (remove_callback);
|
||||||
save_tree (tree);
|
save_tree (tree);
|
||||||
@ -173,7 +177,7 @@ tree_destroy (WTree *tree)
|
|||||||
|
|
||||||
/* Loads the .mc.tree file */
|
/* Loads the .mc.tree file */
|
||||||
static void
|
static void
|
||||||
load_tree (WTree *tree)
|
load_tree (WTree * tree)
|
||||||
{
|
{
|
||||||
tree_store_load ();
|
tree_store_load ();
|
||||||
|
|
||||||
@ -182,41 +186,44 @@ load_tree (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_show_mini_info (WTree *tree, int tree_lines, int tree_cols)
|
tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols)
|
||||||
{
|
{
|
||||||
Dlg_head *h = tree->widget.parent;
|
Dlg_head *h = tree->widget.parent;
|
||||||
int line;
|
int line;
|
||||||
|
|
||||||
/* Show mini info */
|
/* Show mini info */
|
||||||
if (tree->is_panel){
|
if (tree->is_panel)
|
||||||
|
{
|
||||||
if (!show_mini_info)
|
if (!show_mini_info)
|
||||||
return;
|
return;
|
||||||
line = tree_lines+2;
|
line = tree_lines + 2;
|
||||||
} else
|
}
|
||||||
line = tree_lines+1;
|
else
|
||||||
|
line = tree_lines + 1;
|
||||||
|
|
||||||
tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols);
|
tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols);
|
||||||
widget_move (&tree->widget, line, 1);
|
widget_move (&tree->widget, line, 1);
|
||||||
|
|
||||||
if (tree->searching){
|
if (tree->searching)
|
||||||
|
{
|
||||||
/* Show search string */
|
/* Show search string */
|
||||||
tty_setcolor (TREE_NORMALC (h));
|
tty_setcolor (TREE_NORMALC (h));
|
||||||
tty_setcolor (DLG_FOCUSC (h));
|
tty_setcolor (DLG_FOCUSC (h));
|
||||||
tty_print_char (PATH_SEP);
|
tty_print_char (PATH_SEP);
|
||||||
|
|
||||||
tty_print_string (str_fit_to_term (tree->search_buffer,
|
tty_print_string (str_fit_to_term (tree->search_buffer, tree_cols - 2, J_LEFT_FIT));
|
||||||
tree_cols - 2, J_LEFT_FIT));
|
|
||||||
tty_print_char (' ');
|
tty_print_char (' ');
|
||||||
tty_setcolor (DLG_FOCUSC (h));
|
tty_setcolor (DLG_FOCUSC (h));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* Show full name of selected directory */
|
/* Show full name of selected directory */
|
||||||
tty_print_string (str_fit_to_term (tree->selected_ptr->name,
|
tty_print_string (str_fit_to_term (tree->selected_ptr->name, tree_cols, J_LEFT_FIT));
|
||||||
tree_cols, J_LEFT_FIT));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
show_tree (WTree *tree)
|
show_tree (WTree * tree)
|
||||||
{
|
{
|
||||||
Dlg_head *h = tree->widget.parent;
|
Dlg_head *h = tree->widget.parent;
|
||||||
tree_entry *current;
|
tree_entry *current;
|
||||||
@ -230,8 +237,9 @@ show_tree (WTree *tree)
|
|||||||
tree_cols = tree->widget.cols;
|
tree_cols = tree->widget.cols;
|
||||||
|
|
||||||
tty_setcolor (TREE_NORMALC (h));
|
tty_setcolor (TREE_NORMALC (h));
|
||||||
widget_move ((Widget*)tree, y, x);
|
widget_move ((Widget *) tree, y, x);
|
||||||
if (tree->is_panel){
|
if (tree->is_panel)
|
||||||
|
{
|
||||||
tree_cols -= 2;
|
tree_cols -= 2;
|
||||||
x = y = 1;
|
x = y = 1;
|
||||||
}
|
}
|
||||||
@ -243,7 +251,8 @@ show_tree (WTree *tree)
|
|||||||
topsublevel = tree->store->tree_first->sublevel;
|
topsublevel = tree->store->tree_first->sublevel;
|
||||||
else
|
else
|
||||||
topsublevel = 0;
|
topsublevel = 0;
|
||||||
if (!tree->selected_ptr){
|
if (!tree->selected_ptr)
|
||||||
|
{
|
||||||
tree->selected_ptr = tree->store->tree_first;
|
tree->selected_ptr = tree->store->tree_first;
|
||||||
tree->topdiff = 0;
|
tree->topdiff = 0;
|
||||||
}
|
}
|
||||||
@ -252,20 +261,26 @@ show_tree (WTree *tree)
|
|||||||
/* Calculate the directory which is to be shown on the topmost line */
|
/* Calculate the directory which is to be shown on the topmost line */
|
||||||
if (!tree_navigation_flag)
|
if (!tree_navigation_flag)
|
||||||
current = back_ptr (current, &tree->topdiff);
|
current = back_ptr (current, &tree->topdiff);
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
while (current->prev && i < tree->topdiff){
|
while (current->prev && i < tree->topdiff)
|
||||||
|
{
|
||||||
current = current->prev;
|
current = current->prev;
|
||||||
if (current->sublevel < tree->selected_ptr->sublevel){
|
if (current->sublevel < tree->selected_ptr->sublevel)
|
||||||
if (strncmp (current->name, tree->selected_ptr->name,
|
{
|
||||||
strlen (current->name)) == 0)
|
if (strncmp (current->name, tree->selected_ptr->name, strlen (current->name)) == 0)
|
||||||
i++;
|
i++;
|
||||||
} else if (current->sublevel == tree->selected_ptr->sublevel){
|
}
|
||||||
for (j = strlen (current->name) - 1; current->name [j] != PATH_SEP; j--);
|
else if (current->sublevel == tree->selected_ptr->sublevel)
|
||||||
|
{
|
||||||
|
for (j = strlen (current->name) - 1; current->name[j] != PATH_SEP; j--);
|
||||||
if (strncmp (current->name, tree->selected_ptr->name, j) == 0)
|
if (strncmp (current->name, tree->selected_ptr->name, j) == 0)
|
||||||
i++;
|
i++;
|
||||||
} else if (current->sublevel == tree->selected_ptr->sublevel + 1
|
}
|
||||||
&& strlen (tree->selected_ptr->name) > 1){
|
else if (current->sublevel == tree->selected_ptr->sublevel + 1
|
||||||
|
&& strlen (tree->selected_ptr->name) > 1)
|
||||||
|
{
|
||||||
if (strncmp (current->name, tree->selected_ptr->name,
|
if (strncmp (current->name, tree->selected_ptr->name,
|
||||||
strlen (tree->selected_ptr->name)) == 0)
|
strlen (tree->selected_ptr->name)) == 0)
|
||||||
i++;
|
i++;
|
||||||
@ -275,18 +290,21 @@ show_tree (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Loop for every line */
|
/* Loop for every line */
|
||||||
for (i = 0; i < tree_lines; i++){
|
for (i = 0; i < tree_lines; i++)
|
||||||
|
{
|
||||||
/* Move to the beginning of the line */
|
/* Move to the beginning of the line */
|
||||||
tty_draw_hline (tree->widget.y + y + i, tree->widget.x + x, ' ', tree_cols);
|
tty_draw_hline (tree->widget.y + y + i, tree->widget.x + x, ' ', tree_cols);
|
||||||
|
|
||||||
if (!current)
|
if (!current)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
tree->tree_shown [i] = current;
|
tree->tree_shown[i] = current;
|
||||||
if (current->sublevel == topsublevel){
|
if (current->sublevel == topsublevel)
|
||||||
|
{
|
||||||
|
|
||||||
/* Top level directory */
|
/* Top level directory */
|
||||||
if (tree->active && current == tree->selected_ptr) {
|
if (tree->active && current == tree->selected_ptr)
|
||||||
|
{
|
||||||
if (!tty_use_colors () && !tree->is_panel)
|
if (!tty_use_colors () && !tree->is_panel)
|
||||||
tty_setcolor (MARKED_COLOR);
|
tty_setcolor (MARKED_COLOR);
|
||||||
else
|
else
|
||||||
@ -295,12 +313,15 @@ show_tree (WTree *tree)
|
|||||||
|
|
||||||
/* Show full name */
|
/* Show full name */
|
||||||
tty_print_string (str_fit_to_term (current->name, tree_cols - 6, J_LEFT_FIT));
|
tty_print_string (str_fit_to_term (current->name, tree_cols - 6, J_LEFT_FIT));
|
||||||
} else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* Sub level directory */
|
/* Sub level directory */
|
||||||
|
|
||||||
tty_set_alt_charset (TRUE);
|
tty_set_alt_charset (TRUE);
|
||||||
/* Output branch parts */
|
/* Output branch parts */
|
||||||
for (j = 0; j < current->sublevel - topsublevel - 1; j++){
|
for (j = 0; j < current->sublevel - topsublevel - 1; j++)
|
||||||
|
{
|
||||||
if (tree_cols - 8 - 3 * j < 9)
|
if (tree_cols - 8 - 3 * j < 9)
|
||||||
break;
|
break;
|
||||||
tty_print_char (' ');
|
tty_print_char (' ');
|
||||||
@ -310,7 +331,8 @@ show_tree (WTree *tree)
|
|||||||
tty_print_char (' ');
|
tty_print_char (' ');
|
||||||
tty_print_char (' ');
|
tty_print_char (' ');
|
||||||
}
|
}
|
||||||
tty_print_char (' '); j++;
|
tty_print_char (' ');
|
||||||
|
j++;
|
||||||
if (!current->next || !(current->next->submask & (1 << current->sublevel)))
|
if (!current->next || !(current->next->submask & (1 << current->sublevel)))
|
||||||
tty_print_char (ACS_LLCORNER);
|
tty_print_char (ACS_LLCORNER);
|
||||||
else
|
else
|
||||||
@ -318,7 +340,8 @@ show_tree (WTree *tree)
|
|||||||
tty_print_char (ACS_HLINE);
|
tty_print_char (ACS_HLINE);
|
||||||
tty_set_alt_charset (FALSE);
|
tty_set_alt_charset (FALSE);
|
||||||
|
|
||||||
if (tree->active && current == tree->selected_ptr) {
|
if (tree->active && current == tree->selected_ptr)
|
||||||
|
{
|
||||||
/* Selected directory -> change color */
|
/* Selected directory -> change color */
|
||||||
if (!tty_use_colors () && !tree->is_panel)
|
if (!tty_use_colors () && !tree->is_panel)
|
||||||
tty_setcolor (MARKED_COLOR);
|
tty_setcolor (MARKED_COLOR);
|
||||||
@ -338,18 +361,25 @@ show_tree (WTree *tree)
|
|||||||
|
|
||||||
/* Calculate the next value for current */
|
/* Calculate the next value for current */
|
||||||
current = current->next;
|
current = current->next;
|
||||||
if (tree_navigation_flag){
|
if (tree_navigation_flag)
|
||||||
while (current){
|
{
|
||||||
if (current->sublevel < tree->selected_ptr->sublevel){
|
while (current)
|
||||||
|
{
|
||||||
|
if (current->sublevel < tree->selected_ptr->sublevel)
|
||||||
|
{
|
||||||
if (strncmp (current->name, tree->selected_ptr->name,
|
if (strncmp (current->name, tree->selected_ptr->name,
|
||||||
strlen (current->name)) == 0)
|
strlen (current->name)) == 0)
|
||||||
break;
|
break;
|
||||||
} else if (current->sublevel == tree->selected_ptr->sublevel){
|
}
|
||||||
for (j = strlen (current->name) - 1; current->name [j] != PATH_SEP; j--);
|
else if (current->sublevel == tree->selected_ptr->sublevel)
|
||||||
if (strncmp (current->name,tree->selected_ptr->name,j)== 0)
|
{
|
||||||
|
for (j = strlen (current->name) - 1; current->name[j] != PATH_SEP; j--);
|
||||||
|
if (strncmp (current->name, tree->selected_ptr->name, j) == 0)
|
||||||
break;
|
break;
|
||||||
} else if (current->sublevel == tree->selected_ptr->sublevel+1
|
}
|
||||||
&& strlen (tree->selected_ptr->name) > 1){
|
else if (current->sublevel == tree->selected_ptr->sublevel + 1
|
||||||
|
&& strlen (tree->selected_ptr->name) > 1)
|
||||||
|
{
|
||||||
if (strncmp (current->name, tree->selected_ptr->name,
|
if (strncmp (current->name, tree->selected_ptr->name,
|
||||||
strlen (tree->selected_ptr->name)) == 0)
|
strlen (tree->selected_ptr->name)) == 0)
|
||||||
break;
|
break;
|
||||||
@ -362,7 +392,7 @@ show_tree (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_check_focus (WTree *tree)
|
tree_check_focus (WTree * tree)
|
||||||
{
|
{
|
||||||
if (tree->topdiff < 3)
|
if (tree->topdiff < 3)
|
||||||
tree->topdiff = 3;
|
tree->topdiff = 3;
|
||||||
@ -371,19 +401,21 @@ tree_check_focus (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_move_backward (WTree *tree, int i)
|
tree_move_backward (WTree * tree, int i)
|
||||||
{
|
{
|
||||||
if (!tree_navigation_flag)
|
if (!tree_navigation_flag)
|
||||||
tree->selected_ptr = back_ptr (tree->selected_ptr, &i);
|
tree->selected_ptr = back_ptr (tree->selected_ptr, &i);
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
tree_entry *current;
|
tree_entry *current;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
current = tree->selected_ptr;
|
current = tree->selected_ptr;
|
||||||
while (j < i && current->prev
|
while (j < i && current->prev && current->prev->sublevel >= tree->selected_ptr->sublevel)
|
||||||
&& current->prev->sublevel >= tree->selected_ptr->sublevel){
|
{
|
||||||
current = current->prev;
|
current = current->prev;
|
||||||
if (current->sublevel == tree->selected_ptr->sublevel){
|
if (current->sublevel == tree->selected_ptr->sublevel)
|
||||||
|
{
|
||||||
tree->selected_ptr = current;
|
tree->selected_ptr = current;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
@ -396,21 +428,23 @@ tree_move_backward (WTree *tree, int i)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_move_forward (WTree *tree, int i)
|
tree_move_forward (WTree * tree, int i)
|
||||||
{
|
{
|
||||||
if (!tree_navigation_flag)
|
if (!tree_navigation_flag)
|
||||||
tree->selected_ptr = forw_ptr (tree->selected_ptr, &i);
|
tree->selected_ptr = forw_ptr (tree->selected_ptr, &i);
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
tree_entry *current;
|
tree_entry *current;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
current = tree->selected_ptr;
|
current = tree->selected_ptr;
|
||||||
while (j < i && current->next
|
while (j < i && current->next && current->next->sublevel >= tree->selected_ptr->sublevel)
|
||||||
&& current->next->sublevel >= tree->selected_ptr->sublevel){
|
{
|
||||||
current = current->next;
|
current = current->next;
|
||||||
if (current->sublevel == tree->selected_ptr->sublevel){
|
if (current->sublevel == tree->selected_ptr->sublevel)
|
||||||
|
{
|
||||||
tree->selected_ptr = current;
|
tree->selected_ptr = current;
|
||||||
j ++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i = j;
|
i = j;
|
||||||
@ -421,7 +455,7 @@ tree_move_forward (WTree *tree, int i)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_move_to_child (WTree *tree)
|
tree_move_to_child (WTree * tree)
|
||||||
{
|
{
|
||||||
tree_entry *current;
|
tree_entry *current;
|
||||||
|
|
||||||
@ -431,16 +465,20 @@ tree_move_to_child (WTree *tree)
|
|||||||
/* Take the next entry */
|
/* Take the next entry */
|
||||||
current = tree->selected_ptr->next;
|
current = tree->selected_ptr->next;
|
||||||
/* Is it the child of the selected entry */
|
/* Is it the child of the selected entry */
|
||||||
if (current && current->sublevel > tree->selected_ptr->sublevel){
|
if (current && current->sublevel > tree->selected_ptr->sublevel)
|
||||||
|
{
|
||||||
/* Yes -> select this entry */
|
/* Yes -> select this entry */
|
||||||
tree->selected_ptr = current;
|
tree->selected_ptr = current;
|
||||||
tree->topdiff++;
|
tree->topdiff++;
|
||||||
tree_check_focus (tree);
|
tree_check_focus (tree);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* No -> rescan and try again */
|
/* No -> rescan and try again */
|
||||||
tree_rescan (tree);
|
tree_rescan (tree);
|
||||||
current = tree->selected_ptr->next;
|
current = tree->selected_ptr->next;
|
||||||
if (current && current->sublevel > tree->selected_ptr->sublevel){
|
if (current && current->sublevel > tree->selected_ptr->sublevel)
|
||||||
|
{
|
||||||
tree->selected_ptr = current;
|
tree->selected_ptr = current;
|
||||||
tree->topdiff++;
|
tree->topdiff++;
|
||||||
tree_check_focus (tree);
|
tree_check_focus (tree);
|
||||||
@ -449,7 +487,7 @@ tree_move_to_child (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
tree_move_to_parent (WTree *tree)
|
tree_move_to_parent (WTree * tree)
|
||||||
{
|
{
|
||||||
tree_entry *current;
|
tree_entry *current;
|
||||||
tree_entry *old;
|
tree_entry *old;
|
||||||
@ -459,7 +497,8 @@ tree_move_to_parent (WTree *tree)
|
|||||||
|
|
||||||
old = tree->selected_ptr;
|
old = tree->selected_ptr;
|
||||||
current = tree->selected_ptr->prev;
|
current = tree->selected_ptr->prev;
|
||||||
while (current && current->sublevel >= tree->selected_ptr->sublevel){
|
while (current && current->sublevel >= tree->selected_ptr->sublevel)
|
||||||
|
{
|
||||||
current = current->prev;
|
current = current->prev;
|
||||||
tree->topdiff--;
|
tree->topdiff--;
|
||||||
}
|
}
|
||||||
@ -471,14 +510,14 @@ tree_move_to_parent (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_move_to_top (WTree *tree)
|
tree_move_to_top (WTree * tree)
|
||||||
{
|
{
|
||||||
tree->selected_ptr = tree->store->tree_first;
|
tree->selected_ptr = tree->store->tree_first;
|
||||||
tree->topdiff = 0;
|
tree->topdiff = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_move_to_bottom (WTree *tree)
|
tree_move_to_bottom (WTree * tree)
|
||||||
{
|
{
|
||||||
tree->selected_ptr = tree->store->tree_last;
|
tree->selected_ptr = tree->store->tree_last;
|
||||||
tree->topdiff = tlines (tree) - 3 - 1;
|
tree->topdiff = tlines (tree) - 3 - 1;
|
||||||
@ -486,17 +525,18 @@ tree_move_to_bottom (WTree *tree)
|
|||||||
|
|
||||||
/* Handle mouse click */
|
/* Handle mouse click */
|
||||||
static void
|
static void
|
||||||
tree_event (WTree *tree, int y)
|
tree_event (WTree * tree, int y)
|
||||||
{
|
{
|
||||||
if (tree->tree_shown [y]){
|
if (tree->tree_shown[y])
|
||||||
tree->selected_ptr = tree->tree_shown [y];
|
{
|
||||||
|
tree->selected_ptr = tree->tree_shown[y];
|
||||||
tree->topdiff = y;
|
tree->topdiff = y;
|
||||||
}
|
}
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_chdir_sel (WTree *tree)
|
tree_chdir_sel (WTree * tree)
|
||||||
{
|
{
|
||||||
if (!tree->is_panel)
|
if (!tree->is_panel)
|
||||||
return;
|
return;
|
||||||
@ -514,7 +554,7 @@ tree_chdir_sel (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
maybe_chdir (WTree *tree)
|
maybe_chdir (WTree * tree)
|
||||||
{
|
{
|
||||||
if (xtree_mode && tree->is_panel && is_idle ())
|
if (xtree_mode && tree->is_panel && is_idle ())
|
||||||
tree_chdir_sel (tree);
|
tree_chdir_sel (tree);
|
||||||
@ -522,13 +562,13 @@ maybe_chdir (WTree *tree)
|
|||||||
|
|
||||||
/* Mouse callback */
|
/* Mouse callback */
|
||||||
static int
|
static int
|
||||||
event_callback (Gpm_Event *event, void *data)
|
event_callback (Gpm_Event * event, void *data)
|
||||||
{
|
{
|
||||||
WTree *tree = data;
|
WTree *tree = data;
|
||||||
|
|
||||||
/* rest of the upper frame, the menu is invisible - call menu */
|
/* rest of the upper frame, the menu is invisible - call menu */
|
||||||
if (tree->is_panel && (event->type & GPM_DOWN)
|
if (tree->is_panel && (event->type & GPM_DOWN) && event->y == 1 && !menubar_visible)
|
||||||
&& event->y == 1 && !menubar_visible) {
|
{
|
||||||
event->x += tree->widget.x;
|
event->x += tree->widget.x;
|
||||||
return the_menubar->widget.mouse (event, the_menubar);
|
return the_menubar->widget.mouse (event, the_menubar);
|
||||||
}
|
}
|
||||||
@ -544,15 +584,21 @@ event_callback (Gpm_Event *event, void *data)
|
|||||||
if (!tree->active)
|
if (!tree->active)
|
||||||
change_panel ();
|
change_panel ();
|
||||||
|
|
||||||
if (event->y < 0){
|
if (event->y < 0)
|
||||||
|
{
|
||||||
tree_move_backward (tree, tlines (tree) - 1);
|
tree_move_backward (tree, tlines (tree) - 1);
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
} else if (event->y >= tlines (tree)){
|
}
|
||||||
|
else if (event->y >= tlines (tree))
|
||||||
|
{
|
||||||
tree_move_forward (tree, tlines (tree) - 1);
|
tree_move_forward (tree, tlines (tree) - 1);
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
tree_event (tree, event->y);
|
tree_event (tree, event->y);
|
||||||
if ((event->type & (GPM_UP|GPM_DOUBLE)) == (GPM_UP|GPM_DOUBLE)){
|
if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE))
|
||||||
|
{
|
||||||
tree_chdir_sel (tree);
|
tree_chdir_sel (tree);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -561,7 +607,7 @@ event_callback (Gpm_Event *event, void *data)
|
|||||||
|
|
||||||
/* Search tree for text */
|
/* Search tree for text */
|
||||||
static int
|
static int
|
||||||
search_tree (WTree *tree, char *text)
|
search_tree (WTree * tree, char *text)
|
||||||
{
|
{
|
||||||
tree_entry *current;
|
tree_entry *current;
|
||||||
int len;
|
int len;
|
||||||
@ -571,14 +617,17 @@ search_tree (WTree *tree, char *text)
|
|||||||
len = strlen (text);
|
len = strlen (text);
|
||||||
current = tree->selected_ptr;
|
current = tree->selected_ptr;
|
||||||
found = 0;
|
found = 0;
|
||||||
while (!wrapped || current != tree->selected_ptr){
|
while (!wrapped || current != tree->selected_ptr)
|
||||||
if (strncmp (current->subname, text, len) == 0){
|
{
|
||||||
|
if (strncmp (current->subname, text, len) == 0)
|
||||||
|
{
|
||||||
tree->selected_ptr = current;
|
tree->selected_ptr = current;
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
current = current->next;
|
current = current->next;
|
||||||
if (!current){
|
if (!current)
|
||||||
|
{
|
||||||
current = tree->store->tree_first;
|
current = tree->store->tree_first;
|
||||||
wrapped = 1;
|
wrapped = 1;
|
||||||
}
|
}
|
||||||
@ -589,20 +638,21 @@ search_tree (WTree *tree, char *text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_do_search (WTree *tree, int key)
|
tree_do_search (WTree * tree, int key)
|
||||||
{
|
{
|
||||||
size_t l;
|
size_t l;
|
||||||
|
|
||||||
l = strlen (tree->search_buffer);
|
l = strlen (tree->search_buffer);
|
||||||
if ((l != 0) && (key == KEY_BACKSPACE))
|
if ((l != 0) && (key == KEY_BACKSPACE))
|
||||||
tree->search_buffer [--l] = '\0';
|
tree->search_buffer[--l] = '\0';
|
||||||
else if (key && l < sizeof (tree->search_buffer)){
|
else if (key && l < sizeof (tree->search_buffer))
|
||||||
tree->search_buffer [l] = key;
|
{
|
||||||
tree->search_buffer [++l] = '\0';
|
tree->search_buffer[l] = key;
|
||||||
|
tree->search_buffer[++l] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!search_tree (tree, tree->search_buffer))
|
if (!search_tree (tree, tree->search_buffer))
|
||||||
tree->search_buffer [--l] = 0;
|
tree->search_buffer[--l] = 0;
|
||||||
|
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
maybe_chdir (tree);
|
maybe_chdir (tree);
|
||||||
@ -611,7 +661,7 @@ tree_do_search (WTree *tree, int key)
|
|||||||
static void
|
static void
|
||||||
tree_rescan (void *data)
|
tree_rescan (void *data)
|
||||||
{
|
{
|
||||||
char old_dir [MC_MAXPATHLEN];
|
char old_dir[MC_MAXPATHLEN];
|
||||||
WTree *tree = data;
|
WTree *tree = data;
|
||||||
|
|
||||||
if (!tree->selected_ptr || !mc_get_current_wd (old_dir, MC_MAXPATHLEN) ||
|
if (!tree->selected_ptr || !mc_get_current_wd (old_dir, MC_MAXPATHLEN) ||
|
||||||
@ -631,9 +681,9 @@ tree_forget (void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_copy (WTree *tree, const char *default_dest)
|
tree_copy (WTree * tree, const char *default_dest)
|
||||||
{
|
{
|
||||||
char msg [BUF_MEDIUM];
|
char msg[BUF_MEDIUM];
|
||||||
char *dest;
|
char *dest;
|
||||||
|
|
||||||
if (tree->selected_ptr == NULL)
|
if (tree->selected_ptr == NULL)
|
||||||
@ -641,10 +691,11 @@ tree_copy (WTree *tree, const char *default_dest)
|
|||||||
|
|
||||||
g_snprintf (msg, sizeof (msg), _("Copy \"%s\" directory to:"),
|
g_snprintf (msg, sizeof (msg), _("Copy \"%s\" directory to:"),
|
||||||
str_trunc (tree->selected_ptr->name, 50));
|
str_trunc (tree->selected_ptr->name, 50));
|
||||||
dest = input_expand_dialog (Q_("DialogTitle|Copy"),
|
dest = input_expand_dialog (Q_ ("DialogTitle|Copy"),
|
||||||
msg, MC_HISTORY_FM_TREE_COPY, default_dest);
|
msg, MC_HISTORY_FM_TREE_COPY, default_dest);
|
||||||
|
|
||||||
if (dest != NULL && *dest != '\0') {
|
if (dest != NULL && *dest != '\0')
|
||||||
|
{
|
||||||
FileOpContext *ctx;
|
FileOpContext *ctx;
|
||||||
FileOpTotalContext *tctx;
|
FileOpTotalContext *tctx;
|
||||||
|
|
||||||
@ -662,9 +713,9 @@ tree_copy (WTree *tree, const char *default_dest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_move (WTree *tree, const char *default_dest)
|
tree_move (WTree * tree, const char *default_dest)
|
||||||
{
|
{
|
||||||
char msg [BUF_MEDIUM];
|
char msg[BUF_MEDIUM];
|
||||||
char *dest;
|
char *dest;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
FileOpContext *ctx;
|
FileOpContext *ctx;
|
||||||
@ -675,23 +726,26 @@ tree_move (WTree *tree, const char *default_dest)
|
|||||||
|
|
||||||
g_snprintf (msg, sizeof (msg), _("Move \"%s\" directory to:"),
|
g_snprintf (msg, sizeof (msg), _("Move \"%s\" directory to:"),
|
||||||
str_trunc (tree->selected_ptr->name, 50));
|
str_trunc (tree->selected_ptr->name, 50));
|
||||||
dest = input_expand_dialog (Q_("DialogTitle|Move"), msg, MC_HISTORY_FM_TREE_MOVE, default_dest);
|
dest =
|
||||||
|
input_expand_dialog (Q_ ("DialogTitle|Move"), msg, MC_HISTORY_FM_TREE_MOVE, default_dest);
|
||||||
|
|
||||||
if (dest == NULL || *dest == '\0') {
|
if (dest == NULL || *dest == '\0')
|
||||||
|
{
|
||||||
g_free (dest);
|
g_free (dest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat (dest, &buf)){
|
if (stat (dest, &buf))
|
||||||
|
{
|
||||||
message (D_ERROR, MSG_ERROR, _(" Cannot stat the destination \n %s "),
|
message (D_ERROR, MSG_ERROR, _(" Cannot stat the destination \n %s "),
|
||||||
unix_error_string (errno));
|
unix_error_string (errno));
|
||||||
g_free (dest);
|
g_free (dest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!S_ISDIR (buf.st_mode)){
|
if (!S_ISDIR (buf.st_mode))
|
||||||
file_error (_(" Destination \"%s\" must be a directory \n %s "),
|
{
|
||||||
dest);
|
file_error (_(" Destination \"%s\" must be a directory \n %s "), dest);
|
||||||
g_free (dest);
|
g_free (dest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -708,9 +762,9 @@ tree_move (WTree *tree, const char *default_dest)
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
static void
|
static void
|
||||||
tree_mkdir (WTree *tree)
|
tree_mkdir (WTree * tree)
|
||||||
{
|
{
|
||||||
char old_dir [MC_MAXPATHLEN];
|
char old_dir[MC_MAXPATHLEN];
|
||||||
|
|
||||||
if (!tree->selected_ptr)
|
if (!tree->selected_ptr)
|
||||||
return;
|
return;
|
||||||
@ -736,15 +790,13 @@ tree_rmdir (void *data)
|
|||||||
if (!tree->selected_ptr)
|
if (!tree->selected_ptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (confirm_delete) {
|
if (confirm_delete)
|
||||||
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
buf =
|
buf = g_strdup_printf (_(" Delete %s? "), tree->selected_ptr->name);
|
||||||
g_strdup_printf (_(" Delete %s? "),
|
result = query_dialog (Q_ ("DialogTitle|Delete"), buf, D_ERROR, 2, _("&Yes"), _("&No"));
|
||||||
tree->selected_ptr->name);
|
|
||||||
result =
|
|
||||||
query_dialog (Q_("DialogTitle|Delete"), buf, D_ERROR, 2, _("&Yes"), _("&No"));
|
|
||||||
g_free (buf);
|
g_free (buf);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
return;
|
return;
|
||||||
@ -761,7 +813,7 @@ tree_rmdir (void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
tree_move_up (WTree *tree)
|
tree_move_up (WTree * tree)
|
||||||
{
|
{
|
||||||
tree_move_backward (tree, 1);
|
tree_move_backward (tree, 1);
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
@ -769,7 +821,7 @@ tree_move_up (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
tree_move_down (WTree *tree)
|
tree_move_down (WTree * tree)
|
||||||
{
|
{
|
||||||
tree_move_forward (tree, 1);
|
tree_move_forward (tree, 1);
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
@ -777,7 +829,7 @@ tree_move_down (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
tree_move_home (WTree *tree)
|
tree_move_home (WTree * tree)
|
||||||
{
|
{
|
||||||
tree_move_to_top (tree);
|
tree_move_to_top (tree);
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
@ -785,7 +837,7 @@ tree_move_home (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
tree_move_end (WTree *tree)
|
tree_move_end (WTree * tree)
|
||||||
{
|
{
|
||||||
tree_move_to_bottom (tree);
|
tree_move_to_bottom (tree);
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
@ -793,7 +845,7 @@ tree_move_end (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_move_pgup (WTree *tree)
|
tree_move_pgup (WTree * tree)
|
||||||
{
|
{
|
||||||
tree_move_backward (tree, tlines (tree) - 1);
|
tree_move_backward (tree, tlines (tree) - 1);
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
@ -801,7 +853,7 @@ tree_move_pgup (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_move_pgdn (WTree *tree)
|
tree_move_pgdn (WTree * tree)
|
||||||
{
|
{
|
||||||
tree_move_forward (tree, tlines (tree) - 1);
|
tree_move_forward (tree, tlines (tree) - 1);
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
@ -809,11 +861,12 @@ tree_move_pgdn (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
tree_move_left (WTree *tree)
|
tree_move_left (WTree * tree)
|
||||||
{
|
{
|
||||||
gboolean v = FALSE;
|
gboolean v = FALSE;
|
||||||
|
|
||||||
if (tree_navigation_flag) {
|
if (tree_navigation_flag)
|
||||||
|
{
|
||||||
v = tree_move_to_parent (tree);
|
v = tree_move_to_parent (tree);
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
maybe_chdir (tree);
|
maybe_chdir (tree);
|
||||||
@ -823,11 +876,12 @@ tree_move_left (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
tree_move_right (WTree *tree)
|
tree_move_right (WTree * tree)
|
||||||
{
|
{
|
||||||
gboolean v = FALSE;
|
gboolean v = FALSE;
|
||||||
|
|
||||||
if (tree_navigation_flag) {
|
if (tree_navigation_flag)
|
||||||
|
{
|
||||||
tree_move_to_child (tree);
|
tree_move_to_child (tree);
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
maybe_chdir (tree);
|
maybe_chdir (tree);
|
||||||
@ -838,14 +892,16 @@ tree_move_right (WTree *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_start_search (WTree *tree)
|
tree_start_search (WTree * tree)
|
||||||
{
|
{
|
||||||
gboolean i;
|
gboolean i;
|
||||||
|
|
||||||
if (tree->searching) {
|
if (tree->searching)
|
||||||
|
{
|
||||||
if (tree->selected_ptr == tree->store->tree_last)
|
if (tree->selected_ptr == tree->store->tree_last)
|
||||||
tree_move_to_top (tree);
|
tree_move_to_top (tree);
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
/* set navigation mode temporarily to 'Static' because in
|
/* set navigation mode temporarily to 'Static' because in
|
||||||
* dynamic navigation mode tree_move_forward will not move
|
* dynamic navigation mode tree_move_forward will not move
|
||||||
* to a lower sublevel if necessary (sequent searches must
|
* to a lower sublevel if necessary (sequent searches must
|
||||||
@ -857,31 +913,33 @@ tree_start_search (WTree *tree)
|
|||||||
tree_navigation_flag = i;
|
tree_navigation_flag = i;
|
||||||
}
|
}
|
||||||
tree_do_search (tree, 0);
|
tree_do_search (tree, 0);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
tree->searching = 1;
|
tree->searching = 1;
|
||||||
tree->search_buffer[0] = 0;
|
tree->search_buffer[0] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_toggle_navig (WTree *tree)
|
tree_toggle_navig (WTree * tree)
|
||||||
{
|
{
|
||||||
tree_navigation_flag = !tree_navigation_flag;
|
tree_navigation_flag = !tree_navigation_flag;
|
||||||
buttonbar_set_label (find_buttonbar (tree->widget.parent), 4,
|
buttonbar_set_label (find_buttonbar (tree->widget.parent), 4,
|
||||||
tree_navigation_flag ? Q_("ButtonBar|Static")
|
tree_navigation_flag ? Q_ ("ButtonBar|Static")
|
||||||
: Q_("ButtonBar|Dynamc"),
|
: Q_ ("ButtonBar|Dynamc"), tree_map, (Widget *) tree);
|
||||||
tree_map, (Widget *) tree);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
tree_execute_cmd (WTree *tree, unsigned long command)
|
tree_execute_cmd (WTree * tree, unsigned long command)
|
||||||
{
|
{
|
||||||
cb_ret_t res = MSG_HANDLED;
|
cb_ret_t res = MSG_HANDLED;
|
||||||
|
|
||||||
if (command != CK_TreeStartSearch)
|
if (command != CK_TreeStartSearch)
|
||||||
tree->searching = 0;
|
tree->searching = 0;
|
||||||
|
|
||||||
switch (command) {
|
switch (command)
|
||||||
|
{
|
||||||
case CK_TreeHelp:
|
case CK_TreeHelp:
|
||||||
interactive_display (NULL, "[Directory Tree]");
|
interactive_display (NULL, "[Directory Tree]");
|
||||||
break;
|
break;
|
||||||
@ -937,24 +995,27 @@ tree_execute_cmd (WTree *tree, unsigned long command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
tree_key (WTree *tree, int key)
|
tree_key (WTree * tree, int key)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; tree_map [i].key != 0; i++)
|
for (i = 0; tree_map[i].key != 0; i++)
|
||||||
if (key == tree_map [i].key)
|
if (key == tree_map[i].key)
|
||||||
switch (tree_map [i].command) {
|
switch (tree_map[i].command)
|
||||||
|
{
|
||||||
case CK_TreeMoveLeft:
|
case CK_TreeMoveLeft:
|
||||||
return tree_move_left (tree) ? MSG_HANDLED : MSG_NOT_HANDLED;
|
return tree_move_left (tree) ? MSG_HANDLED : MSG_NOT_HANDLED;
|
||||||
case CK_TreeMoveRight:
|
case CK_TreeMoveRight:
|
||||||
return tree_move_right (tree) ? MSG_HANDLED : MSG_NOT_HANDLED;
|
return tree_move_right (tree) ? MSG_HANDLED : MSG_NOT_HANDLED;
|
||||||
default:
|
default:
|
||||||
tree_execute_cmd (tree, tree_map [i].command);
|
tree_execute_cmd (tree, tree_map[i].command);
|
||||||
return MSG_HANDLED;
|
return MSG_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_abort_char (key)) {
|
if (is_abort_char (key))
|
||||||
if (tree->is_panel) {
|
{
|
||||||
|
if (tree->is_panel)
|
||||||
|
{
|
||||||
tree->searching = 0;
|
tree->searching = 0;
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
return MSG_HANDLED; /* eat abort char */
|
return MSG_HANDLED; /* eat abort char */
|
||||||
@ -965,14 +1026,17 @@ tree_key (WTree *tree, int key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Do not eat characters not meant for the tree below ' ' (e.g. C-l). */
|
/* Do not eat characters not meant for the tree below ' ' (e.g. C-l). */
|
||||||
if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE) {
|
if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE)
|
||||||
if (tree->searching){
|
{
|
||||||
|
if (tree->searching)
|
||||||
|
{
|
||||||
tree_do_search (tree, key);
|
tree_do_search (tree, key);
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
return MSG_HANDLED;
|
return MSG_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!command_prompt) {
|
if (!command_prompt)
|
||||||
|
{
|
||||||
tree_start_search (tree);
|
tree_start_search (tree);
|
||||||
tree_do_search (tree, key);
|
tree_do_search (tree, key);
|
||||||
return MSG_HANDLED;
|
return MSG_HANDLED;
|
||||||
@ -984,29 +1048,29 @@ tree_key (WTree *tree, int key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tree_frame (Dlg_head *h, WTree *tree)
|
tree_frame (Dlg_head * h, WTree * tree)
|
||||||
{
|
{
|
||||||
tty_setcolor (NORMAL_COLOR);
|
tty_setcolor (NORMAL_COLOR);
|
||||||
widget_erase ((Widget*) tree);
|
widget_erase ((Widget *) tree);
|
||||||
if (tree->is_panel) {
|
if (tree->is_panel)
|
||||||
draw_box (h, tree->widget.y, tree->widget.x, tree->widget.lines,
|
{
|
||||||
tree->widget.cols, FALSE);
|
draw_box (h, tree->widget.y, tree->widget.x, tree->widget.lines, tree->widget.cols, FALSE);
|
||||||
|
|
||||||
if (show_mini_info)
|
if (show_mini_info)
|
||||||
tty_draw_hline (tree->widget.y + tlines (tree) + 1,
|
tty_draw_hline (tree->widget.y + tlines (tree) + 1,
|
||||||
tree->widget.x + 1,
|
tree->widget.x + 1, ACS_HLINE, tree->widget.cols - 2);
|
||||||
ACS_HLINE, tree->widget.cols - 2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
tree_callback (Widget *w, widget_msg_t msg, int parm)
|
tree_callback (Widget * w, widget_msg_t msg, int parm)
|
||||||
{
|
{
|
||||||
WTree *tree = (WTree *) w;
|
WTree *tree = (WTree *) w;
|
||||||
Dlg_head *h = tree->widget.parent;
|
Dlg_head *h = tree->widget.parent;
|
||||||
WButtonBar *b = find_buttonbar (h);
|
WButtonBar *b = find_buttonbar (h);
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg)
|
||||||
|
{
|
||||||
case WIDGET_DRAW:
|
case WIDGET_DRAW:
|
||||||
tree_frame (h, tree);
|
tree_frame (h, tree);
|
||||||
show_tree (tree);
|
show_tree (tree);
|
||||||
@ -1014,21 +1078,20 @@ tree_callback (Widget *w, widget_msg_t msg, int parm)
|
|||||||
|
|
||||||
case WIDGET_FOCUS:
|
case WIDGET_FOCUS:
|
||||||
tree->active = 1;
|
tree->active = 1;
|
||||||
buttonbar_set_label (b, 1, Q_("ButtonBar|Help"), tree_map, (Widget *) tree);
|
buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), tree_map, (Widget *) tree);
|
||||||
buttonbar_set_label (b, 2, Q_("ButtonBar|Rescan"), tree_map, (Widget *) tree);
|
buttonbar_set_label (b, 2, Q_ ("ButtonBar|Rescan"), tree_map, (Widget *) tree);
|
||||||
buttonbar_set_label (b, 3, Q_("ButtonBar|Forget"), tree_map, (Widget *) tree);
|
buttonbar_set_label (b, 3, Q_ ("ButtonBar|Forget"), tree_map, (Widget *) tree);
|
||||||
buttonbar_set_label (b, 4, tree_navigation_flag ? Q_("ButtonBar|Static")
|
buttonbar_set_label (b, 4, tree_navigation_flag ? Q_ ("ButtonBar|Static")
|
||||||
: Q_("ButtonBar|Dynamc"),
|
: Q_ ("ButtonBar|Dynamc"), tree_map, (Widget *) tree);
|
||||||
tree_map, (Widget *) tree);
|
buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), tree_map, (Widget *) tree);
|
||||||
buttonbar_set_label (b, 5, Q_("ButtonBar|Copy"), tree_map, (Widget *) tree);
|
buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), tree_map, (Widget *) tree);
|
||||||
buttonbar_set_label (b, 6, Q_("ButtonBar|RenMov"), tree_map, (Widget *) tree);
|
|
||||||
#if 0
|
#if 0
|
||||||
/* FIXME: mkdir is currently defunct */
|
/* FIXME: mkdir is currently defunct */
|
||||||
buttonbar_set_label (b, 7, Q_("ButtonBar|Mkdir"), tree_map, (Widget *) tree);
|
buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), tree_map, (Widget *) tree);
|
||||||
#else
|
#else
|
||||||
buttonbar_clear_label (b, 7, (Widget *) tree);
|
buttonbar_clear_label (b, 7, (Widget *) tree);
|
||||||
#endif
|
#endif
|
||||||
buttonbar_set_label (b, 8, Q_("ButtonBar|Rmdir"), tree_map, (Widget *) tree);
|
buttonbar_set_label (b, 8, Q_ ("ButtonBar|Rmdir"), tree_map, (Widget *) tree);
|
||||||
buttonbar_redraw (b);
|
buttonbar_redraw (b);
|
||||||
|
|
||||||
/* FIXME: Should find a better way of only displaying the
|
/* FIXME: Should find a better way of only displaying the
|
||||||
@ -1065,8 +1128,7 @@ tree_new (int is_panel, int y, int x, int lines, int cols)
|
|||||||
{
|
{
|
||||||
WTree *tree = g_new (WTree, 1);
|
WTree *tree = g_new (WTree, 1);
|
||||||
|
|
||||||
init_widget (&tree->widget, y, x, lines, cols,
|
init_widget (&tree->widget, y, x, lines, cols, tree_callback, event_callback);
|
||||||
tree_callback, event_callback);
|
|
||||||
tree->is_panel = is_panel;
|
tree->is_panel = is_panel;
|
||||||
tree->selected_ptr = 0;
|
tree->selected_ptr = 0;
|
||||||
|
|
||||||
@ -1085,13 +1147,14 @@ tree_new (int is_panel, int y, int x, int lines, int cols)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tree_chdir (WTree *tree, const char *dir)
|
tree_chdir (WTree * tree, const char *dir)
|
||||||
{
|
{
|
||||||
tree_entry *current;
|
tree_entry *current;
|
||||||
|
|
||||||
current = tree_store_whereis (dir);
|
current = tree_store_whereis (dir);
|
||||||
|
|
||||||
if (current != NULL) {
|
if (current != NULL)
|
||||||
|
{
|
||||||
tree->selected_ptr = current;
|
tree->selected_ptr = current;
|
||||||
tree_check_focus (tree);
|
tree_check_focus (tree);
|
||||||
}
|
}
|
||||||
@ -1099,7 +1162,7 @@ tree_chdir (WTree *tree, const char *dir)
|
|||||||
|
|
||||||
/* Return name of the currently selected entry */
|
/* Return name of the currently selected entry */
|
||||||
char *
|
char *
|
||||||
tree_selected_name (const WTree *tree)
|
tree_selected_name (const WTree * tree)
|
||||||
{
|
{
|
||||||
return tree->selected_ptr->name;
|
return tree->selected_ptr->name;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user