23
23
24
24
#include "dialog.h"
25
25
26
- static int list_width , check_x , item_x , checkflag ;
26
+ static int list_width , check_x , item_x ;
27
27
28
28
/*
29
29
* Print list item
@@ -41,10 +41,7 @@ static void print_item(WINDOW * win, const char *item, int status, int choice,
41
41
42
42
wmove (win , choice , check_x );
43
43
wattrset (win , selected ? check_selected_attr : check_attr );
44
- if (checkflag == FLAG_CHECK )
45
- wprintw (win , "[%c]" , status ? 'X' : ' ' );
46
- else
47
- wprintw (win , "(%c)" , status ? 'X' : ' ' );
44
+ wprintw (win , "(%c)" , status ? 'X' : ' ' );
48
45
49
46
wattrset (win , selected ? tag_selected_attr : tag_attr );
50
47
mvwaddch (win , choice , item_x , item [0 ]);
@@ -109,18 +106,16 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected)
109
106
110
107
/*
111
108
* Display a dialog box with a list of options that can be turned on or off
112
- * The `flag' parameter is used to select between radiolist and checklist .
109
+ * in the style of radiolist (only one option turned on at a time) .
113
110
*/
114
111
int dialog_checklist (const char * title , const char * prompt , int height ,
115
112
int width , int list_height , int item_no ,
116
- const char * const * items , int flag )
113
+ const char * const * items )
117
114
{
118
115
int i , x , y , box_x , box_y ;
119
116
int key = 0 , button = 0 , choice = 0 , scroll = 0 , max_choice , * status ;
120
117
WINDOW * dialog , * list ;
121
118
122
- checkflag = flag ;
123
-
124
119
/* Allocate space for storing item on/off status */
125
120
if ((status = malloc (sizeof (int ) * item_no )) == NULL ) {
126
121
endwin ();
@@ -303,34 +298,20 @@ int dialog_checklist(const char *title, const char *prompt, int height,
303
298
case ' ' :
304
299
case '\n' :
305
300
if (!button ) {
306
- if (flag == FLAG_CHECK ) {
307
- status [scroll + choice ] = !status [scroll + choice ];
308
- wmove (list , choice , check_x );
309
- wattrset (list , check_selected_attr );
310
- wprintw (list , "[%c]" , status [scroll + choice ] ? 'X' : ' ' );
311
- } else {
312
- if (!status [scroll + choice ]) {
313
- for (i = 0 ; i < item_no ; i ++ )
314
- status [i ] = 0 ;
315
- status [scroll + choice ] = 1 ;
316
- for (i = 0 ; i < max_choice ; i ++ )
317
- print_item (list , items [(scroll + i ) * 3 + 1 ],
318
- status [scroll + i ], i , i == choice );
319
- }
301
+ if (!status [scroll + choice ]) {
302
+ for (i = 0 ; i < item_no ; i ++ )
303
+ status [i ] = 0 ;
304
+ status [scroll + choice ] = 1 ;
305
+ for (i = 0 ; i < max_choice ; i ++ )
306
+ print_item (list , items [(scroll + i ) * 3 + 1 ],
307
+ status [scroll + i ], i , i == choice );
320
308
}
321
309
wnoutrefresh (list );
322
310
wrefresh (dialog );
323
311
324
- for (i = 0 ; i < item_no ; i ++ ) {
325
- if (status [i ]) {
326
- if (flag == FLAG_CHECK ) {
327
- fprintf (stderr , "\"%s\" " , items [i * 3 ]);
328
- } else {
329
- fprintf (stderr , "%s" , items [i * 3 ]);
330
- }
331
-
332
- }
333
- }
312
+ for (i = 0 ; i < item_no ; i ++ )
313
+ if (status [i ])
314
+ fprintf (stderr , "%s" , items [i * 3 ]);
334
315
} else
335
316
fprintf (stderr , "%s" , items [(scroll + choice ) * 3 ]);
336
317
delwin (dialog );
0 commit comments