diff --git a/lib/skin/lines.c b/lib/skin/lines.c index 0d84423c8..13138cd33 100644 --- a/lib/skin/lines.c +++ b/lib/skin/lines.c @@ -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); g_free (frm_val); -/* - switch (ret) { + +#if 0 + switch (ret) + { case 0x80: ret = ACS_HLINE; break; @@ -86,7 +88,8 @@ mc_skin_lines_load_frm (mc_skin_t * mc_skin, const char *name) default: break; } -*/ +#endif + return ret; } diff --git a/lib/tty/tty-ncurses.c b/lib/tty/tty-ncurses.c index 5a494f67d..143d9f649 100644 --- a/lib/tty/tty-ncurses.c +++ b/lib/tty/tty-ncurses.c @@ -37,7 +37,7 @@ #include #include "lib/global.h" -#include "lib/strutil.h" /* str_term_form */ +#include "lib/strutil.h" /* str_term_form */ #include "src/main.h" @@ -45,7 +45,7 @@ # define WANT_TERM_H #endif -#include "tty-internal.h" /* slow_tty */ +#include "tty-internal.h" /* slow_tty */ #include "tty.h" #include "color-internal.h" #include "win.h" @@ -85,7 +85,8 @@ mc_tty_normalize_lines_char (const char *ch) char *str2; int res; - struct mc_tty_lines_struct { + struct mc_tty_lines_struct + { const char *line; int line_code; } const lines_codes[] = { @@ -93,24 +94,24 @@ mc_tty_normalize_lines_char (const char *ch) {"\342\224\220", ACS_LLCORNER}, /* ┐ */ {"\342\224\224", ACS_URCORNER}, /* └ */ {"\342\224\230", ACS_ULCORNER}, /* ┘ */ - {"\342\224\234", ACS_LTEE}, /* ├ */ - {"\342\224\244", ACS_RTEE}, /* ┤ */ - {"\342\224\254", ACS_TTEE}, /* ┬ */ - {"\342\224\264", ACS_BTEE}, /* ┴ */ - {"\342\224\200", ACS_HLINE}, /* ─ */ - {"\342\224\202", ACS_VLINE}, /* │ */ - {"\342\224\274", ACS_PLUS}, /* ┼ */ + {"\342\224\234", ACS_LTEE}, /* ├ */ + {"\342\224\244", ACS_RTEE}, /* ┤ */ + {"\342\224\254", ACS_TTEE}, /* ┬ */ + {"\342\224\264", ACS_BTEE}, /* ┴ */ + {"\342\224\200", ACS_HLINE}, /* ─ */ + {"\342\224\202", ACS_VLINE}, /* │ */ + {"\342\224\274", ACS_PLUS}, /* ┼ */ - {"\342\225\235", ACS_LRCORNER | A_BOLD}, /* ╔ */ - {"\342\225\232", ACS_LLCORNER | A_BOLD}, /* ╗ */ - {"\342\225\227", ACS_URCORNER | A_BOLD}, /* ╚ */ - {"\342\225\224", ACS_ULCORNER | A_BOLD}, /* ╝ */ - {"\342\225\237", ACS_LTEE | A_BOLD}, /* ╟ */ - {"\342\225\242", ACS_RTEE | A_BOLD}, /* ╢ */ - {"\342\225\244", ACS_TTEE | A_BOLD}, /* ╤ */ - {"\342\225\247", ACS_BTEE | A_BOLD}, /* ╧ */ - {"\342\225\220", ACS_HLINE | A_BOLD}, /* ═ */ - {"\342\225\221", ACS_VLINE | A_BOLD}, /* ║ */ + {"\342\225\235", ACS_LRCORNER | A_BOLD}, /* ╔ */ + {"\342\225\232", ACS_LLCORNER | A_BOLD}, /* ╗ */ + {"\342\225\227", ACS_URCORNER | A_BOLD}, /* ╚ */ + {"\342\225\224", ACS_ULCORNER | A_BOLD}, /* ╝ */ + {"\342\225\237", ACS_LTEE | A_BOLD}, /* ╟ */ + {"\342\225\242", ACS_RTEE | A_BOLD}, /* ╢ */ + {"\342\225\244", ACS_TTEE | A_BOLD}, /* ╤ */ + {"\342\225\247", ACS_BTEE | A_BOLD}, /* ╧ */ + {"\342\225\220", ACS_HLINE | A_BOLD}, /* ═ */ + {"\342\225\221", ACS_VLINE | A_BOLD}, /* ║ */ {NULL, 0} }; @@ -118,7 +119,8 @@ mc_tty_normalize_lines_char (const char *ch) if (ch == NULL) 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) return lines_codes[res].line_code; } @@ -158,7 +160,7 @@ tty_init (gboolean slow, gboolean ugly_lines) #endif /* HAVE_ESCDELAY */ /* use Ctrl-g to generate SIGINT */ - cur_term->Nttyb.c_cc[VINTR] = CTRL ('g'); /* ^g */ + cur_term->Nttyb.c_cc[VINTR] = CTRL ('g'); /* ^g */ /* disable SIGQUIT to allow use Ctrl-\ key */ cur_term->Nttyb.c_cc[VQUIT] = NULL_VALUE; tcsetattr (cur_term->Filedes, TCSANOW, &cur_term->Nttyb); @@ -193,14 +195,14 @@ tty_reset_shell_mode (void) void tty_raw_mode (void) { - raw (); /* FIXME: uneeded? */ + raw (); /* FIXME: uneeded? */ cbreak (); } void tty_noraw_mode (void) { - nocbreak (); /* FIXME: unneeded? */ + nocbreak (); /* FIXME: unneeded? */ noraw (); } @@ -293,7 +295,8 @@ tty_fill_region (int y, int x, int rows, int cols, unsigned char ch) { int i; - for (i = 0; i < rows; i++) { + for (i = 0; i < rows; i++) + { move (y + i, x); hline (ch, cols); } @@ -324,18 +327,20 @@ tty_print_anychar (int c) { unsigned char str[6 + 1]; - if (utf8_display || c > 255) { + if (utf8_display || c > 255) + { int res = g_unichar_to_utf8 (c, (char *) str); - if (res == 0) { + if (res == 0) + { str[0] = '.'; str[1] = '\0'; - } else { - str[res] = '\0'; } + else + str[res] = '\0'; addstr (str_term_form ((char *) str)); - } else { - addch (c); } + else + addch (c); } diff --git a/lib/tty/tty-slang.c b/lib/tty/tty-slang.c index 00070bf90..73581e282 100644 --- a/lib/tty/tty-slang.c +++ b/lib/tty/tty-slang.c @@ -40,14 +40,14 @@ #include #include "lib/global.h" -#include "lib/strutil.h" /* str_term_form */ +#include "lib/strutil.h" /* str_term_form */ -#include "tty-internal.h" /* slow_tty */ +#include "tty-internal.h" /* slow_tty */ #include "tty.h" #include "color-slang.h" #include "color-internal.h" -#include "mouse.h" /* Gpm_Event is required in key.h */ -#include "key.h" /* define_sequence */ +#include "mouse.h" /* Gpm_Event is required in key.h */ +#include "key.h" /* define_sequence */ #include "win.h" @@ -83,44 +83,47 @@ static gboolean no_slang_delay; /* This table describes which capabilities we want and which values we * assign to them. */ -static const struct { +static const struct +{ int key_code; const char *key_name; -} key_table[] = { - { - KEY_F (0), "k0"}, { - KEY_F (1), "k1"}, { - KEY_F (2), "k2"}, { - KEY_F (3), "k3"}, { - KEY_F (4), "k4"}, { - KEY_F (5), "k5"}, { - KEY_F (6), "k6"}, { - KEY_F (7), "k7"}, { - KEY_F (8), "k8"}, { - KEY_F (9), "k9"}, { - KEY_F (10), "k;"}, { - KEY_F (11), "F1"}, { - KEY_F (12), "F2"}, { - KEY_F (13), "F3"}, { - KEY_F (14), "F4"}, { - KEY_F (15), "F5"}, { - KEY_F (16), "F6"}, { - KEY_F (17), "F7"}, { - KEY_F (18), "F8"}, { - KEY_F (19), "F9"}, { - KEY_F (20), "FA"}, { - KEY_IC, "kI"}, { - KEY_NPAGE, "kN"}, { - KEY_PPAGE, "kP"}, { - KEY_LEFT, "kl"}, { - KEY_RIGHT, "kr"}, { - KEY_UP, "ku"}, { - KEY_DOWN, "kd"}, { - KEY_DC, "kD"}, { - KEY_BACKSPACE, "kb"}, { - KEY_HOME, "kh"}, { - KEY_END, "@7"}, { - 0, NULL} +} key_table[] = +{ + /* *INDENT-OFF* */ + { KEY_F (0), "k0" }, + { KEY_F (1), "k1" }, + { KEY_F (2), "k2" }, + { KEY_F (3), "k3" }, + { KEY_F (4), "k4" }, + { KEY_F (5), "k5" }, + { KEY_F (6), "k6" }, + { KEY_F (7), "k7" }, + { KEY_F (8), "k8" }, + { KEY_F (9), "k9" }, + { KEY_F (10), "k;" }, + { KEY_F (11), "F1" }, + { KEY_F (12), "F2" }, + { KEY_F (13), "F3" }, + { KEY_F (14), "F4" }, + { KEY_F (15), "F5" }, + { KEY_F (16), "F6" }, + { KEY_F (17), "F7" }, + { KEY_F (18), "F8" }, + { KEY_F (19), "F9" }, + { KEY_F (20), "FA" }, + { KEY_IC, "kI" }, + { KEY_NPAGE, "kN" }, + { KEY_PPAGE, "kP" }, + { KEY_LEFT, "kl" }, + { KEY_RIGHT, "kr" }, + { KEY_UP, "ku" }, + { KEY_DOWN, "kd" }, + { KEY_DC, "kD" }, + { KEY_BACKSPACE, "kb" }, + { KEY_HOME, "kh" }, + { KEY_END, "@7" }, + { 0, NULL } + /* *INDENT-ON* */ }; /*** file scope functions **********************************************/ @@ -148,10 +151,12 @@ slang_reset_softkeys (void) static const char display[] = " "; char tmp[BUF_SMALL]; - for (key = 1; key < 9; key++) { + for (key = 1; key < 9; key++) + { g_snprintf (tmp, sizeof (tmp), "k%d", key); send = (char *) SLtt_tgetstr (tmp); - if (send != NULL) { + if (send != NULL) + { g_snprintf (tmp, sizeof (tmp), "\033&f%dk%dd%dL%s%s", key, (int) (sizeof (display) - 1), (int) strlen (send), display, send); SLtt_write_string (tmp); @@ -188,7 +193,8 @@ mc_tty_normalize_lines_char (const char *str) char *str2; int res; - struct mc_tty_lines_struct { + struct mc_tty_lines_struct + { const char *line; int line_code; } const lines_codes[] = { @@ -210,7 +216,8 @@ mc_tty_normalize_lines_char (const char *str) if (!str) 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) return lines_codes[res].line_code; } @@ -242,7 +249,8 @@ tty_init (gboolean slow, gboolean ugly_lines) * small, large and negative screen dimensions. */ 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, _("Screen size %dx%d is not supported.\n" "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)) 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 new_mode.c_cc[VDSUSP] = NULL_VALUE; /* to ignore ^Y */ #endif @@ -302,7 +311,8 @@ tty_shutdown (void) * active when the program was started up */ op_cap = SLtt_tgetstr ((char *) "op"); - if (op_cap != NULL) { + if (op_cap != NULL) + { fputs (op_cap, stdout); fflush (stdout); } @@ -379,7 +389,8 @@ tty_lowlevel_getch (void) return -1; c = SLang_getkey (); - if (c == SLANG_GETKEY_ERROR) { + if (c == SLANG_GETKEY_ERROR) + { fprintf (stderr, "SLang_getkey returned SLANG_GETKEY_ERROR\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) ch = mc_tty_frm[MC_TTY_FRM_HORIZ]; - if ((y < 0) || (x < 0)) { + if ((y < 0) || (x < 0)) + { y = SLsmg_get_row (); x = SLsmg_get_column (); - } else + } + else SLsmg_gotorc (y, x); if (ch == 0) @@ -447,10 +460,12 @@ tty_draw_vline (int y, int x, int ch, int len) if (ch == ACS_VLINE) ch = mc_tty_frm[MC_TTY_FRM_VERT]; - if ((y < 0) || (x < 0)) { + if ((y < 0) || (x < 0)) + { y = SLsmg_get_row (); x = SLsmg_get_column (); - } else + } + else SLsmg_gotorc (y, x); if (ch == 0) @@ -458,10 +473,12 @@ tty_draw_vline (int y, int x, int ch, int len) if (ch == ACS_VLINE) SLsmg_draw_vline (len); - else { + else + { int pos = 0; - while (len-- != 0) { + while (len-- != 0) + { SLsmg_gotorc (y + pos, x); tty_print_char (ch); pos++; @@ -501,12 +518,13 @@ tty_print_alt_char (int c, gboolean single) #define DRAW(x, y) (x == y) \ ? SLsmg_draw_object (SLsmg_get_row(), SLsmg_get_column(), x) \ : SLsmg_write_char ((unsigned int) y) - switch (c) { + switch (c) + { case ACS_VLINE: DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT]); break; case ACS_HLINE: - DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ]); + DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ]); break; case ACS_LTEE: DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_LEFTMIDDLE : MC_TTY_FRM_DLEFTMIDDLE]); @@ -540,16 +558,22 @@ tty_print_anychar (int c) { char str[6 + 1]; - if (c > 255) { + if (c > 255) + { int res = g_unichar_to_utf8 (c, str); - if (res == 0) { + if (res == 0) + { str[0] = '.'; str[1] = '\0'; - } else { + } + else + { str[res] = '\0'; } SLsmg_write_string ((char *) str_term_form (str)); - } else { + } + else + { SLsmg_write_char ((SLwchar_Type) ((unsigned int) c)); } } diff --git a/lib/tty/tty.c b/lib/tty/tty.c index c4625b310..0677a22fa 100644 --- a/lib/tty/tty.c +++ b/lib/tty/tty.c @@ -170,7 +170,8 @@ mc_tty_normalize_from_utf8 (const char *str) 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); str_close_conv (conv); return g_strdup (str); diff --git a/lib/tty/tty.h b/lib/tty/tty.h index b93bd6c3c..c5abd502b 100644 --- a/lib/tty/tty.h +++ b/lib/tty/tty.h @@ -11,7 +11,7 @@ #ifndef MC_TTY_H #define MC_TTY_H -#include "lib/global.h" /* include */ +#include "lib/global.h" /* include */ #ifdef HAVE_SLANG # include "tty-slang.h" @@ -51,9 +51,9 @@ extern int tty_lowlevel_getch (void); /* {{{ Output }}} */ /* - The output functions do not check themselves for screen overflows, - so make sure that you never write more than what fits on the screen. - While SLang provides such a feature, ncurses does not. + The output functions do not check themselves for screen overflows, + so make sure that you never write more than what fits on the screen. + While SLang provides such a feature, ncurses does not. */ extern int tty_reset_screen (void); @@ -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[]; -typedef enum { +typedef enum +{ /* single lines */ MC_TTY_FRM_VERT, MC_TTY_FRM_HORIZ, diff --git a/src/chmod.c b/src/chmod.c index e1e7f6471..6ee8c88d0 100644 --- a/src/chmod.c +++ b/src/chmod.c @@ -38,35 +38,35 @@ #include "lib/vfs/mc-vfs/vfs.h" #include "lib/strutil.h" -#include "dialog.h" /* add_widget() */ -#include "widget.h" /* NORMAL_BUTTON */ -#include "wtools.h" /* message() */ -#include "panel.h" /* do_file_mark() */ -#include "main.h" /* update_panels() */ -#include "layout.h" /* repaint_screen() */ +#include "dialog.h" /* add_widget() */ +#include "widget.h" /* NORMAL_BUTTON */ +#include "wtools.h" /* message() */ +#include "panel.h" /* do_file_mark() */ +#include "main.h" /* update_panels() */ +#include "layout.h" /* repaint_screen() */ #include "chmod.h" static int single_set; -#define PX 5 -#define PY 2 +#define PX 5 +#define PY 2 -#define FX 40 -#define FY 2 +#define FX 40 +#define FY 2 -#define BX 6 -#define BY 17 +#define BX 6 +#define BY 17 -#define TX 40 -#define TY 12 +#define TX 40 +#define TY 12 -#define PERMISSIONS 12 -#define BUTTONS 6 +#define PERMISSIONS 12 +#define BUTTONS 6 -#define B_MARKED B_USER -#define B_ALL (B_USER+1) -#define B_SETMRK (B_USER+2) -#define B_CLRMRK (B_USER+3) +#define B_MARKED B_USER +#define B_ALL (B_USER+1) +#define B_SETMRK (B_USER+2) +#define B_CLRMRK (B_USER+3) static int mode_change, need_update; static int c_file, end_chmod; @@ -81,41 +81,48 @@ static const char *c_fname, *c_fown, *c_fgrp; static WLabel *statl; -static struct { +static struct +{ mode_t mode; const char *text; int selected; WCheck *check; -} check_perm[PERMISSIONS] = +} check_perm[PERMISSIONS] = { - { S_IXOTH, N_("execute/search by others"), 0, 0, }, - { S_IWOTH, N_("write by others"), 0, 0, }, - { S_IROTH, N_("read by others"), 0, 0, }, - { S_IXGRP, N_("execute/search by group"), 0, 0, }, - { S_IWGRP, N_("write by group"), 0, 0, }, - { S_IRGRP, N_("read by group"), 0, 0, }, - { S_IXUSR, N_("execute/search by owner"), 0, 0, }, - { S_IWUSR, N_("write by owner"), 0, 0, }, - { S_IRUSR, N_("read by owner"), 0, 0, }, - { S_ISVTX, N_("sticky bit"), 0, 0, }, - { S_ISGID, N_("set group ID on execution"), 0, 0, }, - { S_ISUID, N_("set user ID on execution"), 0, 0, }, + /* *INDENT-OFF* */ + { S_IXOTH, N_("execute/search by others"), 0, 0 }, + { S_IWOTH, N_("write by others"), 0, 0 }, + { S_IROTH, N_("read by others"), 0, 0 }, + { S_IXGRP, N_("execute/search by group"), 0, 0 }, + { S_IWGRP, N_("write by group"), 0, 0 }, + { S_IRGRP, N_("read by group"), 0, 0 }, + { S_IXUSR, N_("execute/search by owner"), 0, 0 }, + { S_IWUSR, N_("write by owner"), 0, 0 }, + { S_IRUSR, N_("read by owner"), 0, 0 }, + { S_ISVTX, N_("sticky bit"), 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; const char *text; -} chmod_but[BUTTONS] = +} chmod_but[BUTTONS] = { - { B_CANCEL, NORMAL_BUTTON, 2, 33, N_("&Cancel") }, - { B_ENTER, DEFPUSH_BUTTON, 2, 17, N_("&Set") }, - { B_CLRMRK, NORMAL_BUTTON, 0, 42, N_("C&lear marked") }, - { B_SETMRK, NORMAL_BUTTON, 0, 27, N_("S&et marked") }, - { B_MARKED, NORMAL_BUTTON, 0, 12, N_("&Marked all") }, - { B_ALL, NORMAL_BUTTON, 0, 0, N_("Set &all") }, + /* *INDENT-OFF* */ + { B_CANCEL, NORMAL_BUTTON, 2, 33, N_("&Cancel") }, + { B_ENTER, DEFPUSH_BUTTON, 2, 17, N_("&Set") }, + { B_CLRMRK, NORMAL_BUTTON, 0, 42, N_("C&lear marked") }, + { B_SETMRK, NORMAL_BUTTON, 0, 27, N_("S&et marked") }, + { B_MARKED, NORMAL_BUTTON, 0, 12, N_("&Marked 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); check_perm[Id].selected ^= 1; @@ -125,12 +132,13 @@ static void chmod_toggle_select (Dlg_head *h, int Id) 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); tty_setcolor (COLOR_NORMAL); - + draw_box (h, PY, PX, PERMISSIONS + 2, 33, TRUE); draw_box (h, FY, FX, 10, 25, TRUE); @@ -142,7 +150,7 @@ static void chmod_refresh (Dlg_head *h) tty_print_string (_("Owner name")); dlg_move (h, FY + 7, FX + 2); tty_print_string (_("Group name")); - + dlg_move (h, TY, TX); tty_print_string (_("Use SPACE to change")); dlg_move (h, TY + 1, TX); @@ -161,38 +169,40 @@ static void chmod_refresh (Dlg_head *h) } static cb_ret_t -chmod_callback (Dlg_head *h, Widget *sender, - dlg_msg_t msg, int parm, void *data) +chmod_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { char buffer[BUF_TINY]; int id = h->current->dlg_id - BUTTONS + single_set * 2; - switch (msg) { + switch (msg) + { case DLG_ACTION: - if (id >= 0) { - c_stat ^= check_perm[id].mode; - g_snprintf (buffer, sizeof (buffer), "%o", c_stat); - label_set_text (statl, buffer); - chmod_toggle_select (h, id); - mode_change = 1; - } - return MSG_HANDLED; + if (id >= 0) + { + c_stat ^= check_perm[id].mode; + g_snprintf (buffer, sizeof (buffer), "%o", c_stat); + label_set_text (statl, buffer); + chmod_toggle_select (h, id); + mode_change = 1; + } + return MSG_HANDLED; case DLG_KEY: - if ((parm == 'T' || parm == 't' || parm == KEY_IC) && id > 0) { - chmod_toggle_select (h, id); - if (parm == KEY_IC) - dlg_one_down (h); - return MSG_HANDLED; - } - return MSG_NOT_HANDLED; + if ((parm == 'T' || parm == 't' || parm == KEY_IC) && id > 0) + { + chmod_toggle_select (h, id); + if (parm == KEY_IC) + dlg_one_down (h); + return MSG_HANDLED; + } + return MSG_NOT_HANDLED; case DLG_DRAW: - chmod_refresh (h); - return MSG_HANDLED; + chmod_refresh (h); + return MSG_HANDLED; default: - return default_dlg_callback (h, sender, msg, parm, data); + return default_dlg_callback (h, sender, msg, parm, data); } } @@ -207,178 +217,192 @@ init_chmod (void) single_set = (current_panel->marked < 2) ? 2 : 0; ch_dlg = - create_dlg (0, 0, 22 - single_set, 70, dialog_colors, - chmod_callback, "[Chmod]", _("Chmod command"), - DLG_CENTER | DLG_REVERSE); + create_dlg (0, 0, 22 - single_set, 70, dialog_colors, + chmod_callback, "[Chmod]", _("Chmod command"), DLG_CENTER | DLG_REVERSE); - for (i = 0; i < BUTTONS; i++) { - if (i == 2 && single_set) - break; - else - add_widget (ch_dlg, - button_new (BY + chmod_but[i].y - single_set, - BX + chmod_but[i].x, - chmod_but[i].ret_cmd, - chmod_but[i].flags, - _(chmod_but[i].text), 0)); + for (i = 0; i < BUTTONS; i++) + { + if (i == 2 && single_set) + break; + else + add_widget (ch_dlg, + button_new (BY + chmod_but[i].y - single_set, + BX + chmod_but[i].x, + chmod_but[i].ret_cmd, + chmod_but[i].flags, _(chmod_but[i].text), 0)); } - for (i = 0; i < PERMISSIONS; i++) { - check_perm[i].check = - check_new (PY + (PERMISSIONS - i), PX + 2, 0, - _(check_perm[i].text)); - add_widget (ch_dlg, check_perm[i].check); + for (i = 0; i < PERMISSIONS; i++) + { + check_perm[i].check = check_new (PY + (PERMISSIONS - i), PX + 2, 0, _(check_perm[i].text)); + add_widget (ch_dlg, check_perm[i].check); } return ch_dlg; } -static void chmod_done (void) +static void +chmod_done (void) { if (need_update) - update_panels (UP_OPTIMIZE, UP_KEEPSEL); + update_panels (UP_OPTIMIZE, UP_KEEPSEL); repaint_screen (); } -static char *next_file (void) +static char * +next_file (void) { while (!current_panel->dir.list[c_file].f.marked) - c_file++; + c_file++; 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 |= or_mask; - if (mc_chmod (current_panel->dir.list [c_file].fname, sf->st_mode) == -1) - message (D_ERROR, MSG_ERROR, _(" Cannot chmod \"%s\" \n %s "), - current_panel->dir.list [c_file].fname, unix_error_string (errno)); + if (mc_chmod (current_panel->dir.list[c_file].fname, sf->st_mode) == -1) + message (D_ERROR, MSG_ERROR, _(" Cannot chmod \"%s\" \n %s "), + current_panel->dir.list[c_file].fname, unix_error_string (errno)); do_file_mark (current_panel, c_file, 0); } -static void apply_mask (struct stat *sf) +static void +apply_mask (struct stat *sf) { char *fname; need_update = end_chmod = 1; do_chmod (sf); - do { - fname = next_file (); - if (mc_stat (fname, sf) != 0) - return; - c_stat = sf->st_mode; + do + { + fname = next_file (); + if (mc_stat (fname, sf) != 0) + return; + c_stat = sf->st_mode; - do_chmod (sf); - } while (current_panel->marked); + do_chmod (sf); + } + while (current_panel->marked); } -void chmod_cmd (void) +void +chmod_cmd (void) { - char buffer [BUF_TINY]; + char buffer[BUF_TINY]; char *fname; int i; struct stat sf_stat; Dlg_head *ch_dlg; - do { /* do while any files remaining */ - ch_dlg = init_chmod (); - if (current_panel->marked) - fname = next_file (); /* next marked file */ - else - fname = selection (current_panel)->fname; /* single file */ + do + { /* do while any files remaining */ + ch_dlg = init_chmod (); + if (current_panel->marked) + fname = next_file (); /* next marked file */ + else + fname = selection (current_panel)->fname; /* single file */ - if (mc_stat (fname, &sf_stat) != 0) { /* get status of file */ - destroy_dlg (ch_dlg); - break; - } - - c_stat = sf_stat.st_mode; - mode_change = 0; /* clear changes flag */ + if (mc_stat (fname, &sf_stat) != 0) + { /* get status of file */ + destroy_dlg (ch_dlg); + break; + } - /* set check buttons */ - for (i = 0; i < PERMISSIONS; i++){ - check_perm[i].check->state = (c_stat & check_perm[i].mode) ? 1 : 0; - check_perm[i].selected = 0; - } + c_stat = sf_stat.st_mode; + mode_change = 0; /* clear changes flag */ - /* Set the labels */ - c_fname = str_trunc (fname, 21); - add_widget (ch_dlg, label_new (FY+2, FX+2, c_fname)); - c_fown = str_trunc (get_owner (sf_stat.st_uid), 21); - add_widget (ch_dlg, label_new (FY+6, FX+2, c_fown)); - c_fgrp = str_trunc (get_group (sf_stat.st_gid), 21); - add_widget (ch_dlg, label_new (FY+8, FX+2, c_fgrp)); - g_snprintf (buffer, sizeof (buffer), "%o", c_stat); - statl = label_new (FY+4, FX+2, buffer); - add_widget (ch_dlg, statl); - - run_dlg (ch_dlg); /* retrieve an action */ - - /* do action */ - switch (ch_dlg->ret_value){ - case B_ENTER: - if (mode_change) - if (mc_chmod (fname, c_stat) == -1) - message (D_ERROR, MSG_ERROR, _(" Cannot chmod \"%s\" \n %s "), - fname, unix_error_string (errno)); - need_update = 1; - break; - - case B_CANCEL: - end_chmod = 1; - break; - - case B_ALL: - case B_MARKED: - and_mask = or_mask = 0; - and_mask = ~and_mask; + /* set check buttons */ + for (i = 0; i < PERMISSIONS; i++) + { + check_perm[i].check->state = (c_stat & check_perm[i].mode) ? 1 : 0; + check_perm[i].selected = 0; + } - for (i = 0; i < PERMISSIONS; i++) { - if (check_perm[i].selected || ch_dlg->ret_value == B_ALL) { - if (check_perm[i].check->state & C_BOOL) - or_mask |= check_perm[i].mode; - else - and_mask &= ~check_perm[i].mode; - } - } + /* Set the labels */ + c_fname = str_trunc (fname, 21); + add_widget (ch_dlg, label_new (FY + 2, FX + 2, c_fname)); + c_fown = str_trunc (get_owner (sf_stat.st_uid), 21); + add_widget (ch_dlg, label_new (FY + 6, FX + 2, c_fown)); + c_fgrp = str_trunc (get_group (sf_stat.st_gid), 21); + add_widget (ch_dlg, label_new (FY + 8, FX + 2, c_fgrp)); + g_snprintf (buffer, sizeof (buffer), "%o", c_stat); + statl = label_new (FY + 4, FX + 2, buffer); + add_widget (ch_dlg, statl); - apply_mask (&sf_stat); - break; - - case B_SETMRK: - and_mask = or_mask = 0; - and_mask = ~and_mask; + run_dlg (ch_dlg); /* retrieve an action */ - for (i = 0; i < PERMISSIONS; i++) { - if (check_perm[i].selected) - or_mask |= check_perm[i].mode; - } + /* do action */ + switch (ch_dlg->ret_value) + { + case B_ENTER: + if (mode_change) + if (mc_chmod (fname, c_stat) == -1) + message (D_ERROR, MSG_ERROR, _(" Cannot chmod \"%s\" \n %s "), + fname, unix_error_string (errno)); + need_update = 1; + break; - apply_mask (&sf_stat); - break; - case B_CLRMRK: - and_mask = or_mask = 0; - and_mask = ~and_mask; + case B_CANCEL: + end_chmod = 1; + break; - for (i = 0; i < PERMISSIONS; i++) { - if (check_perm[i].selected) - and_mask &= ~check_perm[i].mode; - } + case B_ALL: + case B_MARKED: + and_mask = or_mask = 0; + and_mask = ~and_mask; - apply_mask (&sf_stat); - break; - } + for (i = 0; i < PERMISSIONS; i++) + { + if (check_perm[i].selected || ch_dlg->ret_value == B_ALL) + { + if (check_perm[i].check->state & C_BOOL) + or_mask |= check_perm[i].mode; + else + and_mask &= ~check_perm[i].mode; + } + } - if (current_panel->marked && ch_dlg->ret_value!=B_CANCEL) { - do_file_mark (current_panel, c_file, 0); - need_update = 1; - } - destroy_dlg (ch_dlg); - } while (current_panel->marked && !end_chmod); + apply_mask (&sf_stat); + break; + + case B_SETMRK: + and_mask = or_mask = 0; + and_mask = ~and_mask; + + for (i = 0; i < PERMISSIONS; i++) + { + if (check_perm[i].selected) + or_mask |= check_perm[i].mode; + } + + apply_mask (&sf_stat); + break; + case B_CLRMRK: + and_mask = or_mask = 0; + and_mask = ~and_mask; + + for (i = 0; i < PERMISSIONS; i++) + { + if (check_perm[i].selected) + and_mask &= ~check_perm[i].mode; + } + + apply_mask (&sf_stat); + break; + } + + if (current_panel->marked && ch_dlg->ret_value != B_CANCEL) + { + do_file_mark (current_panel, c_file, 0); + need_update = 1; + } + destroy_dlg (ch_dlg); + } + while (current_panel->marked && !end_chmod); chmod_done (); } - diff --git a/src/chown.c b/src/chown.c index 8cdf340e2..81f30f3b4 100644 --- a/src/chown.c +++ b/src/chown.c @@ -51,19 +51,19 @@ #include "chown.h" #include "wtools.h" /* For init_box_colors */ -#define UX 5 -#define UY 2 +#define UX 5 +#define UY 2 -#define GX 27 -#define GY 2 +#define GX 27 +#define GY 2 -#define BX 5 -#define BY 15 +#define BX 5 +#define BY 15 -#define TX 50 -#define TY 2 +#define TX 50 +#define TY 2 -#define BUTTONS 5 +#define BUTTONS 5 #define B_SETALL B_USER #define B_SETUSR (B_USER + 1) @@ -91,11 +91,11 @@ static struct { int y, x; WLabel *l; } chown_label [LABELS] = { -{ TY+2, TX+2, NULL }, -{ TY+4, TX+2, NULL }, -{ TY+6, TX+2, NULL }, -{ TY+8, TX+2, NULL }, -{ TY+10,TX+2, NULL } + { TY + 2, TX + 2, NULL }, + { TY + 4, TX + 2, NULL }, + { TY + 6, TX + 2, NULL }, + { TY + 8, TX + 2, NULL }, + { TY + 10,TX + 2, NULL } }; /* *INDENT-ON* */ diff --git a/src/dialog.c b/src/dialog.c index e10232695..313f7929a 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -37,16 +37,16 @@ #include "lib/tty/key.h" #include "lib/strutil.h" -#include "help.h" /* interactive_display() */ +#include "help.h" /* interactive_display() */ #include "dialog.h" #include "layout.h" -#include "execute.h" /* suspend_cmd() */ -#include "main.h" /* fast_refresh */ -#include "setup.h" /* mouse_close_dialog */ +#include "execute.h" /* suspend_cmd() */ +#include "main.h" /* fast_refresh */ +#include "setup.h" /* mouse_close_dialog */ /* Color styles for normal and error dialogs */ -int dialog_colors [4]; -int alarm_colors [4]; +int dialog_colors[4]; +int alarm_colors[4]; /* Primitive way to check if the the current dialog is our dialog */ /* This is needed by async routines like load_prompt */ @@ -58,32 +58,31 @@ Hook *idle_hook = 0; /* left click outside of dialog closes it */ int mouse_close_dialog = 0; -static void dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t message, - int reverse, int flags); +static void dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t message, int reverse, int flags); /* draw box in window */ 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); } void -widget_erase (Widget *w) +widget_erase (Widget * w) { tty_fill_region (w->y, w->x, w->lines, w->cols, ' '); } void -dlg_erase (Dlg_head *h) +dlg_erase (Dlg_head * h) { 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 -init_widget (Widget *w, int y, int x, int lines, int cols, - callback_fn callback, mouse_h mouse_handler) +init_widget (Widget * w, int y, int x, int lines, int cols, + callback_fn callback, mouse_h mouse_handler) { w->x = x; w->y = y; @@ -109,16 +108,17 @@ common_dialog_repaint (struct Dlg_head *h) dlg_erase (h); draw_box (h, space, space, h->lines - 2 * space, h->cols - 2 * space, FALSE); - if (h->title) { - tty_setcolor (DLG_HOT_NORMALC (h)); - dlg_move (h, space, (h->cols - str_term_width1 (h->title)) / 2); - tty_print_string (h->title); + if (h->title) + { + tty_setcolor (DLG_HOT_NORMALC (h)); + dlg_move (h, space, (h->cols - str_term_width1 (h->title)) / 2); + tty_print_string (h->title); } } /* this function allows to set dialog position */ 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 */ int ox, oy, oc, ol; @@ -142,57 +142,65 @@ dlg_set_position (Dlg_head *h, int y1, int x1, int y2, int x2) scale_y = h->lines - ol; if (h->current == NULL) - return; + return; - if ((shift_x != 0) || (shift_y != 0) || (scale_x != 0) || (scale_y != 0)) { - Widget *c = h->current; + if ((shift_x != 0) || (shift_y != 0) || (scale_x != 0) || (scale_y != 0)) + { + Widget *c = h->current; - do { - /* there are, mainly, 2 generally possible - situations: + do + { + /* there are, mainly, 2 generally possible + situations: - 1. control sticks to one side - it - should be moved + 1. control sticks to one side - it + should be moved - 2. control sticks to two sides of - one direction - it should be sized */ + 2. control sticks to two sides of + one direction - it should be sized */ - int x = c->x; - int y = c->y; - int cols = c->cols; - int lines = c->lines; + int x = c->x; + int y = c->y; + int cols = c->cols; + int lines = c->lines; - if ((c->pos_flags & WPOS_KEEP_LEFT) && (c->pos_flags & WPOS_KEEP_RIGHT)) { - x += shift_x; - cols += scale_x; - } else if (c->pos_flags & WPOS_KEEP_LEFT) - x += shift_x; - else if (c->pos_flags & WPOS_KEEP_RIGHT) - x += shift_x + scale_x; + if ((c->pos_flags & WPOS_KEEP_LEFT) && (c->pos_flags & WPOS_KEEP_RIGHT)) + { + x += shift_x; + cols += scale_x; + } + else if (c->pos_flags & WPOS_KEEP_LEFT) + x += shift_x; + else if (c->pos_flags & WPOS_KEEP_RIGHT) + x += shift_x + scale_x; - if ((c->pos_flags & WPOS_KEEP_TOP) && (c->pos_flags & WPOS_KEEP_BOTTOM)) { - y += shift_y; - lines += scale_y; - } else if (c->pos_flags & WPOS_KEEP_TOP) - y += shift_y; - else if (c->pos_flags & WPOS_KEEP_BOTTOM) - y += shift_y + scale_y; + if ((c->pos_flags & WPOS_KEEP_TOP) && (c->pos_flags & WPOS_KEEP_BOTTOM)) + { + y += shift_y; + lines += scale_y; + } + else if (c->pos_flags & WPOS_KEEP_TOP) + y += shift_y; + else if (c->pos_flags & WPOS_KEEP_BOTTOM) + y += shift_y + scale_y; - widget_set_size (c, y, x, lines, cols); + widget_set_size (c, y, x, lines, cols); - c = c->next; - } while (h->current != c); + c = c->next; + } + while (h->current != c); } } /* this function sets only size, leaving positioning to automatic methods */ 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 y = h->y; - if (h->flags & DLG_CENTER) { + if (h->flags & DLG_CENTER) + { y = (LINES - lines) / 2; x = (COLS - cols) / 2; } @@ -205,36 +213,37 @@ dlg_set_size (Dlg_head *h, int lines, int cols) /* Default dialog callback */ cb_ret_t -default_dlg_callback (Dlg_head *h, Widget *sender, - dlg_msg_t msg, int parm, void *data) +default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { (void) sender; (void) parm; (void) data; - switch (msg) { + switch (msg) + { case DLG_DRAW: - if (h->color != NULL) { - common_dialog_repaint (h); - return MSG_HANDLED; - } - return MSG_NOT_HANDLED; + if (h->color != NULL) + { + common_dialog_repaint (h); + return MSG_HANDLED; + } + return MSG_NOT_HANDLED; case DLG_IDLE: - dlg_broadcast_msg_to (h, WIDGET_IDLE, 0, W_WANT_IDLE); - return MSG_HANDLED; + dlg_broadcast_msg_to (h, WIDGET_IDLE, 0, W_WANT_IDLE); + return MSG_HANDLED; case DLG_RESIZE: - /* this is default resizing mechanism */ - /* the main idea of this code is to resize dialog - according to flags (if any of flags require automatic - resizing, like DLG_CENTER, end after that reposition - controls in dialog according to flags of widget) */ - dlg_set_size (h, h->lines, h->cols); - return MSG_HANDLED; + /* this is default resizing mechanism */ + /* the main idea of this code is to resize dialog + according to flags (if any of flags require automatic + resizing, like DLG_CENTER, end after that reposition + controls in dialog according to flags of widget) */ + dlg_set_size (h, h->lines, h->cols); + return MSG_HANDLED; default: - break; + break; } return MSG_NOT_HANDLED; @@ -242,15 +251,15 @@ default_dlg_callback (Dlg_head *h, Widget *sender, Dlg_head * create_dlg (int y1, int x1, int lines, int cols, const int *colors, - dlg_cb_fn callback, const char *help_ctx, const char *title, - int flags) + dlg_cb_fn callback, const char *help_ctx, const char *title, int flags) { Dlg_head *new_d; new_d = g_new0 (Dlg_head, 1); - if (colors != NULL) { - new_d->color = g_new (int, DLG_COLOR_NUM); - memmove (new_d->color, colors, sizeof (int) * DLG_COLOR_NUM); + if (colors != NULL) + { + new_d->color = g_new (int, DLG_COLOR_NUM); + memmove (new_d->color, colors, sizeof (int) * DLG_COLOR_NUM); } new_d->help_ctx = help_ctx; new_d->callback = (callback != NULL) ? callback : default_dlg_callback; @@ -262,13 +271,14 @@ create_dlg (int y1, int x1, int lines, int cols, const int *colors, dlg_set_size (new_d, lines, cols); /* Strip existing spaces, add one space before and after the title */ - if (title) { - char *t; + if (title) + { + char *t; - t = g_strstrip (g_strdup (title)); - if (*t != '\0') - new_d->title = g_strdup_printf (" %s ", t); - g_free (t); + t = g_strstrip (g_strdup (title)); + if (*t != '\0') + new_d->title = g_strdup_printf (" %s ", t); + g_free (t); } return new_d; @@ -277,24 +287,24 @@ create_dlg (int y1, int x1, int lines, int cols, const int *colors, void dlg_set_default_colors (void) { - dialog_colors [0] = COLOR_NORMAL; - dialog_colors [1] = COLOR_FOCUS; - dialog_colors [2] = COLOR_HOT_NORMAL; - dialog_colors [3] = COLOR_HOT_FOCUS; + dialog_colors[0] = COLOR_NORMAL; + dialog_colors[1] = COLOR_FOCUS; + dialog_colors[2] = COLOR_HOT_NORMAL; + dialog_colors[3] = COLOR_HOT_FOCUS; - alarm_colors [0] = ERROR_COLOR; - alarm_colors [1] = REVERSE_COLOR; - alarm_colors [2] = ERROR_HOT_NORMAL; - alarm_colors [3] = ERROR_HOT_FOCUS; + alarm_colors[0] = ERROR_COLOR; + alarm_colors[1] = REVERSE_COLOR; + alarm_colors[2] = ERROR_HOT_NORMAL; + alarm_colors[3] = ERROR_HOT_FOCUS; } void -set_idle_proc (Dlg_head *d, int enable) +set_idle_proc (Dlg_head * d, int enable) { if (enable) - d->flags |= DLG_WANT_IDLE; + d->flags |= DLG_WANT_IDLE; else - d->flags &= ~DLG_WANT_IDLE; + d->flags &= ~DLG_WANT_IDLE; } /* @@ -302,13 +312,13 @@ set_idle_proc (Dlg_head *d, int enable) * from the bottom, make the widget current. Return widget number. */ 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; /* Don't accept 0 widgets, and running dialogs */ if (!widget || h->running) - abort (); + abort (); widget->x += h->x; widget->y += h->y; @@ -316,34 +326,37 @@ add_widget_autopos (Dlg_head *h, void *w, widget_pos_flags_t pos_flags) widget->dlg_id = h->count++; widget->pos_flags = pos_flags; - if (h->current) { - widget->next = h->current; - widget->prev = h->current->prev; - h->current->prev->next = widget; - h->current->prev = widget; - } else { - widget->prev = widget; - widget->next = widget; + if (h->current) + { + widget->next = h->current; + widget->prev = h->current->prev; + h->current->prev->next = widget; + h->current->prev = widget; + } + else + { + widget->prev = widget; + widget->next = widget; } if ((h->flags & DLG_REVERSE) || !h->current) - h->current = widget; + h->current = widget; return widget->dlg_id; } /* wrapper to simply add lefttop positioned controls */ 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); } static void -do_complete_refresh (Dlg_head *dlg) +do_complete_refresh (Dlg_head * dlg) { if (!dlg->fullscreen && dlg->parent) - do_complete_refresh (dlg->parent); + do_complete_refresh (dlg->parent); dlg_redraw (dlg); } @@ -352,13 +365,12 @@ void do_refresh (void) { if (!current_dlg) - return; + return; if (fast_refresh) - dlg_redraw (current_dlg); - else { - do_complete_refresh (current_dlg); - } + dlg_redraw (current_dlg); + else + do_complete_refresh (current_dlg); } /* broadcast a message to all the widgets in a dialog that have @@ -366,88 +378,91 @@ do_refresh (void) * to all widgets. */ static void -dlg_broadcast_msg_to (Dlg_head *h, widget_msg_t message, int reverse, - int flags) +dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t message, int reverse, int flags) { Widget *p, *first, *wi; if (!h->current) - return; + return; if (reverse) - first = p = h->current->prev; + first = p = h->current->prev; else - first = p = h->current->next; + first = p = h->current->next; - do { - wi = p; - if (reverse) - p = p->prev; - else - p = p->next; - if (flags == 0 || (flags & wi->options)) - send_message (wi, message, 0); - } while (first != p); + do + { + wi = p; + if (reverse) + p = p->prev; + else + p = p->next; + if (flags == 0 || (flags & wi->options)) + send_message (wi, message, 0); + } + while (first != p); } /* broadcast a message to all the widgets in a dialog */ 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); } int -dlg_focus (Dlg_head *h) +dlg_focus (Dlg_head * h) { - if ((h->current != NULL) - && (send_message (h->current, WIDGET_FOCUS, 0) == MSG_HANDLED)) { - h->callback (h, h->current, DLG_FOCUS, 0, NULL); - return 1; - } + if ((h->current != NULL) && (send_message (h->current, WIDGET_FOCUS, 0) == MSG_HANDLED)) + { + h->callback (h, h->current, DLG_FOCUS, 0, NULL); + return 1; + } return 0; } static int -dlg_unfocus (Dlg_head *h) +dlg_unfocus (Dlg_head * h) { - if ((h->current != NULL) - && (send_message (h->current, WIDGET_UNFOCUS, 0) == MSG_HANDLED)) { - h->callback (h, h->current, DLG_UNFOCUS, 0, NULL); - return 1; - } + if ((h->current != NULL) && (send_message (h->current, WIDGET_UNFOCUS, 0) == MSG_HANDLED)) + { + h->callback (h, h->current, DLG_UNFOCUS, 0, NULL); + return 1; + } return 0; } /* 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) - || (a->x >= b->x + b->cols) - || (b->y >= a->y + a->lines) - || (a->y >= b->y + b->lines)) - return 0; + || (a->x >= b->x + b->cols) || (b->y >= a->y + a->lines) || (a->y >= b->y + b->lines)) + return 0; return 1; } /* Find the widget with the given callback in the dialog h */ Widget * -find_widget_type (const Dlg_head *h, callback_fn callback) +find_widget_type (const Dlg_head * h, callback_fn callback) { Widget *w = NULL; - if ((h != NULL) && (h->current != NULL)) { - int i; - Widget *item; + if ((h != NULL) && (h->current != NULL)) + { + int i; + Widget *item; - for (i = 0, item = h->current; i < h->count; i++, item = item->next) { - if (item->callback == callback) { - w = item; - break; - } - } + for (i = 0, item = h->current; i < h->count; i++, item = item->next) + { + if (item->callback == callback) + { + w = item; + break; + } + } } return w; @@ -455,34 +470,38 @@ 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 */ 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; if (!h->current) - return; + return; w = h->current; w_found = NULL; - do { - if (w->dlg_id == id) { - w_found = w; - break; - } - w = w->next; - } while (w != h->current); + do + { + if (w->dlg_id == id) + { + w_found = w; + break; + } + w = w->next; + } + while (w != h->current); if (w_found) - dlg_select_widget(w_found); + dlg_select_widget (w_found); } /* What to do if the requested widget doesn't take focus */ -typedef enum { - SELECT_NEXT, /* go the the next widget */ - SELECT_PREV, /* go the the previous widget */ - SELECT_EXACT /* use current widget */ +typedef enum +{ + SELECT_NEXT, /* go the the next widget */ + SELECT_PREV, /* go the the previous widget */ + SELECT_EXACT /* use current widget */ } select_dir_t; /* @@ -490,35 +509,39 @@ typedef enum { * Otherwise go to the previous widget. */ 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; if (!dlg_unfocus (h)) - return; + return; h->current = w; - do { - if (dlg_focus (h)) - break; + do + { + if (dlg_focus (h)) + break; - switch (dir) { - case SELECT_NEXT: - h->current = h->current->next; - break; - case SELECT_PREV: - h->current = h->current->prev; - break; - case SELECT_EXACT: - h->current = w0; - dlg_focus (h); - return; - } - } while (h->current != w); + switch (dir) + { + case SELECT_NEXT: + h->current = h->current->next; + break; + case SELECT_PREV: + h->current = h->current->prev; + break; + case SELECT_EXACT: + h->current = w0; + dlg_focus (h); + return; + } + } + while (h->current != w); - if (dlg_overlap (w0, h->current)) { - send_message (h->current, WIDGET_DRAW, 0); - send_message (h->current, WIDGET_FOCUS, 0); + if (dlg_overlap (w0, h->current)) + { + send_message (h->current, WIDGET_DRAW, 0); + send_message (h->current, WIDGET_FOCUS, 0); } } @@ -535,34 +558,36 @@ dlg_select_widget (void *w) /* Try to select previous widget in the tab order */ void -dlg_one_up (Dlg_head *h) +dlg_one_up (Dlg_head * h) { if (h->current) - do_select_widget (h, h->current->prev, SELECT_PREV); + do_select_widget (h, h->current->prev, SELECT_PREV); } /* Try to select next widget in the tab order */ void -dlg_one_down (Dlg_head *h) +dlg_one_down (Dlg_head * h) { 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; - if (p != NULL) { - if (p->options & W_WANT_CURSOR) - send_message (p, WIDGET_CURSOR, 0); - else - while ((p = p->next) != h->current) - if (p->options & W_WANT_CURSOR) - if (send_message (p, WIDGET_CURSOR, 0) == MSG_HANDLED) - break; + if (p != NULL) + { + if (p->options & W_WANT_CURSOR) + send_message (p, WIDGET_CURSOR, 0); + else + while ((p = p->next) != h->current) + if (p->options & W_WANT_CURSOR) + if (send_message (p, WIDGET_CURSOR, 0) == MSG_HANDLED) + break; } } @@ -570,7 +595,7 @@ void update_cursor (Dlg_head *h) * as the last one */ void -dlg_redraw (Dlg_head *h) +dlg_redraw (Dlg_head * h) { h->callback (h, NULL, DLG_DRAW, 0, NULL); dlg_broadcast_msg (h, WIDGET_DRAW, 1); @@ -578,131 +603,139 @@ dlg_redraw (Dlg_head *h) } void -dlg_stop (Dlg_head *h) +dlg_stop (Dlg_head * h) { h->running = 0; } 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)) { - h->ret_value = B_CANCEL; - dlg_stop (h); - return; + if (is_abort_char (d_key)) + { + h->ret_value = B_CANCEL; + dlg_stop (h); + return; } - switch (d_key) { + switch (d_key) + { case '\n': case KEY_ENTER: - h->ret_value = B_ENTER; - dlg_stop (h); - break; + h->ret_value = B_ENTER; + dlg_stop (h); + break; case KEY_LEFT: case KEY_UP: - dlg_one_up (h); - break; + dlg_one_up (h); + break; case KEY_RIGHT: case KEY_DOWN: - dlg_one_down (h); - break; + dlg_one_down (h); + break; - case KEY_F(1): - interactive_display (NULL, h->help_ctx); - do_refresh (); - break; + case KEY_F (1): + interactive_display (NULL, h->help_ctx); + do_refresh (); + break; - case XCTRL('z'): - suspend_cmd (); - /* Fall through */ + case XCTRL ('z'): + suspend_cmd (); + /* Fall through */ - case XCTRL('l'): + case XCTRL ('l'): #ifdef HAVE_SLANG - tty_touch_screen (); - mc_refresh (); + tty_touch_screen (); + mc_refresh (); #else - /* Use this if the refreshes fail */ - clr_scr (); - repaint_screen (); + /* Use this if the refreshes fail */ + clr_scr (); + repaint_screen (); #endif /* HAVE_SLANG */ - break; + break; default: - break; + break; } } 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; cb_ret_t handled; int c; if (h->current == NULL) - return MSG_NOT_HANDLED; + return MSG_NOT_HANDLED; /* * Explanation: we don't send letter hotkeys to other widgets if * 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 * some encoding */ - if (d_key >= 32 && d_key < 256) - return MSG_NOT_HANDLED; + if (d_key >= 32 && d_key < 256) + return MSG_NOT_HANDLED; } /* If it's an alt key, send the message */ c = d_key & ~ALT (0); if (d_key & ALT (0) && g_ascii_isalpha (c)) - d_key = g_ascii_tolower (c); + d_key = g_ascii_tolower (c); handled = MSG_NOT_HANDLED; if (h->current->options & W_WANT_HOTKEY) - handled = send_message (h->current, WIDGET_HOTKEY, d_key); + handled = send_message (h->current, WIDGET_HOTKEY, d_key); /* If not used, send hotkey to other widgets */ if (handled == MSG_HANDLED) - return MSG_HANDLED; + return MSG_HANDLED; hot_cur = h->current->next; /* send it to all widgets */ - while (h->current != hot_cur && handled == MSG_NOT_HANDLED) { - if (hot_cur->options & W_WANT_HOTKEY) - handled = send_message (hot_cur, WIDGET_HOTKEY, d_key); + while (h->current != hot_cur && handled == MSG_NOT_HANDLED) + { + if (hot_cur->options & W_WANT_HOTKEY) + handled = send_message (hot_cur, WIDGET_HOTKEY, d_key); - if (handled == MSG_NOT_HANDLED) - hot_cur = hot_cur->next; + if (handled == MSG_NOT_HANDLED) + hot_cur = hot_cur->next; } if (handled == MSG_HANDLED) - do_select_widget (h, hot_cur, SELECT_EXACT); + do_select_widget (h, hot_cur, SELECT_EXACT); return handled; } static void -dlg_key_event (Dlg_head *h, int d_key) +dlg_key_event (Dlg_head * h, int d_key) { cb_ret_t handled; if (h->current == NULL) - return; + return; /* TAB used to cycle */ - if (!(h->flags & DLG_WANT_TAB)) { - if (d_key == '\t') { - dlg_one_down (h); - return; - } else if (d_key == KEY_BTAB) { - dlg_one_up (h); - return; - } + if (!(h->flags & DLG_WANT_TAB)) + { + if (d_key == '\t') + { + dlg_one_down (h); + return; + } + else if (d_key == KEY_BTAB) + { + dlg_one_up (h); + return; + } } /* first can dlg_callback handle the key */ @@ -710,20 +743,20 @@ dlg_key_event (Dlg_head *h, int d_key) /* next try the hotkey */ if (handled == MSG_NOT_HANDLED) - handled = dlg_try_hotkey (h, d_key); + handled = dlg_try_hotkey (h, d_key); if (handled == MSG_HANDLED) - h->callback (h, NULL, DLG_HOTKEY_HANDLED, 0, NULL); + h->callback (h, NULL, DLG_HOTKEY_HANDLED, 0, NULL); else - /* not used - then try widget_callback */ - handled = send_message (h->current, WIDGET_KEY, d_key); + /* not used - then try widget_callback */ + handled = send_message (h->current, WIDGET_KEY, d_key); /* not used- try to use the unhandled case */ if (handled == MSG_NOT_HANDLED) - handled = h->callback (h, NULL, DLG_UNHANDLED_KEY, d_key, NULL); + handled = h->callback (h, NULL, DLG_UNHANDLED_KEY, d_key, NULL); if (handled == MSG_NOT_HANDLED) - dialog_handle_key (h, d_key); + dialog_handle_key (h, d_key); h->callback (h, NULL, DLG_POST_KEY, d_key, NULL); } @@ -738,31 +771,34 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event) int y = event->y; /* close the dialog by mouse click out of dialog area */ - if (mouse_close_dialog && !h->fullscreen - && ((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))) { - h->ret_value = B_CANCEL; - dlg_stop (h); - return MOU_NORMAL; + if (mouse_close_dialog && !h->fullscreen && ((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))) + { + h->ret_value = B_CANCEL; + dlg_stop (h); + return MOU_NORMAL; } item = starting_widget; - do { - Widget *widget; + do + { + Widget *widget; - widget = item; - item = item->next; + widget = item; + item = item->next; - if ((x > widget->x) && (x <= widget->x + widget->cols) - && (y > widget->y) && (y <= widget->y + widget->lines)) { - new_event = *event; - new_event.x -= widget->x; - new_event.y -= widget->y; + if ((x > widget->x) && (x <= widget->x + widget->cols) + && (y > widget->y) && (y <= widget->y + widget->lines)) + { + new_event = *event; + new_event.x -= widget->x; + new_event.y -= widget->y; - if (widget->mouse != NULL) - return widget->mouse (&new_event, widget); - } - } while (item != starting_widget); + if (widget->mouse != NULL) + return widget->mouse (&new_event, widget); + } + } + while (item != starting_widget); return MOU_NORMAL; } @@ -771,14 +807,14 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event) /* Init the process */ void -init_dlg (Dlg_head *h) +init_dlg (Dlg_head * h) { /* Initialize dialog manager and widgets */ h->callback (h, NULL, DLG_INIT, 0, NULL); dlg_broadcast_msg (h, WIDGET_INIT, 0); if (h->x == 0 && h->y == 0 && h->cols == COLS && h->lines == LINES) - h->fullscreen = 1; + h->fullscreen = 1; h->parent = current_dlg; current_dlg = h; @@ -788,7 +824,7 @@ init_dlg (Dlg_head *h) /* Select the first widget that takes focus */ while (!dlg_focus (h) && h->current) - h->current = h->current->next; + h->current = h->current->next; /* Redraw the screen */ dlg_redraw (h); @@ -799,63 +835,66 @@ init_dlg (Dlg_head *h) /* Shutdown the run_dlg */ void -dlg_run_done (Dlg_head *h) +dlg_run_done (Dlg_head * h) { if (h->current != NULL) - h->callback (h, h->current, DLG_END, 0, NULL); + h->callback (h, h->current, DLG_END, 0, NULL); current_dlg = h->parent; } 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 (tty_got_interrupt ()) - key = XCTRL('g'); - else - return; + if (key == EV_NONE) + { + if (tty_got_interrupt ()) + key = XCTRL ('g'); + else + return; } if (key == EV_MOUSE) - h->mouse_status = dlg_mouse_event (h, event); + h->mouse_status = dlg_mouse_event (h, event); else - dlg_key_event (h, key); + dlg_key_event (h, key); } static void -frontend_run_dlg (Dlg_head *h) +frontend_run_dlg (Dlg_head * h) { int d_key; Gpm_Event event; event.x = -1; - while (h->running) { - if (winch_flag) - change_screen_size (); + while (h->running) + { + if (winch_flag) + change_screen_size (); - if (is_idle ()) { - if (idle_hook) - execute_hooks (idle_hook); + if (is_idle ()) + { + if (idle_hook) + execute_hooks (idle_hook); - while ((h->flags & DLG_WANT_IDLE) && is_idle ()) - h->callback (h, NULL, DLG_IDLE, 0, NULL); + while ((h->flags & DLG_WANT_IDLE) && is_idle ()) + h->callback (h, NULL, DLG_IDLE, 0, NULL); - /* Allow terminating the dialog from the idle handler */ - if (!h->running) - break; - } + /* Allow terminating the dialog from the idle handler */ + if (!h->running) + break; + } - update_cursor (h); + update_cursor (h); - /* Clear interrupt flag */ - tty_got_interrupt (); - d_key = tty_get_event (&event, h->mouse_status == MOU_REPEAT, TRUE); + /* Clear interrupt flag */ + tty_got_interrupt (); + d_key = tty_get_event (&event, h->mouse_status == MOU_REPEAT, TRUE); - dlg_process_event (h, d_key, &event); + dlg_process_event (h, d_key, &event); - if (!h->running) - h->callback (h, NULL, DLG_VALIDATE, 0, NULL); + if (!h->running) + h->callback (h, NULL, DLG_VALIDATE, 0, NULL); } } @@ -864,7 +903,8 @@ frontend_run_dlg (Dlg_head *h) * behavior on complex routines like the file routines, this way, * 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); frontend_run_dlg (h); @@ -873,17 +913,18 @@ int run_dlg (Dlg_head *h) } void -destroy_dlg (Dlg_head *h) +destroy_dlg (Dlg_head * h) { int i; Widget *c; dlg_broadcast_msg (h, WIDGET_DESTROY, 0); c = h->current; - for (i = 0; i < h->count; i++) { - c = c->next; - g_free (h->current); - h->current = c; + for (i = 0; i < h->count; i++) + { + c = c->next; + g_free (h->current); + h->current = c; } g_free (h->color); g_free (h->title); @@ -892,50 +933,54 @@ destroy_dlg (Dlg_head *h) 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->y = y; widget->cols = cols; 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 */ 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; int should_focus = 0; if (!h->current) - return; + return; if (old_w == h->current) - should_focus = 1; + should_focus = 1; new_w->parent = h; new_w->dlg_id = old_w->dlg_id; - if (old_w == old_w->next) { - /* just one widget */ - new_w->prev = new_w; - new_w->next = new_w; - } else { - new_w->prev = old_w->prev; - new_w->next = old_w->next; - old_w->prev->next = new_w; - old_w->next->prev = new_w; + if (old_w == old_w->next) + { + /* just one widget */ + new_w->prev = new_w; + new_w->next = new_w; + } + else + { + new_w->prev = old_w->prev; + new_w->next = old_w->next; + old_w->prev->next = new_w; + old_w->next->prev = new_w; } if (should_focus) - h->current = new_w; + h->current = new_w; send_message (old_w, WIDGET_DESTROY, 0); send_message (new_w, WIDGET_INIT, 0); if (should_focus) - dlg_select_widget (new_w); + dlg_select_widget (new_w); send_message (new_w, WIDGET_DRAW, 0); } diff --git a/src/dialog.h b/src/dialog.h index 155fd8fdd..b0c92d6b1 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -35,23 +35,25 @@ typedef struct Widget Widget; /* Widget messages */ -typedef enum { - WIDGET_INIT, /* Initialize widget */ - WIDGET_FOCUS, /* Draw widget in focused state */ - WIDGET_UNFOCUS, /* Draw widget in unfocused state */ - WIDGET_DRAW, /* Sent to widget to draw themselves */ - WIDGET_KEY, /* Sent to widgets on key press */ - WIDGET_HOTKEY, /* Sent to widget to catch preprocess key */ - WIDGET_COMMAND, /* Send to widget to handle command */ - WIDGET_DESTROY, /* Sent to widget at destruction time */ - WIDGET_CURSOR, /* Sent to widget to position the cursor */ - WIDGET_IDLE, /* Sent to widgets with options & W_WANT_IDLE*/ - WIDGET_RESIZED /* Sent after a widget has been resized */ +typedef enum +{ + WIDGET_INIT, /* Initialize widget */ + WIDGET_FOCUS, /* Draw widget in focused state */ + WIDGET_UNFOCUS, /* Draw widget in unfocused state */ + WIDGET_DRAW, /* Sent to widget to draw themselves */ + WIDGET_KEY, /* Sent to widgets on key press */ + WIDGET_HOTKEY, /* Sent to widget to catch preprocess key */ + WIDGET_COMMAND, /* Send to widget to handle command */ + WIDGET_DESTROY, /* Sent to widget at destruction time */ + WIDGET_CURSOR, /* Sent to widget to position the cursor */ + WIDGET_IDLE, /* Sent to widgets with options & W_WANT_IDLE */ + WIDGET_RESIZED /* Sent after a widget has been resized */ } widget_msg_t; -typedef enum { - MSG_NOT_HANDLED = 0, - MSG_HANDLED = 1 +typedef enum +{ + MSG_NOT_HANDLED = 0, + MSG_HANDLED = 1 } cb_ret_t; /* Widgets are expected to answer to the following messages: @@ -60,69 +62,72 @@ typedef enum { 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_HOTKEY: 1 if they actually used the key, 0 if not. -*/ + */ /* Dialog messages */ -typedef enum { - DLG_INIT = 0, /* Initialize dialog */ - DLG_IDLE = 1, /* The idle state is active */ - DLG_DRAW = 2, /* Draw dialog on screen */ - DLG_FOCUS = 3, /* A widget has got focus */ - DLG_UNFOCUS = 4, /* A widget has been unfocused */ - DLG_RESIZE = 5, /* Window size has changed */ - DLG_KEY = 6, /* Key before sending to widget */ - DLG_HOTKEY_HANDLED = 7, /* A widget has got the hotkey */ - DLG_POST_KEY = 8, /* The key has been handled */ - DLG_UNHANDLED_KEY = 9, /* Key that no widget handled */ - DLG_ACTION = 10, /* State of check- and radioboxes has changed - * and listbox current entry has changed */ - DLG_VALIDATE = 11, /* Dialog is to be closed */ - DLG_END = 12 /* Shut down dialog */ +typedef enum +{ + DLG_INIT = 0, /* Initialize dialog */ + DLG_IDLE = 1, /* The idle state is active */ + DLG_DRAW = 2, /* Draw dialog on screen */ + DLG_FOCUS = 3, /* A widget has got focus */ + DLG_UNFOCUS = 4, /* A widget has been unfocused */ + DLG_RESIZE = 5, /* Window size has changed */ + DLG_KEY = 6, /* Key before sending to widget */ + DLG_HOTKEY_HANDLED = 7, /* A widget has got the hotkey */ + DLG_POST_KEY = 8, /* The key has been handled */ + DLG_UNHANDLED_KEY = 9, /* Key that no widget handled */ + DLG_ACTION = 10, /* State of check- and radioboxes has changed + * and listbox current entry has changed */ + DLG_VALIDATE = 11, /* Dialog is to be closed */ + DLG_END = 12 /* Shut down dialog */ } dlg_msg_t; /* Dialog callback */ typedef struct Dlg_head Dlg_head; -typedef cb_ret_t (*dlg_cb_fn)(struct Dlg_head *h, Widget *sender, - dlg_msg_t msg, int parm, void *data); +typedef cb_ret_t (*dlg_cb_fn) (struct Dlg_head * h, Widget * sender, + dlg_msg_t msg, int parm, void *data); /* get string representation of shortcut assigned with command */ /* 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 */ -#define DLG_COLOR_NUM 4 -#define DLG_NORMALC(h) ((h)->color[0]) -#define DLG_FOCUSC(h) ((h)->color[1]) -#define DLG_HOT_NORMALC(h) ((h)->color[2]) -#define DLG_HOT_FOCUSC(h) ((h)->color[3]) +#define DLG_COLOR_NUM 4 +#define DLG_NORMALC(h) ((h)->color[0]) +#define DLG_FOCUSC(h) ((h)->color[1]) +#define DLG_HOT_NORMALC(h) ((h)->color[2]) +#define DLG_HOT_FOCUSC(h) ((h)->color[3]) -struct Dlg_head { +struct Dlg_head +{ /* Set by the user */ - int flags; /* User flags */ - const char *help_ctx; /* Name of the help entry */ - int *color; /* Color set. Unused in viewer and editor */ - /*notconst*/ char *title; /* Title of the dialog */ + int flags; /* User flags */ + const char *help_ctx; /* Name of the help entry */ + int *color; /* Color set. Unused in viewer and editor */ + /*notconst */ char *title; + /* Title of the dialog */ /* Set and received by the user */ - int ret_value; /* Result of run_dlg() */ + int ret_value; /* Result of run_dlg() */ /* Geometry */ - int x, y; /* Position relative to screen origin */ - int cols, lines; /* Width and height of the window */ + int x, y; /* Position relative to screen origin */ + int cols, lines; /* Width and height of the window */ /* Internal flags */ - unsigned int running:1; /* The dialog is currently active */ - unsigned int fullscreen:1; /* Parents dialogs don't need refresh */ - int mouse_status; /* For the autorepeat status of the mouse */ + unsigned int running:1; /* The dialog is currently active */ + unsigned int fullscreen:1; /* Parents dialogs don't need refresh */ + int mouse_status; /* For the autorepeat status of the mouse */ /* Internal variables */ - int count; /* Number of widgets */ - struct Widget *current; /* Curently active widget */ - void *data; /* Data can be passed to dialog */ + int count; /* Number of widgets */ + struct Widget *current; /* Curently active widget */ + void *data; /* Data can be passed to dialog */ dlg_cb_fn callback; - dlg_shortcut_str get_shortcut; /* Shortcut string */ - struct Dlg_head *parent; /* Parent dialog */ + dlg_shortcut_str get_shortcut; /* Shortcut string */ + struct Dlg_head *parent; /* Parent dialog */ }; /* Color styles for normal and error dialogs */ @@ -131,34 +136,37 @@ extern int alarm_colors[4]; /* 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 */ -typedef enum { - W_WANT_HOTKEY = (1 << 1), - W_WANT_CURSOR = (1 << 2), - W_WANT_IDLE = (1 << 3), - W_IS_INPUT = (1 << 4) +typedef enum +{ + W_WANT_HOTKEY = (1 << 1), + W_WANT_CURSOR = (1 << 2), + W_WANT_IDLE = (1 << 3), + W_IS_INPUT = (1 << 4) } widget_options_t; /* Flags for widget repositioning on dialog resize */ -typedef enum { - 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_TOP = (1 << 2), /* keep widget distance to top border of dialog */ - WPOS_KEEP_BOTTOM = (1 << 3), /* keep widget distance to bottom border of dialog */ - WPOS_KEEP_HORZ = WPOS_KEEP_LEFT | WPOS_KEEP_RIGHT, - WPOS_KEEP_VERT = WPOS_KEEP_TOP | WPOS_KEEP_BOTTOM, - WPOS_KEEP_ALL = WPOS_KEEP_HORZ | WPOS_KEEP_VERT +typedef enum +{ + 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_TOP = (1 << 2), /* keep widget distance to top border of dialog */ + WPOS_KEEP_BOTTOM = (1 << 3), /* keep widget distance to bottom border of dialog */ + WPOS_KEEP_HORZ = WPOS_KEEP_LEFT | WPOS_KEEP_RIGHT, + WPOS_KEEP_VERT = WPOS_KEEP_TOP | WPOS_KEEP_BOTTOM, + WPOS_KEEP_ALL = WPOS_KEEP_HORZ | WPOS_KEEP_VERT } widget_pos_flags_t; /* Every Widget must have this as its first element */ -struct Widget { +struct Widget +{ int x, y; int cols, lines; widget_options_t options; - widget_pos_flags_t pos_flags; /* repositioning flags */ - int dlg_id; /* Number of the widget, starting with 0 */ + widget_pos_flags_t pos_flags; /* repositioning flags */ + int dlg_id; /* Number of the widget, starting with 0 */ struct Widget *next; struct Widget *prev; callback_fn callback; @@ -167,56 +175,55 @@ struct Widget { }; /* 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: */ -#define DLG_REVERSE (1 << 5) /* Tab order is opposite to the add order */ -#define DLG_WANT_TAB (1 << 4) /* Should the tab key be sent to the dialog? */ -#define DLG_WANT_IDLE (1 << 3) /* Dialog wants idle events */ -#define DLG_COMPACT (1 << 2) /* Suppress spaces around the frame */ -#define DLG_TRYUP (1 << 1) /* Try to move two lines up the dialog */ -#define DLG_CENTER (1 << 0) /* Center the dialog */ -#define DLG_NONE (000000) /* No options */ +#define DLG_REVERSE (1 << 5) /* Tab order is opposite to the add order */ +#define DLG_WANT_TAB (1 << 4) /* Should the tab key be sent to the dialog? */ +#define DLG_WANT_IDLE (1 << 3) /* Dialog wants idle events */ +#define DLG_COMPACT (1 << 2) /* Suppress spaces around the frame */ +#define DLG_TRYUP (1 << 1) /* Try to move two lines up the dialog */ +#define DLG_CENTER (1 << 0) /* Center the dialog */ +#define DLG_NONE (000000) /* No options */ /* Creates a dialog head */ Dlg_head *create_dlg (int y1, int x1, int lines, int cols, - const int *colors, dlg_cb_fn callback, - const char *help_ctx, const char *title, int flags); + const int *colors, dlg_cb_fn callback, + const char *help_ctx, const char *title, int flags); void dlg_set_default_colors (void); -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_autopos (Dlg_head * dest, void *w, widget_pos_flags_t pos_flags); +int add_widget (Dlg_head * dest, void *w); /* sets size of dialog, leaving positioning to automatic mehtods - according to dialog flags */ -void dlg_set_size (Dlg_head *h, int lines, int cols); + according to dialog flags */ +void dlg_set_size (Dlg_head * h, int lines, int cols); /* 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 */ -int run_dlg (Dlg_head *d); +int run_dlg (Dlg_head * d); -void dlg_run_done (Dlg_head *h); -void dlg_process_event (Dlg_head *h, int key, Gpm_Event *event); -void init_dlg (Dlg_head *h); +void dlg_run_done (Dlg_head * h); +void dlg_process_event (Dlg_head * h, int key, Gpm_Event * event); +void init_dlg (Dlg_head * h); /* 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 destroy_dlg (Dlg_head *h); +void dlg_redraw (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, - callback_fn callback, mouse_h mouse_handler); +void init_widget (Widget * w, int y, int x, int lines, int cols, + callback_fn callback, mouse_h mouse_handler); /* Default callback for dialogs */ -cb_ret_t default_dlg_callback (Dlg_head *h, Widget *sender, - dlg_msg_t msg, int parm, void *data); +cb_ret_t default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data); /* Default paint routine for dialogs */ void common_dialog_repaint (struct Dlg_head *h); @@ -230,7 +237,7 @@ extern Dlg_head *current_dlg; extern Hook *idle_hook; 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); } @@ -243,19 +250,19 @@ dlg_widget_active (void *w) return (w1->parent->current == w1); } -void dlg_replace_widget (Widget *old, Widget *new); -int dlg_overlap (Widget *a, Widget *b); -void widget_erase (Widget *); -void dlg_erase (Dlg_head *h); -void dlg_stop (Dlg_head *h); +void dlg_replace_widget (Widget * old, Widget * new); +int dlg_overlap (Widget * a, Widget * b); +void widget_erase (Widget *); +void dlg_erase (Dlg_head * h); +void dlg_stop (Dlg_head * h); /* Widget selection */ -void dlg_select_widget (void *widget); -void dlg_one_up (Dlg_head *h); -void dlg_one_down (Dlg_head *h); -int dlg_focus (Dlg_head *h); -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_widget (void *widget); +void dlg_one_up (Dlg_head * h); +void dlg_one_down (Dlg_head * h); +int dlg_focus (Dlg_head * h); +Widget *find_widget_type (const Dlg_head * h, callback_fn callback); +void dlg_select_by_id (const Dlg_head * h, int id); /* Redraw all dialogs */ 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) /* Used in load_prompt() */ -void update_cursor (Dlg_head *h); +void update_cursor (Dlg_head * h); -#endif /* MC_DIALOG_H */ +#endif /* MC_DIALOG_H */ diff --git a/src/hotlist.c b/src/hotlist.c index a11a97e16..294e403b2 100644 --- a/src/hotlist.c +++ b/src/hotlist.c @@ -3,10 +3,10 @@ 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. Written by: - 1994 Radek Doulik - 1995 Janne Kukonlehto - 1996 Andrej Borsenkow - 1997 Norbert Warmuth + 1994 Radek Doulik + 1995 Janne Kukonlehto + 1996 Andrej Borsenkow + 1997 Norbert Warmuth Janne did the original Hotlist code, Andrej made the groupable hotlist; the move hotlist and revamped the file format and made @@ -42,28 +42,28 @@ #include "lib/global.h" -#include "lib/tty/tty.h" /* COLS */ -#include "lib/tty/key.h" /* KEY_M_CTRL */ -#include "lib/skin.h" /* colors */ -#include "lib/mcconfig.h" /* Load/save directories hotlist */ +#include "lib/tty/tty.h" /* COLS */ +#include "lib/tty/key.h" /* KEY_M_CTRL */ +#include "lib/skin.h" /* colors */ +#include "lib/mcconfig.h" /* Load/save directories hotlist */ #include "lib/fileloc.h" #include "lib/strutil.h" #include "dialog.h" #include "widget.h" -#include "setup.h" /* For profile_bname */ -#include "wtools.h" /* QuickDialog */ -#include "panel.h" /* current_panel */ -#include "main.h" /* update_panels() */ -#include "layout.h" /* repaint_screen() */ +#include "setup.h" /* For profile_bname */ +#include "wtools.h" /* QuickDialog */ +#include "panel.h" /* current_panel */ +#include "main.h" /* update_panels() */ +#include "layout.h" /* repaint_screen() */ #include "hotlist.h" -#include "command.h" /* cmdline */ +#include "command.h" /* cmdline */ #include "history.h" -#define UX 5 -#define UY 2 +#define UX 5 +#define UY 2 -#define BX UX +#define BX UX #define BY (LINES - 6) #define BUTTONS (sizeof(hotlist_but)/sizeof(struct _hotlist_but)) @@ -93,70 +93,76 @@ static Dlg_head *movelist_dlg; static WLabel *pname, *pname_group, *movelist_group; -enum HotListType { +enum HotListType +{ HL_TYPE_GROUP, HL_TYPE_ENTRY, HL_TYPE_COMMENT, HL_TYPE_DOTDOT }; -static struct { +static struct +{ /* * these parameters are intended to be user configurable */ - int expanded; /* expanded view of all groups at startup */ + int expanded; /* expanded view of all groups at startup */ /* * these reflect run time state */ - int loaded; /* hotlist is loaded */ - int readonly; /* hotlist readonly */ - int file_error; /* parse error while reading file */ - int running; /* we are running dlg (and have to - update listbox */ - int moving; /* we are in moving hotlist currently */ - int modified; /* hotlist was modified */ - int type; /* LIST_HOTLIST || LIST_VFSLIST */ -} hotlist_state; + int loaded; /* hotlist is loaded */ + int readonly; /* hotlist readonly */ + int file_error; /* parse error while reading file */ + int running; /* we are running dlg (and have to + update listbox */ + int moving; /* we are in moving hotlist currently */ + int modified; /* hotlist was modified */ + int type; /* LIST_HOTLIST || LIST_VFSLIST */ +} hotlist_state; -static struct _hotlist_but { +static struct _hotlist_but +{ int ret_cmd, flags, y, x; const char *text; - int type; + int type; widget_pos_flags_t pos_flags; -} hotlist_but[] = { - { B_MOVE, NORMAL_BUTTON, 1, 42, N_("&Move"), - LIST_HOTLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, - { B_REMOVE, NORMAL_BUTTON, 1, 30, N_("&Remove"), - LIST_HOTLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, - { B_APPEND, NORMAL_BUTTON, 1, 15, N_("&Append"), - LIST_MOVELIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, - { B_INSERT, NORMAL_BUTTON, 1, 0, N_("&Insert"), - LIST_MOVELIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, - { B_NEW_ENTRY, NORMAL_BUTTON, 1, 15, N_("New &Entry"), - LIST_HOTLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, - { B_NEW_GROUP, NORMAL_BUTTON, 1, 0, N_("New &Group"), - LIST_HOTLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, - { B_CANCEL, NORMAL_BUTTON, 0, 53, N_("&Cancel"), - LIST_HOTLIST | LIST_VFSLIST|LIST_MOVELIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, - { B_UP_GROUP, NORMAL_BUTTON, 0, 42, N_("&Up"), - LIST_HOTLIST | LIST_MOVELIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, - { B_ADD_CURRENT, NORMAL_BUTTON, 0, 20, N_("&Add current"), - LIST_HOTLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, -#ifdef ENABLE_VFS - { B_REFRESH_VFS, NORMAL_BUTTON, 0, 43, N_("&Refresh"), - LIST_VFSLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, - { B_FREE_ALL_VFS, NORMAL_BUTTON, 0, 20, N_("Fr&ee VFSs now"), - LIST_VFSLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, +} hotlist_but[] = +{ + /* *INDENT-OFF* */ + { B_MOVE, NORMAL_BUTTON, 1, 42, N_("&Move"), LIST_HOTLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, + { B_REMOVE, NORMAL_BUTTON, 1, 30, N_("&Remove"), + LIST_HOTLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, + { B_APPEND, NORMAL_BUTTON, 1, 15, N_("&Append"), + LIST_MOVELIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, + { B_INSERT, NORMAL_BUTTON, 1, 0, N_("&Insert"), + LIST_MOVELIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, + { B_NEW_ENTRY, NORMAL_BUTTON, 1, 15, N_("New &Entry"), + LIST_HOTLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, + { B_NEW_GROUP, NORMAL_BUTTON, 1, 0, N_("New &Group"), + LIST_HOTLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, + { B_CANCEL, NORMAL_BUTTON, 0, 53, N_("&Cancel"), + LIST_HOTLIST | LIST_VFSLIST | LIST_MOVELIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, + { B_UP_GROUP, NORMAL_BUTTON, 0, 42, N_("&Up"), + LIST_HOTLIST | LIST_MOVELIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, + { B_ADD_CURRENT, NORMAL_BUTTON, 0, 20, N_("&Add current"), + LIST_HOTLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, +#ifdef ENABLE_VFS + { B_REFRESH_VFS, NORMAL_BUTTON, 0, 43, N_("&Refresh"), + LIST_VFSLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, + { B_FREE_ALL_VFS, NORMAL_BUTTON, 0, 20, N_("Fr&ee VFSs now"), + LIST_VFSLIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM }, #endif - { B_ENTER, DEFPUSH_BUTTON, 0, 0, N_("Change &To"), - LIST_HOTLIST | LIST_VFSLIST | LIST_MOVELIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM } + { B_ENTER, DEFPUSH_BUTTON, 0, 0, N_("Change &To"), + LIST_HOTLIST | LIST_VFSLIST | LIST_MOVELIST, WPOS_KEEP_LEFT | WPOS_KEEP_BOTTOM } + /* *INDENT-ON* */ }; /* Directory hotlist */ -static struct hotlist{ - enum HotListType type; +static struct hotlist +{ + enum HotListType type; char *directory; char *label; struct hotlist *head; @@ -180,10 +186,9 @@ hotlist_refresh (Dlg_head * dlg) { common_dialog_repaint (dlg); tty_setcolor (COLOR_NORMAL); - draw_box (dlg, 2, 5, dlg->lines - (hotlist_state.moving ? 6 : 10), - dlg->cols - (UX * 2), TRUE); + draw_box (dlg, 2, 5, dlg->lines - (hotlist_state.moving ? 6 : 10), dlg->cols - (UX * 2), TRUE); if (!hotlist_state.moving) - draw_box (dlg, dlg->lines - 8, 5, 3, dlg->cols - (UX * 2), TRUE); + draw_box (dlg, dlg->lines - 8, 5, 3, dlg->cols - (UX * 2), TRUE); } /* If current->data is 0, then we are dealing with a VFS pathname */ @@ -195,34 +200,32 @@ update_path_name (void) WListbox *list = hotlist_state.moving ? l_movelist : l_hotlist; Dlg_head *dlg = list->widget.parent; - if (list->count != 0) { - char *ctext = NULL; - void *cdata = NULL; + if (list->count != 0) + { + char *ctext = NULL; + void *cdata = NULL; - listbox_get_current (list, &ctext, &cdata); - if (cdata == NULL) - text = ctext; - else { - struct hotlist *hlp = (struct hotlist *) cdata; + listbox_get_current (list, &ctext, &cdata); + if (cdata == NULL) + text = ctext; + else + { + struct hotlist *hlp = (struct hotlist *) cdata; - if (hlp->type == HL_TYPE_ENTRY || - hlp->type == HL_TYPE_DOTDOT) - text = hlp->directory; - else if (hlp->type == HL_TYPE_GROUP) - text = _("Subgroup - press ENTER to see list"); - } + if (hlp->type == HL_TYPE_ENTRY || hlp->type == HL_TYPE_DOTDOT) + text = hlp->directory; + else if (hlp->type == HL_TYPE_GROUP) + text = _("Subgroup - press ENTER to see list"); + } } if (!hotlist_state.moving) - label_set_text (pname, - str_trunc (text, dlg->cols - (UX * 2 + 4))); + label_set_text (pname, str_trunc (text, dlg->cols - (UX * 2 + 4))); p = g_strconcat (" ", current_group->label, " ", (char *) NULL); if (!hotlist_state.moving) - label_set_text (pname_group, - str_trunc (p, dlg->cols - (UX * 2 + 4))); + label_set_text (pname_group, str_trunc (p, dlg->cols - (UX * 2 + 4))); else - label_set_text (movelist_group, - str_trunc (p, dlg->cols - (UX * 2 + 4))); + label_set_text (movelist_group, str_trunc (p, dlg->cols - (UX * 2 + 4))); g_free (p); dlg_redraw (dlg); @@ -239,36 +242,39 @@ do { \ buf[0] = '\0'; \ } while (0) -static void fill_listbox (void) +static void +fill_listbox (void) { struct hotlist *current = current_group->head; GString *buff = g_string_new (""); - while (current){ - switch (current->type) { - case HL_TYPE_GROUP: - { - /* buff clean up */ - g_string_truncate(buff, 0); - g_string_append(buff,"->"); - g_string_append(buff,current->label); - if (hotlist_state.moving) - listbox_add_item (l_movelist, LISTBOX_APPEND_AT_END, 0, buff->str, current); - else + while (current) + { + switch (current->type) + { + case HL_TYPE_GROUP: + { + /* buff clean up */ + g_string_truncate (buff, 0); + g_string_append (buff, "->"); + g_string_append (buff, current->label); + if (hotlist_state.moving) + listbox_add_item (l_movelist, LISTBOX_APPEND_AT_END, 0, buff->str, current); + else listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, buff->str, current); - } - break; - case HL_TYPE_DOTDOT: - case HL_TYPE_ENTRY: - if (hotlist_state.moving) - listbox_add_item (l_movelist, LISTBOX_APPEND_AT_END, 0, current->label, current); - else - listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, current->label, current); - break; - default: - break; - } - current = current->next; + } + break; + case HL_TYPE_DOTDOT: + case HL_TYPE_ENTRY: + if (hotlist_state.moving) + listbox_add_item (l_movelist, LISTBOX_APPEND_AT_END, 0, current->label, current); + else + listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, current->label, current); + break; + default: + break; + } + current = current->next; } g_string_free (buff, TRUE); } @@ -279,19 +285,20 @@ unlink_entry (struct hotlist *entry) struct hotlist *current = current_group->head; if (current == entry) - current_group->head = entry->next; - else { - while (current && current->next != entry) - current = current->next; - if (current) - current->next = entry->next; + current_group->head = entry->next; + else + { + while (current && current->next != entry) + current = current->next; + if (current) + current->next = entry->next; } - entry->next = - entry->up = 0; + entry->next = entry->up = 0; } #ifdef ENABLE_VFS -static void add_name_to_list (const char *path) +static void +add_name_to_list (const char *path) { listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, path, 0); } @@ -300,261 +307,283 @@ static void add_name_to_list (const char *path) static int hotlist_button_callback (int action) { - switch (action) { + switch (action) + { case B_MOVE: - { - struct hotlist *saved = current_group; - struct hotlist *item = NULL; - struct hotlist *moveto_item = NULL; - struct hotlist *moveto_group = NULL; - int ret; + { + struct hotlist *saved = current_group; + struct hotlist *item = NULL; + struct hotlist *moveto_item = NULL; + struct hotlist *moveto_group = NULL; + int ret; - if (l_hotlist->count == 0) - return MSG_NOT_HANDLED; /* empty group - nothing to do */ + if (l_hotlist->count == 0) + return MSG_NOT_HANDLED; /* empty group - nothing to do */ - listbox_get_current (l_hotlist, NULL, (void **) &item); - hotlist_state.moving = 1; - init_movelist (LIST_MOVELIST, item); + listbox_get_current (l_hotlist, NULL, (void **) &item); + hotlist_state.moving = 1; + init_movelist (LIST_MOVELIST, item); - ret = run_dlg (movelist_dlg); + ret = run_dlg (movelist_dlg); - hotlist_state.moving = 0; - listbox_get_current (l_movelist, NULL, (void **) &moveto_item); - moveto_group = current_group; - destroy_dlg (movelist_dlg); - current_group = saved; - if (ret == B_CANCEL) - return MSG_NOT_HANDLED; - if (moveto_item == item) - return MSG_NOT_HANDLED; /* If we insert/append a before/after a - it hardly changes anything ;) */ - unlink_entry (item); - listbox_remove_current (l_hotlist); - item->up = moveto_group; - if (!moveto_group->head) - moveto_group->head = item; - else if (!moveto_item) { /* we have group with just comments */ - struct hotlist *p = moveto_group->head; + hotlist_state.moving = 0; + listbox_get_current (l_movelist, NULL, (void **) &moveto_item); + moveto_group = current_group; + destroy_dlg (movelist_dlg); + current_group = saved; + if (ret == B_CANCEL) + return MSG_NOT_HANDLED; + if (moveto_item == item) + return MSG_NOT_HANDLED; /* If we insert/append a before/after a + it hardly changes anything ;) */ + unlink_entry (item); + listbox_remove_current (l_hotlist); + item->up = moveto_group; + if (!moveto_group->head) + moveto_group->head = item; + else if (!moveto_item) + { /* we have group with just comments */ + struct hotlist *p = moveto_group->head; - /* skip comments */ - while (p->next) - p = p->next; - p->next = item; - } else if (ret == B_ENTER || ret == B_APPEND) - if (!moveto_item->next) - moveto_item->next = item; - else { - item->next = moveto_item->next; - moveto_item->next = item; - } else if (moveto_group->head == moveto_item) { - moveto_group->head = item; - item->next = moveto_item; - } else { - struct hotlist *p = moveto_group->head; + /* skip comments */ + while (p->next) + p = p->next; + p->next = item; + } + else if (ret == B_ENTER || ret == B_APPEND) + if (!moveto_item->next) + moveto_item->next = item; + else + { + item->next = moveto_item->next; + moveto_item->next = item; + } + else if (moveto_group->head == moveto_item) + { + moveto_group->head = item; + item->next = moveto_item; + } + else + { + struct hotlist *p = moveto_group->head; - while (p->next != moveto_item) - p = p->next; - item->next = p->next; - p->next = item; - } - listbox_remove_list (l_hotlist); - fill_listbox (); - repaint_screen (); - hotlist_state.modified = 1; - return MSG_NOT_HANDLED; - } + while (p->next != moveto_item) + p = p->next; + item->next = p->next; + p->next = item; + } + listbox_remove_list (l_hotlist); + fill_listbox (); + repaint_screen (); + hotlist_state.modified = 1; + return MSG_NOT_HANDLED; + } case B_REMOVE: - { - struct hotlist *entry = NULL; - listbox_get_current (l_hotlist, NULL, (void **) &entry); - remove_from_hotlist (entry); - } - return MSG_NOT_HANDLED; + { + struct hotlist *entry = NULL; + listbox_get_current (l_hotlist, NULL, (void **) &entry); + remove_from_hotlist (entry); + } + return MSG_NOT_HANDLED; case B_NEW_GROUP: - add_new_group_cmd (); - return MSG_NOT_HANDLED; + add_new_group_cmd (); + return MSG_NOT_HANDLED; case B_ADD_CURRENT: - add2hotlist_cmd (); - return MSG_NOT_HANDLED; + add2hotlist_cmd (); + return MSG_NOT_HANDLED; case B_NEW_ENTRY: - add_new_entry_cmd (); - return MSG_NOT_HANDLED; + add_new_entry_cmd (); + return MSG_NOT_HANDLED; case B_ENTER: - { - WListbox *list; - void *data; - struct hotlist *hlp; + { + WListbox *list; + void *data; + struct hotlist *hlp; - list = hotlist_state.moving ? l_movelist : l_hotlist; - listbox_get_current (list, NULL, &data); + list = hotlist_state.moving ? l_movelist : l_hotlist; + listbox_get_current (list, NULL, &data); - if (data == NULL) - return MSG_HANDLED; + if (data == NULL) + return MSG_HANDLED; - hlp = (struct hotlist *) data; + hlp = (struct hotlist *) data; - if (hlp->type == HL_TYPE_ENTRY) - return MSG_HANDLED; - if (hlp->type != HL_TYPE_DOTDOT) { - listbox_remove_list (list); - current_group = hlp; - fill_listbox (); - return MSG_NOT_HANDLED; - } - /* Fall through - go up */ - } - /* Fall through if list empty - just go up */ + if (hlp->type == HL_TYPE_ENTRY) + return MSG_HANDLED; + if (hlp->type != HL_TYPE_DOTDOT) + { + listbox_remove_list (list); + current_group = hlp; + fill_listbox (); + return MSG_NOT_HANDLED; + } + /* Fall through - go up */ + } + /* Fall through if list empty - just go up */ case B_UP_GROUP: - { - WListbox *list = hotlist_state.moving ? l_movelist : l_hotlist; - listbox_remove_list (list); - current_group = current_group->up; - fill_listbox (); - return MSG_NOT_HANDLED; - } + { + WListbox *list = hotlist_state.moving ? l_movelist : l_hotlist; + listbox_remove_list (list); + current_group = current_group->up; + fill_listbox (); + return MSG_NOT_HANDLED; + } #ifdef ENABLE_VFS case B_FREE_ALL_VFS: - vfs_expire (1); - /* fall through */ + vfs_expire (1); + /* fall through */ case B_REFRESH_VFS: - listbox_remove_list (l_hotlist); - listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, home_dir, 0); - vfs_fill_names (add_name_to_list); - return MSG_NOT_HANDLED; -#endif /* ENABLE_VFS */ + listbox_remove_list (l_hotlist); + listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, home_dir, 0); + vfs_fill_names (add_name_to_list); + return MSG_NOT_HANDLED; +#endif /* ENABLE_VFS */ default: - return MSG_HANDLED; + return MSG_HANDLED; } } static inline cb_ret_t -hotlist_handle_key (Dlg_head *h, int key) +hotlist_handle_key (Dlg_head * h, int key) { - switch (key) { + switch (key) + { case KEY_M_CTRL | '\n': - goto l1; + goto l1; case '\n': case KEY_ENTER: case KEY_RIGHT: - if (hotlist_button_callback (B_ENTER)) { - h->ret_value = B_ENTER; - dlg_stop (h); - } - return MSG_HANDLED; + if (hotlist_button_callback (B_ENTER)) + { + h->ret_value = B_ENTER; + dlg_stop (h); + } + return MSG_HANDLED; case KEY_LEFT: - if (hotlist_state.type != LIST_VFSLIST) - return !hotlist_button_callback (B_UP_GROUP); - else - return MSG_NOT_HANDLED; + if (hotlist_state.type != LIST_VFSLIST) + return !hotlist_button_callback (B_UP_GROUP); + else + return MSG_NOT_HANDLED; case KEY_DC: - if (hotlist_state.moving) - return MSG_NOT_HANDLED; - else { - hotlist_button_callback (B_REMOVE); - return MSG_HANDLED; - } + if (hotlist_state.moving) + return MSG_NOT_HANDLED; + else + { + hotlist_button_callback (B_REMOVE); + return MSG_HANDLED; + } -l1: - case ALT ('\n'): - case ALT ('\r'): - if (!hotlist_state.moving) { - void *ldata = NULL; + l1: + case ALT ('\n'): + case ALT ('\r'): + if (!hotlist_state.moving) + { + void *ldata = NULL; - listbox_get_current (l_hotlist, NULL, &ldata); + listbox_get_current (l_hotlist, NULL, &ldata); - if (ldata != NULL) { - struct hotlist *hlp = (struct hotlist *) ldata; + if (ldata != NULL) + { + struct hotlist *hlp = (struct hotlist *) ldata; - if (hlp->type == HL_TYPE_ENTRY) { - char *tmp; + if (hlp->type == HL_TYPE_ENTRY) + { + char *tmp; - tmp = g_strconcat ("cd ", hlp->directory, (char *) NULL); - stuff (cmdline, tmp, 0); - g_free (tmp); - h->ret_value = B_CANCEL; - dlg_stop (h); - } - } - } - return MSG_HANDLED; /* ignore key */ + tmp = g_strconcat ("cd ", hlp->directory, (char *) NULL); + stuff (cmdline, tmp, 0); + g_free (tmp); + h->ret_value = B_CANCEL; + dlg_stop (h); + } + } + } + return MSG_HANDLED; /* ignore key */ default: - return MSG_NOT_HANDLED; + return MSG_NOT_HANDLED; } } static cb_ret_t -hotlist_callback (Dlg_head *h, Widget *sender, - dlg_msg_t msg, int parm, void *data) +hotlist_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { - switch (msg) { + switch (msg) + { case DLG_DRAW: - hotlist_refresh (h); - return MSG_HANDLED; + hotlist_refresh (h); + return MSG_HANDLED; case DLG_UNHANDLED_KEY: - return hotlist_handle_key (h, parm); + return hotlist_handle_key (h, parm); case DLG_POST_KEY: - if (hotlist_state.moving) - dlg_select_widget (l_movelist); - else - dlg_select_widget (l_hotlist); - /* always stay on hotlist */ - /* fall through */ + if (hotlist_state.moving) + dlg_select_widget (l_movelist); + else + dlg_select_widget (l_hotlist); + /* always stay on hotlist */ + /* fall through */ case DLG_INIT: - tty_setcolor (MENU_ENTRY_COLOR); - update_path_name (); - return MSG_HANDLED; + tty_setcolor (MENU_ENTRY_COLOR); + update_path_name (); + return MSG_HANDLED; case DLG_RESIZE: - /* simply call dlg_set_size() with new size */ - dlg_set_size (h, LINES - 2, COLS - 6); - return MSG_HANDLED; + /* simply call dlg_set_size() with new size */ + dlg_set_size (h, LINES - 2, COLS - 6); + return MSG_HANDLED; default: - return default_dlg_callback (h, sender, msg, parm, data); + return default_dlg_callback (h, sender, msg, parm, data); } } static int -l_call (WListbox *list) +l_call (WListbox * list) { Dlg_head *dlg = list->widget.parent; - if (list->count != 0) { - void *data = NULL; + if (list->count != 0) + { + void *data = NULL; - listbox_get_current (list, NULL, &data); + listbox_get_current (list, NULL, &data); - if (data != NULL) { - struct hotlist *hlp = (struct hotlist*) data; - if (hlp->type == HL_TYPE_ENTRY) { - dlg->ret_value = B_ENTER; - dlg_stop (dlg); - return LISTBOX_DONE; - } else { - hotlist_button_callback (B_ENTER); - hotlist_callback (dlg, NULL, DLG_POST_KEY, '\n', NULL); - return LISTBOX_CONT; - } - } else { - dlg->ret_value = B_ENTER; - dlg_stop (dlg); - return LISTBOX_DONE; - } + if (data != NULL) + { + struct hotlist *hlp = (struct hotlist *) data; + if (hlp->type == HL_TYPE_ENTRY) + { + dlg->ret_value = B_ENTER; + dlg_stop (dlg); + return LISTBOX_DONE; + } + else + { + hotlist_button_callback (B_ENTER); + hotlist_callback (dlg, NULL, DLG_POST_KEY, '\n', NULL); + return LISTBOX_CONT; + } + } + else + { + dlg->ret_value = B_ENTER; + dlg_stop (dlg); + return LISTBOX_DONE; + } } hotlist_button_callback (B_UP_GROUP); @@ -571,77 +600,76 @@ l_call (WListbox *list) * width - sorry :) (anyway this did not handled in previous version too) */ static int -init_i18n_stuff(int list_type, int cols) +init_i18n_stuff (int list_type, int cols) { - register int i; - static const char* cancel_but = N_("&Cancel"); + register int i; + static const char *cancel_but = N_("&Cancel"); #ifdef ENABLE_NLS - static int hotlist_i18n_flag = 0; + static int hotlist_i18n_flag = 0; - if (!hotlist_i18n_flag) - { - i = sizeof (hotlist_but) / sizeof (hotlist_but [0]); - while (i--) - hotlist_but [i].text = _(hotlist_but [i].text); + if (!hotlist_i18n_flag) + { + i = sizeof (hotlist_but) / sizeof (hotlist_but[0]); + while (i--) + hotlist_but[i].text = _(hotlist_but[i].text); - cancel_but = _(cancel_but); - hotlist_i18n_flag = 1; - } + cancel_but = _(cancel_but); + hotlist_i18n_flag = 1; + } #endif /* ENABLE_NLS */ - /* Dynamic resizing of buttonbars */ - { - int len[2], count[2]; /* at most two lines of buttons */ - int cur_x[2], row; + /* Dynamic resizing of buttonbars */ + { + int len[2], count[2]; /* at most two lines of buttons */ + int cur_x[2], row; - i = sizeof (hotlist_but) / sizeof (hotlist_but [0]); - len[0] = len[1] = count[0] = count[1] = 0; + i = sizeof (hotlist_but) / sizeof (hotlist_but[0]); + len[0] = len[1] = count[0] = count[1] = 0; - /* Count len of buttonbars, assuming 2 extra space between buttons */ - while (i--) - { - if (! (hotlist_but[i].type & list_type)) - continue; + /* Count len of buttonbars, assuming 2 extra space between buttons */ + while (i--) + { + if (!(hotlist_but[i].type & list_type)) + continue; - row = hotlist_but [i].y; - ++count [row]; - len [row] += str_term_width1 (hotlist_but [i].text) + 5; - if (hotlist_but [i].flags == DEFPUSH_BUTTON) - len [row] += 2; - } - len[0] -= 2; - len[1] -= 2; + row = hotlist_but[i].y; + ++count[row]; + len[row] += str_term_width1 (hotlist_but[i].text) + 5; + if (hotlist_but[i].flags == DEFPUSH_BUTTON) + len[row] += 2; + } + len[0] -= 2; + len[1] -= 2; - cols = max(cols, max(len[0], len[1])); + cols = max (cols, max (len[0], len[1])); - /* arrange buttons */ + /* arrange buttons */ - cur_x[0] = cur_x[1] = 0; - i = sizeof (hotlist_but) / sizeof (hotlist_but [0]); - while (i--) - { - if (! (hotlist_but[i].type & list_type)) - continue; + cur_x[0] = cur_x[1] = 0; + i = sizeof (hotlist_but) / sizeof (hotlist_but[0]); + while (i--) + { + if (!(hotlist_but[i].type & list_type)) + continue; - row = hotlist_but [i].y; + row = hotlist_but[i].y; - if (hotlist_but [i].x != 0) - { - /* not first int the row */ - if (!strcmp (hotlist_but [i].text, cancel_but)) - hotlist_but [i].x = - cols - str_term_width1 (hotlist_but [i].text) - 13; - else - hotlist_but [i].x = cur_x [row]; - } + if (hotlist_but[i].x != 0) + { + /* not first int the row */ + if (!strcmp (hotlist_but[i].text, cancel_but)) + hotlist_but[i].x = cols - str_term_width1 (hotlist_but[i].text) - 13; + else + hotlist_but[i].x = cur_x[row]; + } - cur_x [row] += str_term_width1 (hotlist_but [i].text) + 2 - + (hotlist_but [i].flags == DEFPUSH_BUTTON ? 5 : 3); - } - } + cur_x[row] += str_term_width1 (hotlist_but[i].text) + 2 + + (hotlist_but[i].flags == DEFPUSH_BUTTON ? 5 : 3); + } + } - return cols; + return cols; } static void @@ -656,30 +684,33 @@ init_hotlist (int list_type) do_refresh (); hotlist_state.expanded = - mc_config_get_int (mc_main_config, "HotlistConfig", "expanded_view_of_groups", 0); + mc_config_get_int (mc_main_config, "HotlistConfig", "expanded_view_of_groups", 0); - if (list_type == LIST_VFSLIST) { - title = _("Active VFS directories"); - help_node = "[vfshot]"; /* FIXME - no such node */ - } else { - title = _("Directory hotlist"); - help_node = "[Hotlist]"; + if (list_type == LIST_VFSLIST) + { + title = _("Active VFS directories"); + help_node = "[vfshot]"; /* FIXME - no such node */ + } + else + { + title = _("Directory hotlist"); + help_node = "[Hotlist]"; } hotlist_dlg = - create_dlg (0, 0, LINES - 2, hotlist_cols, dialog_colors, - hotlist_callback, help_node, title, DLG_CENTER | DLG_REVERSE); + create_dlg (0, 0, LINES - 2, hotlist_cols, dialog_colors, + hotlist_callback, help_node, title, DLG_CENTER | DLG_REVERSE); - for (i = 0; i < BUTTONS; i++) { - if (hotlist_but[i].type & list_type) - add_widget_autopos (hotlist_dlg, - button_new (BY + hotlist_but[i].y, - BX + hotlist_but[i].x, - hotlist_but[i].ret_cmd, - hotlist_but[i].flags, - hotlist_but[i].text, - hotlist_button_callback), - hotlist_but[i].pos_flags); + for (i = 0; i < BUTTONS; i++) + { + if (hotlist_but[i].type & list_type) + add_widget_autopos (hotlist_dlg, + button_new (BY + hotlist_but[i].y, + BX + hotlist_but[i].x, + hotlist_but[i].ret_cmd, + hotlist_but[i].flags, + hotlist_but[i].text, + hotlist_button_callback), hotlist_but[i].pos_flags); } /* We add the labels. @@ -688,29 +719,29 @@ init_hotlist (int list_type) */ pname = label_new (UY - 11 + LINES, UX + 2, ""); add_widget_autopos (hotlist_dlg, pname, WPOS_KEEP_BOTTOM | WPOS_KEEP_LEFT); - if (!hotlist_state.moving) { - add_widget_autopos (hotlist_dlg, - label_new (UY - 12 + LINES, UX + 1, - _(" Directory path ")), - WPOS_KEEP_BOTTOM | WPOS_KEEP_LEFT); + if (!hotlist_state.moving) + { + add_widget_autopos (hotlist_dlg, + label_new (UY - 12 + LINES, UX + 1, + _(" Directory path ")), WPOS_KEEP_BOTTOM | WPOS_KEEP_LEFT); - /* This one holds the displayed pathname */ - pname_group = label_new (UY, UX + 1, _(" Directory label ")); - add_widget (hotlist_dlg, pname_group); + /* This one holds the displayed pathname */ + pname_group = label_new (UY, UX + 1, _(" Directory label ")); + add_widget (hotlist_dlg, pname_group); } /* get new listbox */ - l_hotlist = - listbox_new (UY + 1, UX + 1, LINES - 14, COLS - 2 * UX - 8, - FALSE, l_call); + l_hotlist = listbox_new (UY + 1, UX + 1, LINES - 14, COLS - 2 * UX - 8, FALSE, l_call); /* Fill the hotlist with the active VFS or the hotlist */ #ifdef ENABLE_VFS - if (list_type == LIST_VFSLIST) { - listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, home_dir, 0); - vfs_fill_names (add_name_to_list); - } else -#endif /* !ENABLE_VFS */ - fill_listbox (); + if (list_type == LIST_VFSLIST) + { + listbox_add_item (l_hotlist, LISTBOX_APPEND_AT_END, 0, home_dir, 0); + vfs_fill_names (add_name_to_list); + } + else +#endif /* !ENABLE_VFS */ + fill_listbox (); add_widget_autopos (hotlist_dlg, l_hotlist, WPOS_KEEP_ALL); /* add listbox to the dialogs */ @@ -726,19 +757,19 @@ init_movelist (int list_type, struct hotlist *item) do_refresh (); movelist_dlg = - create_dlg (0, 0, LINES - 6, movelist_cols, dialog_colors, - hotlist_callback, "[Hotlist]", hdr, DLG_CENTER | DLG_REVERSE); + create_dlg (0, 0, LINES - 6, movelist_cols, dialog_colors, + hotlist_callback, "[Hotlist]", hdr, DLG_CENTER | DLG_REVERSE); g_free (hdr); - for (i = 0; i < BUTTONS; i++) { - if (hotlist_but[i].type & list_type) - add_widget (movelist_dlg, - button_new (BY - 4 + hotlist_but[i].y, - BX + hotlist_but[i].x, - hotlist_but[i].ret_cmd, - hotlist_but[i].flags, - hotlist_but[i].text, - hotlist_button_callback)); + for (i = 0; i < BUTTONS; i++) + { + if (hotlist_but[i].type & list_type) + add_widget (movelist_dlg, + button_new (BY - 4 + hotlist_but[i].y, + BX + hotlist_but[i].x, + hotlist_but[i].ret_cmd, + hotlist_but[i].flags, + hotlist_but[i].text, hotlist_button_callback)); } /* We add the labels. We are interested in the last one, @@ -748,8 +779,8 @@ init_movelist (int list_type, struct hotlist *item) add_widget (movelist_dlg, movelist_group); /* get new listbox */ l_movelist = - listbox_new (UY + 1, UX + 1, movelist_dlg->lines - 8, - movelist_dlg->cols - 2 * UX - 2, FALSE, l_call); + listbox_new (UY + 1, UX + 1, movelist_dlg->lines - 8, + movelist_dlg->cols - 2 * UX - 2, FALSE, l_call); fill_listbox (); @@ -761,12 +792,13 @@ init_movelist (int list_type, struct hotlist *item) * Destroy the list dialog. * Don't confuse with done_hotlist() for the list in memory. */ -static void hotlist_done (void) +static void +hotlist_done (void) { destroy_dlg (hotlist_dlg); l_hotlist = NULL; if (0) - update_panels (UP_OPTIMIZE, UP_KEEPSEL); + update_panels (UP_OPTIMIZE, UP_KEEPSEL); repaint_screen (); } @@ -787,63 +819,76 @@ add2hotlist (char *label, char *directory, enum HotListType type, listbox_append * Must be called by "Ctrl-x a" before using hotlist. */ if (!current_group) - load_hotlist (); + load_hotlist (); listbox_get_current (l_hotlist, NULL, (void **) ¤t); /* Make sure `..' stays at the top of the list. */ if ((current != NULL) && (current->type == HL_TYPE_DOTDOT)) - pos = LISTBOX_APPEND_AFTER; + pos = LISTBOX_APPEND_AFTER; new = new_hotlist (); - new->type = type; - new->label = label; + new->type = type; + new->label = label; new->directory = directory; - new->up = current_group; + new->up = current_group; - if (type == HL_TYPE_GROUP) { - current_group = new; - add_dotdot_to_list (); - current_group = new->up; + if (type == HL_TYPE_GROUP) + { + current_group = new; + add_dotdot_to_list (); + current_group = new->up; } - if (!current_group->head) { - /* first element in group */ - current_group->head = new; - } else if (pos == LISTBOX_APPEND_AFTER) { - new->next = current->next; - current->next = new; - } else if (pos == LISTBOX_APPEND_BEFORE && current == current_group->head) { - /* should be inserted before first item */ - new->next = current; - current_group->head = new; - } else if (pos == LISTBOX_APPEND_BEFORE) { - struct hotlist *p = current_group->head; + if (!current_group->head) + { + /* first element in group */ + current_group->head = new; + } + else if (pos == LISTBOX_APPEND_AFTER) + { + new->next = current->next; + current->next = new; + } + else if (pos == LISTBOX_APPEND_BEFORE && current == current_group->head) + { + /* should be inserted before first item */ + new->next = current; + current_group->head = new; + } + else if (pos == LISTBOX_APPEND_BEFORE) + { + struct hotlist *p = current_group->head; - while (p->next != current) - p = p->next; + while (p->next != current) + p = p->next; - new->next = current; - p->next = new; - } else { /* append at the end */ - struct hotlist *p = current_group->head; + new->next = current; + p->next = new; + } + else + { /* append at the end */ + struct hotlist *p = current_group->head; - while (p->next) - p = p->next; + while (p->next) + p = p->next; - p->next = new; + p->next = new; } - if (hotlist_state.running && type != HL_TYPE_COMMENT && type != HL_TYPE_DOTDOT) { - if (type == HL_TYPE_GROUP) { - char *lbl = g_strconcat ("->", new->label, (char *) NULL); + if (hotlist_state.running && type != HL_TYPE_COMMENT && type != HL_TYPE_DOTDOT) + { + if (type == HL_TYPE_GROUP) + { + char *lbl = g_strconcat ("->", new->label, (char *) NULL); - listbox_add_item (l_hotlist, pos, 0, lbl, new); - g_free (lbl); - } else - listbox_add_item (l_hotlist, pos, 0, new->label, new); - listbox_select_entry (l_hotlist, l_hotlist->pos); + listbox_add_item (l_hotlist, pos, 0, lbl, new); + g_free (lbl); + } + else + listbox_add_item (l_hotlist, pos, 0, new->label, new); + listbox_select_entry (l_hotlist, l_hotlist->pos); } return new; @@ -859,41 +904,42 @@ add2hotlist (char *label, char *directory, enum HotListType type, listbox_append * 64 is longer anyway. */ static void -add_widgets_i18n (QuickWidget* qw, int len) +add_widgets_i18n (QuickWidget * qw, int len) { int i, l[3], space, cur_x; - for (i = 0; i < 3; i++) { - qw [i].u.button.text = _(qw [i].u.button.text); - l[i] = str_term_width1 (qw [i].u.button.text) + 3; + for (i = 0; i < 3; i++) + { + qw[i].u.button.text = _(qw[i].u.button.text); + l[i] = str_term_width1 (qw[i].u.button.text) + 3; } space = (len - 4 - l[0] - l[1] - l[2]) / 4; - for (cur_x = 2 + space, i = 3; i--; cur_x += l[i] + space) { - qw [i].relative_x = cur_x; - qw [i].x_divisions = len; + for (cur_x = 2 + space, i = 3; i--; cur_x += l[i] + space) + { + qw[i].relative_x = cur_x; + qw[i].x_divisions = len; } } #endif /* ENABLE_NLS */ static int add_new_entry_input (const char *header, const char *text1, const char *text2, - const char *help, char **r1, char **r2) + const char *help, char **r1, char **r2) { #define RELATIVE_Y_BUTTONS 4 #define RELATIVE_Y_LABEL_PTH 3 #define RELATIVE_Y_INPUT_PTH 4 - QuickWidget quick_widgets [] = - { - /* 0 */ QUICK_BUTTON (55, 80, RELATIVE_Y_BUTTONS, 0, N_("&Cancel"), B_CANCEL, NULL), - /* 1 */ QUICK_BUTTON (30, 80, RELATIVE_Y_BUTTONS, 0, N_("&Insert"), B_INSERT, NULL), - /* 2 */ QUICK_BUTTON (10, 80, RELATIVE_Y_BUTTONS, 0, N_("&Append"), B_APPEND, NULL), - /* 3 */ QUICK_INPUT (4, 80, RELATIVE_Y_INPUT_PTH, 0, *r2, 58, 2, "input-pth", r2), - /* 4 */ QUICK_LABEL (RELATIVE_Y_LABEL_PTH, 80, 3, 0, text2), - /* 5 */ QUICK_INPUT (4, 80, 3, 0, *r1, 58, 0, "input-lbl", r1), - /* 6 */ QUICK_LABEL (3, 80, 2, 0, text1), - QUICK_END + QuickWidget quick_widgets[] = { + /* 0 */ QUICK_BUTTON (55, 80, RELATIVE_Y_BUTTONS, 0, N_("&Cancel"), B_CANCEL, NULL), + /* 1 */ QUICK_BUTTON (30, 80, RELATIVE_Y_BUTTONS, 0, N_("&Insert"), B_INSERT, NULL), + /* 2 */ QUICK_BUTTON (10, 80, RELATIVE_Y_BUTTONS, 0, N_("&Append"), B_APPEND, NULL), + /* 3 */ QUICK_INPUT (4, 80, RELATIVE_Y_INPUT_PTH, 0, *r2, 58, 2, "input-pth", r2), + /* 4 */ QUICK_LABEL (RELATIVE_Y_LABEL_PTH, 80, 3, 0, text2), + /* 5 */ QUICK_INPUT (4, 80, 3, 0, *r1, 58, 0, "input-lbl", r1), + /* 6 */ QUICK_LABEL (3, 80, 2, 0, text1), + QUICK_END }; int len; @@ -905,35 +951,35 @@ add_new_entry_input (const char *header, const char *text1, const char *text2, static gboolean i18n_flag = FALSE; #endif /* ENABLE_NLS */ - msglen(text1, &lines1, &cols1); - msglen(text2, &lines2, &cols2); + msglen (text1, &lines1, &cols1); + msglen (text2, &lines2, &cols2); len = max (str_term_width1 (header), cols1); len = max (max (len, cols2) + 4, 64); #ifdef ENABLE_NLS - if (!i18n_flag) { - add_widgets_i18n (quick_widgets, len); - i18n_flag = TRUE; + if (!i18n_flag) + { + add_widgets_i18n (quick_widgets, len); + i18n_flag = TRUE; } #endif /* ENABLE_NLS */ { - QuickDialog Quick_input = - { - len, lines1 + lines2 + 7, -1, -1, header, - help, quick_widgets, FALSE - }; + QuickDialog Quick_input = { + len, lines1 + lines2 + 7, -1, -1, header, + help, quick_widgets, FALSE + }; - for (i = 0; i < 7; i++) - quick_widgets [i].y_divisions = Quick_input.ylen; + for (i = 0; i < 7; i++) + quick_widgets[i].y_divisions = Quick_input.ylen; - quick_widgets [0].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2); - quick_widgets [1].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2); - quick_widgets [2].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2); - quick_widgets [3].relative_y = RELATIVE_Y_INPUT_PTH + (lines1); - quick_widgets [4].relative_y = RELATIVE_Y_LABEL_PTH + (lines1); + quick_widgets[0].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2); + quick_widgets[1].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2); + quick_widgets[2].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2); + quick_widgets[3].relative_y = RELATIVE_Y_INPUT_PTH + (lines1); + quick_widgets[4].relative_y = RELATIVE_Y_LABEL_PTH + (lines1); - i = quick_dialog (&Quick_input); + i = quick_dialog (&Quick_input); } return (i != B_CANCEL) ? i : 0; @@ -943,7 +989,8 @@ add_new_entry_input (const char *header, const char *text1, const char *text2, #undef RELATIVE_Y_INPUT_PTH } -static void add_new_entry_cmd (void) +static void +add_new_entry_cmd (void) { char *title, *url, *to_free; int ret; @@ -952,21 +999,22 @@ static void add_new_entry_cmd (void) to_free = title = url = strip_password (g_strdup (current_panel->cwd), 1); ret = add_new_entry_input (_("New hotlist entry"), _("Directory label"), - _("Directory path"), "[Hotlist]", &title, &url); + _("Directory path"), "[Hotlist]", &title, &url); g_free (to_free); if (!ret) - return; - if (!title || !*title || !url || !*url) { - g_free (title); - g_free (url); - return; + return; + if (!title || !*title || !url || !*url) + { + g_free (title); + g_free (url); + return; } if (ret == B_ENTER || ret == B_APPEND) - add2hotlist (title, url, HL_TYPE_ENTRY, LISTBOX_APPEND_AFTER); + add2hotlist (title, url, HL_TYPE_ENTRY, LISTBOX_APPEND_AFTER); else - add2hotlist (title, url, HL_TYPE_ENTRY, LISTBOX_APPEND_BEFORE); + add2hotlist (title, url, HL_TYPE_ENTRY, LISTBOX_APPEND_BEFORE); hotlist_state.modified = 1; } @@ -974,14 +1022,13 @@ static void add_new_entry_cmd (void) static int add_new_group_input (const char *header, const char *label, char **result) { - QuickWidget quick_widgets [] = - { - /* 0 */ QUICK_BUTTON (55, 80, 1, 0, N_("&Cancel"), B_CANCEL, NULL), - /* 1 */ QUICK_BUTTON (30, 80, 1, 0, N_("&Insert"), B_INSERT, NULL), - /* 2 */ QUICK_BUTTON (10, 80, 1, 0, N_("&Append"), B_APPEND, NULL), - /* 3 */ QUICK_INPUT (4, 80, 0, 0, "", 58, 0, "input" , result), - /* 4 */ QUICK_LABEL (3, 80, 2, 0, label), - QUICK_END + QuickWidget quick_widgets[] = { + /* 0 */ QUICK_BUTTON (55, 80, 1, 0, N_("&Cancel"), B_CANCEL, NULL), + /* 1 */ QUICK_BUTTON (30, 80, 1, 0, N_("&Insert"), B_INSERT, NULL), + /* 2 */ QUICK_BUTTON (10, 80, 1, 0, N_("&Append"), B_APPEND, NULL), + /* 3 */ QUICK_INPUT (4, 80, 0, 0, "", 58, 0, "input", result), + /* 4 */ QUICK_LABEL (3, 80, 2, 0, label), + QUICK_END }; int len; @@ -997,52 +1044,54 @@ add_new_group_input (const char *header, const char *label, char **result) len = max (max (str_term_width1 (header), cols) + 4, 64); #ifdef ENABLE_NLS - if (!i18n_flag) { - add_widgets_i18n (quick_widgets, len); - i18n_flag = TRUE; + if (!i18n_flag) + { + add_widgets_i18n (quick_widgets, len); + i18n_flag = TRUE; } #endif /* ENABLE_NLS */ { - QuickDialog Quick_input = - { - len, lines + 6, -1, -1, header, - "[Hotlist]", quick_widgets, FALSE - }; + QuickDialog Quick_input = { + len, lines + 6, -1, -1, header, + "[Hotlist]", quick_widgets, FALSE + }; - int relative_y[] = {1, 1, 1, 0, 2}; /* the relative_x component from the - quick_widgets variable above */ + int relative_y[] = { 1, 1, 1, 0, 2 }; /* the relative_x component from the + quick_widgets variable above */ - for (i = 0; i < 5; i++) - quick_widgets[i].y_divisions = Quick_input.ylen; + for (i = 0; i < 5; i++) + quick_widgets[i].y_divisions = Quick_input.ylen; - for (i = 0; i < 4; i++) - quick_widgets[i].relative_y = relative_y[i] + 2 + lines; + for (i = 0; i < 4; i++) + quick_widgets[i].relative_y = relative_y[i] + 2 + lines; - ret = quick_dialog (&Quick_input); + ret = quick_dialog (&Quick_input); } return (ret != B_CANCEL) ? ret : 0; } -static void add_new_group_cmd (void) +static void +add_new_group_cmd (void) { - char *label; - int ret; + char *label; + int ret; ret = add_new_group_input (_(" New hotlist group "), _("Name of new group"), &label); if (!ret || !label || !*label) - return; + return; if (ret == B_ENTER || ret == B_APPEND) - add2hotlist (label, 0, HL_TYPE_GROUP, LISTBOX_APPEND_AFTER); + add2hotlist (label, 0, HL_TYPE_GROUP, LISTBOX_APPEND_AFTER); else - add2hotlist (label, 0, HL_TYPE_GROUP, LISTBOX_APPEND_BEFORE); + add2hotlist (label, 0, HL_TYPE_GROUP, LISTBOX_APPEND_BEFORE); hotlist_state.modified = 1; } -void add2hotlist_cmd (void) +void +add2hotlist_cmd (void) { char *lc_prompt, *label; const char *cp = _("Label for \"%s\":"); @@ -1051,84 +1100,86 @@ void add2hotlist_cmd (void) strip_password (label_string, 1); - lc_prompt = g_strdup_printf (cp, path_trunc (current_panel->cwd, COLS-2*UX-(l+8))); + lc_prompt = g_strdup_printf (cp, path_trunc (current_panel->cwd, COLS - 2 * UX - (l + 8))); label = input_dialog (_(" Add to hotlist "), lc_prompt, MC_HISTORY_HOTLIST_ADD, label_string); g_free (lc_prompt); - if (!label || !*label) { - g_free (label_string); - g_free (label); - return; + if (!label || !*label) + { + g_free (label_string); + g_free (label); + return; } add2hotlist (label, label_string, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END); hotlist_state.modified = 1; } -static void remove_group (struct hotlist *grp) +static void +remove_group (struct hotlist *grp) { struct hotlist *current = grp->head; - while (current) { - struct hotlist *next = current->next; + while (current) + { + struct hotlist *next = current->next; - if (current->type == HL_TYPE_GROUP) - remove_group (current); + if (current->type == HL_TYPE_GROUP) + remove_group (current); - g_free (current->label); - g_free (current->directory); - g_free (current); + g_free (current->label); + g_free (current->directory); + g_free (current); - current = next; + current = next; } } -static void remove_from_hotlist (struct hotlist *entry) +static void +remove_from_hotlist (struct hotlist *entry) { if (entry == NULL) - return; + return; if (entry->type == HL_TYPE_DOTDOT) - return; + return; - if (confirm_directory_hotlist_delete) { - char *title; - int result; + if (confirm_directory_hotlist_delete) + { + char *title; + int result; - title = g_strconcat (_(" Remove: "), - str_trunc (entry->label, 30), - " ", (char *) NULL); + title = g_strconcat (_(" Remove: "), str_trunc (entry->label, 30), " ", (char *) NULL); - if (safe_delete) - query_set_sel (1); - result = query_dialog (title, - _("\n Are you sure you want to remove this entry?"), - D_ERROR, 2, _("&Yes"), _("&No")); + if (safe_delete) + query_set_sel (1); + result = query_dialog (title, + _("\n Are you sure you want to remove this entry?"), + D_ERROR, 2, _("&Yes"), _("&No")); - g_free (title); + g_free (title); - if (result != 0) - return; + if (result != 0) + return; } - if (entry->type == HL_TYPE_GROUP) { - if (entry->head) { - char *header; - int result; + if (entry->type == HL_TYPE_GROUP) + { + if (entry->head) + { + char *header; + int result; - header = g_strconcat (_(" Remove: "), - str_trunc (entry->label, 30), - " ", (char *) NULL); - result = query_dialog (header, _("\n Group not empty.\n Remove it?"), - D_ERROR, 2, - _("&Yes"), _("&No")); - g_free (header); + header = g_strconcat (_(" Remove: "), str_trunc (entry->label, 30), " ", (char *) NULL); + result = query_dialog (header, _("\n Group not empty.\n Remove it?"), + D_ERROR, 2, _("&Yes"), _("&No")); + g_free (header); - if (result != 0) - return; - } + if (result != 0) + return; + } - remove_group (entry); + remove_group (entry); } unlink_entry (entry); @@ -1159,21 +1210,22 @@ hotlist_cmd (int vfs_or_hotlist) hotlist_state.running = 0; save_hotlist (); - switch (hotlist_dlg->ret_value) { + switch (hotlist_dlg->ret_value) + { default: case B_CANCEL: - break; + break; case B_ENTER: - { - char *text = NULL; - struct hotlist *hlp = NULL; + { + char *text = NULL; + struct hotlist *hlp = NULL; - listbox_get_current (l_hotlist, &text, (void **) &hlp); - target = g_strdup (hlp != NULL ? hlp->directory : text); - break; - } - } /* switch */ + listbox_get_current (l_hotlist, &text, (void **) &hlp); + target = g_strdup (hlp != NULL ? hlp->directory : text); + break; + } + } /* switch */ hotlist_done (); return target; @@ -1182,8 +1234,8 @@ hotlist_cmd (int vfs_or_hotlist) static void load_group (struct hotlist *grp) { - gchar **profile_keys, **keys; - gsize len; + gchar **profile_keys, **keys; + gsize len; char *group_section; struct hotlist *current = 0; @@ -1193,37 +1245,33 @@ load_group (struct hotlist *grp) current_group = grp; - while (*profile_keys){ - add2hotlist ( - mc_config_get_string(mc_main_config, group_section, *profile_keys, ""), - g_strdup (*profile_keys), - HL_TYPE_GROUP, - LISTBOX_APPEND_AT_END); - profile_keys++; + while (*profile_keys) + { + add2hotlist (mc_config_get_string (mc_main_config, group_section, *profile_keys, ""), + g_strdup (*profile_keys), HL_TYPE_GROUP, LISTBOX_APPEND_AT_END); + profile_keys++; } g_free (group_section); - g_strfreev(keys); + g_strfreev (keys); - profile_keys = keys = mc_config_get_keys (mc_main_config, grp->directory,&len); + profile_keys = keys = mc_config_get_keys (mc_main_config, grp->directory, &len); - while (*profile_keys){ - add2hotlist ( - mc_config_get_string(mc_main_config,group_section,*profile_keys,""), - g_strdup (*profile_keys), - HL_TYPE_ENTRY, - LISTBOX_APPEND_AT_END); - profile_keys++; + while (*profile_keys) + { + add2hotlist (mc_config_get_string (mc_main_config, group_section, *profile_keys, ""), + g_strdup (*profile_keys), HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END); + profile_keys++; } - g_strfreev(keys); + g_strfreev (keys); for (current = grp->head; current; current = current->next) - load_group (current); + load_group (current); } -#define TKN_GROUP 0 -#define TKN_ENTRY 1 -#define TKN_STRING 2 -#define TKN_URL 3 +#define TKN_GROUP 0 +#define TKN_ENTRY 1 +#define TKN_STRING 2 +#define TKN_URL 3 #define TKN_ENDGROUP 4 #define TKN_COMMENT 5 #define TKN_EOL 125 @@ -1236,83 +1284,92 @@ static char *hotlist_file_name; static FILE *hotlist_file; static time_t hotlist_file_mtime; -static int hot_skip_blanks (void) +static int +hot_skip_blanks (void) { int c; while ((c = getc (hotlist_file)) != EOF && c != '\n' && g_ascii_isspace (c)) - ; + ; return c; } -static int hot_next_token (void) +static int +hot_next_token (void) { - int c, ret=0; + int c, ret = 0; size_t l; - if (tkn_buf == NULL) tkn_buf = g_string_new (""); - g_string_set_size(tkn_buf,0); + if (tkn_buf == NULL) + tkn_buf = g_string_new (""); + g_string_set_size (tkn_buf, 0); -again: + again: c = hot_skip_blanks (); - switch (c) { + switch (c) + { case EOF: - ret = TKN_EOF; - break; + ret = TKN_EOF; + break; case '\n': - ret = TKN_EOL; - break; + ret = TKN_EOL; + break; case '#': - while ((c = getc (hotlist_file)) != EOF && c != '\n') { - g_string_append_c (tkn_buf, c); - } - ret = TKN_COMMENT; - break; + while ((c = getc (hotlist_file)) != EOF && c != '\n') + { + g_string_append_c (tkn_buf, c); + } + ret = TKN_COMMENT; + break; case '"': - while ((c = getc (hotlist_file)) != EOF && c != '"') { - if (c == '\\') - if ((c = getc (hotlist_file)) == EOF){ - g_string_free (tkn_buf, TRUE); - return TKN_EOF; - } - g_string_append_c (tkn_buf, c == '\n' ? ' ' : c); - } - if (c == EOF) - ret = TKN_EOF; - else - ret = TKN_STRING; - break; + while ((c = getc (hotlist_file)) != EOF && c != '"') + { + if (c == '\\') + if ((c = getc (hotlist_file)) == EOF) + { + g_string_free (tkn_buf, TRUE); + return TKN_EOF; + } + g_string_append_c (tkn_buf, c == '\n' ? ' ' : c); + } + if (c == EOF) + ret = TKN_EOF; + else + ret = TKN_STRING; + break; case '\\': - if ((c = getc (hotlist_file)) == EOF){ - g_string_free (tkn_buf, TRUE); - return TKN_EOF; - } - if (c == '\n') - goto again; + if ((c = getc (hotlist_file)) == EOF) + { + g_string_free (tkn_buf, TRUE); + return TKN_EOF; + } + if (c == '\n') + goto again; - /* fall through; it is taken as normal character */ + /* fall through; it is taken as normal character */ default: - do { - g_string_append_c (tkn_buf, g_ascii_toupper (c)); - } while ((c = fgetc (hotlist_file)) != EOF && - (g_ascii_isalnum (c) || !isascii (c))); - if (c != EOF) - ungetc (c, hotlist_file); + do + { + g_string_append_c (tkn_buf, g_ascii_toupper (c)); + } + while ((c = fgetc (hotlist_file)) != EOF && (g_ascii_isalnum (c) || !isascii (c))); + if (c != EOF) + ungetc (c, hotlist_file); l = tkn_buf->len; - if (strncmp (tkn_buf->str, "GROUP", l) == 0) - ret = TKN_GROUP; - else if (strncmp (tkn_buf->str, "ENTRY", l) == 0) - ret = TKN_ENTRY; - else if (strncmp (tkn_buf->str, "ENDGROUP", l) == 0) - ret = TKN_ENDGROUP; - else if (strncmp (tkn_buf->str, "URL", l) == 0) - ret = TKN_URL; - else - ret = TKN_UNKNOWN; - break; + if (strncmp (tkn_buf->str, "GROUP", l) == 0) + ret = TKN_GROUP; + else if (strncmp (tkn_buf->str, "ENTRY", l) == 0) + ret = TKN_ENTRY; + else if (strncmp (tkn_buf->str, "ENDGROUP", l) == 0) + ret = TKN_ENDGROUP; + else if (strncmp (tkn_buf->str, "URL", l) == 0) + ret = TKN_URL; + else + ret = TKN_UNKNOWN; + break; } return ret; } @@ -1327,120 +1384,126 @@ if ((tkn = hot_next_token ()) != _TKN_) { \ hotlist_state.readonly = 1; \ hotlist_state.file_error = 1; \ while (tkn != TKN_EOL && tkn != TKN_EOF) \ - tkn = hot_next_token (); \ + tkn = hot_next_token (); \ break; \ } static void -hot_load_group (struct hotlist * grp) +hot_load_group (struct hotlist *grp) { - int tkn; + int tkn; struct hotlist *new_grp; - char *label, *url; + char *label, *url; current_group = grp; - while ((tkn = hot_next_token()) != TKN_ENDGROUP) - switch (tkn) { - case TKN_GROUP: - CHECK_TOKEN(TKN_STRING); - new_grp = add2hotlist (g_strdup (tkn_buf->str), 0, HL_TYPE_GROUP, LISTBOX_APPEND_AT_END); - SKIP_TO_EOL; - hot_load_group (new_grp); - current_group = grp; - break; - case TKN_ENTRY: - CHECK_TOKEN(TKN_STRING); + while ((tkn = hot_next_token ()) != TKN_ENDGROUP) + switch (tkn) + { + case TKN_GROUP: + CHECK_TOKEN (TKN_STRING); + new_grp = + add2hotlist (g_strdup (tkn_buf->str), 0, HL_TYPE_GROUP, LISTBOX_APPEND_AT_END); + SKIP_TO_EOL; + hot_load_group (new_grp); + current_group = grp; + break; + case TKN_ENTRY: + CHECK_TOKEN (TKN_STRING); label = g_strdup (tkn_buf->str); - CHECK_TOKEN(TKN_URL); - CHECK_TOKEN(TKN_STRING); - url = g_strdup (tkn_buf->str); - add2hotlist (label, url, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END); - SKIP_TO_EOL; - break; - case TKN_COMMENT: + CHECK_TOKEN (TKN_URL); + CHECK_TOKEN (TKN_STRING); + url = g_strdup (tkn_buf->str); + add2hotlist (label, url, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END); + SKIP_TO_EOL; + break; + case TKN_COMMENT: label = g_strdup (tkn_buf->str); - add2hotlist (label, 0, HL_TYPE_COMMENT, LISTBOX_APPEND_AT_END); - break; - case TKN_EOF: - hotlist_state.readonly = 1; - hotlist_state.file_error = 1; - return; - break; - case TKN_EOL: - /* skip empty lines */ - break; - default: - hotlist_state.readonly = 1; - hotlist_state.file_error = 1; - SKIP_TO_EOL; - break; - } + add2hotlist (label, 0, HL_TYPE_COMMENT, LISTBOX_APPEND_AT_END); + break; + case TKN_EOF: + hotlist_state.readonly = 1; + hotlist_state.file_error = 1; + return; + break; + case TKN_EOL: + /* skip empty lines */ + break; + default: + hotlist_state.readonly = 1; + hotlist_state.file_error = 1; + SKIP_TO_EOL; + break; + } SKIP_TO_EOL; } static void -hot_load_file (struct hotlist * grp) +hot_load_file (struct hotlist *grp) { - int tkn; + int tkn; struct hotlist *new_grp; - char *label, *url; + char *label, *url; current_group = grp; - while ((tkn = hot_next_token())!= TKN_EOF) - switch (tkn) { - case TKN_GROUP: - CHECK_TOKEN(TKN_STRING); - new_grp = add2hotlist (g_strdup (tkn_buf->str), 0, HL_TYPE_GROUP, LISTBOX_APPEND_AT_END); - SKIP_TO_EOL; - hot_load_group (new_grp); - current_group = grp; - break; - case TKN_ENTRY: - CHECK_TOKEN(TKN_STRING); + while ((tkn = hot_next_token ()) != TKN_EOF) + switch (tkn) + { + case TKN_GROUP: + CHECK_TOKEN (TKN_STRING); + new_grp = + add2hotlist (g_strdup (tkn_buf->str), 0, HL_TYPE_GROUP, LISTBOX_APPEND_AT_END); + SKIP_TO_EOL; + hot_load_group (new_grp); + current_group = grp; + break; + case TKN_ENTRY: + CHECK_TOKEN (TKN_STRING); label = g_strdup (tkn_buf->str); - CHECK_TOKEN(TKN_URL); - CHECK_TOKEN(TKN_STRING); + CHECK_TOKEN (TKN_URL); + CHECK_TOKEN (TKN_STRING); url = g_strdup (tkn_buf->str); - add2hotlist (label, url, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END); - SKIP_TO_EOL; - break; - case TKN_COMMENT: + add2hotlist (label, url, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END); + SKIP_TO_EOL; + break; + case TKN_COMMENT: label = g_strdup (tkn_buf->str); - add2hotlist (label, 0, HL_TYPE_COMMENT, LISTBOX_APPEND_AT_END); - break; - case TKN_EOL: - /* skip empty lines */ - break; - default: - hotlist_state.readonly = 1; - hotlist_state.file_error = 1; - SKIP_TO_EOL; - break; - } + add2hotlist (label, 0, HL_TYPE_COMMENT, LISTBOX_APPEND_AT_END); + break; + case TKN_EOL: + /* skip empty lines */ + break; + default: + hotlist_state.readonly = 1; + hotlist_state.file_error = 1; + SKIP_TO_EOL; + break; + } } static void clean_up_hotlist_groups (const char *section) { - char *grp_section; + char *grp_section; gchar **profile_keys, **keys; gsize len; grp_section = g_strconcat (section, ".Group", (char *) NULL); - if (mc_config_has_group(mc_main_config, section)) - mc_config_del_group (mc_main_config, section); + if (mc_config_has_group (mc_main_config, section)) + mc_config_del_group (mc_main_config, section); - if (mc_config_has_group (mc_main_config, grp_section)) { - profile_keys = keys = mc_config_get_keys (mc_main_config, grp_section,&len); + if (mc_config_has_group (mc_main_config, grp_section)) + { + profile_keys = keys = mc_config_get_keys (mc_main_config, grp_section, &len); - while (*profile_keys) { - clean_up_hotlist_groups (*profile_keys); - profile_keys++; - } - g_strfreev(keys); - mc_config_del_group (mc_main_config, grp_section); + while (*profile_keys) + { + clean_up_hotlist_groups (*profile_keys); + profile_keys++; + } + g_strfreev (keys); + mc_config_del_group (mc_main_config, grp_section); } g_free (grp_section); } @@ -1450,58 +1513,63 @@ clean_up_hotlist_groups (const char *section) static void load_hotlist (void) { - int remove_old_list = 0; + int remove_old_list = 0; struct stat stat_buf; - if (hotlist_state.loaded) { - stat (hotlist_file_name, &stat_buf); - if (hotlist_file_mtime < stat_buf.st_mtime) - done_hotlist (); - else - return; + if (hotlist_state.loaded) + { + stat (hotlist_file_name, &stat_buf); + if (hotlist_file_mtime < stat_buf.st_mtime) + done_hotlist (); + else + return; } if (!hotlist_file_name) - hotlist_file_name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_HOTLIST_FILE, NULL); + hotlist_file_name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_HOTLIST_FILE, NULL); - hotlist = new_hotlist (); - hotlist->type = HL_TYPE_GROUP; - hotlist->label = g_strdup (_(" Top level group ")); - hotlist->up = hotlist; + hotlist = new_hotlist (); + hotlist->type = HL_TYPE_GROUP; + hotlist->label = g_strdup (_(" Top level group ")); + hotlist->up = hotlist; /* * compatibility :-( */ hotlist->directory = g_strdup ("Hotlist"); - if ((hotlist_file = fopen (hotlist_file_name, "r")) == 0) { - int result; + if ((hotlist_file = fopen (hotlist_file_name, "r")) == 0) + { + int result; - load_group (hotlist); - hotlist_state.loaded = 1; - /* - * just to be sure we got copy - */ - hotlist_state.modified = 1; - result = save_hotlist (); - hotlist_state.modified = 0; - if (result) { - remove_old_list = 1; - } else { - message (D_ERROR, _(" Hotlist Load "), - _("MC was unable to write ~/%s file, your old hotlist entries were not deleted"), - MC_USERCONF_DIR PATH_SEP_STR MC_HOTLIST_FILE); - } - } else { - hot_load_file (hotlist); - fclose (hotlist_file); - hotlist_state.loaded = 1; + load_group (hotlist); + hotlist_state.loaded = 1; + /* + * just to be sure we got copy + */ + hotlist_state.modified = 1; + result = save_hotlist (); + hotlist_state.modified = 0; + if (result) + remove_old_list = 1; + else + message (D_ERROR, _(" Hotlist Load "), + _ + ("MC was unable to write ~/%s file, your old hotlist entries were not deleted"), + MC_USERCONF_DIR PATH_SEP_STR MC_HOTLIST_FILE); + } + else + { + hot_load_file (hotlist); + fclose (hotlist_file); + hotlist_state.loaded = 1; } - if (remove_old_list) { - GError *error = NULL; - clean_up_hotlist_groups ("Hotlist"); - if (! mc_config_save_file (mc_main_config, &error)) - setup_save_config_show_error(mc_main_config->ini_path, &error); + if (remove_old_list) + { + GError *error = NULL; + clean_up_hotlist_groups ("Hotlist"); + if (!mc_config_save_file (mc_main_config, &error)) + setup_save_config_show_error (mc_main_config->ini_path, &error); } stat (hotlist_file_name, &stat_buf); @@ -1510,80 +1578,88 @@ load_hotlist (void) } -static int list_level = 0; +static int list_level = 0; static void hot_save_group (struct hotlist *grp) { struct hotlist *current = grp->head; - int i; - char *s; + int i; + char *s; #define INDENT(n) \ do { \ for (i = 0; i < n; i++) \ - putc (' ', hotlist_file); \ + putc (' ', hotlist_file); \ } while (0) - for (;current; current = current->next) - switch (current->type) { + for (; current; current = current->next) + switch (current->type) + { case HL_TYPE_GROUP: - INDENT (list_level); - fputs ("GROUP \"", hotlist_file); - for (s = current->label; *s; s++) { - if (*s == '"' || *s == '\\') - putc ('\\', hotlist_file); - putc (*s, hotlist_file); - } - fputs ("\"\n", hotlist_file); - list_level += 2; - hot_save_group (current); - list_level -= 2; - INDENT (list_level); - fputs ("ENDGROUP\n", hotlist_file); - break; + INDENT (list_level); + fputs ("GROUP \"", hotlist_file); + for (s = current->label; *s; s++) + { + if (*s == '"' || *s == '\\') + putc ('\\', hotlist_file); + putc (*s, hotlist_file); + } + fputs ("\"\n", hotlist_file); + list_level += 2; + hot_save_group (current); + list_level -= 2; + INDENT (list_level); + fputs ("ENDGROUP\n", hotlist_file); + break; case HL_TYPE_ENTRY: - INDENT(list_level); - fputs ("ENTRY \"", hotlist_file); - for (s = current->label; *s; s++) { - if (*s == '"' || *s == '\\') - putc ('\\', hotlist_file); - putc (*s, hotlist_file); - } - fputs ("\" URL \"", hotlist_file); - for (s = current->directory; *s; s++) { - if (*s == '"' || *s == '\\') - putc ('\\', hotlist_file); - putc (*s, hotlist_file); - } - fputs ("\"\n", hotlist_file); - break; - case HL_TYPE_COMMENT: - fprintf (hotlist_file, "#%s\n", current->label); - break; - case HL_TYPE_DOTDOT: - /* do nothing */ - break; - } + INDENT (list_level); + fputs ("ENTRY \"", hotlist_file); + for (s = current->label; *s; s++) + { + if (*s == '"' || *s == '\\') + putc ('\\', hotlist_file); + putc (*s, hotlist_file); + } + fputs ("\" URL \"", hotlist_file); + for (s = current->directory; *s; s++) + { + if (*s == '"' || *s == '\\') + putc ('\\', hotlist_file); + putc (*s, hotlist_file); + } + fputs ("\"\n", hotlist_file); + break; + case HL_TYPE_COMMENT: + fprintf (hotlist_file, "#%s\n", current->label); + break; + case HL_TYPE_DOTDOT: + /* do nothing */ + break; + } } -int save_hotlist (void) +int +save_hotlist (void) { - int saved = 0; - struct stat stat_buf; + int saved = 0; + struct stat stat_buf; - if (!hotlist_state.readonly && hotlist_state.modified && hotlist_file_name) { - mc_util_make_backup_if_possible (hotlist_file_name, ".bak"); + if (!hotlist_state.readonly && hotlist_state.modified && hotlist_file_name) + { + mc_util_make_backup_if_possible (hotlist_file_name, ".bak"); - if ((hotlist_file = fopen (hotlist_file_name, "w")) != 0) { - hot_save_group (hotlist); - fclose (hotlist_file); - stat (hotlist_file_name, &stat_buf); - hotlist_file_mtime = stat_buf.st_mtime; - saved = 1; - hotlist_state.modified = 0; - } else - mc_util_restore_from_backup_if_possible (hotlist_file_name, ".bak"); + if ((hotlist_file = fopen (hotlist_file_name, "w")) != 0) + { + hot_save_group (hotlist); + fclose (hotlist_file); + stat (hotlist_file_name, &stat_buf); + hotlist_file_mtime = stat_buf.st_mtime; + saved = 1; + hotlist_state.modified = 0; + } + else + mc_util_restore_from_backup_if_possible (hotlist_file_name, ".bak"); } return saved; @@ -1593,14 +1669,16 @@ int save_hotlist (void) * Unload list from memory. * Don't confuse with hotlist_done() for GUI. */ -void done_hotlist (void) +void +done_hotlist (void) { - if (hotlist){ - remove_group (hotlist); - g_free (hotlist->label); - g_free (hotlist->directory); - g_free (hotlist); - hotlist = 0; + if (hotlist) + { + remove_group (hotlist); + g_free (hotlist->label); + g_free (hotlist->directory); + g_free (hotlist); + hotlist = 0; } hotlist_state.loaded = 0; @@ -1610,17 +1688,19 @@ void done_hotlist (void) l_hotlist = 0; current_group = 0; - if (tkn_buf){ - g_string_free (tkn_buf, TRUE); - tkn_buf = NULL; + if (tkn_buf) + { + g_string_free (tkn_buf, TRUE); + tkn_buf = NULL; } } static void add_dotdot_to_list (void) { - if (current_group != hotlist) { - if (hotlist_has_dot_dot != 0) - add2hotlist (g_strdup (".."), g_strdup (".."), HL_TYPE_DOTDOT, LISTBOX_APPEND_AT_END); + if (current_group != hotlist) + { + if (hotlist_has_dot_dot != 0) + add2hotlist (g_strdup (".."), g_strdup (".."), HL_TYPE_DOTDOT, LISTBOX_APPEND_AT_END); } } diff --git a/src/info.c b/src/info.c index 73bc58685..91499799f 100644 --- a/src/info.c +++ b/src/info.c @@ -1,12 +1,12 @@ /* Panel managing. Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc. - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -27,19 +27,19 @@ #include "lib/global.h" #include "lib/tty/tty.h" -#include "lib/tty/key.h" /* is_idle() */ -#include "lib/tty/mouse.h" /* Gpm_Event */ +#include "lib/tty/key.h" /* is_idle() */ +#include "lib/tty/mouse.h" /* Gpm_Event */ #include "lib/skin.h" #include "lib/unixcompat.h" #include "lib/strutil.h" #include "dialog.h" -#include "widget.h" /* default_proc*/ -#include "main-widgets.h" /* the_menubar*/ -#include "dir.h" /* required by panel */ -#include "panel.h" /* for the panel structure */ -#include "main.h" /* other_panel, current_panel definitions */ -#include "menu.h" /* menubar_visible */ +#include "widget.h" /* default_proc */ +#include "main-widgets.h" /* the_menubar */ +#include "dir.h" /* required by panel */ +#include "panel.h" /* for the panel structure */ +#include "main.h" /* other_panel, current_panel definitions */ +#include "menu.h" /* menubar_visible */ #include "layout.h" #include "mountlist.h" #include "info.h" @@ -48,7 +48,8 @@ # define VERSION "undefined" #endif -struct WInfo { +struct WInfo +{ Widget widget; int ready; }; @@ -57,13 +58,13 @@ struct WInfo { static gboolean initialized = FALSE; 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_setcolor (NORMAL_COLOR); widget_erase (&info->widget); - draw_box (h, info->widget.y, info->widget.x, - info->widget.lines, info->widget.cols, FALSE); + draw_box (h, info->widget.y, info->widget.x, info->widget.lines, info->widget.cols, FALSE); } static void @@ -75,209 +76,208 @@ info_show_info (struct WInfo *info) struct stat st; if (!is_idle ()) - return; + return; info_box (info->widget.parent, info); tty_setcolor (MARKED_COLOR); widget_move (&info->widget, 1, 3); tty_printf (_("Midnight Commander %s"), VERSION); tty_setcolor (NORMAL_COLOR); - tty_draw_hline (info->widget.y + 2, info->widget.x + 1, - ACS_HLINE, info->widget.cols - 2); + tty_draw_hline (info->widget.y + 2, info->widget.x + 1, ACS_HLINE, info->widget.cols - 2); if (get_current_type () != view_listing) - return; + return; if (!info->ready) - return; + return; 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 */ - if (i18n_adjust == 0) { - /* This printf pattern string is used as a reference for size */ - file_label = _("File: %s"); - i18n_adjust = str_term_width1 (file_label) + 2; + if (i18n_adjust == 0) + { + /* This printf pattern string is used as a reference for size */ + file_label = _("File: %s"); + i18n_adjust = str_term_width1 (file_label) + 2; } buff = g_string_new (""); - switch (info->widget.lines-2){ - /* Note: all cases are fall-throughs */ + switch (info->widget.lines - 2) + { + /* Note: all cases are fall-throughs */ default: case 16: - widget_move (&info->widget, 16, 3); - if (myfs_stats.nfree >0 || myfs_stats.nodes > 0) - tty_printf (_("Free nodes: %d (%d%%) of %d"), - myfs_stats.nfree, - myfs_stats.total - ? 100 * myfs_stats.nfree / myfs_stats.nodes : 0, - myfs_stats.nodes); - else - tty_print_string (_("No node information")); + widget_move (&info->widget, 16, 3); + if (myfs_stats.nfree > 0 || myfs_stats.nodes > 0) + tty_printf (_("Free nodes: %d (%d%%) of %d"), + myfs_stats.nfree, + myfs_stats.total + ? 100 * myfs_stats.nfree / myfs_stats.nodes : 0, myfs_stats.nodes); + else + tty_print_string (_("No node information")); case 15: - widget_move (&info->widget, 15, 3); - if (myfs_stats.avail > 0 || myfs_stats.total > 0){ - char buffer1 [6], buffer2[6]; - size_trunc_len (buffer1, 5, myfs_stats.avail, 1); - size_trunc_len (buffer2, 5, myfs_stats.total, 1); - tty_printf (_("Free space: %s (%d%%) of %s"), buffer1, myfs_stats.total ? - (int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0, - buffer2); - } else - tty_print_string (_("No space information")); + widget_move (&info->widget, 15, 3); + if (myfs_stats.avail > 0 || myfs_stats.total > 0) + { + char buffer1[6], buffer2[6]; + size_trunc_len (buffer1, 5, myfs_stats.avail, 1); + size_trunc_len (buffer2, 5, myfs_stats.total, 1); + tty_printf (_("Free space: %s (%d%%) of %s"), buffer1, myfs_stats.total ? + (int) (100 * (double) myfs_stats.avail / myfs_stats.total) : 0, buffer2); + } + else + tty_print_string (_("No space information")); case 14: - widget_move (&info->widget, 14, 3); - tty_printf (_("Type: %s "), - myfs_stats.typename ? myfs_stats.typename : _("non-local vfs")); - if (myfs_stats.type != 0xffff && myfs_stats.type != -1) - tty_printf (" (%Xh)", myfs_stats.type); + widget_move (&info->widget, 14, 3); + tty_printf (_("Type: %s "), + myfs_stats.typename ? myfs_stats.typename : _("non-local vfs")); + if (myfs_stats.type != 0xffff && myfs_stats.type != -1) + tty_printf (" (%Xh)", myfs_stats.type); case 13: - widget_move (&info->widget, 13, 3); - str_printf (buff, _("Device: %s"), - str_trunc (myfs_stats.device, info->widget.cols - i18n_adjust)); + widget_move (&info->widget, 13, 3); + str_printf (buff, _("Device: %s"), + str_trunc (myfs_stats.device, info->widget.cols - i18n_adjust)); tty_print_string (buff->str); - g_string_set_size(buff, 0); + g_string_set_size (buff, 0); case 12: - widget_move (&info->widget, 12, 3); + widget_move (&info->widget, 12, 3); 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); - g_string_set_size(buff, 0); + g_string_set_size (buff, 0); case 11: - widget_move (&info->widget, 11, 3); + widget_move (&info->widget, 11, 3); str_printf (buff, _("Accessed: %s"), file_date (st.st_atime)); tty_print_string (buff->str); - g_string_set_size(buff, 0); + g_string_set_size (buff, 0); case 10: - widget_move (&info->widget, 10, 3); + widget_move (&info->widget, 10, 3); str_printf (buff, _("Modified: %s"), file_date (st.st_mtime)); tty_print_string (buff->str); - g_string_set_size(buff, 0); + g_string_set_size (buff, 0); case 9: - widget_move (&info->widget, 9, 3); - /* TRANSLATORS: "Status changed", like in the stat(2) man page */ + widget_move (&info->widget, 9, 3); + /* TRANSLATORS: "Status changed", like in the stat(2) man page */ str_printf (buff, _("Status: %s"), file_date (st.st_ctime)); tty_print_string (buff->str); - g_string_set_size(buff, 0); + g_string_set_size (buff, 0); case 8: - widget_move (&info->widget, 8, 3); + widget_move (&info->widget, 8, 3); #ifdef HAVE_STRUCT_STAT_ST_RDEV - if (S_ISCHR (st.st_mode) || S_ISBLK(st.st_mode)) - tty_printf (_("Dev. type: major %lu, minor %lu"), - (unsigned long) major (st.st_rdev), - (unsigned long) minor (st.st_rdev)); - else + if (S_ISCHR (st.st_mode) || S_ISBLK (st.st_mode)) + tty_printf (_("Dev. type: major %lu, minor %lu"), + (unsigned long) major (st.st_rdev), (unsigned long) minor (st.st_rdev)); + else #endif - { - char buffer[10]; - size_trunc_len(buffer, 9, st.st_size, 0); - tty_printf (_("Size: %s"), buffer); + { + char buffer[10]; + size_trunc_len (buffer, 9, st.st_size, 0); + tty_printf (_("Size: %s"), buffer); #ifdef HAVE_STRUCT_STAT_ST_BLOCKS - tty_printf (ngettext(" (%ld block)", " (%ld blocks)", - (unsigned long int) st.st_blocks), - (long int) st.st_blocks); + tty_printf (ngettext (" (%ld block)", " (%ld blocks)", + (unsigned long int) st.st_blocks), (long int) st.st_blocks); #endif - } + } case 7: - widget_move (&info->widget, 7, 3); - tty_printf (_("Owner: %s/%s"), - get_owner (st.st_uid), - get_group (st.st_gid)); + widget_move (&info->widget, 7, 3); + tty_printf (_("Owner: %s/%s"), get_owner (st.st_uid), get_group (st.st_gid)); case 6: - widget_move (&info->widget, 6, 3); - tty_printf (_("Links: %d"), (int) st.st_nlink); + widget_move (&info->widget, 6, 3); + tty_printf (_("Links: %d"), (int) st.st_nlink); case 5: - widget_move (&info->widget, 5, 3); - tty_printf (_("Mode: %s (%04o)"), - string_perm (st.st_mode), (unsigned) st.st_mode & 07777); + widget_move (&info->widget, 5, 3); + tty_printf (_("Mode: %s (%04o)"), + string_perm (st.st_mode), (unsigned) st.st_mode & 07777); case 4: - widget_move (&info->widget, 4, 3); - tty_printf (_("Location: %Xh:%Xh"), (int)st.st_dev, (int)st.st_ino); + widget_move (&info->widget, 4, 3); + tty_printf (_("Location: %Xh:%Xh"), (int) st.st_dev, (int) st.st_ino); case 3: - { - const char *fname; + { + const char *fname; - widget_move (&info->widget, 3, 2); - fname = current_panel->dir.list [current_panel->selected].fname; - str_printf (buff, file_label, - str_trunc (fname, info->widget.cols - i18n_adjust)); - tty_print_string (buff->str); - } + widget_move (&info->widget, 3, 2); + fname = current_panel->dir.list[current_panel->selected].fname; + str_printf (buff, file_label, str_trunc (fname, info->widget.cols - i18n_adjust)); + tty_print_string (buff->str); + } case 2: case 1: case 0: - ; - } /* switch */ + ; + } /* switch */ g_string_free (buff, TRUE); } -static void info_hook (void *data) +static void +info_hook (void *data) { struct WInfo *info = (struct WInfo *) data; Widget *other_widget; other_widget = get_panel_widget (get_current_index ()); if (!other_widget) - return; + return; if (dlg_overlap (&info->widget, other_widget)) - return; + return; info->ready = 1; info_show_info (info); } 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; - switch (msg) { + switch (msg) + { case WIDGET_INIT: - add_hook (&select_file_hook, info_hook, info); - info->ready = 0; - return MSG_HANDLED; + add_hook (&select_file_hook, info_hook, info); + info->ready = 0; + return MSG_HANDLED; case WIDGET_DRAW: - info_hook (info); - info_show_info (info); - return MSG_HANDLED; + info_hook (info); + info_show_info (info); + return MSG_HANDLED; case WIDGET_FOCUS: - return MSG_NOT_HANDLED; + return MSG_NOT_HANDLED; case WIDGET_DESTROY: - delete_hook (&select_file_hook, info_hook); - return MSG_HANDLED; + delete_hook (&select_file_hook, info_hook); + return MSG_HANDLED; default: - return default_proc (msg, parm); + return default_proc (msg, parm); } } static int -info_event (Gpm_Event *event, void *data) +info_event (Gpm_Event * event, void *data) { Widget *w = &((WInfo *) data)->widget; /* rest of the upper frame, the menu is invisible - call menu */ - if (event->type & GPM_DOWN && event->y == 1 && !menubar_visible) { - event->x += w->x; - return the_menubar->widget.mouse (event, the_menubar); + if (event->type & GPM_DOWN && event->y == 1 && !menubar_visible) + { + event->x += w->x; + return the_menubar->widget.mouse (event, the_menubar); } return MOU_NORMAL; @@ -293,9 +293,10 @@ info_new (void) /* We do not want the cursor */ widget_want_cursor (info->widget, 0); - if (!initialized) { - initialized = TRUE; - init_my_statfs (); + if (!initialized) + { + initialized = TRUE; + init_my_statfs (); } return info; diff --git a/src/menu.c b/src/menu.c index 0fd704b35..800854ef8 100644 --- a/src/menu.c +++ b/src/menu.c @@ -31,19 +31,19 @@ #include "lib/tty/tty.h" #include "lib/skin.h" #include "lib/tty/mouse.h" -#include "lib/tty/key.h" /* key macros */ +#include "lib/tty/key.h" /* key macros */ #include "lib/strutil.h" -#include "cmddef.h" /* CK_Ignore_Key */ +#include "cmddef.h" /* CK_Ignore_Key */ #include "help.h" #include "dialog.h" #include "widget.h" -#include "main.h" /* is_right */ +#include "main.h" /* is_right */ #include "menu.h" -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_create (const char *name, unsigned long command) @@ -60,50 +60,55 @@ menu_entry_create (const char *name, unsigned long command) } void -menu_entry_free (menu_entry_t *entry) +menu_entry_free (menu_entry_t * entry) { - if (entry != NULL) { - release_hotkey (entry->text); - g_free (entry->shortcut); - g_free (entry); + if (entry != NULL) + { + release_hotkey (entry->text); + g_free (entry->shortcut); + g_free (entry); } } static void -menu_arrange (Menu *menu, dlg_shortcut_str get_shortcut) +menu_arrange (Menu * menu, dlg_shortcut_str get_shortcut) { - if (menu != NULL) { - GList *i; - size_t max_shortcut_len = 0; + if (menu != NULL) + { + GList *i; + size_t max_shortcut_len = 0; - menu->max_entry_len = 1; - menu->max_hotkey_len = 1; + menu->max_entry_len = 1; + menu->max_hotkey_len = 1; - for (i = menu->entries; i != NULL; i = g_list_next (i)) { - menu_entry_t *entry = i->data; + for (i = menu->entries; i != NULL; i = g_list_next (i)) + { + menu_entry_t *entry = i->data; - if (entry != NULL) { - size_t len; + if (entry != NULL) + { + size_t len; - len = (size_t) hotkey_width (entry->text); - menu->max_hotkey_len = max (menu->max_hotkey_len, len); + len = (size_t) hotkey_width (entry->text); + menu->max_hotkey_len = max (menu->max_hotkey_len, len); - if (get_shortcut != NULL) - entry->shortcut = get_shortcut (entry->command); + if (get_shortcut != NULL) + entry->shortcut = get_shortcut (entry->command); - if (entry->shortcut != NULL) { - len = (size_t) str_term_width1 (entry->shortcut); - max_shortcut_len = max (max_shortcut_len, len); - } - } - } + if (entry->shortcut != NULL) + { + len = (size_t) str_term_width1 (entry->shortcut); + max_shortcut_len = max (max_shortcut_len, len); + } + } + } - menu->max_entry_len = menu->max_hotkey_len + max_shortcut_len; + menu->max_entry_len = menu->max_hotkey_len + max_shortcut_len; } } 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; @@ -120,7 +125,7 @@ create_menu (const char *name, GList *entries, const char *help_node) } void -destroy_menu (Menu *menu) +destroy_menu (Menu * menu) { release_hotkey (menu->text); g_list_foreach (menu->entries, (GFunc) menu_entry_free, NULL); @@ -130,7 +135,7 @@ destroy_menu (Menu *menu) } 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_entry_t *entry = g_list_nth_data (menu->entries, idx); @@ -138,50 +143,54 @@ menubar_paint_idx (WMenuBar *menubar, unsigned int idx, int color) int x = menu->start_x; 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) { - /* menu separator */ - tty_setcolor (MENU_ENTRY_COLOR); + if (entry == NULL) + { + /* menu separator */ + tty_setcolor (MENU_ENTRY_COLOR); - widget_move (&menubar->widget, y, x - 1); - tty_print_alt_char (ACS_LTEE, FALSE); + widget_move (&menubar->widget, y, x - 1); + tty_print_alt_char (ACS_LTEE, FALSE); - tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x, - ACS_HLINE, menu->max_entry_len + 3); + tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x, + ACS_HLINE, menu->max_entry_len + 3); - widget_move (&menubar->widget, y, x + menu->max_entry_len + 3); - tty_print_alt_char (ACS_RTEE, FALSE); - } else { - /* menu text */ - tty_setcolor (color); - widget_move (&menubar->widget, y, x); - tty_print_char ((unsigned char) entry->first_letter); - tty_draw_hline (-1, -1, ' ', menu->max_entry_len + 2); /* clear line */ - tty_print_string (entry->text.start); + widget_move (&menubar->widget, y, x + menu->max_entry_len + 3); + tty_print_alt_char (ACS_RTEE, FALSE); + } + else + { + /* menu text */ + tty_setcolor (color); + widget_move (&menubar->widget, y, x); + tty_print_char ((unsigned char) entry->first_letter); + tty_draw_hline (-1, -1, ' ', menu->max_entry_len + 2); /* clear line */ + tty_print_string (entry->text.start); - if (entry->text.hotkey != NULL) { - tty_setcolor (color == MENU_SELECTED_COLOR ? - MENU_HOTSEL_COLOR : MENU_HOT_COLOR); - tty_print_string (entry->text.hotkey); - tty_setcolor (color); - } + if (entry->text.hotkey != NULL) + { + tty_setcolor (color == MENU_SELECTED_COLOR ? MENU_HOTSEL_COLOR : MENU_HOT_COLOR); + tty_print_string (entry->text.hotkey); + tty_setcolor (color); + } - if (entry->text.end != NULL) - tty_print_string (entry->text.end); + if (entry->text.end != NULL) + tty_print_string (entry->text.end); - if (entry->shortcut != NULL) { - widget_move (&menubar->widget, y, x + menu->max_hotkey_len + 3); - tty_print_string (entry->shortcut); - } + if (entry->shortcut != NULL) + { + widget_move (&menubar->widget, y, x + menu->max_hotkey_len + 3); + tty_print_string (entry->shortcut); + } - /* move cursor to the start of entry text */ - widget_move (&menubar->widget, y, x + 1); + /* move cursor to the start of entry text */ + widget_move (&menubar->widget, y, x + 1); } } static void -menubar_draw_drop (WMenuBar *menubar) +menubar_draw_drop (WMenuBar * menubar) { const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected); const unsigned int count = g_list_length (menu->entries); @@ -189,35 +198,35 @@ menubar_draw_drop (WMenuBar *menubar) unsigned int i; if (column + menu->max_entry_len + 5 > (gsize) menubar->widget.cols) - column = menubar->widget.cols - menu->max_entry_len - 5; + column = menubar->widget.cols - menu->max_entry_len - 5; tty_setcolor (MENU_ENTRY_COLOR); draw_box (menubar->widget.parent, - menubar->widget.y + 1, menubar->widget.x + column, - count + 2, menu->max_entry_len + 5, FALSE); + menubar->widget.y + 1, menubar->widget.x + column, + count + 2, menu->max_entry_len + 5, FALSE); /* draw items except selected */ for (i = 0; i < count; i++) - if (i != menu->selected) - menubar_paint_idx (menubar, i, MENU_ENTRY_COLOR); + if (i != menu->selected) + menubar_paint_idx (menubar, i, MENU_ENTRY_COLOR); /* draw selected item at last to move cursor to the nice location */ menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR); } static void -menubar_set_color (WMenuBar *menubar, gboolean current, gboolean hotkey) +menubar_set_color (WMenuBar * menubar, gboolean current, gboolean hotkey) { if (!menubar->is_active) - tty_setcolor (MENU_INACTIVE_COLOR); + tty_setcolor (MENU_INACTIVE_COLOR); else if (current) - tty_setcolor (hotkey ? MENU_HOTSEL_COLOR : MENU_SELECTED_COLOR); + tty_setcolor (hotkey ? MENU_HOTSEL_COLOR : MENU_SELECTED_COLOR); else - tty_setcolor (hotkey ? MENU_HOT_COLOR : MENU_ENTRY_COLOR); + tty_setcolor (hotkey ? MENU_HOT_COLOR : MENU_ENTRY_COLOR); } static void -menubar_draw (WMenuBar *menubar) +menubar_draw (WMenuBar * menubar) { GList *i; @@ -226,59 +235,61 @@ menubar_draw (WMenuBar *menubar) tty_draw_hline (menubar->widget.y, menubar->widget.x, ' ', menubar->widget.cols); /* Now each one of the entries */ - for (i = menubar->menu; i != NULL; i = g_list_next (i)) { - Menu *menu = i->data; - gboolean is_selected = (menubar->selected == (gsize) g_list_position (menubar->menu, i)); + for (i = menubar->menu; i != NULL; i = g_list_next (i)) + { + Menu *menu = i->data; + gboolean is_selected = (menubar->selected == (gsize) g_list_position (menubar->menu, i)); - menubar_set_color (menubar, is_selected, FALSE); - widget_move (&menubar->widget, 0, menu->start_x); + menubar_set_color (menubar, is_selected, FALSE); + widget_move (&menubar->widget, 0, menu->start_x); - tty_print_char (' '); - tty_print_string (menu->text.start); + tty_print_char (' '); + tty_print_string (menu->text.start); - if (menu->text.hotkey != NULL) { - menubar_set_color (menubar, is_selected, TRUE); - tty_print_string (menu->text.hotkey); - menubar_set_color (menubar, is_selected, FALSE); - } + if (menu->text.hotkey != NULL) + { + menubar_set_color (menubar, is_selected, TRUE); + tty_print_string (menu->text.hotkey); + menubar_set_color (menubar, is_selected, FALSE); + } - if (menu->text.end != NULL) - tty_print_string (menu->text.end); + if (menu->text.end != NULL) + tty_print_string (menu->text.end); - tty_print_char (' '); + tty_print_char (' '); } if (menubar->is_dropped) - menubar_draw_drop (menubar); + menubar_draw_drop (menubar); else - widget_move (&menubar->widget, 0, - ((Menu *) g_list_nth_data (menubar->menu, - menubar->selected))->start_x); + widget_move (&menubar->widget, 0, + ((Menu *) g_list_nth_data (menubar->menu, menubar->selected))->start_x); } static void -menubar_remove (WMenuBar *menubar) +menubar_remove (WMenuBar * menubar) { - if (menubar->is_dropped) { - menubar->is_dropped = FALSE; - do_refresh (); - menubar->is_dropped = TRUE; + if (menubar->is_dropped) + { + menubar->is_dropped = FALSE; + do_refresh (); + menubar->is_dropped = TRUE; } } static void -menubar_left (WMenuBar *menubar) +menubar_left (WMenuBar * menubar) { menubar_remove (menubar); if (menubar->selected == 0) - menubar->selected = g_list_length (menubar->menu) - 1; + menubar->selected = g_list_length (menubar->menu) - 1; else - menubar->selected--; + menubar->selected--; menubar_draw (menubar); } static void -menubar_right (WMenuBar *menubar) +menubar_right (WMenuBar * menubar) { menubar_remove (menubar); menubar->selected = (menubar->selected + 1) % g_list_length (menubar->menu); @@ -286,7 +297,7 @@ menubar_right (WMenuBar *menubar) } static void -menubar_finish (WMenuBar *menubar) +menubar_finish (WMenuBar * menubar) { menubar->is_dropped = FALSE; menubar->is_active = FALSE; @@ -298,7 +309,7 @@ menubar_finish (WMenuBar *menubar) } static void -menubar_drop (WMenuBar *menubar, unsigned int selected) +menubar_drop (WMenuBar * menubar, unsigned int selected) { menubar->is_dropped = TRUE; menubar->selected = selected; @@ -306,22 +317,23 @@ menubar_drop (WMenuBar *menubar, unsigned int selected) } static void -menubar_execute (WMenuBar *menubar) +menubar_execute (WMenuBar * menubar) { const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected); const menu_entry_t *entry = g_list_nth_data (menu->entries, menu->selected); - if ((entry != NULL) && (entry->command != CK_Ignore_Key)) { - is_right = (menubar->selected != 0); - menubar_finish (menubar); - menubar->widget.parent->callback (menubar->widget.parent, &menubar->widget, - DLG_ACTION, entry->command, NULL); - do_refresh (); + if ((entry != NULL) && (entry->command != CK_Ignore_Key)) + { + is_right = (menubar->selected != 0); + menubar_finish (menubar); + menubar->widget.parent->callback (menubar->widget.parent, &menubar->widget, + DLG_ACTION, entry->command, NULL); + do_refresh (); } } static void -menubar_down (WMenuBar *menubar) +menubar_down (WMenuBar * menubar) { Menu *menu = g_list_nth_data (menubar->menu, menubar->selected); 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); - do { - menu->selected = (menu->selected + 1) % len; - entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected); - } while ((entry == NULL) || (entry->command == CK_Ignore_Key)); + do + { + menu->selected = (menu->selected + 1) % len; + entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected); + } + while ((entry == NULL) || (entry->command == CK_Ignore_Key)); menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR); } static void -menubar_up (WMenuBar *menubar) +menubar_up (WMenuBar * menubar) { Menu *menu = g_list_nth_data (menubar->menu, menubar->selected); const unsigned int len = g_list_length (menu->entries); @@ -346,235 +360,248 @@ menubar_up (WMenuBar *menubar) menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR); - do { - if (menu->selected == 0) - menu->selected = len - 1; - else - menu->selected--; - entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected); - } while ((entry == NULL) || (entry->command == CK_Ignore_Key)); + do + { + if (menu->selected == 0) + menu->selected = len - 1; + else + menu->selected--; + entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected); + } + while ((entry == NULL) || (entry->command == CK_Ignore_Key)); menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR); } static void -menubar_first (WMenuBar *menubar) +menubar_first (WMenuBar * menubar) { Menu *menu = g_list_nth_data (menubar->menu, menubar->selected); menu_entry_t *entry; if (menu->selected == 0) - return; + return; menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR); menu->selected = 0; - while (TRUE) { - entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected); + while (TRUE) + { + entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected); - if ((entry == NULL) || (entry->command == CK_Ignore_Key)) - menu->selected++; - else - break; + if ((entry == NULL) || (entry->command == CK_Ignore_Key)) + menu->selected++; + else + break; } menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR); } static void -menubar_last (WMenuBar *menubar) +menubar_last (WMenuBar * menubar) { Menu *menu = g_list_nth_data (menubar->menu, menubar->selected); const unsigned int len = g_list_length (menu->entries); menu_entry_t *entry; if (menu->selected == len - 1) - return; + return; menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR); menu->selected = len; - do { - menu->selected--; - entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected); - } while ((entry == NULL) || (entry->command == CK_Ignore_Key)); + do + { + menu->selected--; + entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected); + } + while ((entry == NULL) || (entry->command == CK_Ignore_Key)); menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR); } static int -menubar_handle_key (WMenuBar *menubar, int key) +menubar_handle_key (WMenuBar * menubar, int key) { /* Lowercase */ if (isascii (key)) - key = g_ascii_tolower (key); + key = g_ascii_tolower (key); - if (is_abort_char (key)) { - menubar_finish (menubar); - return 1; + if (is_abort_char (key)) + { + menubar_finish (menubar); + return 1; } /* menubar help or menubar navigation */ - switch (key) { - case KEY_F(1): - if (menubar->is_dropped) - interactive_display (NULL, - ((Menu *) g_list_nth_data (menubar->menu, - menubar->selected))->help_node); - else - interactive_display (NULL, "[Menu Bar]"); - menubar_draw (menubar); - return 1; + switch (key) + { + case KEY_F (1): + if (menubar->is_dropped) + interactive_display (NULL, + ((Menu *) g_list_nth_data (menubar->menu, + menubar->selected))->help_node); + else + interactive_display (NULL, "[Menu Bar]"); + menubar_draw (menubar); + return 1; case KEY_LEFT: - case XCTRL('b'): - menubar_left (menubar); - return 1; + case XCTRL ('b'): + menubar_left (menubar); + return 1; case KEY_RIGHT: case XCTRL ('f'): - menubar_right (menubar); - return 1; + menubar_right (menubar); + return 1; } - if (!menubar->is_dropped) { - GList *i; + if (!menubar->is_dropped) + { + GList *i; - /* drop menu by hotkey */ - for (i = menubar->menu; i != NULL; i = g_list_next (i)) { - Menu *menu = i->data; + /* drop menu by hotkey */ + for (i = menubar->menu; i != NULL; i = g_list_next (i)) + { + Menu *menu = i->data; - if ((menu->text.hotkey != NULL) - && (key == g_ascii_tolower (menu->text.hotkey[0]))) { - menubar_drop (menubar, g_list_position (menubar->menu, i)); - return 1; - } - } + if ((menu->text.hotkey != NULL) && (key == g_ascii_tolower (menu->text.hotkey[0]))) + { + menubar_drop (menubar, g_list_position (menubar->menu, i)); + return 1; + } + } - /* drop menu by Enter or Dowwn key */ - if (key == KEY_ENTER || key == XCTRL ('n') - || key == KEY_DOWN || key == '\n') - menubar_drop (menubar, menubar->selected); + /* drop menu by Enter or Dowwn key */ + if (key == KEY_ENTER || key == XCTRL ('n') || key == KEY_DOWN || key == '\n') + menubar_drop (menubar, menubar->selected); - return 1; + return 1; } { - Menu *menu = g_list_nth_data (menubar->menu, menubar->selected); - GList *i; + Menu *menu = g_list_nth_data (menubar->menu, menubar->selected); + GList *i; - /* execute menu command by hotkey */ - for (i = menu->entries; i != NULL; i = g_list_next (i)) { - const menu_entry_t *entry = i->data; + /* execute menu command by hotkey */ + for (i = menu->entries; i != NULL; i = g_list_next (i)) + { + const menu_entry_t *entry = i->data; - if ((entry != NULL) && (entry->command != CK_Ignore_Key) - && (entry->text.hotkey != NULL) - && (key == g_ascii_tolower (entry->text.hotkey[0]))) { - menu->selected = g_list_position (menu->entries, i); - menubar_execute (menubar); - return 1; - } + if ((entry != NULL) && (entry->command != CK_Ignore_Key) + && (entry->text.hotkey != NULL) && (key == g_ascii_tolower (entry->text.hotkey[0]))) + { + menu->selected = g_list_position (menu->entries, i); + menubar_execute (menubar); + return 1; + } } - /* menu execute by Enter or menu navigation */ - switch (key) { - case KEY_ENTER: - case '\n': - menubar_execute (menubar); - return 1; + /* menu execute by Enter or menu navigation */ + switch (key) + { + case KEY_ENTER: + case '\n': + menubar_execute (menubar); + return 1; - case KEY_HOME: - case ALT ('<'): - menubar_first (menubar); - break; + case KEY_HOME: + case ALT ('<'): + menubar_first (menubar); + break; - case KEY_END: - case ALT ('>'): - menubar_last (menubar); - break; + case KEY_END: + case ALT ('>'): + menubar_last (menubar); + break; - case KEY_DOWN: - case XCTRL ('n'): - menubar_down (menubar); - break; + case KEY_DOWN: + case XCTRL ('n'): + menubar_down (menubar); + break; - case KEY_UP: - case XCTRL ('p'): - menubar_up (menubar); - break; - } + case KEY_UP: + case XCTRL ('p'): + menubar_up (menubar); + break; + } } return 0; } 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; - switch (msg) { - /* We do not want the focus unless we have been activated */ + switch (msg) + { + /* We do not want the focus unless we have been activated */ case WIDGET_FOCUS: - if (!menubar->is_active) - return MSG_NOT_HANDLED; + if (!menubar->is_active) + return MSG_NOT_HANDLED; - widget_want_cursor (menubar->widget, 1); + widget_want_cursor (menubar->widget, 1); - /* Trick to get all the mouse events */ - menubar->widget.lines = LINES; + /* Trick to get all the mouse events */ + menubar->widget.lines = LINES; - /* Trick to get all of the hotkeys */ - widget_want_hotkey (menubar->widget, 1); - menubar_draw (menubar); - return MSG_HANDLED; + /* Trick to get all of the hotkeys */ + widget_want_hotkey (menubar->widget, 1); + menubar_draw (menubar); + return MSG_HANDLED; - /* 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_KEY: - if (menubar->is_active) { - menubar_handle_key (menubar, parm); - return MSG_HANDLED; - } - return MSG_NOT_HANDLED; + if (menubar->is_active) + { + menubar_handle_key (menubar, parm); + return MSG_HANDLED; + } + return MSG_NOT_HANDLED; case WIDGET_CURSOR: - /* Put the cursor in a suitable place */ - return MSG_NOT_HANDLED; + /* Put the cursor in a suitable place */ + return MSG_NOT_HANDLED; case WIDGET_UNFOCUS: - if (menubar->is_active) - return MSG_NOT_HANDLED; - - widget_want_cursor (menubar->widget, 0); - return MSG_HANDLED; + if (menubar->is_active) + return MSG_NOT_HANDLED; + + widget_want_cursor (menubar->widget, 0); + return MSG_HANDLED; case WIDGET_DRAW: - if (menubar_visible) { - menubar_draw (menubar); - return MSG_HANDLED; - } - /* fall through */ + if (menubar_visible) + { + menubar_draw (menubar); + return MSG_HANDLED; + } + /* fall through */ case WIDGET_RESIZED: - /* try show menu after screen resize */ - send_message (w, WIDGET_FOCUS, 0); - return MSG_HANDLED; - + /* try show menu after screen resize */ + send_message (w, WIDGET_FOCUS, 0); + return MSG_HANDLED; + case WIDGET_DESTROY: - menubar_set_menu (menubar, NULL); - return MSG_HANDLED; + menubar_set_menu (menubar, NULL); + return MSG_HANDLED; default: - return default_proc (msg, parm); + return default_proc (msg, parm); } } static int -menubar_event (Gpm_Event *event, void *data) +menubar_event (Gpm_Event * event, void *data) { WMenuBar *menubar = data; gboolean was_active = TRUE; @@ -583,129 +610,139 @@ menubar_event (Gpm_Event *event, void *data) /* ignore unsupported events */ if ((event->type & (GPM_UP | GPM_DOWN | GPM_DRAG)) == 0) - return MOU_NORMAL; + return MOU_NORMAL; /* ignore wheel events if menu is inactive */ - if (!menubar->is_active - && ((event->buttons & (GPM_B_MIDDLE | GPM_B_UP | GPM_B_DOWN)) != 0)) - return MOU_NORMAL; + if (!menubar->is_active && ((event->buttons & (GPM_B_MIDDLE | GPM_B_UP | GPM_B_DOWN)) != 0)) + return MOU_NORMAL; - if (!menubar->is_dropped) { - menubar->previous_widget = menubar->widget.parent->current->dlg_id; - menubar->is_active = TRUE; - menubar->is_dropped = TRUE; - was_active = FALSE; + if (!menubar->is_dropped) + { + menubar->previous_widget = menubar->widget.parent->current->dlg_id; + menubar->is_active = TRUE; + menubar->is_dropped = TRUE; + was_active = FALSE; } /* Mouse operations on the menubar */ - if (event->y == 1 || !was_active) { - if ((event->type & GPM_UP) != 0) - return MOU_NORMAL; + if (event->y == 1 || !was_active) + { + if ((event->type & GPM_UP) != 0) + return MOU_NORMAL; - /* wheel events on menubar */ - if (event->buttons & GPM_B_UP) - menubar_left (menubar); - else if (event->buttons & GPM_B_DOWN) - menubar_right (menubar); - else { - const unsigned int len = g_list_length (menubar->menu); - unsigned int new_selection = 0; + /* wheel events on menubar */ + if (event->buttons & GPM_B_UP) + menubar_left (menubar); + else if (event->buttons & GPM_B_DOWN) + menubar_right (menubar); + else + { + const unsigned int len = g_list_length (menubar->menu); + unsigned int new_selection = 0; - while ((new_selection < len) - && (event->x > ((Menu *) g_list_nth_data (menubar->menu, - new_selection))->start_x)) - new_selection++; + while ((new_selection < len) + && (event->x > ((Menu *) g_list_nth_data (menubar->menu, + new_selection))->start_x)) + new_selection++; - if (new_selection != 0) /* Don't set the invalid value -1 */ - new_selection--; - - if (!was_active) { - menubar->selected = new_selection; - dlg_select_widget (menubar); - } else { - menubar_remove (menubar); - menubar->selected = new_selection; - } - menubar_draw (menubar); - } - return MOU_NORMAL; + if (new_selection != 0) /* Don't set the invalid value -1 */ + new_selection--; + + if (!was_active) + { + menubar->selected = new_selection; + dlg_select_widget (menubar); + } + else + { + menubar_remove (menubar); + menubar->selected = new_selection; + } + menubar_draw (menubar); + } + return MOU_NORMAL; } if (!menubar->is_dropped || (event->y < 2)) - return MOU_NORMAL; + return MOU_NORMAL; /* middle click -- everywhere */ - if (((event->buttons & GPM_B_MIDDLE) != 0) - && ((event->type & GPM_DOWN) != 0)) { - menubar_execute (menubar); - return MOU_NORMAL; + if (((event->buttons & GPM_B_MIDDLE) != 0) && ((event->type & GPM_DOWN) != 0)) + { + menubar_execute (menubar); + return MOU_NORMAL; } /* the mouse operation is on the menus or it is not */ menu = (Menu *) g_list_nth_data (menubar->menu, menubar->selected); left_x = menu->start_x; right_x = left_x + menu->max_entry_len + 3; - if (right_x > menubar->widget.cols) { - left_x = menubar->widget.cols - menu->max_entry_len - 3; - right_x = menubar->widget.cols; + if (right_x > menubar->widget.cols) + { + left_x = menubar->widget.cols - menu->max_entry_len - 3; + right_x = menubar->widget.cols; } bottom_y = g_list_length (menu->entries) + 3; - if ((event->x >= left_x) && (event->x <= right_x) && (event->y <= bottom_y)){ - int pos = event->y - 3; - const menu_entry_t *entry = g_list_nth_data (menu->entries, pos); + if ((event->x >= left_x) && (event->x <= right_x) && (event->y <= bottom_y)) + { + int pos = event->y - 3; + const menu_entry_t *entry = g_list_nth_data (menu->entries, pos); - /* mouse wheel */ - if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN)) { - menubar_up (menubar); - return MOU_NORMAL; - } - if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN)) { - menubar_down (menubar); - return MOU_NORMAL; - } + /* mouse wheel */ + if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN)) + { + menubar_up (menubar); + return MOU_NORMAL; + } + if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN)) + { + menubar_down (menubar); + return MOU_NORMAL; + } - /* ignore events above and below dropped down menu */ - if ((pos < 0) || (pos >= bottom_y - 3)) - return MOU_NORMAL; + /* ignore events above and below dropped down menu */ + if ((pos < 0) || (pos >= bottom_y - 3)) + return MOU_NORMAL; - if ((entry != NULL) && (entry->command != CK_Ignore_Key)) { - menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR); - menu->selected = pos; - menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR); + if ((entry != NULL) && (entry->command != CK_Ignore_Key)) + { + menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR); + menu->selected = pos; + menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR); - if ((event->type & GPM_UP) != 0) - menubar_execute (menubar); - } - } else - /* use click not wheel to close menu */ - if (((event->type & GPM_DOWN) != 0) - && ((event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0)) - menubar_finish (menubar); + if ((event->type & GPM_UP) != 0) + menubar_execute (menubar); + } + } + else + /* use click not wheel to close menu */ + if (((event->type & GPM_DOWN) != 0) && ((event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0)) + menubar_finish (menubar); return MOU_NORMAL; } 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); - init_widget (&menubar->widget, y, x, 1, cols, - menubar_callback, menubar_event); + init_widget (&menubar->widget, y, x, 1, cols, menubar_callback, menubar_event); widget_want_cursor (menubar->widget, 0); menubar_set_menu (menubar, menu); return menubar; } void -menubar_set_menu (WMenuBar *menubar, GList *menu) +menubar_set_menu (WMenuBar * menubar, GList * menu) { /* delete previous menu */ - if (menubar->menu != NULL) { - g_list_foreach (menubar->menu, (GFunc) destroy_menu, NULL); - g_list_free (menubar->menu); + if (menubar->menu != NULL) + { + g_list_foreach (menubar->menu, (GFunc) destroy_menu, NULL); + g_list_free (menubar->menu); } /* add new menu */ menubar->is_active = FALSE; @@ -716,11 +753,12 @@ menubar_set_menu (WMenuBar *menubar, GList *menu) } void -menubar_add_menu (WMenuBar *menubar, Menu *menu) +menubar_add_menu (WMenuBar * menubar, Menu * menu) { - if (menu != NULL) { - menu_arrange (menu, menubar->widget.parent->get_shortcut); - menubar->menu = g_list_append (menubar->menu, menu); + if (menu != NULL) + { + menu_arrange (menu, menubar->widget.parent->get_shortcut); + menubar->menu = g_list_append (menubar->menu, menu); } menubar_arrange (menubar); @@ -731,57 +769,61 @@ menubar_add_menu (WMenuBar *menubar, Menu *menu) * and also when widget width is changed (i.e. upon xterm resize). */ void -menubar_arrange (WMenuBar* menubar) +menubar_arrange (WMenuBar * menubar) { int start_x = 1; GList *i; int gap; if (menubar->menu == NULL) - return; + return; #ifndef RESIZABLE_MENUBAR gap = 3; - for (i = menubar->menu; i != NULL; i = g_list_next (i)) { - Menu *menu = i->data; - int len = hotkey_width (menu->text) + 2; + for (i = menubar->menu; i != NULL; i = g_list_next (i)) + { + Menu *menu = i->data; + int len = hotkey_width (menu->text) + 2; - menu->start_x = start_x; - start_x += len + gap; + menu->start_x = start_x; + start_x += len + gap; } #else /* RESIZABLE_MENUBAR */ gap = menubar->widget.cols - 2; /* First, calculate gap between items... */ - for (i = menubar->menu; i != NULL; i = g_list_nwxt (i)) { - Menu *menu = i->data; - /* preserve length here, to be used below */ - menu->start_x = hotkey_width (menu->text) + 2; - gap -= menu->start_x; + for (i = menubar->menu; i != NULL; i = g_list_nwxt (i)) + { + Menu *menu = i->data; + /* preserve length here, to be used below */ + menu->start_x = hotkey_width (menu->text) + 2; + gap -= menu->start_x; } gap /= (menubar->menu->len - 1); - if (gap <= 0) { - /* We are out of luck - window is too narrow... */ - gap = 1; + if (gap <= 0) + { + /* We are out of luck - window is too narrow... */ + gap = 1; } /* ...and now fix start positions of menubar items */ - for (i = menubar->menu; i != NULL; i = g_list_nwxt (i)) { - Menu *menu = i->data; - int len = menu->start_x; + for (i = menubar->menu; i != NULL; i = g_list_nwxt (i)) + { + Menu *menu = i->data; + int len = menu->start_x; - menu->start_x = start_x; - start_x += len + gap; + menu->start_x = start_x; + start_x += len + gap; } #endif /* RESIZABLE_MENUBAR */ } /* Find MenuBar widget in the dialog */ WMenuBar * -find_menubar (const Dlg_head *h) +find_menubar (const Dlg_head * h) { return (WMenuBar *) find_widget_type (h, menubar_callback); } diff --git a/src/panelize.c b/src/panelize.c index 0a87ae911..1c6620f1b 100644 --- a/src/panelize.c +++ b/src/panelize.c @@ -1,9 +1,9 @@ /* External panelize Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2009 Free Software Foundation, Inc. - + Written by: 1995 Janne Kukonlehto - 1995 Jakub Jelinek + 1995 Jakub Jelinek This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,16 +37,16 @@ #include "lib/skin.h" #include "lib/vfs/mc-vfs/vfs.h" -#include "lib/mcconfig.h" /* Load/save directories panelize */ +#include "lib/mcconfig.h" /* Load/save directories panelize */ #include "lib/strutil.h" #include "dialog.h" #include "widget.h" -#include "wtools.h" /* For common_dialog_repaint() */ -#include "setup.h" /* For profile_bname */ +#include "wtools.h" /* For common_dialog_repaint() */ +#include "setup.h" /* For profile_bname */ #include "dir.h" -#include "panel.h" /* current_panel */ -#include "layout.h" /* repaint_screen() */ +#include "panel.h" /* current_panel */ +#include "layout.h" /* repaint_screen() */ #include "main.h" #include "panelize.h" #include "history.h" @@ -67,21 +67,26 @@ static Dlg_head *panelize_dlg; static int last_listitem; static WInput *pname; -static struct { +static struct +{ int ret_cmd, flags, y, x; const char *text; -} panelize_but [BUTTONS] = { - { B_CANCEL, NORMAL_BUTTON, 0, 53, N_("&Cancel") }, - { B_ADD, NORMAL_BUTTON, 0, 28, N_("&Add new") }, - { B_REMOVE, NORMAL_BUTTON, 0, 16, N_("&Remove") }, - { B_ENTER, DEFPUSH_BUTTON, 0, 0, N_("Pane&lize") }, +} panelize_but[BUTTONS] = +{ + /* *INDENT-OFF* */ + { B_CANCEL, NORMAL_BUTTON, 0, 53, N_("&Cancel") }, + { B_ADD, NORMAL_BUTTON, 0, 28, N_("&Add new") }, + { B_REMOVE, NORMAL_BUTTON, 0, 16, N_("&Remove") }, + { B_ENTER, DEFPUSH_BUTTON, 0, 0, N_("Pane&lize") } + /* *INDENT-ON* */ }; static const char *panelize_section = "Panelize"; static void do_external_panelize (char *command); /* Directory panelize */ -static struct panelize { +static struct panelize +{ char *command; char *label; struct panelize *next; @@ -90,36 +95,37 @@ static struct panelize { static void update_command (void) { - if (l_panelize->pos != last_listitem) { - struct panelize *data = NULL; + if (l_panelize->pos != last_listitem) + { + struct panelize *data = NULL; - last_listitem = l_panelize->pos; - listbox_get_current (l_panelize, NULL, (void **) &data); - assign_text (pname, data->command); - pname->point = 0; - update_input (pname, 1); + last_listitem = l_panelize->pos; + listbox_get_current (l_panelize, NULL, (void **) &data); + assign_text (pname, data->command); + pname->point = 0; + update_input (pname, 1); } } static cb_ret_t -panelize_callback (Dlg_head *h, Widget *sender, - dlg_msg_t msg, int parm, void *data) +panelize_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { - switch (msg) { + switch (msg) + { case DLG_INIT: case DLG_POST_KEY: - tty_setcolor (MENU_ENTRY_COLOR); - update_command (); - return MSG_HANDLED; + tty_setcolor (MENU_ENTRY_COLOR); + update_command (); + return MSG_HANDLED; case DLG_DRAW: - common_dialog_repaint (h); - tty_setcolor (COLOR_NORMAL); - draw_box (h, UY, UX, h->lines - 10, h->cols - 10, TRUE); - return MSG_HANDLED; + common_dialog_repaint (h); + tty_setcolor (COLOR_NORMAL); + draw_box (h, UY, UX, h->lines - 10, h->cols - 10, TRUE); + return MSG_HANDLED; default: - return default_dlg_callback (h, sender, msg, parm, data); + return default_dlg_callback (h, sender, msg, parm, data); } } @@ -133,97 +139,99 @@ init_panelize (void) static int i18n_flag = 0; static int maxlen = 0; - if (!i18n_flag) { - i = sizeof (panelize_but) / sizeof (panelize_but[0]); - while (i--) { - panelize_but[i].text = _(panelize_but[i].text); - maxlen += str_term_width1 (panelize_but[i].text) + 5; - } - maxlen += 10; + if (!i18n_flag) + { + i = sizeof (panelize_but) / sizeof (panelize_but[0]); + while (i--) + { + panelize_but[i].text = _(panelize_but[i].text); + maxlen += str_term_width1 (panelize_but[i].text) + 5; + } + maxlen += 10; - i18n_flag = 1; + i18n_flag = 1; } panelize_cols = max (panelize_cols, maxlen); - panelize_but[2].x = - 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[0].x = - panelize_cols - str_term_width1 (panelize_but[0].text) - 8 - BX; + panelize_but[2].x = 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[0].x = panelize_cols - str_term_width1 (panelize_but[0].text) - 8 - BX; -#endif /* ENABLE_NLS */ +#endif /* ENABLE_NLS */ last_listitem = 0; do_refresh (); panelize_dlg = - create_dlg (0, 0, 22, panelize_cols, dialog_colors, - panelize_callback, "[External panelize]", - _("External panelize"), DLG_CENTER | DLG_REVERSE); + create_dlg (0, 0, 22, panelize_cols, dialog_colors, + panelize_callback, "[External panelize]", + _("External panelize"), DLG_CENTER | DLG_REVERSE); for (i = 0; i < BUTTONS; i++) - add_widget (panelize_dlg, - button_new (BY + panelize_but[i].y, - BX + panelize_but[i].x, - panelize_but[i].ret_cmd, - panelize_but[i].flags, - panelize_but[i].text, 0)); + add_widget (panelize_dlg, + button_new (BY + panelize_but[i].y, + BX + panelize_but[i].x, + panelize_but[i].ret_cmd, + panelize_but[i].flags, panelize_but[i].text, 0)); pname = - input_new (UY + 14, UX, INPUT_COLOR, panelize_dlg->cols - 10, "", - "in", INPUT_COMPLETE_DEFAULT); + input_new (UY + 14, UX, INPUT_COLOR, panelize_dlg->cols - 10, "", + "in", INPUT_COMPLETE_DEFAULT); add_widget (panelize_dlg, pname); add_widget (panelize_dlg, label_new (UY + 13, UX, _("Command"))); /* get new listbox */ - l_panelize = - listbox_new (UY + 1, UX + 1, 10, panelize_dlg->cols - 12, FALSE, NULL); + l_panelize = listbox_new (UY + 1, UX + 1, 10, panelize_dlg->cols - 12, FALSE, NULL); - while (current) { - listbox_add_item (l_panelize, LISTBOX_APPEND_AT_END, 0, current->label, current); - current = current->next; + while (current) + { + listbox_add_item (l_panelize, LISTBOX_APPEND_AT_END, 0, current->label, current); + current = current->next; } /* add listbox to the dialogs */ add_widget (panelize_dlg, l_panelize); - listbox_select_entry (l_panelize, - listbox_search_text (l_panelize, - _("Other command"))); + listbox_select_entry (l_panelize, listbox_search_text (l_panelize, _("Other command"))); } -static void panelize_done (void) +static void +panelize_done (void) { destroy_dlg (panelize_dlg); repaint_screen (); } -static void add2panelize (char *label, char *command) +static void +add2panelize (char *label, char *command) { struct panelize *current, *old; old = NULL; current = panelize; - while (current && strcmp (current->label, label) <= 0){ - old = current; - current = current->next; + while (current && strcmp (current->label, label) <= 0) + { + old = current; + current = current->next; } - if (old == NULL){ - panelize = g_new (struct panelize, 1); - panelize->label = label; - panelize->command = command; - panelize->next = current; - } else { - struct panelize *new; - new = g_new (struct panelize, 1); - new->label = label; - new->command = command; - old->next = new; - new->next = current; + if (old == NULL) + { + panelize = g_new (struct panelize, 1); + panelize->label = label; + panelize->command = command; + panelize->next = current; + } + else + { + struct panelize *new; + new = g_new (struct panelize, 1); + new->label = label; + new->command = command; + old->next = new; + new->next = current; } } @@ -232,39 +240,45 @@ add2panelize_cmd (void) { char *label; - if (pname->buffer && (*pname->buffer)) { - label = input_dialog (_(" Add to external panelize "), - _(" Enter command label: "), - MC_HISTORY_FM_PANELIZE_ADD, - ""); - if (!label) - return; - if (!*label) { - g_free (label); - return; - } - - add2panelize (label, g_strdup (pname->buffer)); + if (pname->buffer && (*pname->buffer)) + { + label = input_dialog (_(" Add to external panelize "), + _(" Enter command label: "), MC_HISTORY_FM_PANELIZE_ADD, ""); + if (!label) + return; + if (!*label) + { + g_free (label); + return; + } + + add2panelize (label, g_strdup (pname->buffer)); } } -static void remove_from_panelize (struct panelize *entry) +static void +remove_from_panelize (struct panelize *entry) { - if (strcmp (entry->label, _("Other command")) != 0) { - if (entry == panelize) { - panelize = panelize->next; - } else { - struct panelize *current = panelize; - while (current && current->next != entry) - current = current->next; - if (current) { - current->next = entry->next; - } - } + if (strcmp (entry->label, _("Other command")) != 0) + { + if (entry == panelize) + { + panelize = panelize->next; + } + else + { + struct panelize *current = panelize; + while (current && current->next != entry) + current = current->next; + if (current) + { + current->next = entry->next; + } + } - g_free (entry->label); - g_free (entry->command); - g_free (entry); + g_free (entry->label); + g_free (entry->command); + g_free (entry); } } @@ -273,190 +287,209 @@ external_panelize (void) { char *target = NULL; - if (!vfs_current_is_local ()){ - message (D_ERROR, MSG_ERROR, - _(" Cannot run external panelize in a non-local directory ")); - return; + if (!vfs_current_is_local ()) + { + message (D_ERROR, MSG_ERROR, _(" Cannot run external panelize in a non-local directory ")); + return; } init_panelize (); - + /* display file info */ tty_setcolor (SELECTED_COLOR); run_dlg (panelize_dlg); - switch (panelize_dlg->ret_value) { + switch (panelize_dlg->ret_value) + { case B_CANCEL: - break; + break; case B_ADD: - add2panelize_cmd (); - break; + add2panelize_cmd (); + break; case B_REMOVE: - { - struct panelize *entry; + { + struct panelize *entry; - listbox_get_current (l_panelize, NULL, (void **) &entry); - remove_from_panelize (entry); - break; - } + listbox_get_current (l_panelize, NULL, (void **) &entry); + remove_from_panelize (entry); + break; + } case B_ENTER: - target = pname->buffer; - if (target != NULL && *target) { - char *cmd = g_strdup (target); - destroy_dlg (panelize_dlg); - do_external_panelize (cmd); - g_free (cmd); - repaint_screen (); - return; - } - break; + target = pname->buffer; + if (target != NULL && *target) + { + char *cmd = g_strdup (target); + destroy_dlg (panelize_dlg); + do_external_panelize (cmd); + g_free (cmd); + repaint_screen (); + return; + } + break; } panelize_done (); } -void load_panelize (void) +void +load_panelize (void) { - gchar **profile_keys, **keys; + gchar **profile_keys, **keys; gsize len; GIConv conv; GString *buffer; 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 ("")); - 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 SUID and SGID programs")), g_strdup ("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print")); - return; + 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 SUID and SGID programs")), + g_strdup + ("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print")); + 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); - } else { + } + else + { buffer = g_string_new (""); 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); } } - add2panelize ( - g_string_free(buffer, FALSE), - mc_config_get_string(mc_main_config,panelize_section,*profile_keys,"") - ); - profile_keys++; + add2panelize (g_string_free (buffer, FALSE), + mc_config_get_string (mc_main_config, panelize_section, *profile_keys, "")); + profile_keys++; } - g_strfreev(keys); + g_strfreev (keys); str_close_conv (conv); } -void save_panelize (void) +void +save_panelize (void) { struct panelize *current = panelize; - + mc_config_del_group (mc_main_config, panelize_section); - for (;current; current = current->next){ - if (strcmp (current->label, _("Other command"))) - mc_config_set_string(mc_main_config, - panelize_section, - current->label, - current->command); + for (; current; current = current->next) + { + if (strcmp (current->label, _("Other command"))) + mc_config_set_string (mc_main_config, + panelize_section, current->label, current->command); } mc_config_save_file (mc_main_config, NULL); } -void done_panelize (void) +void +done_panelize (void) { struct panelize *current = panelize; struct panelize *next; - for (; current; current = next){ - next = current->next; - g_free (current->label); - g_free (current->command); - g_free (current); + for (; current; current = next) + { + next = current->next; + g_free (current->label); + g_free (current->command); + g_free (current); } } -static void do_external_panelize (char *command) +static void +do_external_panelize (char *command) { int status, link_to_dir, stale_link; int next_free = 0; struct stat st; dir_list *list = ¤t_panel->dir; - char line [MC_MAXPATHLEN]; + char line[MC_MAXPATHLEN]; char *name; FILE *external; open_error_pipe (); external = popen (command, "r"); - if (!external){ - close_error_pipe (D_ERROR, _("Cannot invoke command.")); - return; + if (!external) + { + close_error_pipe (D_ERROR, _("Cannot invoke command.")); + return; } /* Clear the counters and the directory list */ panel_clean_dir (current_panel); - while (1) { - clearerr(external); - if (fgets (line, MC_MAXPATHLEN, external) == NULL) { - if (ferror(external) && errno == EINTR) - continue; - else - break; - } - if (line[strlen(line)-1] == '\n') - line[strlen(line)-1] = 0; - if (strlen(line) < 1) - continue; - if (line [0] == '.' && line[1] == PATH_SEP) - name = line + 2; - else - name = line; - status = handle_path (list, name, &st, next_free, &link_to_dir, - &stale_link); - if (status == 0) - continue; - if (status == -1) - break; - list->list [next_free].fnamelen = strlen (name); - list->list [next_free].fname = g_strdup (name); - file_mark (current_panel, next_free, 0); - 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.dir_size_computed = 0; - list->list [next_free].st = st; + while (1) + { + clearerr (external); + if (fgets (line, MC_MAXPATHLEN, external) == NULL) + { + if (ferror (external) && errno == EINTR) + continue; + else + break; + } + if (line[strlen (line) - 1] == '\n') + line[strlen (line) - 1] = 0; + if (strlen (line) < 1) + continue; + if (line[0] == '.' && line[1] == PATH_SEP) + name = line + 2; + else + name = line; + status = handle_path (list, name, &st, next_free, &link_to_dir, &stale_link); + if (status == 0) + continue; + if (status == -1) + break; + list->list[next_free].fnamelen = strlen (name); + list->list[next_free].fname = g_strdup (name); + file_mark (current_panel, next_free, 0); + 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.dir_size_computed = 0; + list->list[next_free].st = st; list->list[next_free].sort_key = NULL; list->list[next_free].second_sort_key = NULL; - next_free++; - if (!(next_free & 32)) - rotate_dash (); + next_free++; + if (!(next_free & 32)) + rotate_dash (); } current_panel->is_panelized = 1; - if (next_free){ - current_panel->count = next_free; - if (list->list [0].fname [0] == PATH_SEP){ - strcpy (current_panel->cwd, PATH_SEP_STR); - chdir (PATH_SEP_STR); - } - } else { - current_panel->count = set_zero_dir (list) ? 1 : 0; + if (next_free) + { + current_panel->count = next_free; + if (list->list[0].fname[0] == PATH_SEP) + { + strcpy (current_panel->cwd, PATH_SEP_STR); + chdir (PATH_SEP_STR); + } + } + else + { + current_panel->count = set_zero_dir (list) ? 1 : 0; } if (pclose (external) < 0) - message (D_NORMAL, _("External panelize"), _("Pipe close failed")); + message (D_NORMAL, _("External panelize"), _("Pipe close failed")); close_error_pipe (D_NORMAL, NULL); try_to_select (current_panel, NULL); panel_re_sort (current_panel); diff --git a/src/screen.c b/src/screen.c index 06ff4cd17..06ee01281 100644 --- a/src/screen.c +++ b/src/screen.c @@ -89,10 +89,11 @@ typedef struct format_e const char *id; } format_e; -enum { - QSEARCH_CASE_INSENSITIVE = 0, /* quick search in case insensitive mode */ +enum +{ + QSEARCH_CASE_INSENSITIVE = 0, /* quick search in case insensitive 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 */ }; int quick_search_case_sensitive = QSEARCH_PANEL_CASE; @@ -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. */ 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 gboolean is_active = dlg_widget_active (panel); diff --git a/src/tree.c b/src/tree.c index d4036e4e0..30d0b0249 100644 --- a/src/tree.c +++ b/src/tree.c @@ -3,8 +3,8 @@ 2003, 2004, 2005, 2007 Free Software Foundation, Inc. Written: 1994, 1996 Janne Kukonlehto - 1997 Norbert Warmuth - 1996, 1999 Miguel de Icaza + 1997 Norbert Warmuth + 1996, 1999 Miguel de Icaza This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,7 +26,7 @@ created and destroyed. This is required for the future vfs layer, it will be possible to have tree views over virtual file systems. - */ + */ /** \file tree.c * \brief Source: directory tree browser @@ -49,16 +49,16 @@ #include "lib/fileloc.h" #include "lib/strutil.h" -#include "wtools.h" /* message() */ +#include "wtools.h" /* message() */ #include "dir.h" #include "dialog.h" #include "widget.h" #include "panel.h" #include "main.h" -#include "main-widgets.h" /* the_menubar */ -#include "menu.h" /* menubar_visible */ -#include "file.h" /* copy_dir_dir(), move_dir_dir(), erase_dir() */ -#include "layout.h" /* command_prompt */ +#include "main-widgets.h" /* the_menubar */ +#include "menu.h" /* menubar_visible */ +#include "file.h" /* copy_dir_dir(), move_dir_dir(), erase_dir() */ +#include "layout.h" /* command_prompt */ #include "help.h" #include "treestore.h" #include "cmd.h" @@ -78,64 +78,68 @@ const global_keymap_t *tree_map; /* Specifies the display mode: 1d or 2d */ static gboolean tree_navigation_flag = FALSE; -struct WTree { +struct WTree +{ Widget widget; struct TreeStore *store; - tree_entry *selected_ptr; /* The selected directory */ - char search_buffer[256]; /* Current search string */ - tree_entry **tree_shown; /* Entries currently on screen */ - int is_panel; /* panel or plain widget flag */ - int active; /* if it's currently selected */ - int searching; /* Are we on searching mode? */ - int topdiff; /* The difference between the topmost - shown and the selected */ + tree_entry *selected_ptr; /* The selected directory */ + char search_buffer[256]; /* Current search string */ + tree_entry **tree_shown; /* Entries currently on screen */ + int is_panel; /* panel or plain widget flag */ + int active; /* if it's currently selected */ + int searching; /* Are we on searching mode? */ + int topdiff; /* The difference between the topmost + shown and the selected */ }; /* Forwards */ static void tree_rescan (void *data); static tree_entry * -back_ptr (tree_entry *ptr, int *count) +back_ptr (tree_entry * ptr, int *count) { int i = 0; - while (ptr && ptr->prev && i < *count){ - ptr = ptr->prev; - i ++; + while (ptr && ptr->prev && i < *count) + { + ptr = ptr->prev; + i++; } *count = i; return ptr; } static tree_entry * -forw_ptr (tree_entry *ptr, int *count) +forw_ptr (tree_entry * ptr, int *count) { int i = 0; - while (ptr && ptr->next && i < *count){ - ptr = ptr->next; - i ++; + while (ptr && ptr->next && i < *count) + { + ptr = ptr->next; + i++; } *count = i; return ptr; } static void -remove_callback (tree_entry *entry, void *data) +remove_callback (tree_entry * entry, void *data) { WTree *tree = data; - if (tree->selected_ptr == entry){ - if (tree->selected_ptr->next) - tree->selected_ptr = tree->selected_ptr->next; - else - tree->selected_ptr = tree->selected_ptr->prev; + if (tree->selected_ptr == entry) + { + if (tree->selected_ptr->next) + tree->selected_ptr = tree->selected_ptr->next; + else + tree->selected_ptr = tree->selected_ptr->prev; } } /* Save the ~/.mc/Tree file */ static void -save_tree (WTree *tree) +save_tree (WTree * tree) { int error; char *tree_name; @@ -144,24 +148,24 @@ save_tree (WTree *tree) error = tree_store_save (); - if (error){ - 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, - unix_error_string (error)); - g_free (tree_name); + if (error) + { + 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, + unix_error_string (error)); + g_free (tree_name); } } static void -tree_remove_entry (WTree *tree, char *name) +tree_remove_entry (WTree * tree, char *name) { (void) tree; tree_store_remove_entry (name); } static void -tree_destroy (WTree *tree) +tree_destroy (WTree * tree) { tree_store_remove_entry_remove_hook (remove_callback); save_tree (tree); @@ -173,7 +177,7 @@ tree_destroy (WTree *tree) /* Loads the .mc.tree file */ static void -load_tree (WTree *tree) +load_tree (WTree * tree) { tree_store_load (); @@ -182,41 +186,44 @@ load_tree (WTree *tree) } 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; - int line; + int line; /* Show mini info */ - if (tree->is_panel){ - if (!show_mini_info) - return; - line = tree_lines+2; - } else - line = tree_lines+1; + if (tree->is_panel) + { + if (!show_mini_info) + return; + line = tree_lines + 2; + } + else + line = tree_lines + 1; tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols); widget_move (&tree->widget, line, 1); - if (tree->searching){ - /* Show search string */ - tty_setcolor (TREE_NORMALC (h)); - tty_setcolor (DLG_FOCUSC (h)); - tty_print_char (PATH_SEP); + if (tree->searching) + { + /* Show search string */ + tty_setcolor (TREE_NORMALC (h)); + tty_setcolor (DLG_FOCUSC (h)); + tty_print_char (PATH_SEP); - tty_print_string (str_fit_to_term (tree->search_buffer, - tree_cols - 2, J_LEFT_FIT)); - tty_print_char (' '); - tty_setcolor (DLG_FOCUSC (h)); - } else { - /* Show full name of selected directory */ - tty_print_string (str_fit_to_term (tree->selected_ptr->name, - tree_cols, J_LEFT_FIT)); + tty_print_string (str_fit_to_term (tree->search_buffer, tree_cols - 2, J_LEFT_FIT)); + tty_print_char (' '); + tty_setcolor (DLG_FOCUSC (h)); + } + else + { + /* Show full name of selected directory */ + tty_print_string (str_fit_to_term (tree->selected_ptr->name, tree_cols, J_LEFT_FIT)); } } static void -show_tree (WTree *tree) +show_tree (WTree * tree) { Dlg_head *h = tree->widget.parent; tree_entry *current; @@ -227,168 +234,193 @@ show_tree (WTree *tree) /* Initialize */ x = y = 0; tree_lines = tlines (tree); - tree_cols = tree->widget.cols; + tree_cols = tree->widget.cols; tty_setcolor (TREE_NORMALC (h)); - widget_move ((Widget*)tree, y, x); - if (tree->is_panel){ - tree_cols -= 2; - x = y = 1; + widget_move ((Widget *) tree, y, x); + if (tree->is_panel) + { + tree_cols -= 2; + x = y = 1; } g_free (tree->tree_shown); tree->tree_shown = g_new0 (tree_entry *, tree_lines); if (tree->store->tree_first) - topsublevel = tree->store->tree_first->sublevel; + topsublevel = tree->store->tree_first->sublevel; else - topsublevel = 0; - if (!tree->selected_ptr){ - tree->selected_ptr = tree->store->tree_first; - tree->topdiff = 0; + topsublevel = 0; + if (!tree->selected_ptr) + { + tree->selected_ptr = tree->store->tree_first; + tree->topdiff = 0; } current = tree->selected_ptr; /* Calculate the directory which is to be shown on the topmost line */ if (!tree_navigation_flag) - current = back_ptr (current, &tree->topdiff); - else { - i = 0; - while (current->prev && i < tree->topdiff){ - current = current->prev; - if (current->sublevel < tree->selected_ptr->sublevel){ - if (strncmp (current->name, tree->selected_ptr->name, - strlen (current->name)) == 0) - i++; - } 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) - i++; - } else if (current->sublevel == tree->selected_ptr->sublevel + 1 - && strlen (tree->selected_ptr->name) > 1){ - if (strncmp (current->name, tree->selected_ptr->name, - strlen (tree->selected_ptr->name)) == 0) - i++; - } - } - tree->topdiff = i; + current = back_ptr (current, &tree->topdiff); + else + { + i = 0; + while (current->prev && i < tree->topdiff) + { + current = current->prev; + if (current->sublevel < tree->selected_ptr->sublevel) + { + if (strncmp (current->name, tree->selected_ptr->name, strlen (current->name)) == 0) + i++; + } + 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) + i++; + } + else if (current->sublevel == tree->selected_ptr->sublevel + 1 + && strlen (tree->selected_ptr->name) > 1) + { + if (strncmp (current->name, tree->selected_ptr->name, + strlen (tree->selected_ptr->name)) == 0) + i++; + } + } + tree->topdiff = i; } /* Loop for every line */ - for (i = 0; i < tree_lines; i++){ - /* Move to the beginning of the line */ - tty_draw_hline (tree->widget.y + y + i, tree->widget.x + x, ' ', tree_cols); + for (i = 0; i < tree_lines; i++) + { + /* Move to the beginning of the line */ + tty_draw_hline (tree->widget.y + y + i, tree->widget.x + x, ' ', tree_cols); - if (!current) - continue; + if (!current) + continue; - tree->tree_shown [i] = current; - if (current->sublevel == topsublevel){ + tree->tree_shown[i] = current; + if (current->sublevel == topsublevel) + { - /* Top level directory */ - if (tree->active && current == tree->selected_ptr) { - if (!tty_use_colors () && !tree->is_panel) - tty_setcolor (MARKED_COLOR); - else - tty_setcolor (SELECTED_COLOR); - } + /* Top level directory */ + if (tree->active && current == tree->selected_ptr) + { + if (!tty_use_colors () && !tree->is_panel) + tty_setcolor (MARKED_COLOR); + else + tty_setcolor (SELECTED_COLOR); + } - /* Show full name */ - tty_print_string (str_fit_to_term (current->name, tree_cols - 6, J_LEFT_FIT)); - } else{ - /* Sub level directory */ + /* Show full name */ + tty_print_string (str_fit_to_term (current->name, tree_cols - 6, J_LEFT_FIT)); + } + else + { + /* Sub level directory */ - tty_set_alt_charset (TRUE); - /* Output branch parts */ - for (j = 0; j < current->sublevel - topsublevel - 1; j++){ - if (tree_cols - 8 - 3 * j < 9) - break; - tty_print_char (' '); - if (current->submask & (1 << (j + topsublevel + 1))) - tty_print_char (ACS_VLINE); - else - tty_print_char (' '); - tty_print_char (' '); - } - tty_print_char (' '); j++; - if (!current->next || !(current->next->submask & (1 << current->sublevel))) - tty_print_char (ACS_LLCORNER); - else - tty_print_char (ACS_LTEE); - tty_print_char (ACS_HLINE); - tty_set_alt_charset (FALSE); + tty_set_alt_charset (TRUE); + /* Output branch parts */ + for (j = 0; j < current->sublevel - topsublevel - 1; j++) + { + if (tree_cols - 8 - 3 * j < 9) + break; + tty_print_char (' '); + if (current->submask & (1 << (j + topsublevel + 1))) + tty_print_char (ACS_VLINE); + else + tty_print_char (' '); + tty_print_char (' '); + } + tty_print_char (' '); + j++; + if (!current->next || !(current->next->submask & (1 << current->sublevel))) + tty_print_char (ACS_LLCORNER); + else + tty_print_char (ACS_LTEE); + tty_print_char (ACS_HLINE); + tty_set_alt_charset (FALSE); - if (tree->active && current == tree->selected_ptr) { - /* Selected directory -> change color */ - if (!tty_use_colors () && !tree->is_panel) - tty_setcolor (MARKED_COLOR); - else - tty_setcolor (SELECTED_COLOR); - } + if (tree->active && current == tree->selected_ptr) + { + /* Selected directory -> change color */ + if (!tty_use_colors () && !tree->is_panel) + tty_setcolor (MARKED_COLOR); + else + tty_setcolor (SELECTED_COLOR); + } - /* Show sub-name */ - tty_print_char (' '); - tty_print_string (str_fit_to_term (current->subname, - tree_cols - 2 - 4 - 3 * j, J_LEFT_FIT)); - } - tty_print_char (' '); + /* Show sub-name */ + tty_print_char (' '); + tty_print_string (str_fit_to_term (current->subname, + tree_cols - 2 - 4 - 3 * j, J_LEFT_FIT)); + } + tty_print_char (' '); - /* Return to normal color */ - tty_setcolor (TREE_NORMALC (h)); + /* Return to normal color */ + tty_setcolor (TREE_NORMALC (h)); - /* Calculate the next value for current */ - current = current->next; - if (tree_navigation_flag){ - while (current){ - if (current->sublevel < tree->selected_ptr->sublevel){ - if (strncmp (current->name, tree->selected_ptr->name, - strlen (current->name)) == 0) - break; - } 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) - break; - } else if (current->sublevel == tree->selected_ptr->sublevel+1 - && strlen (tree->selected_ptr->name) > 1){ - if (strncmp (current->name, tree->selected_ptr->name, - strlen (tree->selected_ptr->name)) == 0) - break; - } - current = current->next; - } - } + /* Calculate the next value for current */ + current = current->next; + if (tree_navigation_flag) + { + while (current) + { + if (current->sublevel < tree->selected_ptr->sublevel) + { + if (strncmp (current->name, tree->selected_ptr->name, + strlen (current->name)) == 0) + break; + } + 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) + break; + } + else if (current->sublevel == tree->selected_ptr->sublevel + 1 + && strlen (tree->selected_ptr->name) > 1) + { + if (strncmp (current->name, tree->selected_ptr->name, + strlen (tree->selected_ptr->name)) == 0) + break; + } + current = current->next; + } + } } tree_show_mini_info (tree, tree_lines, tree_cols); } static void -tree_check_focus (WTree *tree) +tree_check_focus (WTree * tree) { if (tree->topdiff < 3) - tree->topdiff = 3; + tree->topdiff = 3; else if (tree->topdiff >= tlines (tree) - 3) - tree->topdiff = tlines (tree) - 3 - 1; + tree->topdiff = tlines (tree) - 3 - 1; } static void -tree_move_backward (WTree *tree, int i) +tree_move_backward (WTree * tree, int i) { if (!tree_navigation_flag) - tree->selected_ptr = back_ptr (tree->selected_ptr, &i); - else { - tree_entry *current; - int j = 0; + tree->selected_ptr = back_ptr (tree->selected_ptr, &i); + else + { + tree_entry *current; + int j = 0; - current = tree->selected_ptr; - while (j < i && current->prev - && current->prev->sublevel >= tree->selected_ptr->sublevel){ - current = current->prev; - if (current->sublevel == tree->selected_ptr->sublevel){ - tree->selected_ptr = current; - j++; - } - } - i = j; + current = tree->selected_ptr; + while (j < i && current->prev && current->prev->sublevel >= tree->selected_ptr->sublevel) + { + current = current->prev; + if (current->sublevel == tree->selected_ptr->sublevel) + { + tree->selected_ptr = current; + j++; + } + } + i = j; } tree->topdiff -= i; @@ -396,24 +428,26 @@ tree_move_backward (WTree *tree, int i) } static void -tree_move_forward (WTree *tree, int i) +tree_move_forward (WTree * tree, int i) { if (!tree_navigation_flag) - tree->selected_ptr = forw_ptr (tree->selected_ptr, &i); - else { - tree_entry *current; - int j = 0; + tree->selected_ptr = forw_ptr (tree->selected_ptr, &i); + else + { + tree_entry *current; + int j = 0; - current = tree->selected_ptr; - while (j < i && current->next - && current->next->sublevel >= tree->selected_ptr->sublevel){ - current = current->next; - if (current->sublevel == tree->selected_ptr->sublevel){ - tree->selected_ptr = current; - j ++; - } - } - i = j; + current = tree->selected_ptr; + while (j < i && current->next && current->next->sublevel >= tree->selected_ptr->sublevel) + { + current = current->next; + if (current->sublevel == tree->selected_ptr->sublevel) + { + tree->selected_ptr = current; + j++; + } + } + i = j; } tree->topdiff += i; @@ -421,64 +455,69 @@ tree_move_forward (WTree *tree, int i) } static void -tree_move_to_child (WTree *tree) +tree_move_to_child (WTree * tree) { tree_entry *current; /* Do we have a starting point? */ if (!tree->selected_ptr) - return; + return; /* Take the next entry */ current = tree->selected_ptr->next; /* Is it the child of the selected entry */ - if (current && current->sublevel > tree->selected_ptr->sublevel){ - /* Yes -> select this entry */ - tree->selected_ptr = current; - tree->topdiff++; - tree_check_focus (tree); - } else { - /* No -> rescan and try again */ - tree_rescan (tree); - current = tree->selected_ptr->next; - if (current && current->sublevel > tree->selected_ptr->sublevel){ - tree->selected_ptr = current; - tree->topdiff++; - tree_check_focus (tree); - } + if (current && current->sublevel > tree->selected_ptr->sublevel) + { + /* Yes -> select this entry */ + tree->selected_ptr = current; + tree->topdiff++; + tree_check_focus (tree); + } + else + { + /* No -> rescan and try again */ + tree_rescan (tree); + current = tree->selected_ptr->next; + if (current && current->sublevel > tree->selected_ptr->sublevel) + { + tree->selected_ptr = current; + tree->topdiff++; + tree_check_focus (tree); + } } } static gboolean -tree_move_to_parent (WTree *tree) +tree_move_to_parent (WTree * tree) { tree_entry *current; tree_entry *old; if (!tree->selected_ptr) - return FALSE; + return FALSE; old = tree->selected_ptr; current = tree->selected_ptr->prev; - while (current && current->sublevel >= tree->selected_ptr->sublevel){ - current = current->prev; - tree->topdiff--; + while (current && current->sublevel >= tree->selected_ptr->sublevel) + { + current = current->prev; + tree->topdiff--; } if (!current) - current = tree->store->tree_first; + current = tree->store->tree_first; tree->selected_ptr = current; tree_check_focus (tree); return tree->selected_ptr != old; } static void -tree_move_to_top (WTree *tree) +tree_move_to_top (WTree * tree) { tree->selected_ptr = tree->store->tree_first; tree->topdiff = 0; } static void -tree_move_to_bottom (WTree *tree) +tree_move_to_bottom (WTree * tree) { tree->selected_ptr = tree->store->tree_last; tree->topdiff = tlines (tree) - 3 - 1; @@ -486,82 +525,89 @@ tree_move_to_bottom (WTree *tree) /* Handle mouse click */ static void -tree_event (WTree *tree, int y) +tree_event (WTree * tree, int y) { - if (tree->tree_shown [y]){ - tree->selected_ptr = tree->tree_shown [y]; - tree->topdiff = y; + if (tree->tree_shown[y]) + { + tree->selected_ptr = tree->tree_shown[y]; + tree->topdiff = y; } show_tree (tree); } static void -tree_chdir_sel (WTree *tree) +tree_chdir_sel (WTree * tree) { if (!tree->is_panel) - return; + return; change_panel (); if (do_cd (tree->selected_ptr->name, cd_exact)) - select_item (current_panel); + select_item (current_panel); else - message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "), - tree->selected_ptr->name, unix_error_string (errno)); + message (D_ERROR, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "), + tree->selected_ptr->name, unix_error_string (errno)); change_panel (); show_tree (tree); } static void -maybe_chdir (WTree *tree) +maybe_chdir (WTree * tree) { if (xtree_mode && tree->is_panel && is_idle ()) - tree_chdir_sel (tree); + tree_chdir_sel (tree); } /* Mouse callback */ static int -event_callback (Gpm_Event *event, void *data) +event_callback (Gpm_Event * event, void *data) { WTree *tree = data; /* rest of the upper frame, the menu is invisible - call menu */ - if (tree->is_panel && (event->type & GPM_DOWN) - && event->y == 1 && !menubar_visible) { - event->x += tree->widget.x; - return the_menubar->widget.mouse (event, the_menubar); + if (tree->is_panel && (event->type & GPM_DOWN) && event->y == 1 && !menubar_visible) + { + event->x += tree->widget.x; + return the_menubar->widget.mouse (event, the_menubar); } if (!(event->type & GPM_UP)) - return MOU_NORMAL; + return MOU_NORMAL; if (tree->is_panel) - event->y--; + event->y--; event->y--; if (!tree->active) - change_panel (); + change_panel (); - if (event->y < 0){ - tree_move_backward (tree, tlines (tree) - 1); - show_tree (tree); - } else if (event->y >= tlines (tree)){ - tree_move_forward (tree, tlines (tree) - 1); - show_tree (tree); - } else { - tree_event (tree, event->y); - if ((event->type & (GPM_UP|GPM_DOUBLE)) == (GPM_UP|GPM_DOUBLE)){ - tree_chdir_sel (tree); - } + if (event->y < 0) + { + tree_move_backward (tree, tlines (tree) - 1); + show_tree (tree); + } + else if (event->y >= tlines (tree)) + { + tree_move_forward (tree, tlines (tree) - 1); + show_tree (tree); + } + else + { + tree_event (tree, event->y); + if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE)) + { + tree_chdir_sel (tree); + } } return MOU_NORMAL; } /* Search tree for text */ static int -search_tree (WTree *tree, char *text) +search_tree (WTree * tree, char *text) { tree_entry *current; int len; @@ -571,38 +617,42 @@ search_tree (WTree *tree, char *text) len = strlen (text); current = tree->selected_ptr; found = 0; - while (!wrapped || current != tree->selected_ptr){ - if (strncmp (current->subname, text, len) == 0){ - tree->selected_ptr = current; - found = 1; - break; - } - current = current->next; - if (!current){ - current = tree->store->tree_first; - wrapped = 1; - } - tree->topdiff++; + while (!wrapped || current != tree->selected_ptr) + { + if (strncmp (current->subname, text, len) == 0) + { + tree->selected_ptr = current; + found = 1; + break; + } + current = current->next; + if (!current) + { + current = tree->store->tree_first; + wrapped = 1; + } + tree->topdiff++; } tree_check_focus (tree); return found; } static void -tree_do_search (WTree *tree, int key) +tree_do_search (WTree * tree, int key) { size_t l; l = strlen (tree->search_buffer); if ((l != 0) && (key == KEY_BACKSPACE)) - tree->search_buffer [--l] = '\0'; - else if (key && l < sizeof (tree->search_buffer)){ - tree->search_buffer [l] = key; - tree->search_buffer [++l] = '\0'; + tree->search_buffer[--l] = '\0'; + else if (key && l < sizeof (tree->search_buffer)) + { + tree->search_buffer[l] = key; + tree->search_buffer[++l] = '\0'; } if (!search_tree (tree, tree->search_buffer)) - tree->search_buffer [--l] = 0; + tree->search_buffer[--l] = 0; show_tree (tree); maybe_chdir (tree); @@ -611,12 +661,12 @@ tree_do_search (WTree *tree, int key) static void tree_rescan (void *data) { - char old_dir [MC_MAXPATHLEN]; + char old_dir[MC_MAXPATHLEN]; WTree *tree = data; if (!tree->selected_ptr || !mc_get_current_wd (old_dir, MC_MAXPATHLEN) || - mc_chdir (tree->selected_ptr->name)) - return; + mc_chdir (tree->selected_ptr->name)) + return; tree_store_rescan (tree->selected_ptr->name); mc_chdir (old_dir); @@ -627,73 +677,77 @@ tree_forget (void *data) { WTree *tree = data; if (tree->selected_ptr) - tree_remove_entry (tree, tree->selected_ptr->name); + tree_remove_entry (tree, tree->selected_ptr->name); } static void -tree_copy (WTree *tree, const char *default_dest) +tree_copy (WTree * tree, const char *default_dest) { - char msg [BUF_MEDIUM]; - char *dest; + char msg[BUF_MEDIUM]; + char *dest; if (tree->selected_ptr == NULL) - return; + return; g_snprintf (msg, sizeof (msg), _("Copy \"%s\" directory to:"), - str_trunc (tree->selected_ptr->name, 50)); - dest = input_expand_dialog (Q_("DialogTitle|Copy"), - msg, MC_HISTORY_FM_TREE_COPY, default_dest); + str_trunc (tree->selected_ptr->name, 50)); + dest = input_expand_dialog (Q_ ("DialogTitle|Copy"), + msg, MC_HISTORY_FM_TREE_COPY, default_dest); - if (dest != NULL && *dest != '\0') { - FileOpContext *ctx; - FileOpTotalContext *tctx; + if (dest != NULL && *dest != '\0') + { + FileOpContext *ctx; + FileOpTotalContext *tctx; - ctx = file_op_context_new (OP_COPY); - tctx = file_op_total_context_new (); - file_op_context_create_ui (ctx, FALSE, FILEGUI_DIALOG_MULTI_ITEM); - tctx->ask_overwrite = FALSE; - tctx->is_toplevel_file = FALSE; - copy_dir_dir (tctx, ctx, tree->selected_ptr->name, dest, TRUE, FALSE, FALSE, NULL); - file_op_total_context_destroy (tctx); - file_op_context_destroy (ctx); + ctx = file_op_context_new (OP_COPY); + tctx = file_op_total_context_new (); + file_op_context_create_ui (ctx, FALSE, FILEGUI_DIALOG_MULTI_ITEM); + tctx->ask_overwrite = FALSE; + tctx->is_toplevel_file = FALSE; + copy_dir_dir (tctx, ctx, tree->selected_ptr->name, dest, TRUE, FALSE, FALSE, NULL); + file_op_total_context_destroy (tctx); + file_op_context_destroy (ctx); } g_free (dest); } static void -tree_move (WTree *tree, const char *default_dest) +tree_move (WTree * tree, const char *default_dest) { - char msg [BUF_MEDIUM]; - char *dest; + char msg[BUF_MEDIUM]; + char *dest; struct stat buf; FileOpContext *ctx; FileOpTotalContext *tctx; if (tree->selected_ptr == NULL) - return; + return; g_snprintf (msg, sizeof (msg), _("Move \"%s\" directory to:"), - str_trunc (tree->selected_ptr->name, 50)); - dest = input_expand_dialog (Q_("DialogTitle|Move"), msg, MC_HISTORY_FM_TREE_MOVE, default_dest); + str_trunc (tree->selected_ptr->name, 50)); + dest = + input_expand_dialog (Q_ ("DialogTitle|Move"), msg, MC_HISTORY_FM_TREE_MOVE, default_dest); - if (dest == NULL || *dest == '\0') { - g_free (dest); - return; + if (dest == NULL || *dest == '\0') + { + g_free (dest); + return; } - if (stat (dest, &buf)){ - message (D_ERROR, MSG_ERROR, _(" Cannot stat the destination \n %s "), - unix_error_string (errno)); - g_free (dest); - return; + if (stat (dest, &buf)) + { + message (D_ERROR, MSG_ERROR, _(" Cannot stat the destination \n %s "), + unix_error_string (errno)); + g_free (dest); + return; } - if (!S_ISDIR (buf.st_mode)){ - file_error (_(" Destination \"%s\" must be a directory \n %s "), - dest); - g_free (dest); - return; + if (!S_ISDIR (buf.st_mode)) + { + file_error (_(" Destination \"%s\" must be a directory \n %s "), dest); + g_free (dest); + return; } ctx = file_op_context_new (OP_MOVE); @@ -708,19 +762,19 @@ tree_move (WTree *tree, const char *default_dest) #if 0 static void -tree_mkdir (WTree *tree) +tree_mkdir (WTree * tree) { - char old_dir [MC_MAXPATHLEN]; + char old_dir[MC_MAXPATHLEN]; if (!tree->selected_ptr) - return; + return; if (!mc_get_current_wd (old_dir, MC_MAXPATHLEN)) - return; + return; if (chdir (tree->selected_ptr->name)) - return; + return; /* FIXME - mkdir_cmd (tree); - */ + mkdir_cmd (tree); + */ tree_rescan (tree); chdir (old_dir); } @@ -734,20 +788,18 @@ tree_rmdir (void *data) FileOpTotalContext *tctx; if (!tree->selected_ptr) - return; + return; - if (confirm_delete) { - char *buf; - int result; + if (confirm_delete) + { + char *buf; + int result; - buf = - g_strdup_printf (_(" Delete %s? "), - tree->selected_ptr->name); - result = - query_dialog (Q_("DialogTitle|Delete"), buf, D_ERROR, 2, _("&Yes"), _("&No")); - g_free (buf); - if (result != 0) - return; + buf = g_strdup_printf (_(" Delete %s? "), tree->selected_ptr->name); + result = query_dialog (Q_ ("DialogTitle|Delete"), buf, D_ERROR, 2, _("&Yes"), _("&No")); + g_free (buf); + if (result != 0) + return; } ctx = file_op_context_new (OP_DELETE); @@ -755,13 +807,13 @@ tree_rmdir (void *data) file_op_context_create_ui (ctx, FALSE, FILEGUI_DIALOG_ONE_ITEM); if (erase_dir (tctx, ctx, tree->selected_ptr->name) == FILE_CONT) - tree_forget (tree); + tree_forget (tree); file_op_total_context_destroy (tctx); file_op_context_destroy (ctx); } static inline void -tree_move_up (WTree *tree) +tree_move_up (WTree * tree) { tree_move_backward (tree, 1); show_tree (tree); @@ -769,7 +821,7 @@ tree_move_up (WTree *tree) } static inline void -tree_move_down (WTree *tree) +tree_move_down (WTree * tree) { tree_move_forward (tree, 1); show_tree (tree); @@ -777,7 +829,7 @@ tree_move_down (WTree *tree) } static inline void -tree_move_home (WTree *tree) +tree_move_home (WTree * tree) { tree_move_to_top (tree); show_tree (tree); @@ -785,7 +837,7 @@ tree_move_home (WTree *tree) } static inline void -tree_move_end (WTree *tree) +tree_move_end (WTree * tree) { tree_move_to_bottom (tree); show_tree (tree); @@ -793,7 +845,7 @@ tree_move_end (WTree *tree) } static void -tree_move_pgup (WTree *tree) +tree_move_pgup (WTree * tree) { tree_move_backward (tree, tlines (tree) - 1); show_tree (tree); @@ -801,7 +853,7 @@ tree_move_pgup (WTree *tree) } static void -tree_move_pgdn (WTree *tree) +tree_move_pgdn (WTree * tree) { tree_move_forward (tree, tlines (tree) - 1); show_tree (tree); @@ -809,124 +861,130 @@ tree_move_pgdn (WTree *tree) } static gboolean -tree_move_left (WTree *tree) +tree_move_left (WTree * tree) { gboolean v = FALSE; - if (tree_navigation_flag) { - v = tree_move_to_parent (tree); - show_tree (tree); - maybe_chdir (tree); + if (tree_navigation_flag) + { + v = tree_move_to_parent (tree); + show_tree (tree); + maybe_chdir (tree); } return v; } static gboolean -tree_move_right (WTree *tree) +tree_move_right (WTree * tree) { gboolean v = FALSE; - if (tree_navigation_flag) { - tree_move_to_child (tree); - show_tree (tree); - maybe_chdir (tree); - v = TRUE; + if (tree_navigation_flag) + { + tree_move_to_child (tree); + show_tree (tree); + maybe_chdir (tree); + v = TRUE; } return v; } static void -tree_start_search (WTree *tree) +tree_start_search (WTree * tree) { gboolean i; - if (tree->searching) { - if (tree->selected_ptr == tree->store->tree_last) - tree_move_to_top (tree); - else { - /* set navigation mode temporarily to 'Static' because in - * dynamic navigation mode tree_move_forward will not move - * to a lower sublevel if necessary (sequent searches must - * start with the directory followed the last found directory) - */ - i = tree_navigation_flag; - tree_navigation_flag = 0; - tree_move_forward (tree, 1); - tree_navigation_flag = i; - } - tree_do_search (tree, 0); - } else { - tree->searching = 1; - tree->search_buffer[0] = 0; + if (tree->searching) + { + if (tree->selected_ptr == tree->store->tree_last) + tree_move_to_top (tree); + else + { + /* set navigation mode temporarily to 'Static' because in + * dynamic navigation mode tree_move_forward will not move + * to a lower sublevel if necessary (sequent searches must + * start with the directory followed the last found directory) + */ + i = tree_navigation_flag; + tree_navigation_flag = 0; + tree_move_forward (tree, 1); + tree_navigation_flag = i; + } + tree_do_search (tree, 0); + } + else + { + tree->searching = 1; + tree->search_buffer[0] = 0; } } static void -tree_toggle_navig (WTree *tree) +tree_toggle_navig (WTree * tree) { tree_navigation_flag = !tree_navigation_flag; buttonbar_set_label (find_buttonbar (tree->widget.parent), 4, - tree_navigation_flag ? Q_("ButtonBar|Static") - : Q_("ButtonBar|Dynamc"), - tree_map, (Widget *) tree); + tree_navigation_flag ? Q_ ("ButtonBar|Static") + : Q_ ("ButtonBar|Dynamc"), tree_map, (Widget *) tree); } 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; if (command != CK_TreeStartSearch) - tree->searching = 0; + tree->searching = 0; - switch (command) { + switch (command) + { case CK_TreeHelp: - interactive_display (NULL, "[Directory Tree]"); - break; + interactive_display (NULL, "[Directory Tree]"); + break; case CK_TreeForget: - tree_forget (tree); - break; + tree_forget (tree); + break; case CK_TreeToggleNav: - tree_toggle_navig (tree); - break; + tree_toggle_navig (tree); + break; case CK_TreeCopy: - tree_copy (tree, ""); - break; + tree_copy (tree, ""); + break; case CK_TreeMove: - tree_move (tree, ""); - break; + tree_move (tree, ""); + break; case CK_TreeMoveUp: - tree_move_up (tree); - break; + tree_move_up (tree); + break; case CK_TreeMoveDown: - tree_move_down (tree); - break; + tree_move_down (tree); + break; case CK_TreeMoveHome: - tree_move_home (tree); - break; + tree_move_home (tree); + break; case CK_TreeMoveEnd: - tree_move_end (tree); - break; + tree_move_end (tree); + break; case CK_TreeMovePgUp: - tree_move_pgup (tree); - break; + tree_move_pgup (tree); + break; case CK_TreeMovePgDn: - tree_move_pgdn (tree); - break; + tree_move_pgdn (tree); + break; case CK_TreeOpen: - tree_chdir_sel (tree); - break; + tree_chdir_sel (tree); + break; case CK_TreeRescan: - tree_rescan (tree); - break; + tree_rescan (tree); + break; case CK_TreeStartSearch: - tree_start_search (tree); - break; + tree_start_search (tree); + break; case CK_TreeRemove: - tree_rmdir (tree); - break; + tree_rmdir (tree); + break; default: res = MSG_NOT_HANDLED; } @@ -937,126 +995,131 @@ tree_execute_cmd (WTree *tree, unsigned long command) } static cb_ret_t -tree_key (WTree *tree, int key) +tree_key (WTree * tree, int key) { size_t i; - for (i = 0; tree_map [i].key != 0; i++) - if (key == tree_map [i].key) - switch (tree_map [i].command) { - case CK_TreeMoveLeft: - return tree_move_left (tree) ? MSG_HANDLED : MSG_NOT_HANDLED; - case CK_TreeMoveRight: - return tree_move_right (tree) ? MSG_HANDLED : MSG_NOT_HANDLED; - default: - tree_execute_cmd (tree, tree_map [i].command); - return MSG_HANDLED; - } + for (i = 0; tree_map[i].key != 0; i++) + if (key == tree_map[i].key) + switch (tree_map[i].command) + { + case CK_TreeMoveLeft: + return tree_move_left (tree) ? MSG_HANDLED : MSG_NOT_HANDLED; + case CK_TreeMoveRight: + return tree_move_right (tree) ? MSG_HANDLED : MSG_NOT_HANDLED; + default: + tree_execute_cmd (tree, tree_map[i].command); + return MSG_HANDLED; + } - if (is_abort_char (key)) { - if (tree->is_panel) { - tree->searching = 0; - show_tree (tree); - return MSG_HANDLED; /* eat abort char */ - } - /* modal tree dialog: let upper layer see the - abort character and close the dialog */ - return MSG_NOT_HANDLED; + if (is_abort_char (key)) + { + if (tree->is_panel) + { + tree->searching = 0; + show_tree (tree); + return MSG_HANDLED; /* eat abort char */ + } + /* modal tree dialog: let upper layer see the + abort character and close the dialog */ + return MSG_NOT_HANDLED; } /* Do not eat characters not meant for the tree below ' ' (e.g. C-l). */ - if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE) { - if (tree->searching){ - tree_do_search (tree, key); - show_tree (tree); - return MSG_HANDLED; - } + if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE) + { + if (tree->searching) + { + tree_do_search (tree, key); + show_tree (tree); + return MSG_HANDLED; + } - if (!command_prompt) { - tree_start_search (tree); - tree_do_search (tree, key); - return MSG_HANDLED; - } - return tree->is_panel ? MSG_HANDLED : MSG_NOT_HANDLED; + if (!command_prompt) + { + tree_start_search (tree); + tree_do_search (tree, key); + return MSG_HANDLED; + } + return tree->is_panel ? MSG_HANDLED : MSG_NOT_HANDLED; } return MSG_NOT_HANDLED; } static void -tree_frame (Dlg_head *h, WTree *tree) +tree_frame (Dlg_head * h, WTree * tree) { tty_setcolor (NORMAL_COLOR); - widget_erase ((Widget*) tree); - if (tree->is_panel) { - draw_box (h, tree->widget.y, tree->widget.x, tree->widget.lines, - tree->widget.cols, FALSE); + widget_erase ((Widget *) tree); + if (tree->is_panel) + { + draw_box (h, tree->widget.y, tree->widget.x, tree->widget.lines, tree->widget.cols, FALSE); - if (show_mini_info) - tty_draw_hline (tree->widget.y + tlines (tree) + 1, - tree->widget.x + 1, - ACS_HLINE, tree->widget.cols - 2); + if (show_mini_info) + tty_draw_hline (tree->widget.y + tlines (tree) + 1, + tree->widget.x + 1, ACS_HLINE, tree->widget.cols - 2); } } 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; Dlg_head *h = tree->widget.parent; WButtonBar *b = find_buttonbar (h); - switch (msg) { + switch (msg) + { case WIDGET_DRAW: - tree_frame (h, tree); - show_tree (tree); - return MSG_HANDLED; + tree_frame (h, tree); + show_tree (tree); + return MSG_HANDLED; case WIDGET_FOCUS: - tree->active = 1; - 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, 3, Q_("ButtonBar|Forget"), tree_map, (Widget *) tree); - buttonbar_set_label (b, 4, tree_navigation_flag ? Q_("ButtonBar|Static") - : Q_("ButtonBar|Dynamc"), - 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); + tree->active = 1; + 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, 3, Q_ ("ButtonBar|Forget"), tree_map, (Widget *) tree); + buttonbar_set_label (b, 4, tree_navigation_flag ? Q_ ("ButtonBar|Static") + : Q_ ("ButtonBar|Dynamc"), 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); #if 0 - /* FIXME: mkdir is currently defunct */ - buttonbar_set_label (b, 7, Q_("ButtonBar|Mkdir"), tree_map, (Widget *) tree); + /* FIXME: mkdir is currently defunct */ + buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), tree_map, (Widget *) tree); #else - buttonbar_clear_label (b, 7, (Widget *) tree); + buttonbar_clear_label (b, 7, (Widget *) tree); #endif - buttonbar_set_label (b, 8, Q_("ButtonBar|Rmdir"), tree_map, (Widget *) tree); - buttonbar_redraw (b); + buttonbar_set_label (b, 8, Q_ ("ButtonBar|Rmdir"), tree_map, (Widget *) tree); + buttonbar_redraw (b); - /* FIXME: Should find a better way of only displaying the - currently selected item */ - show_tree (tree); - return MSG_HANDLED; + /* FIXME: Should find a better way of only displaying the + currently selected item */ + show_tree (tree); + return MSG_HANDLED; - /* FIXME: Should find a better way of changing the color of the - selected item */ + /* FIXME: Should find a better way of changing the color of the + selected item */ case WIDGET_UNFOCUS: - tree->active = 0; - show_tree (tree); - return MSG_HANDLED; + tree->active = 0; + show_tree (tree); + return MSG_HANDLED; case WIDGET_KEY: - return tree_key (tree, parm); + return tree_key (tree, parm); case WIDGET_COMMAND: - /* command from buttonbar */ - return tree_execute_cmd (tree, parm); + /* command from buttonbar */ + return tree_execute_cmd (tree, parm); case WIDGET_DESTROY: - tree_destroy (tree); - return MSG_HANDLED; + tree_destroy (tree); + return MSG_HANDLED; default: - return default_proc (msg, parm); + return default_proc (msg, parm); } } @@ -1065,8 +1128,7 @@ tree_new (int is_panel, int y, int x, int lines, int cols) { WTree *tree = g_new (WTree, 1); - init_widget (&tree->widget, y, x, lines, cols, - tree_callback, event_callback); + init_widget (&tree->widget, y, x, lines, cols, tree_callback, event_callback); tree->is_panel = is_panel; tree->selected_ptr = 0; @@ -1085,21 +1147,22 @@ tree_new (int is_panel, int y, int x, int lines, int cols) } void -tree_chdir (WTree *tree, const char *dir) +tree_chdir (WTree * tree, const char *dir) { tree_entry *current; current = tree_store_whereis (dir); - if (current != NULL) { - tree->selected_ptr = current; - tree_check_focus (tree); + if (current != NULL) + { + tree->selected_ptr = current; + tree_check_focus (tree); } } /* Return name of the currently selected entry */ char * -tree_selected_name (const WTree *tree) +tree_selected_name (const WTree * tree) { return tree->selected_ptr->name; }