static int
find_parameters (char **start_dir, char **pattern, char **content)
{
    int return_value;
    char *temp_dir;
    static char *in_contents = NULL;
    static char *in_start_dir = NULL;
    static char *in_start_name = NULL;

	static char* labs[] = {N_("Start at:"), N_("Filename:"), N_("Content: ")};
	static char* buts[] = {N_("&Ok"), N_("&Tree"), N_("&Cancel")};
	static int ilen = 30, istart = 14;
	static int b0 = 3, b1 = 16, b2 = 36;

#ifdef ENABLE_NLS
	static int i18n_flag = 0;
	
	if (!i18n_flag)
	{
		register int i = sizeof(labs)/sizeof(labs[0]);
		int l1, maxlen = 0;
		
		while (i--)
		{
			l1 = strlen (labs [i] = _(labs [i]));
			if (l1 > maxlen)
				maxlen = l1;
		}
		i = maxlen + ilen + 7;
		if (i > FIND_X)
			FIND_X = i;
		
		for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
		{
			l1 += strlen (buts [i] = _(buts [i]));
		}
		l1 += 21;
		if (l1 > FIND_X)
			FIND_X = l1;

		ilen = FIND_X - 7 - maxlen; /* for the case of very long buttons :) */
		istart = FIND_X - 3 - ilen;
		
		b1 = b0 + strlen(buts[0]) + 7;
		b2 = FIND_X - (strlen(buts[2]) + 6);
		
		i18n_flag = 1;
	}
	
#endif /* ENABLE_NLS */

find_par_start:
    if (!in_start_dir)
	in_start_dir = strdup (".");
    if (!in_start_name)
	in_start_name = strdup (easy_patterns ? "*" : ".");
    if (!in_contents)
	in_contents = strdup ("");
    
    find_dlg = create_dlg (0, 0, FIND_Y, FIND_X, dialog_colors,
			   common_dialog_callback, "[Find File]", "findfile",
			   DLG_CENTER | DLG_GRID);
    x_set_dialog_title (find_dlg, _("Find File"));

	add_widgetl (find_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
		buts[2], 0 ,0, "cancel"), XV_WLAY_RIGHTOF);
#ifndef HAVE_GNOME
	add_widgetl (find_dlg, button_new (9, b1, B_TREE, NORMAL_BUTTON,
		buts[1], 0, 0, "tree"), XV_WLAY_RIGHTOF);
#endif
	add_widgetl (find_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
		buts[0], 0, 0, "ok"), XV_WLAY_CENTERROW);

	in_with  = input_new (7, istart, INPUT_COLOR, ilen,	in_contents, "content");
    add_widgetl (find_dlg, in_with, XV_WLAY_BELOWOF);

	in_name  = input_new (5, istart, INPUT_COLOR, ilen, in_start_name, "name");
    add_widgetl (find_dlg, in_name, XV_WLAY_BELOWOF);

	in_start = input_new (3, istart, INPUT_COLOR, ilen,	in_start_dir, "start");
    add_widgetl (find_dlg, in_start, XV_WLAY_NEXTCOLUMN);

	add_widgetl (find_dlg, label_new (7, 3, labs[2], "label-cont"), XV_WLAY_BELOWOF);
	add_widgetl (find_dlg, label_new (5, 3, labs[1], "label-file"), XV_WLAY_BELOWOF);
	add_widgetl (find_dlg, label_new (3, 3, labs[0], "label-start"), XV_WLAY_NEXTCOLUMN);

    run_dlg (find_dlg);

    switch (find_dlg->ret_value){
    case B_CANCEL:
	return_value = 0;
	break;

#ifndef HAVE_GNOME
    case B_TREE:
	temp_dir = strdup (in_start->buffer);
	destroy_dlg (find_dlg);
	free (in_start_dir);
	if (strcmp (temp_dir, ".") == 0){
	    free (temp_dir);
	    temp_dir = strdup (cpanel->cwd);
	}
	in_start_dir = tree (temp_dir);
	if (in_start_dir)
	    free (temp_dir);
	else
	    in_start_dir = temp_dir;
	/* Warning: Dreadful goto */
	goto find_par_start;
	break;
#endif
	
    default:
	return_value = 1;
	*start_dir = strdup (in_start->buffer);
	*pattern   = strdup (in_name->buffer);

	free (in_contents);
	if (in_with->buffer [0]){
	    *content    = strdup (in_with->buffer);
	    in_contents = strdup (*content);
	} else 
	    *content = in_contents = NULL;

	free (in_start_dir);
	in_start_dir = strdup (*start_dir);
	free (in_start_name);
	in_start_name = strdup (*pattern);
    }

    destroy_dlg (find_dlg);
			 
    return return_value;
}
Beispiel #2
0
static void init_layout (void)
{
    static int i18n_layt_flag = 0;
	static int b1, b2, b3;
    int i = sizeof (s_split_direction) / sizeof(char*) ;
	char* ok_button = _("&Ok");
	char* cancel_button = _("&Cancel");
	char* save_button = _("&Save");
    
    if (!i18n_layt_flag)
    {
		register int l1;
		
		first_width = 19; /* length of line with '<' '>' buttons */
		
		layout_title = _(" Layout ");
		title1 = _(" Panel split ");
		title2 = _(" Highlight... ");
		title3 = _(" Other options ");
		output_lines_label = _("output lines");
		
		while (i--)
		{
		    s_split_direction [i] = _(s_split_direction [i]);
			l1 = strlen (s_split_direction [i]) + 7;
			if (l1 > first_width)
				first_width = l1;
		}

		for (i = 0; i <= 8; i++)
		{
			check_options[i].text = _(check_options[i].text);
			l1 = strlen (check_options[i].text) + 7;
			if (l1 > first_width)
				first_width = l1;
		}

		l1 = strlen (title1) + 1;
		if (l1 > first_width)
			first_width = l1;
		
		l1 = strlen (title2) + 1;
		if (l1 > first_width)
			first_width = l1;
		

		second_width = strlen (title3) + 1;
		for (i = 0; i < 6; i++)
		{
			check_options[i].text = _(check_options[i].text);
			l1 = strlen (check_options[i].text) + 7;
			if (l1 > second_width)
				second_width = l1;
		}
		if (console_flag)
		{
			l1 = strlen (output_lines_label) + 13;
			if (l1 > second_width)
				second_width = l1;
		}

		/* 
		 * [email protected]:
		 * To be completely correct, one need to check if layout_title
		 * does not exceed dialog length and total length of 3 buttons
		 * allows their placement in one row. But assuming this dialog
		 * is wide enough, I don't include such a tests.
		 *
		 * Now the last thing to do - properly space buttons...
		 */
		l1 = 11 + strlen (ok_button)   /* 14 - all brackets and inner space */
		 	+ strlen (save_button)     /* notice: it is 3 char less because */
			+ strlen (cancel_button);  /* of '&' char in button text */
		
		i = (first_width + second_width - l1) / 4;
		b1 = 5 + i;
		b2 = b1 + strlen(ok_button) + i + 6;
		b3 = b2 + strlen(save_button) + i + 4;

		i18n_layt_flag = 1;
    }

    layout_dlg = create_dlg (0, 0, 15, first_width + second_width + 9, 
		dialog_colors, layout_callback,
		"[Layout]", "layout", DLG_CENTER | DLG_GRID);
			     
    x_set_dialog_title (layout_dlg, _("Layout"));

    add_widgetl (layout_dlg,
		button_new (BY, b3, B_CANCEL, NORMAL_BUTTON, cancel_button, 0, 0, "c"), 
		XV_WLAY_RIGHTOF);
    add_widgetl (layout_dlg,
		button_new (BY, b2, B_EXIT, NORMAL_BUTTON, save_button, 0, 0, "s"),
		XV_WLAY_RIGHTOF);
    add_widgetl (layout_dlg,
		button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON, ok_button, 0, 0, "o"),
		XV_WLAY_CENTERROW);
#ifndef HAVE_X
    if (console_flag){
	add_widget (layout_dlg,
		    button_new (9, 12 + first_width, B_MINUS, NARROW_BUTTON, "&-",
			bminus_cback, 0, NULL));
	add_widget (layout_dlg,
		    button_new (9, 7 + first_width, B_PLUS, NARROW_BUTTON, "&+", 
			bplus_cback, 0, NULL));
    }
#endif    

#define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options[i].tkname

    for (i = 0; i < 6; i++){
	check_options [i].widget = check_new (8 - i, 7 + first_width, XTRACT(i));
	add_widgetl (layout_dlg, check_options [i].widget, XV_WLAY_BELOWCLOSE);
    }
#ifdef HAVE_XVIEW
    add_widgetl (layout_dlg, label_new (2, 7 + first_width, _("Other options"), "oo"),
        XV_WLAY_NEXTCOLUMN);
    add_widgetl (layout_dlg, label_new (8, 5, _("Highlight..."), "hl"),
        XV_WLAY_NEXTCOLUMN);
    add_widgetl (layout_dlg, label_new (2, 5, _("Panel split"), "ps"),
        XV_WLAY_NEXTCOLUMN);
#endif        
    check_options [8].widget = check_new (10, 6, XTRACT(8));
    add_widgetl (layout_dlg, check_options [8].widget, XV_WLAY_BELOWCLOSE);
    check_options [7].widget = check_new (9, 6, XTRACT(7));
    add_widgetl (layout_dlg, check_options [7].widget, XV_WLAY_BELOWCLOSE);

    _filetype_mode = filetype_mode;
    _permission_mode = permission_mode;
    _equal_split = equal_split;
    _menubar_visible = menubar_visible;
    _command_prompt = command_prompt;
    _keybar_visible = keybar_visible;
    _message_visible = message_visible;
    _xterm_hintbar = xterm_hintbar;
#ifndef HAVE_X
    bright_widget = button_new(6, 15, B_2RIGHT, NARROW_BUTTON, "&>", b2right_cback, 0, ">");
    add_widgetl (layout_dlg, bright_widget, XV_WLAY_RIGHTOF);
    bleft_widget = button_new (6, 9, B_2LEFT, NARROW_BUTTON, "&<", b2left_cback, 0, "<");
    add_widgetl (layout_dlg, bleft_widget, XV_WLAY_RIGHTOF);
    check_options [6].widget = check_new (5, 6, XTRACT(6));
#endif
    old_first_panel_size = -1;
    old_horizontal_split = -1;
    old_output_lines     = -1;
    
    _first_panel_size = first_panel_size;
    _output_lines = output_lines;
#ifndef HAVE_X
    add_widget (layout_dlg, check_options [6].widget);
    radio_widget = radio_new (3, 6, 2, s_split_direction, 1, "r");
    add_widget (layout_dlg, radio_widget);
    radio_widget->sel = horizontal_split;
#endif
}
void
create_op_win (FileOperation op, int with_eta)
{
    int i, x_size;
    int minus = verbose ? 0 : 3;
    int eta_offset = with_eta ? (WX_ETA_EXTRA) / 2 : 0;

    char *sixty = "";
    char *fifteen = "";
    
    file_progress_replace_result = 0;
    file_progress_recursive_result = 0;
    showing_eta = with_eta;
    showing_bps = with_eta;
    eta_extra = with_eta ? WX_ETA_EXTRA : 0;
    x_size = (WX + 4) + eta_extra;

    op_dlg = create_dlg (0, 0, WY-minus+4, x_size, dialog_colors,
			 op_win_callback, "", "opwin", DLG_CENTER);

#ifndef HAVE_X
    last_hint_line = the_hint->widget.y;
    if ((op_dlg->y + op_dlg->lines) > last_hint_line)
	the_hint->widget.y = op_dlg->y + op_dlg->lines+1;
#endif
    
    x_set_dialog_title (op_dlg, "");

    add_widgetl (op_dlg, button_new (BY-minus, WX - 19 + eta_offset, FILE_ABORT,
				     NORMAL_BUTTON, _("&Abort"), 0, 0, "abort"),
        XV_WLAY_RIGHTOF);
    add_widgetl (op_dlg, button_new (BY-minus, 14 + eta_offset, FILE_SKIP,
				     NORMAL_BUTTON, _("&Skip"), 0, 0, "skip"),
        XV_WLAY_CENTERROW);

    add_widgetl (op_dlg, ProgressGauge [2] = gauge_new (7, FCOPY_GAUGE_X, 0, 100, 0, "g-1"), 
        XV_WLAY_RIGHTOF);
    add_widgetl (op_dlg, ProgressLabel [2] = label_new (7, FCOPY_LABEL_X, fifteen, "l-1"), 
        XV_WLAY_NEXTROW);
    add_widgetl (op_dlg, bps_label = label_new (7, WX, "", "bps-label"), XV_WLAY_NEXTROW);

    add_widgetl (op_dlg, ProgressGauge [1] = gauge_new (8, FCOPY_GAUGE_X, 0, 100, 0, "g-2"), 
        XV_WLAY_RIGHTOF);
    add_widgetl (op_dlg, ProgressLabel [1] = label_new (8, FCOPY_LABEL_X, fifteen, "l-2"), 
        XV_WLAY_RIGHTOF);
    add_widgetl (op_dlg, stalled_label = label_new (8, WX, "", "stalled"), XV_WLAY_NEXTROW);
	
    add_widgetl (op_dlg, ProgressGauge [0] = gauge_new (6, FCOPY_GAUGE_X, 0, 100, 0, "g-3"), 
        XV_WLAY_RIGHTOF);
    add_widgetl (op_dlg, ProgressLabel [0] = label_new (6, FCOPY_LABEL_X, fifteen, "l-3"), 
        XV_WLAY_RIGHTOF);
    add_widgetl (op_dlg, eta_label = label_new (6, WX, "", "eta_label"), XV_WLAY_NEXTROW);
    
    add_widgetl (op_dlg, FileString [1] = label_new (4, FCOPY_GAUGE_X, sixty, "fs-l-1"),
        XV_WLAY_RIGHTOF);
    add_widgetl (op_dlg, FileLabel [1] = label_new (4, FCOPY_LABEL_X, fifteen, "fs-l-2"), 
        XV_WLAY_NEXTROW);
    add_widgetl (op_dlg, FileString [0] = label_new (3, FCOPY_GAUGE_X, sixty, "fs-x-1"),
        XV_WLAY_RIGHTOF);
    add_widgetl (op_dlg, FileLabel [0] = label_new (3, FCOPY_LABEL_X, fifteen, "fs-x-2"), 
        XV_WLAY_NEXTROW);
	
    /* We will manage the dialog without any help, that's why
       we have to call init_dlg */
    init_dlg (op_dlg);
    op_dlg->running = 1;
    selected_button = FILE_SKIP;
    for (i = 0; i < 3; i++)
	last_percentage [i] = -99;
}
static void
init_replace (enum OperationMode mode)
{
    char buffer [128];
	static int rd_xlen = 60, rd_trunc = X_TRUNC;

#ifdef ENABLE_NLS
	static int i18n_flag;
	if (!i18n_flag)
	{
		int l1, l2, l, row;
		register int i = sizeof (rd_widgets) / sizeof (rd_widgets [0]); 
		while (i--)
			rd_widgets [i].text = _(rd_widgets [i].text);

		/* 
		 *longest of "Overwrite..." labels 
		 * (assume "Target date..." are short enough)
		 */
		l1 = max (strlen (rd_widgets [6].text), strlen (rd_widgets [11].text));

		/* longest of button rows */
		i = sizeof (rd_widgets) / sizeof (rd_widgets [0]);
		for (row = l = l2 = 0; i--;)
		{
			if (rd_widgets [i].value != 0)
			{
				if (row != rd_widgets [i].ypos)
				{
					row = rd_widgets [i].ypos;
					l2 = max (l2, l);
					l = 0;
				}
				l += strlen (rd_widgets [i].text) + 4;
			}
		}
		l2 = max (l2, l); /* last row */
		rd_xlen = max (rd_xlen, l1 + l2 + 8);
		rd_trunc = rd_xlen - 6;

		/* Now place buttons */
		l1 += 5; /* start of first button in the row */
		i = sizeof (rd_widgets) / sizeof (rd_widgets [0]);
		
		for (l = l1, row = 0; --i > 1;)
		{
			if (rd_widgets [i].value != 0)
			{
				if (row != rd_widgets [i].ypos)
				{
					row = rd_widgets [i].ypos;
					l = l1;
				}
				rd_widgets [i].xpos = l;
				l += strlen (rd_widgets [i].text) + 4;
			}
		}
		/* Abort button is centered */
		rd_widgets [1].xpos = (rd_xlen - strlen (rd_widgets [1].text) - 3) / 2;

	}
#endif /* ENABLE_NLS */

    replace_colors [0] = ERROR_COLOR;
    replace_colors [1] = COLOR_NORMAL;
    replace_colors [2] = ERROR_COLOR;
    replace_colors [3] = COLOR_NORMAL;
    
    replace_dlg = create_dlg (0, 0, 16, rd_xlen, replace_colors, replace_callback,
			      "[ Replace ]", "replace", DLG_CENTER);
    
    x_set_dialog_title (replace_dlg,
        mode == Foreground ? _(" File exists ") : _(" Background process: File exists "));


	ADD_RD_LABEL(0, name_trunc (file_progress_replace_filename, rd_trunc - strlen (rd_widgets [0].text)), 0 );
	ADD_RD_BUTTON(1);    
    
	ADD_RD_BUTTON(2);
	ADD_RD_BUTTON(3);
	ADD_RD_BUTTON(4);
	ADD_RD_BUTTON(5);
	ADD_RD_LABEL(6,0,0);

    /* "this target..." widgets */
	if (!S_ISDIR (d_stat->st_mode)){
		if ((d_stat->st_size && s_stat->st_size > d_stat->st_size))
			ADD_RD_BUTTON(7);

		ADD_RD_BUTTON(8);
    }
	ADD_RD_BUTTON(9);
	ADD_RD_BUTTON(10);
	ADD_RD_LABEL(11,0,0);
    
	ADD_RD_LABEL(12, file_date (d_stat->st_mtime), (int) d_stat->st_size);
	ADD_RD_LABEL(13, file_date (s_stat->st_mtime), (int) s_stat->st_size);
}
static void init_configure (void)
{
    int i;
	static int i18n_config_flag = 0;
	static int b1, b2, b3;
	char* ok_button = _("&Ok");
	char* cancel_button = _("&Cancel");
	char* save_button = _("&Save");

	if (!i18n_config_flag)
	{
		register int l1;

		/* Similar code is in layout.c (init_layout())  */

		configure_title = _(" Configure options ");
		title1 = _(" Panel options ");
		title2 = _(" Pause after run... ");
		title3 = _(" Other options ");

		first_width = strlen (title1) + 1;
		for (i = 13; i < 18; i++)
		{
			check_options[i].text = _(check_options[i].text);
			l1 = strlen (check_options[i].text) + 7;
			if (l1 > first_width)
				first_width = l1;
		}

		i = sizeof(pause_options)/sizeof(char*);
		while (i--)
		{
			pause_options [i] = _(pause_options [i]);
			l1 = strlen (pause_options [i]) + 7;
			if (l1 > first_width)
				first_width = l1;
		}

		l1 = strlen (title2) + 1;
		if (l1 > first_width)
			first_width = l1;

		OX = first_width + 5;

		second_width = strlen (title3) + 1;
		for (i = 0; i < 13; i++)
		{
			check_options[i].text = _(check_options[i].text);
			l1 = strlen (check_options[i].text) + 7;
			if (l1 > second_width)
				second_width = l1;
		}

		l1 = 11 + strlen (ok_button)
		 	+ strlen (save_button)
			+ strlen (cancel_button);
		
		i = (first_width + second_width - l1) / 4;
		b1 = 5 + i;
		b2 = b1 + strlen(ok_button) + i + 6;
		b3 = b2 + strlen(save_button) + i + 4;

		i18n_config_flag = 1;
	}

    conf_dlg = create_dlg (0, 0, 20, first_width + second_width + 9,
		dialog_colors, configure_callback, "[Options Menu]",
		"option", DLG_CENTER | DLG_GRID);

    x_set_dialog_title (conf_dlg, _("Configure options"));

    add_widgetl (conf_dlg,
	button_new (BY, b3, B_CANCEL, NORMAL_BUTTON, cancel_button, 0, 0, "button-cancel"),
	XV_WLAY_RIGHTOF);

    add_widgetl (conf_dlg,
	button_new (BY, b2, B_EXIT, NORMAL_BUTTON, save_button, 0, 0, "button-save"),
	XV_WLAY_RIGHTOF);
    
    add_widgetl (conf_dlg,
        button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON, ok_button, 0, 0, "button-ok"),
        XV_WLAY_CENTERROW);

#define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options [i].tk

    /* Add all the checkboxes */
    for (i = 0; i < 13; i++){
	check_options [i].widget = check_new (OY + (13-i), OX+2, XTRACT(i));
	add_widgetl (conf_dlg, check_options [i].widget,
	    XV_WLAY_BELOWCLOSE);
    }

    pause_radio = radio_new (RY+1, RX+2, 3, pause_options, 1, "pause-radio");
    pause_radio->sel = pause_after_run;
#ifndef HAVE_GNOME
    add_widgetl (conf_dlg, pause_radio, XV_WLAY_BELOWCLOSE);
#endif
    for (i = 0; i < 6; i++){
	check_options [i+13].widget = check_new (PY + (6-i), PX+2,
						  XTRACT(i+13));
	add_widgetl (conf_dlg, check_options [i+13].widget,
	    XV_WLAY_BELOWCLOSE);
    }
}
sortfn *
sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive)
{
    int i, r, l;
    sortfn *result;
    WCheck *c, *case_sense;

	char* ok_button = _("&Ok");
	char* cancel_button = _("&Cancel");
	char* reverse_label = _("&Reverse");
	char* case_label = _("case sensi&tive");
	char* sort_title = _("Sort order");

	static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0;

	if (!i18n_sort_flag)
	{
		int maxlen = 0;
		for (i = SORT_TYPES-1; i >= 0; i--)
		{
			sort_orders_names [i] = _(sort_orders [i].sort_name);
			r = strlen (sort_orders_names [i]);
			if (r > maxlen)
				maxlen = r;
		}

		check_pos = maxlen + 9;

		r = strlen (reverse_label) + 4;
		i = strlen (case_label) + 4;
		if (i > r)
			r = i;
		
		l = strlen (ok_button) + 6;
		i = strlen (cancel_button) + 4;
		if (i > l)
			l = i;
			
		i = check_pos + max(r,l) + 2;

		if (i > SORT_X)
			SORT_X = i;

		i = strlen (sort_title) + 6;
		if (i > SORT_X)
			SORT_X = i;

		button_pos = SORT_X - l - 2;

		i18n_sort_flag = 1;
	}

    result = 0;
    
    for (i = 0; i < SORT_TYPES; i++)
	if ((sortfn *) (sort_orders [i].sort_fn) == sort_fn){
	    current_mode = i;
	    break;
	}
    
    dd = create_dlg (0, 0, SORT_Y, SORT_X, dialog_colors, common_dialog_callback,
		     "[Left and Right Menus]", "sort", DLG_CENTER | DLG_GRID);
		     
    x_set_dialog_title (dd, sort_title);

    add_widgetl (dd, 
		button_new (10, button_pos, B_CANCEL, NORMAL_BUTTON, cancel_button, 
		0, 0, "cancel-button"), XV_WLAY_CENTERROW);

    add_widgetl (dd, 
		button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON, ok_button,
		0, 0, "ok-button"),	XV_WLAY_RIGHTDOWN);

    case_sense = check_new (4, check_pos, *case_sensitive, case_label, "case-check");
    add_widgetl (dd, case_sense, XV_WLAY_RIGHTDOWN);
    c = check_new (3, check_pos, *reverse, reverse_label, "reverse-check");
    add_widgetl (dd, c, XV_WLAY_RIGHTDOWN);

    my_radio = radio_new (3, 3, SORT_TYPES, sort_orders_names, 1, "radio-1");
    my_radio->sel = my_radio->pos = current_mode;
    
    add_widget (dd, my_radio);
    run_dlg (dd);

    r = dd->ret_value;
    if (r != B_CANCEL){
	result = (sortfn *) sort_orders [my_radio->sel].sort_fn;
	*reverse = c->state & C_BOOL;
	*case_sensitive = case_sense->state & C_BOOL;
    } else
	result = sort_fn;
    destroy_dlg (dd);

    return result;
}
static void
display_init (int radio_sel, char *init_text,
	      int _check_status, char ** _status)
{
	char* user_mini_status = _("user &Mini status");
	char* ok_button = _("&Ok");
	char* cancel_button = _("&Cancel");
	
	static int button_start = 30;
	
    displays_status = _status;

    if (!i18n_displays_flag){
		int i, l, maxlen = 0;
		char* cp;

 		display_title = _(display_title);
		for (i = 0; i < LIST_TYPES; i++)
		{
		    displays [i] = _(displays [i]);
			if ((l = strlen(displays [i])) > maxlen)
				maxlen = l;
		}

		i = strlen (ok_button) + 5;
		l = strlen (cancel_button) + 3;
		l = max(i, l);

		i = maxlen + l + 16;
		if (i > DISPLAY_X)
			DISPLAY_X = i;

		i = strlen (user_mini_status) + 13;
		if (i > DISPLAY_X)
			DISPLAY_X = i;
			
		i = strlen (display_title) + 8;
		if (i > DISPLAY_X)
			DISPLAY_X = i;

		button_start = DISPLAY_X - l - 5;
		
		/* get hotkey of user-defined format string */
		cp = strchr(displays[LIST_TYPES-1],'&');
		if (cp != NULL && *++cp != '\0')
			user_hotkey = tolower(*cp);

        i18n_displays_flag = 1;
    }
    dd = create_dlg (0, 0, DISPLAY_Y, DISPLAY_X, dialog_colors,
		     display_callback, "[Left and Right Menus]", "display",
		     DLG_CENTER | DLG_GRID);

    x_set_dialog_title (dd, _("Listing mode"));
    add_widgetl (dd,
        button_new (4, button_start, B_CANCEL, 
			NORMAL_BUTTON, cancel_button, 0, 0, "cancel-button"),
	XV_WLAY_RIGHTOF);

    add_widgetl (dd,
		button_new (3, button_start, B_ENTER, 
			DEFPUSH_BUTTON, ok_button, 0, 0, "ok-button"),
	 XV_WLAY_CENTERROW);

    status = input_new (10, 9, INPUT_COLOR, DISPLAY_X-14, _status [radio_sel], "mini-input");
    add_widgetl (dd, status, XV_WLAY_RIGHTDOWN);
    input_set_point (status, 0);

    check_status = check_new (9, 5, _check_status, user_mini_status, "mini-status");
    add_widgetl (dd, check_status, XV_WLAY_NEXTROW);
    
    user = input_new  (7, 9, INPUT_COLOR, DISPLAY_X-14, init_text, "user-fmt-input");
    add_widgetl (dd, user, XV_WLAY_RIGHTDOWN);
    input_set_point (user, 0);

#ifdef PORT_HAS_ICON_VIEW
    my_radio = radio_new (3, 5, LIST_TYPES, displays, 1, "radio");
#else
    my_radio = radio_new (3, 5, LIST_TYPES-1, displays, 1, "radio");
#endif
    my_radio->sel = my_radio->pos = current_mode;
    add_widgetl (dd, my_radio, XV_WLAY_BELOWCLOSE);
}
static void init_learn (void)
{
    int x, y, i, j;
    key_code_name_t *key;
    char buffer [22];
	static int i18n_flag = 0;

    do_refresh ();

#ifdef ENABLE_NLS
	if (!i18n_flag)
	{
		char* cp;
		
		learn_but [0].text = _(learn_but [0].text);
		learn_but [0].x = 78 / 2 + 4;

		learn_but [1].text = _(learn_but [1].text);
		learn_but [1].x = 78 / 2 - (strlen (learn_but [1].text) + 9);

		for (i = 0; i < BUTTONS; i++)
		{
			cp = strchr(learn_but [i].text, '&');
			if (cp != NULL && *++cp != '\0')
				learn_but [i].hotkey = toupper(*cp);
		}

		learn_title = _(learn_title);
		i18n_flag = 1;
	}
#endif /* ENABLE_NLS */

    learn_dlg = create_dlg (0, 0, 23, 78, dialog_colors,
			      learn_callback, "[Learn keys]", "Learn keys",
			      DLG_CENTER);
    x_set_dialog_title (learn_dlg, _("Learn keys"));

#define XTRACT(i) BY+learn_but[i].y, learn_but[i].x, learn_but[i].ret_cmd, learn_but[i].flags, _(learn_but[i].text), 0, 0, NULL

    for (i = 0; i < BUTTONS; i++)
	add_widget (learn_dlg, button_new (XTRACT (i)));
    
    x = UX;
    y = UY;
    for (key = key_name_conv_tab, j = 0; key->name != NULL &&
        strcmp (key->name, "kpleft"); key++, j++);
    learnkeys = (learnkey *) xmalloc (sizeof (learnkey) * j, "Learn keys");
    x += ((j - 1) / ROWS) * COLSHIFT;
    y += (j - 1) % ROWS;
    learn_total = j;
    learnok = 0;
    learnchanged = 0;
    for (i = j - 1, key = key_name_conv_tab + j - 1; i >= 0; i--, key--) {
    	learnkeys [i].ok = 0;
    	learnkeys [i].sequence = NULL;
        sprintf (buffer, "%-16s", _(key->longname));
	add_widget (learn_dlg, learnkeys [i].button = (Widget *)
	    button_new (y, x, B_USER + i, NARROW_BUTTON, buffer, learn_button, 0, NULL));
	add_widget (learn_dlg, learnkeys [i].label = (Widget *)
	    label_new (y, x + 19, "", NULL));
	if (i % 13)
	    y--;
	else {
	    x -= COLSHIFT;
	    y = UY + ROWS - 1;
	}
    }
    add_widget (learn_dlg,
		label_new (UY+14, 5, _("Press all the keys mentioned here. After you have done it, check"), NULL));
    add_widget (learn_dlg,
		label_new (UY+15, 5, _("which keys are not marked with OK.  Press space on the missing"), NULL));
    add_widget (learn_dlg,
		label_new (UY+16, 5, _("key, or click with the mouse to define it. Move around with Tab."), NULL));
}
static void init_listmode (char *oldlistformat)
{
    int i;
    char *s;
    int format_width = 0;
    int format_columns = 0;

    do_refresh ();

    listmode_dlg = create_dlg (0, 0, 22, 74, dialog_colors,
			      listmode_callback, listmode_section, "listmode",
			      DLG_CENTER);
    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

    for (i = 0; i < BUTTONS; i++)
	add_widgetl (listmode_dlg, button_new (XTRACT (i)), (i == BUTTONS - 1) ?
	    XV_WLAY_CENTERROW : XV_WLAY_RIGHTOF);

    /* We add the labels. */
    for (i = 0; i < LABELS; i++){
	pname = label_new (listmode_text [i].y,
			   listmode_text [i].x, listmode_text [i].text, NULL);
	add_widget (listmode_dlg, pname);
    }

    add_widget (listmode_dlg, button_new (UY+13, UX+37, B_MINUS, NORMAL_BUTTON,
					  "&-", bminus_cback, 0, NULL));
    add_widget (listmode_dlg, 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);
    radio_itemwidth = 0;
    radio_justify = radio_new (UY+5, UX+22, 3, s_justify, 1, NULL);
    add_widget (listmode_dlg, radio_justify);
    radio_justify->sel = 1;

    /* get new listbox */
    l_listmode = listbox_new (UY + 5, UX + 1, 16, 9, 0, l_call, NULL);

    if (strncmp (oldlistformat, "full ", 5) == 0){
	format_width = 1;
	oldlistformat += 5;
    }
    if (strncmp (oldlistformat, "half ", 5) == 0){
	oldlistformat += 5;
    }
    if (strncmp (oldlistformat, "2 ", 2) == 0){
	format_columns = 1;
	oldlistformat += 2;
    }
    if (strncmp (oldlistformat, "1 ", 2) == 0){
	oldlistformat += 2;
    }
    s = strtok (oldlistformat, ",");

    while (s){
	listbox_add_item (l_listmode, 0, 0, s, NULL);
	s = strtok (NULL, ",");
    }

    /* add listbox to the dialogs */
    add_widgetl (listmode_dlg, l_listmode, XV_WLAY_EXTENDWIDTH);

    radio_columns = radio_new (UY+1, UX+32, 2, s_columns, 1, NULL);
    add_widget (listmode_dlg, radio_columns);
    radio_columns->sel = format_columns;
    radio_genwidth = radio_new (UY+1, UX+2, 2, s_genwidth, 1, NULL);
    add_widget (listmode_dlg, radio_genwidth);
    radio_genwidth->sel = format_width;
}