* 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().
This commit is contained in:
Pavel Roskin 2003-09-01 09:03:30 +00:00
parent 3632b705de
commit 198e0035e4
3 changed files with 41 additions and 47 deletions

View File

@ -1,5 +1,11 @@
2003-09-01 Pavel Roskin <proski@gnu.org>
* 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.

View File

@ -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);

View File

@ -798,10 +798,21 @@ static void
listmode_cmd (void)
{
char *newmode;
newmode = listmode_edit ("half <type,>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 */