1
1

* listmode.c (listmode_refresh): Use common_dialog_repaint().

Eliminate all global variables.  Reformat the whole file.
Этот коммит содержится в:
Pavel Roskin 2002-09-02 06:06:49 +00:00
родитель 946e09abc2
Коммит cec127c569
2 изменённых файлов: 99 добавлений и 77 удалений

Просмотреть файл

@ -1,5 +1,8 @@
2002-09-02 Pavel Roskin <proski@gnu.org> 2002-09-02 Pavel Roskin <proski@gnu.org>
* listmode.c (listmode_refresh): Use common_dialog_repaint().
Eliminate all global variables. Reformat the whole file.
* boxes.c (init_disp_bits_box): Use common_dialog_callback(). * boxes.c (init_disp_bits_box): Use common_dialog_callback().
Return the new dialog. Return the new dialog.

Просмотреть файл

@ -60,73 +60,78 @@
static WListbox *l_listmode; static WListbox *l_listmode;
static Dlg_head *listmode_dlg;
static WLabel *pname; static WLabel *pname;
static char *listmode_section = "[Listing format edit]"; static char *listmode_section = "[Listing format edit]";
static char *s_genwidth [2] = {"Half width", "Full width"}; static char *s_genwidth[2] = { "Half width", "Full width" };
WRadio *radio_genwidth; static WRadio *radio_genwidth;
static char *s_columns [2] = {"One column", "Two columns"}; static char *s_columns[2] = { "One column", "Two columns" };
WRadio *radio_columns; static WRadio *radio_columns;
static char *s_justify [3] = static char *s_justify[3] =
{"Left justified", "Default justification", "Right justified"}; { "Left justified", "Default justification", "Right justified" };
WRadio *radio_justify; static WRadio *radio_justify;
static char *s_itemwidth [3] = static char *s_itemwidth[3] =
{"Free width", "Fixed width", "Growable width"}; { "Free width", "Fixed width", "Growable width" };
WRadio *radio_itemwidth; static WRadio *radio_itemwidth;
struct { struct listmode_button {
int ret_cmd, flags, y, x; int ret_cmd, flags, y, x;
char *text; char *text;
} listmode_but[BUTTONS] = { };
{ B_CANCEL, NORMAL_BUTTON, 0, 53, "&Cancel" },
{ B_ADD, NORMAL_BUTTON, 0, 22, "&Add item"}, static struct listmode_button listmode_but[BUTTONS] = {
{ B_REMOVE, NORMAL_BUTTON, 0, 10, "&Remove" }, {B_CANCEL, NORMAL_BUTTON, 0, 53, "&Cancel"},
{ B_ENTER, DEFPUSH_BUTTON, 0, 0, "&Ok" }, {B_ADD, NORMAL_BUTTON, 0, 22, "&Add item"},
{B_REMOVE, NORMAL_BUTTON, 0, 10, "&Remove"},
{B_ENTER, DEFPUSH_BUTTON, 0, 0, "&Ok"},
}; };
#define B_PLUS B_USER #define B_PLUS B_USER
#define B_MINUS B_USER+1 #define B_MINUS B_USER+1
struct { struct listmode_label {
int y, x; int y, x;
char *text; char *text;
} listmode_text [LABELS] = {
{ UY, UX + 1, " General options " },
{ UY+4, UX+1, " Items "},
{ UY+4, UX+21, " Item options" },
{ UY+13, UX+22, "Item width:" }
}; };
static void listmode_refresh (void) 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 void
listmode_refresh (Dlg_head * h)
{ {
common_dialog_repaint (h);
attrset (COLOR_NORMAL); attrset (COLOR_NORMAL);
dlg_erase (listmode_dlg); draw_box (h, UY, UX, 4, 63);
draw_box (h, UY + 4, UX, 11, 18);
draw_box (listmode_dlg, 1, 2, 20, 70); draw_box (h, UY + 4, UX + 20, 11, 43);
draw_box (listmode_dlg, UY, UX, 4, 63);
draw_box (listmode_dlg, UY + 4, UX, 11, 18);
draw_box (listmode_dlg, UY + 4, UX+20, 11, 43);
} }
static int bplus_cback (int action, void *data) static int
bplus_cback (int action, void *data)
{ {
return 0; return 0;
} }
static int bminus_cback (int action, void *data) static int
bminus_cback (int action, void *data)
{ {
return 0; return 0;
} }
static int listmode_callback (Dlg_head * h, int Par, int Msg) static int
listmode_callback (Dlg_head * h, int Par, int Msg)
{ {
switch (Msg) { switch (Msg) {
case DLG_DRAW: case DLG_DRAW:
listmode_refresh (); listmode_refresh (h);
break; break;
case DLG_POST_KEY: case DLG_POST_KEY:
@ -134,7 +139,7 @@ static int listmode_callback (Dlg_head * h, int Par, int Msg)
case DLG_INIT: case DLG_INIT:
attrset (COLOR_NORMAL); attrset (COLOR_NORMAL);
dlg_move (h, UY+13, UX+35); dlg_move (h, UY + 13, UX + 35);
printw ("%02d", 99); printw ("%02d", 99);
attrset (MENU_ENTRY_COLOR); attrset (MENU_ENTRY_COLOR);
break; break;
@ -142,23 +147,26 @@ static int listmode_callback (Dlg_head * h, int Par, int Msg)
return 0; return 0;
} }
static int l_call (void *data) static int
l_call (void *data)
{ {
return 1; return 1;
} }
static void init_listmode (char *oldlistformat) static Dlg_head *
init_listmode (char *oldlistformat)
{ {
int i; int i;
char *s; char *s;
int format_width = 0; int format_width = 0;
int format_columns = 0; int format_columns = 0;
Dlg_head *listmode_dlg;
do_refresh (); do_refresh ();
listmode_dlg = create_dlg (0, 0, 22, 74, dialog_colors, listmode_dlg =
listmode_callback, listmode_section, "listmode", create_dlg (0, 0, 22, 74, dialog_colors, listmode_callback,
DLG_CENTER); listmode_section, "listmode", DLG_CENTER);
x_set_dialog_title (listmode_dlg, "Listing format edit"); x_set_dialog_title (listmode_dlg, "Listing format edit");
#define XTRACT(i) BY+listmode_but[i].y, BX+listmode_but[i].x, listmode_but[i].ret_cmd, listmode_but[i].flags, listmode_but[i].text, 0, 0, NULL #define XTRACT(i) BY+listmode_but[i].y, BX+listmode_but[i].x, listmode_but[i].ret_cmd, listmode_but[i].flags, listmode_but[i].text, 0, 0, NULL
@ -167,43 +175,46 @@ static void init_listmode (char *oldlistformat)
add_widget (listmode_dlg, button_new (XTRACT (i))); add_widget (listmode_dlg, button_new (XTRACT (i)));
/* We add the labels. */ /* We add the labels. */
for (i = 0; i < LABELS; i++){ for (i = 0; i < LABELS; i++) {
pname = label_new (listmode_text [i].y, pname =
listmode_text [i].x, listmode_text [i].text, NULL); label_new (listmode_labels[i].y, listmode_labels[i].x,
listmode_labels[i].text, NULL);
add_widget (listmode_dlg, pname); add_widget (listmode_dlg, pname);
} }
add_widget (listmode_dlg, button_new (UY+13, UX+37, B_MINUS, NORMAL_BUTTON, add_widget (listmode_dlg,
"&-", bminus_cback, 0, NULL)); button_new (UY + 13, UX + 37, B_MINUS, NORMAL_BUTTON, "&-",
add_widget (listmode_dlg, button_new (UY+13, UX+34, B_PLUS, NORMAL_BUTTON, bminus_cback, 0, NULL));
"&+", bplus_cback, 0, NULL)); add_widget (listmode_dlg,
radio_itemwidth = radio_new (UY+9, UX+22, 3, s_itemwidth, 1, NULL); button_new (UY + 13, UX + 34, B_PLUS, NORMAL_BUTTON, "&+",
bplus_cback, 0, NULL));
radio_itemwidth = radio_new (UY + 9, UX + 22, 3, s_itemwidth, 1, NULL);
add_widget (listmode_dlg, radio_itemwidth); add_widget (listmode_dlg, radio_itemwidth);
radio_itemwidth = 0; radio_itemwidth = 0;
radio_justify = radio_new (UY+5, UX+22, 3, s_justify, 1, NULL); radio_justify = radio_new (UY + 5, UX + 22, 3, s_justify, 1, NULL);
add_widget (listmode_dlg, radio_justify); add_widget (listmode_dlg, radio_justify);
radio_justify->sel = 1; radio_justify->sel = 1;
/* get new listbox */ /* get new listbox */
l_listmode = listbox_new (UY + 5, UX + 1, 16, 9, 0, l_call, NULL); l_listmode = listbox_new (UY + 5, UX + 1, 16, 9, 0, l_call, NULL);
if (strncmp (oldlistformat, "full ", 5) == 0){ if (strncmp (oldlistformat, "full ", 5) == 0) {
format_width = 1; format_width = 1;
oldlistformat += 5; oldlistformat += 5;
} }
if (strncmp (oldlistformat, "half ", 5) == 0){ if (strncmp (oldlistformat, "half ", 5) == 0) {
oldlistformat += 5; oldlistformat += 5;
} }
if (strncmp (oldlistformat, "2 ", 2) == 0){ if (strncmp (oldlistformat, "2 ", 2) == 0) {
format_columns = 1; format_columns = 1;
oldlistformat += 2; oldlistformat += 2;
} }
if (strncmp (oldlistformat, "1 ", 2) == 0){ if (strncmp (oldlistformat, "1 ", 2) == 0) {
oldlistformat += 2; oldlistformat += 2;
} }
s = strtok (oldlistformat, ","); s = strtok (oldlistformat, ",");
while (s){ while (s) {
listbox_add_item (l_listmode, 0, 0, s, NULL); listbox_add_item (l_listmode, 0, 0, s, NULL);
s = strtok (NULL, ","); s = strtok (NULL, ",");
} }
@ -211,43 +222,50 @@ static void init_listmode (char *oldlistformat)
/* add listbox to the dialogs */ /* add listbox to the dialogs */
add_widget (listmode_dlg, l_listmode); add_widget (listmode_dlg, l_listmode);
radio_columns = radio_new (UY+1, UX+32, 2, s_columns, 1, NULL); radio_columns = radio_new (UY + 1, UX + 32, 2, s_columns, 1, NULL);
add_widget (listmode_dlg, radio_columns); add_widget (listmode_dlg, radio_columns);
radio_columns->sel = format_columns; radio_columns->sel = format_columns;
radio_genwidth = radio_new (UY+1, UX+2, 2, s_genwidth, 1, NULL); radio_genwidth = radio_new (UY + 1, UX + 2, 2, s_genwidth, 1, NULL);
add_widget (listmode_dlg, radio_genwidth); add_widget (listmode_dlg, radio_genwidth);
radio_genwidth->sel = format_width; radio_genwidth->sel = format_width;
return listmode_dlg;
} }
static void listmode_done (void) static void
listmode_done (Dlg_head * h)
{ {
destroy_dlg (listmode_dlg); destroy_dlg (h);
if (0) if (0)
update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen (); repaint_screen ();
} }
static char *select_new_item (void) static char *
select_new_item (void)
{ {
/* NOTE: The following array of possible items must match the /* NOTE: The following array of possible items must match the
formats array in screen.c. Better approach might be to make the formats array in screen.c. Better approach might be to make the
formats array global */ formats array global */
char *possible_items [] = char *possible_items[] =
{ "name", "size", "type", "mtime", "perm", "mode", "|", "nlink", { "name", "size", "type", "mtime", "perm", "mode", "|", "nlink",
"owner", "group", "atime", "ctime", "space", "mark", "owner", "group", "atime", "ctime", "space", "mark",
"inode", NULL }; "inode", NULL
};
int i; int i;
Listbox *mylistbox; Listbox *mylistbox;
mylistbox = create_listbox_window (12, 20, " Add listing format item ", listmode_section); mylistbox =
for (i = 0; possible_items [i]; i++){ create_listbox_window (12, 20, " Add listing format item ",
listbox_add_item (mylistbox->list, 0, 0, possible_items [i], NULL); listmode_section);
for (i = 0; possible_items[i]; i++) {
listbox_add_item (mylistbox->list, 0, 0, possible_items[i], NULL);
} }
i = run_listbox (mylistbox); i = run_listbox (mylistbox);
if (i >= 0) if (i >= 0)
return possible_items [i]; return possible_items[i];
else else
return NULL; return NULL;
} }
@ -268,7 +286,7 @@ collect_new_format (void)
if (radio_columns->sel) if (radio_columns->sel)
strcat (newformat, "2 "); strcat (newformat, "2 ");
last = NULL; last = NULL;
for (i = 0;;i++){ for (i = 0;; i++) {
listbox_select_by_number (l_listmode, i); listbox_select_by_number (l_listmode, i);
listbox_get_current (l_listmode, &text, &extra); listbox_get_current (l_listmode, &text, &extra);
if (text == last) if (text == last)
@ -281,17 +299,18 @@ collect_new_format (void)
return newformat; return newformat;
} }
char *listmode_edit (char *oldlistformat) char *
listmode_edit (char *oldlistformat)
{ {
char *newformat = NULL; char *newformat = NULL;
char *s; char *s;
Dlg_head *listmode_dlg;
s = g_strdup (oldlistformat); s = g_strdup (oldlistformat);
init_listmode (s); listmode_dlg = init_listmode (s);
g_free (s); g_free (s);
while (newformat == NULL) while (newformat == NULL) {
{
/* display file info */ /* display file info */
attrset (SELECTED_COLOR); attrset (SELECTED_COLOR);
@ -318,8 +337,8 @@ char *listmode_edit (char *oldlistformat)
} }
} }
listmode_done (); listmode_done (listmode_dlg);
return newformat; return newformat;
} }
#endif /* LISTMODE_EDITOR */ #endif /* LISTMODE_EDITOR */