diff --git a/src/ChangeLog b/src/ChangeLog index 8f23ba6ba..c8c1bd4f6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2003-09-01 Pavel Roskin + * listmode.c: Create all buttons in one place. Remove unneeded + low-level drawing. + (listmode_edit): Return NULL on cancel. + * main.c (listmode_cmd): Actually use the result of + listmode_edit(). + * listmode.c: Use callbacks for Add and Remove buttons. Don't run dialog in the loop, it doesn't work this way. diff --git a/src/listmode.c b/src/listmode.c index 30e17a24b..d879226bf 100644 --- a/src/listmode.c +++ b/src/listmode.c @@ -53,7 +53,7 @@ #define BX 5 #define BY 18 -#define BUTTONS 4 +#define BUTTONS 6 #define LABELS 4 #define B_ADD B_USER #define B_REMOVE B_USER + 1 @@ -89,13 +89,6 @@ struct listmode_label { char *text; }; -static struct listmode_label listmode_labels[LABELS] = { - {UY, UX + 1, " General options "}, - {UY + 4, UX + 1, " Items "}, - {UY + 4, UX + 21, " Item options"}, - {UY + 13, UX + 22, "Item width:"} -}; - static char * select_new_item (void) { @@ -165,13 +158,6 @@ bremove_cback (int action) return 0; } -static struct listmode_button listmode_but[BUTTONS] = { - {B_CANCEL, NORMAL_BUTTON, 0, 53, "&Cancel", NULL}, - {B_ADD, NORMAL_BUTTON, 0, 22, "&Add item", badd_cback}, - {B_REMOVE, NORMAL_BUTTON, 0, 10, "&Remove", bremove_cback}, - {B_ENTER, DEFPUSH_BUTTON, 0, 0, "&OK", NULL}, -}; - static int listmode_callback (Dlg_head *h, int Par, int Msg) { @@ -181,15 +167,6 @@ listmode_callback (Dlg_head *h, int Par, int Msg) listmode_refresh (h); break; - case DLG_POST_KEY: - /* fall */ - - case DLG_INIT: - attrset (COLOR_NORMAL); - dlg_move (h, UY + 13, UX + 35); - printw ("%02d", 99); - attrset (MENU_ENTRY_COLOR); - break; } return 0; } @@ -203,6 +180,22 @@ init_listmode (char *oldlistformat) int format_columns = 0; Dlg_head *listmode_dlg; + static struct listmode_label listmode_labels[LABELS] = { + {UY, UX + 1, " General options "}, + {UY + 4, UX + 1, " Items "}, + {UY + 4, UX + 21, " Item options "}, + {UY + 13, UX + 22, "Item width:"} + }; + + static struct listmode_button listmode_but[BUTTONS] = { + {B_CANCEL, NORMAL_BUTTON, BY, BX + 53, "&Cancel", NULL}, + {B_ADD, NORMAL_BUTTON, BY, BX + 22, "&Add item", badd_cback}, + {B_REMOVE, NORMAL_BUTTON, BY, BX + 10, "&Remove", bremove_cback}, + {B_ENTER, DEFPUSH_BUTTON, BY, BX, "&OK", NULL}, + {B_PLUS, NARROW_BUTTON, UY + 13, UX + 37, "&+", bplus_cback}, + {B_MINUS, NARROW_BUTTON, UY + 13, UX + 34, "&-", bminus_cback}, + }; + do_refresh (); listmode_dlg = @@ -211,8 +204,7 @@ init_listmode (char *oldlistformat) for (i = 0; i < BUTTONS; i++) add_widget (listmode_dlg, - button_new (BY + listmode_but[i].y, - BX + listmode_but[i].x, + button_new (listmode_but[i].y, listmode_but[i].x, listmode_but[i].ret_cmd, listmode_but[i].flags, listmode_but[i].text, @@ -226,12 +218,6 @@ init_listmode (char *oldlistformat) add_widget (listmode_dlg, pname); } - add_widget (listmode_dlg, - button_new (UY + 13, UX + 37, B_MINUS, NORMAL_BUTTON, "&-", - bminus_cback)); - add_widget (listmode_dlg, - button_new (UY + 13, UX + 34, B_PLUS, NORMAL_BUTTON, "&+", - bplus_cback)); radio_itemwidth = radio_new (UY + 9, UX + 22, 3, s_itemwidth, 1); add_widget (listmode_dlg, radio_itemwidth); radio_itemwidth = 0; @@ -314,6 +300,7 @@ collect_new_format (void) return newformat; } +/* Return new format or NULL if the user cancelled the dialog */ char * listmode_edit (char *oldlistformat) { @@ -325,18 +312,8 @@ listmode_edit (char *oldlistformat) listmode_dlg = init_listmode (s); g_free (s); - attrset (SELECTED_COLOR); - - run_dlg (listmode_dlg); - - switch (listmode_dlg->ret_value) { - case B_CANCEL: - newformat = g_strdup (oldlistformat); - break; - - case B_ENTER: + if (run_dlg (listmode_dlg) == B_ENTER) { newformat = collect_new_format (); - break; } listmode_done (listmode_dlg); diff --git a/src/main.c b/src/main.c index 47eeffe4c..7758da7c2 100644 --- a/src/main.c +++ b/src/main.c @@ -798,10 +798,21 @@ static void listmode_cmd (void) { char *newmode; - newmode = listmode_edit ("half name,|,size:8,|,perm:4+"); - message (0, _(" Listing format edit "), _(" New mode is \"%s\" "), - newmode); - g_free (newmode); + + if (get_current_type () != view_listing) + return; + + newmode = listmode_edit (cpanel->user_format); + if (!newmode) + return; + + g_free (cpanel->user_format); + cpanel->list_type = list_user; + cpanel->user_format = newmode; + set_panel_formats (cpanel); + paint_panel (cpanel); + + do_refresh (); } #endif /* LISTMODE_EDITOR */