예제 #1
0
static Dlg_head *
init_chmod (void)
{
    int i;
    Dlg_head *ch_dlg;

    do_refresh ();
    end_chmod = c_file = need_update = 0;
    single_set = (current_panel->marked < 2) ? 2 : 0;

    ch_dlg =
        create_dlg (TRUE, 0, 0, 22 - single_set, 70, dialog_colors,
                    chmod_callback, "[Chmod]", _("Chmod command"), DLG_CENTER | DLG_REVERSE);

    for (i = 0; i < BUTTONS; i++)
    {
        if (i == 2 && single_set)
            break;
        else
            add_widget (ch_dlg,
                        button_new (BY + chmod_but[i].y - single_set,
                                    BX + chmod_but[i].x,
                                    chmod_but[i].ret_cmd,
                                    chmod_but[i].flags, _(chmod_but[i].text), 0));
    }

    add_widget (ch_dlg, groupbox_new (FY, FX, 10, 25, _("File")));

    for (i = 0; i < PERMISSIONS; i++)
    {
        check_perm[i].check = check_new (PY + (PERMISSIONS - i), PX + 2, 0, _(check_perm[i].text));
        add_widget (ch_dlg, check_perm[i].check);
    }

    add_widget (ch_dlg, groupbox_new (PY, PX, PERMISSIONS + 2, 33, _("Permission")));

    return ch_dlg;
}
예제 #2
0
파일: chown.c 프로젝트: LubkaB/mc
static WDialog *
init_chown (void)
{
    int lines, cols;
    int i;
    int y;
    struct passwd *l_pass;
    struct group *l_grp;
    WDialog *ch_dlg;

    do_refresh ();

    end_chown = need_update = current_file = 0;
    single_set = (current_panel->marked < 2) ? 3 : 0;

    cols = GW * 3 + 2 + 6;
    lines = GH + 4 + (single_set ? 2 : 4);

    ch_dlg =
        dlg_create (TRUE, 0, 0, lines, cols, dialog_colors, chown_callback, NULL, "[Chown]",
                    _("Chown command"), DLG_CENTER);

    add_widget (ch_dlg, groupbox_new (2, 3, GH, GW, _("User name")));
    l_user = listbox_new (3, 4, GH - 2, GW - 2, FALSE, NULL);
    add_widget (ch_dlg, l_user);
    /* add field for unknown names (numbers) */
    listbox_add_item (l_user, LISTBOX_APPEND_AT_END, 0, _("<Unknown user>"), NULL);
    /* get and put user names in the listbox */
    setpwent ();
    while ((l_pass = getpwent ()) != NULL)
        listbox_add_item (l_user, LISTBOX_APPEND_SORTED, 0, l_pass->pw_name, NULL);
    endpwent ();

    add_widget (ch_dlg, groupbox_new (2, 4 + GW, GH, GW, _("Group name")));
    l_group = listbox_new (3, 5 + GW, GH - 2, GW - 2, FALSE, NULL);
    add_widget (ch_dlg, l_group);
    /* add field for unknown names (numbers) */
    listbox_add_item (l_group, LISTBOX_APPEND_AT_END, 0, _("<Unknown group>"), NULL);
    /* get and put group names in the listbox */
    setgrent ();
    while ((l_grp = getgrent ()) != NULL)
        listbox_add_item (l_group, LISTBOX_APPEND_SORTED, 0, l_grp->gr_name, NULL);
    endgrent ();

    add_widget (ch_dlg, groupbox_new (2, 5 + GW * 2, GH, GW, _("File")));
    /* add widgets for the file information */
    for (i = 0; i < LABELS; i++)
    {
        chown_label[i].l = label_new (chown_label[i].y, 7 + GW * 2, "");
        add_widget (ch_dlg, chown_label[i].l);
    }

    if (!single_set)
    {
        int x;

        add_widget (ch_dlg, hline_new (lines - chown_but[0].y - 1, -1, -1));

        y = lines - chown_but[0].y;
        x = (cols - blen) / 2;

        for (i = 0; i < BUTTONS - 2; i++)
        {
            add_widget (ch_dlg,
                        button_new (y, x, chown_but[i].ret_cmd, chown_but[i].flags,
                                    chown_but[i].text, NULL));
            x += chown_but[i].len + 1;
        }
    }

    i = BUTTONS - 2;
    y = lines - chown_but[i].y;
    add_widget (ch_dlg, hline_new (y - 1, -1, -1));
    add_widget (ch_dlg,
                button_new (y, WIDGET (ch_dlg)->cols / 2 - chown_but[i].len, chown_but[i].ret_cmd,
                            chown_but[i].flags, chown_but[i].text, NULL));
    i++;
    add_widget (ch_dlg,
                button_new (y, WIDGET (ch_dlg)->cols / 2 + 1, chown_but[i].ret_cmd,
                            chown_but[i].flags, chown_but[i].text, NULL));

    /* select first listbox */
    dlg_select_widget (l_user);

    return ch_dlg;
}
예제 #3
0
파일: listmode.c 프로젝트: Distrotech/mc
static WDialog *
init_listmode (char *oldlistformat)
{
    int i;
    char *s;
    int format_width = 0;
    int format_columns = 0;
    WDialog *listmode_dlg;

    static struct listmode_label listmode_labels[] = {
        {UY + 13, UX + 22, "Item width:"}
    };

    static struct listmode_button listmode_but[] = {
        {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 =
        dlg_create (TRUE, 0, 0, 22, 74, dialog_colors, NULL, NULL, listmode_section,
                    "Listing format edit", DLG_CENTER | DLG_REVERSE);

    add_widget (listmode_dlg, groupbox_new (UY, UX, 4, 63, "General options"));
    add_widget (listmode_dlg, groupbox_new (UY + 4, UX, 11, 18, "Items"));
    add_widget (listmode_dlg, groupbox_new (UY + 4, UX + 20, 11, 43, "Item options"));

    for (i = 0; i < sizeof (listmode_but) / sizeof (struct listmode_button); i++)
        add_widget (listmode_dlg,
                    button_new (listmode_but[i].y, listmode_but[i].x,
                                listmode_but[i].ret_cmd,
                                listmode_but[i].flags,
                                listmode_but[i].text, listmode_but[i].callback));

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

    radio_itemwidth = radio_new (UY + 9, UX + 22, 3, s_itemwidth);
    add_widget (listmode_dlg, radio_itemwidth);
    radio_itemwidth = 0;
    radio_justify = radio_new (UY + 5, UX + 22, 3, s_justify);
    add_widget (listmode_dlg, radio_justify);
    radio_justify->sel = 1;

    /* get new listbox */
    l_listmode = listbox_new (UY + 5, UX + 1, 9, 16, FALSE, 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, LISTBOX_APPEND_AT_END, 0, s, NULL, FALSE);
        s = strtok (NULL, ",");
    }

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

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

    return listmode_dlg;
}
예제 #4
0
파일: quick.c 프로젝트: BrEacK/mc
int
quick_dialog_skip (QuickDialog * qd, int nskip)
{
#ifdef ENABLE_NLS
#define I18N(x) (x = !qd->i18n && x != NULL && *x != '\0' ? _(x): x)
#else
#define I18N(x) (x = x)
#endif
    Dlg_head *dd;
    QuickWidget *qw;
    WInput *in;
    WRadio *r;
    int return_val;

    I18N (qd->title);

    if ((qd->xpos == -1) || (qd->ypos == -1))
        dd = create_dlg (TRUE, 0, 0, qd->ylen, qd->xlen,
                         dialog_colors, qd->callback, qd->mouse, qd->help, qd->title,
                         DLG_CENTER | DLG_TRYUP | DLG_REVERSE);
    else
        dd = create_dlg (TRUE, qd->ypos, qd->xpos, qd->ylen, qd->xlen,
                         dialog_colors, qd->callback, qd->mouse, qd->help, qd->title, DLG_REVERSE);

    for (qw = qd->widgets; qw->widget_type != quick_end; qw++)
    {
        int xpos;
        int ypos;

        xpos = (qd->xlen * qw->relative_x) / qw->x_divisions;
        ypos = (qd->ylen * qw->relative_y) / qw->y_divisions;

        switch (qw->widget_type)
        {
        case quick_checkbox:
            qw->widget =
                (Widget *) check_new (ypos, xpos, *qw->u.checkbox.state,
                                      I18N (qw->u.checkbox.text));
            break;

        case quick_button:
            qw->widget = (Widget *) button_new (ypos, xpos, qw->u.button.action,
                                                (qw->u.button.action ==
                                                 B_ENTER) ? DEFPUSH_BUTTON : NORMAL_BUTTON,
                                                I18N (qw->u.button.text), qw->u.button.callback);
            break;

        case quick_input:
            in = input_new (ypos, xpos, input_get_default_colors (),
                            qw->u.input.len, qw->u.input.text, qw->u.input.histname,
                            INPUT_COMPLETE_DEFAULT);
            in->is_password = (qw->u.input.flags == 1);
            if ((qw->u.input.flags & 2) != 0)
                in->completion_flags |= INPUT_COMPLETE_CD;
            if ((qw->u.input.flags & 4) != 0)
                in->strip_password = TRUE;
            qw->widget = (Widget *) in;
            *qw->u.input.result = NULL;
            break;

        case quick_label:
            qw->widget = (Widget *) label_new (ypos, xpos, I18N (qw->u.label.text));
            break;

        case quick_groupbox:
            qw->widget = (Widget *) groupbox_new (ypos, xpos,
                                                  qw->u.groupbox.height,
                                                  qw->u.groupbox.width,
                                                  I18N (qw->u.groupbox.title));
            break;

        case quick_radio:
            {
                int i;
                char **items = NULL;

                /* create the copy of radio_items to avoid mwmory leak */
                items = g_new0 (char *, qw->u.radio.count + 1);

                if (!qd->i18n)
                    for (i = 0; i < qw->u.radio.count; i++)
                        items[i] = g_strdup (_(qw->u.radio.items[i]));
                else
                    for (i = 0; i < qw->u.radio.count; i++)
                        items[i] = g_strdup (qw->u.radio.items[i]);

                r = radio_new (ypos, xpos, qw->u.radio.count, (const char **) items);
                r->pos = r->sel = *qw->u.radio.value;
                qw->widget = (Widget *) r;
                g_strfreev (items);
                break;
            }

        default:
            qw->widget = NULL;
            fprintf (stderr, "QuickWidget: unknown widget type\n");
            break;
        }

        if (qw->widget != NULL)
        {
            qw->widget->options |= qw->options; /* FIXME: cannot reset flags, setup only */
            add_widget (dd, qw->widget);
        }
    }

    while (nskip-- != 0)
    {
        dd->current = g_list_next (dd->current);
        if (dd->current == NULL)
            dd->current = dd->widgets;
    }

    return_val = run_dlg (dd);

    /* Get the data if we found something interesting */
    if (return_val != B_CANCEL)
    {
        for (qw = qd->widgets; qw->widget_type != quick_end; qw++)
        {
            switch (qw->widget_type)
            {
            case quick_checkbox:
                *qw->u.checkbox.state = ((WCheck *) qw->widget)->state & C_BOOL;
                break;

            case quick_input:
                if ((qw->u.input.flags & 2) != 0)
                    *qw->u.input.result = tilde_expand (((WInput *) qw->widget)->buffer);
                else
                    *qw->u.input.result = g_strdup (((WInput *) qw->widget)->buffer);
                break;

            case quick_radio:
                *qw->u.radio.value = ((WRadio *) qw->widget)->sel;
                break;

            default:
                break;
            }
        }
    }

    destroy_dlg (dd);

    return return_val;
#undef I18N
}
예제 #5
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");
    static char *title1, *title2, *title3;

    if (!i18n_layt_flag) {
	register int l1;

	first_width = 19;	/* length of line with '<' '>' buttons */

	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 the 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_REVERSE);

    add_widget (layout_dlg, groupbox_new (4, 2, first_width, 6, title1));
    add_widget (layout_dlg, groupbox_new (4, 8, first_width, 4, title2));
    add_widget (layout_dlg,
		groupbox_new (5 + first_width, 2, second_width, 10,
			      title3));

    add_widget (layout_dlg,
		button_new (BY, b3, B_CANCEL, NORMAL_BUTTON, cancel_button,
			    0));
    add_widget (layout_dlg,
		button_new (BY, b2, B_EXIT, NORMAL_BUTTON, save_button,
			    0));
    add_widget (layout_dlg,
		button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON, ok_button,
			    0));
    if (console_flag) {
	add_widget (layout_dlg,
		    button_new (9, 12 + first_width, B_MINUS,
				NARROW_BUTTON, "&-", bminus_cback));
	add_widget (layout_dlg,
		    button_new (9, 7 + first_width, B_PLUS, NARROW_BUTTON,
				"&+", bplus_cback));
    }
#define XTRACT(i) *check_options[i].variable, check_options[i].text

    for (i = 0; i < 6; i++) {
	check_options[i].widget =
	    check_new (8 - i, 7 + first_width, XTRACT (i));
	add_widget (layout_dlg, check_options[i].widget);
    }
    check_options[8].widget = check_new (10, 6, XTRACT (8));
    add_widget (layout_dlg, check_options[8].widget);
    check_options[7].widget = check_new (9, 6, XTRACT (7));
    add_widget (layout_dlg, check_options[7].widget);

    _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_title = xterm_title; */
    bright_widget =
	button_new (6, 15, B_2RIGHT, NARROW_BUTTON, "&>", b2right_cback);
    add_widget (layout_dlg, bright_widget);
    bleft_widget =
	button_new (6, 9, B_2LEFT, NARROW_BUTTON, "&<", b2left_cback);
    add_widget (layout_dlg, bleft_widget);
    check_options[6].widget = check_new (5, 6, XTRACT (6));
    old_first_panel_size = -1;
    old_horizontal_split = -1;
    old_output_lines = -1;

    _first_panel_size = first_panel_size;
    _output_lines = output_lines;
    add_widget (layout_dlg, check_options[6].widget);
    radio_widget = radio_new (3, 6, 2, s_split_direction, 1);
    add_widget (layout_dlg, radio_widget);
    radio_widget->sel = horizontal_split;
}
예제 #6
0
파일: panelize.c 프로젝트: andi5/mc
static void
init_panelize (void)
{
    struct
    {
        int ret_cmd;
        button_flags_t flags;
        const char *text;
    } panelize_but[] =
    {
        /* *INDENT-OFF* */
        { B_ENTER, DEFPUSH_BUTTON, N_("Pane&lize") },
        { B_REMOVE, NORMAL_BUTTON, N_("&Remove") },
        { B_ADD, NORMAL_BUTTON, N_("&Add new") },
        { B_CANCEL, NORMAL_BUTTON, N_("&Cancel") }
        /* *INDENT-ON* */
    };

    size_t i;
    int blen;
    int panelize_cols;
    struct panelize *current;
    int x, y;

    last_listitem = 0;

    do_refresh ();

    i = G_N_ELEMENTS (panelize_but);
    blen = i - 1;               /* gaps between buttons */
    while (i-- != 0)
    {
#ifdef ENABLE_NLS
        panelize_but[i].text = _(panelize_but[i].text);
#endif
        blen += str_term_width1 (panelize_but[i].text) + 3 + 1;
        if (panelize_but[i].flags == DEFPUSH_BUTTON)
            blen += 2;
    }

    panelize_cols = COLS - 6;
    panelize_cols = max (panelize_cols, blen + 4);

    panelize_dlg =
        dlg_create (TRUE, 0, 0, 20, panelize_cols, dialog_colors, panelize_callback, NULL,
                    "[External panelize]", _("External panelize"), DLG_CENTER);

    /* add listbox to the dialogs */
    y = UY;
    add_widget (panelize_dlg, groupbox_new (y++, UX, 12, panelize_cols - UX * 2, ""));

    l_panelize = listbox_new (y, UX + 1, 10, panelize_cols - UX * 2 - 2, FALSE, NULL);
    for (current = panelize; current != NULL; current = current->next)
        listbox_add_item (l_panelize, LISTBOX_APPEND_AT_END, 0, current->label, current);
    listbox_select_entry (l_panelize, listbox_search_text (l_panelize, _("Other command")));
    add_widget (panelize_dlg, l_panelize);

    y += WIDGET (l_panelize)->lines + 1;
    add_widget (panelize_dlg, label_new (y++, UX, _("Command")));
    pname =
        input_new (y++, UX, input_colors, panelize_cols - UX * 2, "", "in",
                   INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_HOSTNAMES | INPUT_COMPLETE_COMMANDS |
                   INPUT_COMPLETE_VARIABLES | INPUT_COMPLETE_USERNAMES | INPUT_COMPLETE_CD |
                   INPUT_COMPLETE_SHELL_ESC);
    add_widget (panelize_dlg, pname);



    add_widget (panelize_dlg, hline_new (y++, -1, -1));

    x = (panelize_cols - blen) / 2;
    for (i = 0; i < G_N_ELEMENTS (panelize_but); i++)
    {
        WButton *b;

        b = button_new (y, x,
                        panelize_but[i].ret_cmd, panelize_but[i].flags, panelize_but[i].text, NULL);
        add_widget (panelize_dlg, b);

        x += button_get_len (b) + 1;
    }

    dlg_select_widget (l_panelize);
}
예제 #7
0
파일: quick.c 프로젝트: rutsky/mc
int
quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip)
{
    int len;
    int blen = 0;
    int x, y;                   /* current positions */
    int y1 = 0;                 /* bottom of 1st column in case of two columns */
    int y2 = -1;                /* start of two columns */
    int width1 = 0;             /* width of single column */
    int width2 = 0;             /* width of each of two columns */
    gboolean have_groupbox = FALSE;
    gboolean two_columns = FALSE;
    gboolean put_buttons = FALSE;

    /* x position of 1st column is 3 */
    const int x1 = 3;
    /* x position of 2nd column is 4 and it will be fixed later, after creation of all widgets */
    int x2 = 4;

    GArray *widgets;
    size_t i;
    quick_widget_t *quick_widget;
    WGroupbox *g = NULL;
    WDialog *dd;
    int return_val;

    len = str_term_width1 (I18N (quick_dlg->title)) + 6;
    quick_dlg->cols = max (quick_dlg->cols, len);

    y = 1;
    x = x1;

    /* create widgets */
    widgets = g_array_sized_new (FALSE, FALSE, sizeof (quick_widget_item_t), 8);

    for (quick_widget = quick_dlg->widgets; quick_widget->widget_type != quick_end; quick_widget++)
    {
        quick_widget_item_t item = { NULL, quick_widget };
        int width = 0;

        switch (quick_widget->widget_type)
        {
        case quick_checkbox:
            item.widget =
                WIDGET (check_new
                        (++y, x, *quick_widget->u.checkbox.state,
                         I18N (quick_widget->u.checkbox.text)));
            g_array_append_val (widgets, item);
            width = item.widget->cols;
            if (g != NULL)
                width += 2;
            if (two_columns)
                width2 = max (width2, width);
            else
                width1 = max (width1, width);
            break;

        case quick_button:
            /* single button */
            item.widget = WIDGET (button_new (++y, x, quick_widget->u.button.action,
                                              quick_widget->u.button.action == B_ENTER ?
                                              DEFPUSH_BUTTON : NORMAL_BUTTON,
                                              I18N (quick_widget->u.button.text),
                                              quick_widget->u.button.callback));
            g_array_append_val (widgets, item);
            width = item.widget->cols;
            if (g != NULL)
                width += 2;
            if (two_columns)
                width2 = max (width2, width);
            else
                width1 = max (width1, width);
            break;

        case quick_input:
            *quick_widget->u.input.result = NULL;
            y++;
            if (quick_widget->u.input.label_location != input_label_none)
                quick_create_labeled_input (widgets, &y, x, quick_widget, &width);
            else
            {
                item.widget = WIDGET (quick_create_input (y, x, quick_widget));
                g_array_append_val (widgets, item);
                width = item.widget->cols;
            }
            if (g != NULL)
                width += 2;
            if (two_columns)
                width2 = max (width2, width);
            else
                width1 = max (width1, width);
            break;

        case quick_label:
            item.widget = WIDGET (label_new (++y, x, I18N (quick_widget->u.label.text)));
            g_array_append_val (widgets, item);
            y += item.widget->lines - 1;
            width = item.widget->cols;
            if (g != NULL)
                width += 2;
            if (two_columns)
                width2 = max (width2, width);
            else
                width1 = max (width1, width);
            break;

        case quick_radio:
        {
            WRadio *r;
            char **items = NULL;

            /* create the copy of radio_items to avoid mwmory leak */
            items = g_new (char *, quick_widget->u.radio.count + 1);
            for (i = 0; i < (size_t) quick_widget->u.radio.count; i++)
                items[i] = g_strdup (_(quick_widget->u.radio.items[i]));
            items[i] = NULL;

            r = radio_new (++y, x, quick_widget->u.radio.count, (const char **) items);
            r->pos = r->sel = *quick_widget->u.radio.value;
            g_strfreev (items);
            item.widget = WIDGET (r);
            g_array_append_val (widgets, item);
            y += item.widget->lines - 1;
            width = item.widget->cols;
            if (g != NULL)
                width += 2;
            if (two_columns)
                width2 = max (width2, width);
            else
                width1 = max (width1, width);
        }
        break;

        case quick_start_groupbox:
            I18N (quick_widget->u.groupbox.title);
            len = str_term_width1 (quick_widget->u.groupbox.title);
            g = groupbox_new (++y, x, 1, len + 4, quick_widget->u.groupbox.title);
            item.widget = WIDGET (g);
            g_array_append_val (widgets, item);
            have_groupbox = TRUE;
            break;

        case quick_stop_groupbox:
            if (g != NULL)
            {
                Widget *w = WIDGET (g);

                y++;
                w->lines = y + 1 - w->y;
                g = NULL;

                g_array_append_val (widgets, item);
            }
            break;

        case quick_separator:
            y++;
            if (quick_widget->u.separator.line)
            {
                item.widget = WIDGET (hline_new (y, x, 1));
                g_array_append_val (widgets, item);
            }
            break;

        case quick_start_columns:
            y2 = y;
            g_array_append_val (widgets, item);
            two_columns = TRUE;
            break;

        case quick_next_column:
            x = x2;
            y1 = y;
            y = y2;
            break;

        case quick_stop_columns:
            x = x1;
            y = max (y1, y);
            g_array_append_val (widgets, item);
            two_columns = FALSE;
            break;

        case quick_buttons:
            /* start put several buttons in bottom line */
            if (quick_widget->u.separator.space)
            {
                y++;

                if (quick_widget->u.separator.line)
                    item.widget = WIDGET (hline_new (y, 1, -1));
            }

            g_array_append_val (widgets, item);

            /* several buttons in bottom line */
            y++;
            quick_widget++;
            for (; quick_widget->widget_type == quick_button; quick_widget++)
            {
                item.widget = WIDGET (button_new (y, x++, quick_widget->u.button.action,
                                                  quick_widget->u.button.action == B_ENTER ?
                                                  DEFPUSH_BUTTON : NORMAL_BUTTON,
                                                  I18N (quick_widget->u.button.text),
                                                  quick_widget->u.button.callback));
                item.quick_widget = quick_widget;
                g_array_append_val (widgets, item);
                blen += item.widget->cols + 1;
            }

            /* stop dialog build here */
            blen--;
            quick_widget->widget_type = quick_end;
            quick_widget--;
            break;

        default:
            break;
        }
    }

    /* adjust dialog width */
    quick_dlg->cols = max (quick_dlg->cols, blen + 6);
    if (have_groupbox)
    {
        if (width1 != 0)
            width1 += 2;
        if (width2 != 0)
            width2 += 2;
    }
    if (width2 == 0)
        len = width1 + 6;
    else
    {
        len = width2 * 2 + 7;
        if (width1 != 0)
            len = max (len, width1 + 6);
    }

    quick_dlg->cols = max (quick_dlg->cols, len);
    width1 = quick_dlg->cols - 6;
    width2 = (quick_dlg->cols - 7) / 2;

    if (quick_dlg->x == -1 || quick_dlg->y == -1)
        dd = create_dlg (TRUE, 0, 0, y + 3, quick_dlg->cols,
                         dialog_colors, quick_dlg->callback, quick_dlg->mouse, quick_dlg->help,
                         quick_dlg->title, DLG_CENTER | DLG_TRYUP);
    else
        dd = create_dlg (TRUE, quick_dlg->y, quick_dlg->x, y + 3, quick_dlg->cols,
                         dialog_colors, quick_dlg->callback, quick_dlg->mouse, quick_dlg->help,
                         quick_dlg->title, DLG_NONE);

    /* add widgets into the dialog */
    x2 = x1 + width2 + 1;
    g = NULL;
    two_columns = FALSE;
    x = (WIDGET (dd)->cols - blen) / 2;

    for (i = 0; i < widgets->len; i++)
    {
        quick_widget_item_t *item;
        int column_width;

        item = &g_array_index (widgets, quick_widget_item_t, i);
        column_width = two_columns ? width2 : width1;

        /* adjust widget width and x position */
        switch (item->quick_widget->widget_type)
        {
        case quick_label:
        {
            quick_widget_t *input = item->quick_widget->u.label.input;

            if (input != NULL && input->u.input.label_location == input_label_right)
            {
                /* location of this label will be adjusted later */
                break;
            }
        }
        /* fall through */
        case quick_checkbox:
        case quick_radio:
            if (item->widget->x != x1)
                item->widget->x = x2;
            if (g != NULL)
                item->widget->x += 2;
            break;

        case quick_button:
            if (!put_buttons)
            {
                if (item->widget->x != x1)
                    item->widget->x = x2;
                if (g != NULL)
                    item->widget->x += 2;
            }
            else
            {
                item->widget->x = x;
                x += item->widget->cols + 1;
            }
            break;

        case quick_input:
        {
            Widget *label = WIDGET (INPUT (item->widget)->label);
            int width = column_width;

            if (g != NULL)
                width -= 4;

            switch (item->quick_widget->u.input.label_location)
            {
            case input_label_left:
                /* label was adjusted before; adjust input line */
                item->widget->x = label->x + label->cols + 1 - WIDGET (label->owner)->x;
                item->widget->cols = width - label->cols - 1;
                break;

            case input_label_right:
                label->x =
                    item->widget->x + item->widget->cols + 1 - WIDGET (item->widget->owner)->x;
                item->widget->cols = width - label->cols - 1;
                break;

            default:
                if (item->widget->x != x1)
                    item->widget->x = x2;
                if (g != NULL)
                    item->widget->x += 2;
                item->widget->cols = width;
                break;
            }

            /* forced update internal variables of inpuit line */
            input_set_origin (INPUT (item->widget), item->widget->x, item->widget->cols);
        }
        break;

        case quick_start_groupbox:
            g = GROUPBOX (item->widget);
            if (item->widget->x != x1)
                item->widget->x = x2;
            item->widget->cols = column_width;
            break;

        case quick_stop_groupbox:
            g = NULL;
            break;

        case quick_separator:
            if (item->widget != NULL)
            {
                if (g != NULL)
                {
                    Widget *wg = WIDGET (g);

                    HLINE (item->widget)->auto_adjust_cols = FALSE;
                    item->widget->x = wg->x + 1 - WIDGET (wg->owner)->x;
                    item->widget->cols = wg->cols;
                }
                else if (two_columns)
                {
                    HLINE (item->widget)->auto_adjust_cols = FALSE;
                    if (item->widget->x != x1)
                        item->widget->x = x2;
                    item->widget->x--;
                    item->widget->cols = column_width + 2;
                }
                else
                    HLINE (item->widget)->auto_adjust_cols = TRUE;
            }
            break;

        case quick_start_columns:
            two_columns = TRUE;
            break;

        case quick_stop_columns:
            two_columns = FALSE;
            break;

        case quick_buttons:
            /* several buttons in bottom line */
            put_buttons = TRUE;
            break;

        default:
            break;
        }

        if (item->widget != NULL)
        {
            unsigned long id;

            /* add widget into dialog */
            item->widget->options |= item->quick_widget->options;       /* FIXME: cannot reset flags, setup only */
            id = add_widget_autopos (dd, item->widget, item->quick_widget->pos_flags, NULL);
            if (item->quick_widget->id != NULL)
                *item->quick_widget->id = id;
        }
    }

    while (nskip-- != 0)
    {
        dd->current = g_list_next (dd->current);
        if (dd->current == NULL)
            dd->current = dd->widgets;
    }

    return_val = run_dlg (dd);

    /* Get the data if we found something interesting */
    if (return_val != B_CANCEL)
        for (i = 0; i < widgets->len; i++)
        {
            quick_widget_item_t *item;

            item = &g_array_index (widgets, quick_widget_item_t, i);

            switch (item->quick_widget->widget_type)
            {
            case quick_checkbox:
                *item->quick_widget->u.checkbox.state = CHECK (item->widget)->state & C_BOOL;
                break;

            case quick_input:
                if ((quick_widget->u.input.flags & 2) != 0)
                    *item->quick_widget->u.input.result =
                        tilde_expand (INPUT (item->widget)->buffer);
                else
                    *item->quick_widget->u.input.result = g_strdup (INPUT (item->widget)->buffer);
                break;

            case quick_radio:
                *item->quick_widget->u.radio.value = RADIO (item->widget)->sel;
                break;

            default:
                break;
            }
        }

    destroy_dlg (dd);

    /* destroy input labels created before */
    for (i = 0; i < widgets->len; i++)
    {
        quick_widget_item_t *item;

        item = &g_array_index (widgets, quick_widget_item_t, i);
        if (item->quick_widget->widget_type == quick_input)
            g_free (item->quick_widget->u.input.label);
    }

    g_array_free (widgets, TRUE);

    return return_val;
}
예제 #8
0
파일: layout.c 프로젝트: m32/mc
static WDialog *
init_layout (void)
{
    WDialog *layout_dlg;
    int l1 = 0, width;
    int b1, b2, b;
    size_t i;

    const char *title1 = N_("Panel split");
    const char *title2 = N_("Console output");
    const char *title3 = N_("Other options");

    const char *s_split_direction[2] = {
        N_("&Vertical"),
        N_("&Horizontal")
    };

    const char *ok_button = N_("&OK");
    const char *cancel_button = N_("&Cancel");

    output_lines_label = _("Output lines:");

    /* save old params */
    _menubar_visible = menubar_visible;
    _command_prompt = command_prompt;
    _keybar_visible = mc_global.keybar_visible;
    _message_visible = mc_global.message_visible;
    _xterm_title = xterm_title;
    _free_space = free_space;
    old_output_lines = -1;
    _output_lines = output_lines;

#ifdef ENABLE_NLS
    {
        static gboolean i18n = FALSE;

        title1 = _(title1);
        title2 = _(title2);
        title3 = _(title3);

        i = G_N_ELEMENTS (s_split_direction);
        while (i-- != 0)
            s_split_direction[i] = _(s_split_direction[i]);

        if (!i18n)
        {
            for (i = 0; i < (size_t) LAYOUT_OPTIONS_COUNT; i++)
                check_options[i].text = _(check_options[i].text);
            i18n = TRUE;
        }

        ok_button = _(ok_button);
        cancel_button = _(cancel_button);
    }
#endif

    /* radiobuttons */
    i = G_N_ELEMENTS (s_split_direction);
    while (i-- != 0)
        l1 = max (l1, str_term_width1 (s_split_direction[i]) + 7);
    /* checkboxes */
    for (i = 0; i < (size_t) LAYOUT_OPTIONS_COUNT; i++)
        l1 = max (l1, str_term_width1 (check_options[i].text) + 7);
    /* groupboxes */
    l1 = max (l1, str_term_width1 (title1) + 4);
    l1 = max (l1, str_term_width1 (title2) + 4);
    l1 = max (l1, str_term_width1 (title3) + 4);
    /* label + "+"/"-" buttons */
    output_lines_label_len = str_term_width1 (output_lines_label);
    l1 = max (l1, output_lines_label_len + 12);
    /* buttons */
    b1 = str_term_width1 (ok_button) + 5;       /* default button */
    b2 = str_term_width1 (cancel_button) + 3;
    b = b1 + b2 + 1;
    /* dialog width */
    width = max (l1 * 2 + 7, b);

    layout_dlg =
        dlg_create (TRUE, 0, 0, 15, width, dialog_colors, layout_callback, NULL, "[Layout]",
                    _("Layout"), DLG_CENTER);

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

    /* "Panel split" groupbox */
    add_widget (layout_dlg, groupbox_new (2, 3, 6, l1, title1));

    radio_widget = radio_new (3, 5, 2, s_split_direction);
    radio_widget->sel = panels_layout.horizontal_split;
    add_widget (layout_dlg, radio_widget);

    check_options[0].widget = check_new (5, 5, XTRACT (0));
    add_widget (layout_dlg, check_options[0].widget);

    equal_split = panels_layout.horizontal_split ?
                  panels_layout.horizontal_equal : panels_layout.vertical_equal;

    bleft_widget = button_new (6, 8, B_2LEFT, NARROW_BUTTON, "&<", b_left_right_cback);
    widget_disable (WIDGET (bleft_widget), equal_split);
    add_widget (layout_dlg, bleft_widget);

    bright_widget = button_new (6, 14, B_2RIGHT, NARROW_BUTTON, "&>", b_left_right_cback);
    widget_disable (WIDGET (bright_widget), equal_split);
    add_widget (layout_dlg, bright_widget);

    /* "Console output" groupbox */
    {
        const int disabled = mc_global.tty.console_flag != '\0' ? 0 : W_DISABLED;
        Widget *w;

        w = WIDGET (groupbox_new (8, 3, 3, l1, title2));
        w->options |= disabled;
        add_widget (layout_dlg, w);

        w = WIDGET (button_new (9, output_lines_label_len + 5, B_PLUS,
                                NARROW_BUTTON, "&+", bplus_cback));
        w->options |= disabled;
        add_widget (layout_dlg, w);

        w = WIDGET (button_new (9, output_lines_label_len + 5 + 5, B_MINUS,
                                NARROW_BUTTON, "&-", bminus_cback));
        w->options |= disabled;
        add_widget (layout_dlg, w);
    }

    /* "Other options" groupbox */
    add_widget (layout_dlg, groupbox_new (2, 4 + l1, 9, l1, title3));

    for (i = 1; i < (size_t) LAYOUT_OPTIONS_COUNT; i++)
    {
        check_options[i].widget = check_new (i + 2, 6 + l1, XTRACT (i));
        add_widget (layout_dlg, check_options[i].widget);
    }

#undef XTRACT

    add_widget (layout_dlg, hline_new (11, -1, -1));
    /* buttons */
    add_widget (layout_dlg,
                button_new (12, (width - b) / 2, B_ENTER, DEFPUSH_BUTTON, ok_button, 0));
    add_widget (layout_dlg,
                button_new (12, (width - b) / 2 + b1 + 1, B_CANCEL, NORMAL_BUTTON,
                            cancel_button, 0));

    dlg_select_widget (radio_widget);

    return layout_dlg;
}
예제 #9
0
파일: chmod.c 프로젝트: BrEacK/mc
static Dlg_head *
init_chmod (const char *fname, const struct stat *sf_stat)
{
    Dlg_head *ch_dlg;
    int lines, cols;
    int perm_gb_len;
    int file_gb_len;
    unsigned int i;
    const char *c_fname, *c_fown, *c_fgrp;
    char buffer[BUF_TINY];

    single_set = (current_panel->marked < 2);
    perm_gb_len = check_perm_len + 2;
    file_gb_len = file_info_labels_len + 2;
    cols = str_term_width1 (fname) + 2 + 1;
    file_gb_len = max (file_gb_len, cols);

    lines = single_set ? 20 : 23;
    cols = perm_gb_len + file_gb_len + 1 + 6;

    if (cols > COLS)
    {
        /* shrink the right groupbox */
        cols = COLS;
        file_gb_len = cols - (perm_gb_len + 1 + 6);
    }

    ch_dlg =
        create_dlg (TRUE, 0, 0, lines, cols, dialog_colors,
                    chmod_callback, NULL, "[Chmod]", _("Chmod command"), DLG_CENTER | DLG_REVERSE);

    for (i = 0; i < chmod_but_num; i++)
    {
        add_widget (ch_dlg,
                    button_new (lines - chmod_but[i].y, ch_dlg->cols / 2 + 1,
                                chmod_but[i].ret_cmd, chmod_but[i].flags, chmod_but[i].text, 0));

        i++;

        add_widget (ch_dlg,
                    button_new (lines - chmod_but[i].y, ch_dlg->cols / 2 - chmod_but[i].len,
                                chmod_but[i].ret_cmd, chmod_but[i].flags, chmod_but[i].text, 0));

        if (single_set)
            break;
    }

    file_gb = groupbox_new (PY, PX + perm_gb_len + 1, check_perm_num + 2, file_gb_len, _("File"));
    add_widget (ch_dlg, file_gb);

    for (i = 0; i < check_perm_num; i++)
    {
        check_perm[i].check = check_new (PY + (check_perm_num - i), PX + 2,
                                         (c_stat & check_perm[i].mode) != 0 ? 1 : 0,
                                         check_perm[i].text);
        add_widget (ch_dlg, check_perm[i].check);
    }

    add_widget (ch_dlg, groupbox_new (PY, PX, check_perm_num + 2, perm_gb_len, _("Permission")));

    /* Set the labels */
    /* Do this at end to have a widget id in a simple way */
    lines = PY + 2;
    cols = PX + perm_gb_len + 3;
    c_fname = str_trunc (fname, file_gb_len - 3);
    add_widget (ch_dlg, label_new (lines, cols, c_fname));
    c_fown = str_trunc (get_owner (sf_stat->st_uid), file_gb_len - 3);
    add_widget (ch_dlg, label_new (lines + 4, cols, c_fown));
    c_fgrp = str_trunc (get_group (sf_stat->st_gid), file_gb_len - 3);
    add_widget (ch_dlg, label_new (lines + 6, cols, c_fgrp));
    g_snprintf (buffer, sizeof (buffer), "%o", (unsigned int) c_stat);
    statl = label_new (lines + 2, cols, buffer);
    add_widget (ch_dlg, statl);

    return ch_dlg;
}
예제 #10
0
파일: chown.c 프로젝트: ilia-maslakov/mc
static Dlg_head *
init_chown (void)
{
    int i;
    struct passwd *l_pass;
    struct group *l_grp;
    Dlg_head *ch_dlg;

    do_refresh ();
    end_chown = need_update = current_file = 0;
    single_set = (current_panel->marked < 2) ? 3 : 0;

    ch_dlg =
        create_dlg (TRUE, 0, 0, 18, 74, dialog_colors, chown_callback, "[Chown]",
                    _("Chown command"), DLG_CENTER | DLG_REVERSE);

    for (i = 0; i < BUTTONS - single_set; i++)
        add_widget (ch_dlg,
                    button_new (BY + chown_but[i].y, BX + chown_but[i].x,
                                chown_but[i].ret_cmd, chown_but[i].flags, _(chown_but[i].text), 0));

    /* Add the widgets for the file information */
    for (i = 0; i < LABELS; i++)
    {
        chown_label[i].l = label_new (chown_label[i].y, chown_label[i].x, "");
        add_widget (ch_dlg, chown_label[i].l);
    }

    /* get new listboxes */
    l_user = listbox_new (UY + 1, UX + 1, 10, 19, FALSE, NULL);
    l_group = listbox_new (GY + 1, GX + 1, 10, 19, FALSE, NULL);

    /* add fields for unknown names (numbers) */
    listbox_add_item (l_user, LISTBOX_APPEND_AT_END, 0, _("<Unknown user>"), NULL);
    listbox_add_item (l_group, LISTBOX_APPEND_AT_END, 0, _("<Unknown group>"), NULL);

    /* get and put user names in the listbox */
    setpwent ();
    while ((l_pass = getpwent ()) != NULL)
    {
        listbox_add_item (l_user, LISTBOX_APPEND_SORTED, 0, l_pass->pw_name, NULL);
    }
    endpwent ();

    /* get and put group names in the listbox */
    setgrent ();
    while ((l_grp = getgrent ()) != NULL)
    {
        listbox_add_item (l_group, LISTBOX_APPEND_SORTED, 0, l_grp->gr_name, NULL);
    }
    endgrent ();

    add_widget (ch_dlg, groupbox_new (TY, TX, 12, 19, _("File")));

    /* add listboxes to the dialogs */
    add_widget (ch_dlg, l_group);
    add_widget (ch_dlg, groupbox_new (GY, GX, 12, 21, _("Group name")));
    add_widget (ch_dlg, l_user);
    add_widget (ch_dlg, groupbox_new (UY, UX, 12, 21, _("User name")));

    return ch_dlg;
}