Esempio n. 1
0
static char *
collect_new_format (void)
{
    char *newformat;
    int i;
    char *last;
    char *text, *extra;

    newformat = g_malloc (1024);
    if (radio_genwidth->sel)
        strcpy (newformat, "full ");
    else
        strcpy (newformat, "half ");
    if (radio_columns->sel)
        strcat (newformat, "2 ");
    last = NULL;
    for (i = 0;; i++)
    {
        listbox_select_entry (l_listmode, i);
        listbox_get_current (l_listmode, &text, &extra);
        if (text == last)
            break;
        if (last != NULL)
            strcat (newformat, ",");
        strcat (newformat, text);
        last = text;
    }
    return newformat;
}
Esempio n. 2
0
File: boxes.c Progetto: andi5/mc
static int
sel_skin_button (WButton * button, int action)
{
    int result;
    WListbox *skin_list;
    WDialog *skin_dlg;
    const gchar *skin_name;
    int lxx, lyy;
    unsigned int i;
    unsigned int pos = 1;

    (void) action;

    lxx = COLS / 2;
    lyy = (LINES - 13) / 2;
    skin_dlg =
        dlg_create (TRUE, lyy, lxx, 13, 24, dialog_colors, NULL, NULL, "[Appearance]", _("Skins"),
                    DLG_COMPACT);

    skin_list = listbox_new (1, 1, 11, 22, FALSE, NULL);
    skin_name = "default";
    listbox_add_item (skin_list, LISTBOX_APPEND_AT_END, 0, skin_name_to_label (skin_name),
                      (void *) skin_name);

    if (strcmp (skin_name, current_skin_name) == 0)
        listbox_select_entry (skin_list, 0);

    for (i = 0; i < skin_names->len; i++)
    {
        skin_name = g_ptr_array_index (skin_names, i);
        if (strcmp (skin_name, "default") != 0)
        {
            listbox_add_item (skin_list, LISTBOX_APPEND_AT_END, 0, skin_name_to_label (skin_name),
                              (void *) skin_name);
            if (strcmp (skin_name, current_skin_name) == 0)
                listbox_select_entry (skin_list, pos);
            pos++;
        }
    }

    add_widget (skin_dlg, skin_list);

    result = dlg_run (skin_dlg);
    if (result == B_ENTER)
    {
        Widget *w;
        gchar *skin_label;

        listbox_get_current (skin_list, &skin_label, (void **) &skin_name);
        g_free (current_skin_name);
        current_skin_name = g_strdup (skin_name);
        skin_apply (skin_name);

        w = dlg_find_by_id (WIDGET (button)->owner, skin_name_id);
        button_set_text (BUTTON (w), str_fit_to_term (skin_label, 20, J_LEFT_FIT));
    }
    dlg_destroy (skin_dlg);

    return 0;
}
Esempio n. 3
0
File: panelize.c Progetto: andi5/mc
static void
update_command (void)
{
    if (l_panelize->pos != last_listitem)
    {
        struct panelize *data = NULL;

        last_listitem = l_panelize->pos;
        listbox_get_current (l_panelize, NULL, (void **) &data);
        input_assign_text (pname, data->command);
        pname->point = 0;
        input_update (pname, TRUE);
    }
}
Esempio n. 4
0
static int
task_cb (WButton * button, int action)
{
    TaskList *tl;
    int sig = 0;

    (void) button;

    if (bg_list->list == NULL)
        return 0;

    /* Get this instance information */
    listbox_get_current (bg_list, NULL, (void **) &tl);

#ifdef SIGTSTP
    if (action == B_STOP)
    {
        sig = SIGSTOP;
        tl->state = Task_Stopped;
    }
    else if (action == B_RESUME)
    {
        sig = SIGCONT;
        tl->state = Task_Running;
    }
    else
#endif
    if (action == B_KILL)
    {
        sig = SIGKILL;
    }

    if (sig == SIGKILL)
        unregister_task_running (tl->pid, tl->fd);

    kill (tl->pid, sig);
    listbox_remove_list (bg_list);
    jobs_fill_listbox ();

    /* This can be optimized to just redraw this widget :-) */
    dlg_redraw (jobs_dlg);

    return 0;
}
Esempio n. 5
0
File: chown.c Progetto: LubkaB/mc
void
chown_cmd (void)
{
    char *fname;
    struct stat sf_stat;
    uid_t new_user;
    gid_t new_group;
    char buffer[BUF_TINY];

    chown_i18n ();

    do
    {                           /* do while any files remaining */
        vfs_path_t *vpath;
        WDialog *ch_dlg;

        ch_dlg = init_chown ();
        new_user = new_group = -1;

        if (current_panel->marked)
            fname = next_file ();       /* next marked file */
        else
            fname = selection (current_panel)->fname;   /* single file */

        vpath = vfs_path_from_str (fname);
        if (mc_stat (vpath, &sf_stat) != 0)
        {                       /* get status of file */
            dlg_destroy (ch_dlg);
            vfs_path_free (vpath);
            break;
        }
        vfs_path_free (vpath);

        /* select in listboxes */
        listbox_select_entry (l_user, listbox_search_text (l_user, get_owner (sf_stat.st_uid)));
        listbox_select_entry (l_group, listbox_search_text (l_group, get_group (sf_stat.st_gid)));

        chown_label (0, str_trunc (fname, GW - 4));
        chown_label (1, str_trunc (get_owner (sf_stat.st_uid), GW - 4));
        chown_label (2, str_trunc (get_group (sf_stat.st_gid), GW - 4));
        size_trunc_len (buffer, GW - 4, sf_stat.st_size, 0, panels_options.kilobyte_si);
        chown_label (3, buffer);
        chown_label (4, string_perm (sf_stat.st_mode));

        switch (dlg_run (ch_dlg))
        {
        case B_CANCEL:
            end_chown = 1;
            break;

        case B_SETUSR:
            {
                struct passwd *user;
                char *text;

                listbox_get_current (l_user, &text, NULL);
                user = getpwnam (text);
                if (user)
                {
                    new_user = user->pw_uid;
                    apply_chowns (new_user, new_group);
                }
                break;
            }

        case B_SETGRP:
            {
                struct group *grp;
                char *text;

                listbox_get_current (l_group, &text, NULL);
                grp = getgrnam (text);
                if (grp)
                {
                    new_group = grp->gr_gid;
                    apply_chowns (new_user, new_group);
                }
                break;
            }

        case B_SETALL:
        case B_ENTER:
            {
                struct group *grp;
                struct passwd *user;
                char *text;

                listbox_get_current (l_group, &text, NULL);
                grp = getgrnam (text);
                if (grp)
                    new_group = grp->gr_gid;
                listbox_get_current (l_user, &text, NULL);
                user = getpwnam (text);
                if (user)
                    new_user = user->pw_uid;
                if (ch_dlg->ret_value == B_ENTER)
                {
                    vfs_path_t *fname_vpath;

                    fname_vpath = vfs_path_from_str (fname);
                    need_update = 1;
                    if (mc_chown (fname_vpath, new_user, new_group) == -1)
                        message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"),
                                 fname, unix_error_string (errno));
                    vfs_path_free (fname_vpath);
                }
                else
                    apply_chowns (new_user, new_group);
                break;
            }
        }                       /* switch */

        if (current_panel->marked && ch_dlg->ret_value != B_CANCEL)
        {
            do_file_mark (current_panel, current_file, 0);
            need_update = 1;
        }

        dlg_destroy (ch_dlg);
    }
    while (current_panel->marked && !end_chown);

    chown_done ();
}
Esempio n. 6
0
/* Returns 1 if the user would like to see us again */
static int
complete_engine (WInput *in, int what_to_do)
{
    if (in->completions && in->point != end)
    	free_completions (in);
    if (!in->completions){
    	end = in->point;
        for (start = end ? end - 1 : 0; start > -1; start--)
    	    if (strchr (" \t;|<>", in->buffer [start]))
    	        break;
    	if (start < end)
    	    start++;
    	in->completions = try_complete (in->buffer, &start, &end, in->completion_flags);
    }
    if (in->completions){
    	if (what_to_do & DO_INSERTION || ((what_to_do & DO_QUERY) && !in->completions[1])) {
    	    if (insert_text (in, in->completions [0], strlen (in->completions [0]))){
    	        if (in->completions [1])
    	    	    beep ();
		else
		    free_completions (in);
	    } else
	        beep ();
        }
    	if ((what_to_do & DO_QUERY) && in->completions && in->completions [1]) {
    	    int maxlen = 0, i, count = 0;
    	    int x, y, w, h;
    	    int start_x, start_y;
    	    char **p, *q;
    	    Dlg_head *query_dlg;
    	    WListbox *query_list;
    	    
    	    for (p=in->completions + 1; *p; count++, p++)
    	    	if ((i = strlen (*p)) > maxlen)
    	    	    maxlen = i;
    	    start_x = in->widget.x;
    	    start_y = in->widget.y;
    	    if (start_y - 2 >= count) {
    	    	y = start_y - 2 - count;
    	    	h = 2 + count;
    	    } else {
    	    	if (start_y >= LINES - start_y - 1) {
    	    	    y = 0;
    	    	    h = start_y;
    	    	} else {
    	    	    y = start_y + 1;
    	    	    h = LINES - start_y - 1;
    	    	}
    	    }
    	    x = start - in->first_shown - 2 + start_x;
    	    w = maxlen + 4;
    	    if (x + w > COLS)
    	    	x = COLS - w;
    	    if (x < 0)
    	    	x = 0;
    	    if (x + w > COLS)
    	    	w = COLS;
    	    input = in;
    	    min_end = end;
	    query_height = h;
	    query_width  = w;
    	    query_dlg = create_dlg (y, x, query_height, query_width,
				    dialog_colors, query_callback,
				    "[Completion]", NULL, DLG_COMPACT);
    	    query_list = listbox_new (1, 1, w - 2, h - 2, NULL);
    	    add_widget (query_dlg, query_list);
    	    for (p = in->completions + 1; *p; p++)
    	    	listbox_add_item (query_list, 0, 0, *p, NULL);
    	    run_dlg (query_dlg);
    	    q = NULL;
    	    if (query_dlg->ret_value == B_ENTER){
    	    	listbox_get_current (query_list, &q, NULL);
    	    	if (q)
    	    	    insert_text (in, q, strlen (q));
    	    }
    	    if (q || end != min_end)
    	    	free_completions (in);
    	    i = query_dlg->ret_value; /* B_USER if user wants to start over again */
    	    destroy_dlg (query_dlg);
    	    if (i == B_USER)
    	    	return 1;
    	}
    } else
    	beep ();
    return 0;
}
Esempio n. 7
0
void
editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_len, int word_len,
                                       etags_hash_t * def_hash, int num_lines)
{

    int start_x, start_y, offset, i;
    char *curr = NULL;
    etags_hash_t *curr_def = NULL;
    WDialog *def_dlg;
    WListbox *def_list;
    int def_dlg_h;              /* dialog height */
    int def_dlg_w;              /* dialog width */

    (void) word_len;
    /* calculate the dialog metrics */
    def_dlg_h = num_lines + 2;
    def_dlg_w = max_len + 4;
    start_x = edit->curs_col + edit->start_col - (def_dlg_w / 2) +
        EDIT_TEXT_HORIZONTAL_OFFSET + (edit->fullscreen ? 0 : 1) + option_line_state_width;
    start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + (edit->fullscreen ? 0 : 1) + 1;

    if (start_x < 0)
        start_x = 0;
    if (def_dlg_w > COLS)
        def_dlg_w = COLS;
    if (def_dlg_h > LINES - 2)
        def_dlg_h = LINES - 2;

    offset = start_x + def_dlg_w - COLS;
    if (offset > 0)
        start_x -= offset;
    offset = start_y + def_dlg_h - LINES;
    if (offset > 0)
        start_y -= (offset + 1);

    /* create the dialog */
    def_dlg = dlg_create (TRUE, start_y, start_x, def_dlg_h, def_dlg_w, WPOS_KEEP_DEFAULT, TRUE,
                          dialog_colors, NULL, NULL, "[Definitions]", match_expr);

    /* create the listbox */
    def_list = listbox_new (1, 1, def_dlg_h - 2, def_dlg_w - 2, FALSE, NULL);

    /* add the dialog */
    add_widget (def_dlg, def_list);

    /* fill the listbox with the completions */
    for (i = 0; i < num_lines; i++)
    {
        char *label_def;

        label_def =
            g_strdup_printf ("%s -> %s:%ld", def_hash[i].short_define, def_hash[i].filename,
                             def_hash[i].line);
        listbox_add_item (def_list, LISTBOX_APPEND_AT_END, 0, label_def, &def_hash[i], FALSE);
        g_free (label_def);
    }

    /* pop up the dialog and apply the chosen completion */
    if (dlg_run (def_dlg) == B_ENTER)
    {
        char *tmp_curr_def = (char *) curr_def;
        int do_moveto = 0;

        listbox_get_current (def_list, &curr, (void **) &tmp_curr_def);
        curr_def = (etags_hash_t *) tmp_curr_def;
        if (edit->modified)
        {
            if (!edit_query_dialog2
                (_("Warning"),
                 _("Current text was modified without a file save.\n"
                   "Continue discards these changes."), _("C&ontinue"), _("&Cancel")))
            {
                edit->force |= REDRAW_COMPLETELY;
                do_moveto = 1;
            }
        }
        else
        {
            do_moveto = 1;
        }

        if (curr && do_moveto)
        {
            if (edit_stack_iterator + 1 < MAX_HISTORY_MOVETO)
            {
                vfs_path_free (edit_history_moveto[edit_stack_iterator].filename_vpath);
                if (edit->dir_vpath != NULL)
                {
                    edit_history_moveto[edit_stack_iterator].filename_vpath =
                        vfs_path_append_vpath_new (edit->dir_vpath, edit->filename_vpath, NULL);
                }
                else
                {
                    edit_history_moveto[edit_stack_iterator].filename_vpath =
                        vfs_path_clone (edit->filename_vpath);
                }
                edit_history_moveto[edit_stack_iterator].line = edit->start_line +
                    edit->curs_row + 1;
                edit_stack_iterator++;
                vfs_path_free (edit_history_moveto[edit_stack_iterator].filename_vpath);
                edit_history_moveto[edit_stack_iterator].filename_vpath =
                    vfs_path_from_str ((char *) curr_def->fullpath);
                edit_history_moveto[edit_stack_iterator].line = curr_def->line;
                edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename_vpath,
                                  edit_history_moveto[edit_stack_iterator].line);
            }
        }
    }

    /* clear definition hash */
    for (i = 0; i < MAX_DEFINITIONS; i++)
    {
        g_free (def_hash[i].filename);
    }

    /* destroy dialog before return */
    dlg_destroy (def_dlg);
}
Esempio n. 8
0
char *
editcmd_dialog_completion_show (const WEdit * edit, int max_len, GString ** compl, int num_compl)
{
    const Widget *we = CONST_WIDGET (edit);
    int start_x, start_y, offset, i;
    char *curr = NULL;
    WDialog *compl_dlg;
    WListbox *compl_list;
    int compl_dlg_h;            /* completion dialog height */
    int compl_dlg_w;            /* completion dialog width */

    /* calculate the dialog metrics */
    compl_dlg_h = num_compl + 2;
    compl_dlg_w = max_len + 4;
    start_x = we->x + edit->curs_col + edit->start_col + EDIT_TEXT_HORIZONTAL_OFFSET +
        (edit->fullscreen ? 0 : 1) + option_line_state_width;
    start_y = we->y + edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + (edit->fullscreen ? 0 : 1) + 1;

    if (start_x < 0)
        start_x = 0;
    if (start_x < we->x + 1)
        start_x = we->x + 1 + option_line_state_width;
    if (compl_dlg_w > COLS)
        compl_dlg_w = COLS;
    if (compl_dlg_h > LINES - 2)
        compl_dlg_h = LINES - 2;

    offset = start_x + compl_dlg_w - COLS;
    if (offset > 0)
        start_x -= offset;
    offset = start_y + compl_dlg_h - LINES;
    if (offset > 0)
        start_y -= offset;

    /* create the dialog */
    compl_dlg =
        dlg_create (TRUE, start_y, start_x, compl_dlg_h, compl_dlg_w, WPOS_KEEP_DEFAULT, TRUE,
                    dialog_colors, NULL, NULL, "[Completion]", NULL);

    /* create the listbox */
    compl_list = listbox_new (1, 1, compl_dlg_h - 2, compl_dlg_w - 2, FALSE, NULL);

    /* add the dialog */
    add_widget (compl_dlg, compl_list);

    /* fill the listbox with the completions */
    for (i = num_compl - 1; i >= 0; i--)        /* reverse order */
        listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i]->str, NULL,
                          FALSE);

    /* pop up the dialog and apply the chosen completion */
    if (dlg_run (compl_dlg) == B_ENTER)
    {
        listbox_get_current (compl_list, &curr, NULL);
        curr = g_strdup (curr);
    }

    /* destroy dialog before return */
    dlg_destroy (compl_dlg);

    return curr;
}
Esempio n. 9
0
File: achown.c Progetto: jskDr/mc
static void
do_enter_key (WDialog * h, int f_pos)
{
    WListbox *chl_list;
    struct passwd *chl_pass;
    struct group *chl_grp;
    int fe;
    gboolean chl_end, is_owner;

    do
    {
        int result;
        WDialog *chl_dlg;
        const char *title;
        int lxx, lyy, b_pos;

        is_owner = (f_pos == 3);
        title = is_owner ? _("owner") : _("group");

        lxx = (COLS - 74) / 2 + (is_owner ? 35 : 53);
        lyy = (LINES - 13) / 2;
        chl_end = FALSE;

        chl_dlg =
            dlg_create (TRUE, lyy, lxx, 13, 17, WPOS_KEEP_DEFAULT, TRUE, dialog_colors,
                        chl_callback, NULL, "[Advanced Chown]", title);

        /* get new listboxes */
        chl_list = listbox_new (1, 1, 11, 15, FALSE, NULL);
        listbox_add_item (chl_list, LISTBOX_APPEND_AT_END, 0, "<Unknown>", NULL, FALSE);
        if (is_owner)
        {
            /* get and put user names in the listbox */
            setpwent ();
            while ((chl_pass = getpwent ()) != NULL)
                listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_pass->pw_name, NULL,
                                  FALSE);
            endpwent ();
            fe = listbox_search_text (chl_list, get_owner (sf_stat->st_uid));
        }
        else
        {
            /* get and put group names in the listbox */
            setgrent ();
            while ((chl_grp = getgrent ()) != NULL)
                listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_grp->gr_name, NULL,
                                  FALSE);
            endgrent ();
            fe = listbox_search_text (chl_list, get_group (sf_stat->st_gid));
        }

        listbox_select_entry (chl_list, fe);

        b_pos = chl_list->pos;
        add_widget (chl_dlg, chl_list);

        result = dlg_run (chl_dlg);

        if (result != B_CANCEL)
        {
            if (b_pos != chl_list->pos)
            {
                gboolean ok = FALSE;
                char *text;

                listbox_get_current (chl_list, &text, NULL);
                if (is_owner)
                {
                    chl_pass = getpwnam (text);
                    if (chl_pass != NULL)
                    {
                        ok = TRUE;
                        sf_stat->st_uid = chl_pass->pw_uid;
                    }
                }
                else
                {
                    chl_grp = getgrnam (text);
                    if (chl_grp != NULL)
                    {
                        sf_stat->st_gid = chl_grp->gr_gid;
                        ok = TRUE;
                    }
                }
                if (ok)
                {
                    ch_flags[f_pos + 6] = '+';
                    update_ownership ();
                }
                dlg_focus (h);
                if (ok)
                    print_flags ();
            }
            if (result == KEY_LEFT)
            {
                if (!is_owner)
                    chl_end = TRUE;
                dlg_one_up (ch_dlg);
                f_pos--;
            }
            else if (result == KEY_RIGHT)
            {
                if (is_owner)
                    chl_end = TRUE;
                dlg_one_down (ch_dlg);
                f_pos++;
            }
        }

        /* Here we used to redraw the window */
        dlg_destroy (chl_dlg);
    }
    while (chl_end);
}
Esempio n. 10
0
static int
complete_engine (WInput * in, int what_to_do)
{
    if (in->completions != NULL && str_offset_to_pos (in->buffer, in->point) != end)
        input_free_completions (in);
    if (in->completions == NULL)
    {
        char *s;

        end = str_offset_to_pos (in->buffer, in->point);

        s = in->buffer;
        if (in->point != 0)
        {
            /* get symbol before in->point */
            size_t i;
            for (i = in->point - 1; i > 0; i--)
                str_next_char (&s);
        }

        for (; s >= in->buffer; str_prev_char (&s))
        {
            start = s - in->buffer;
            if (strchr (" \t;|<>", *s) != NULL)
                break;
        }

        if (start < end)
        {
            str_next_char (&s);
            start = s - in->buffer;
        }

        in->completions = try_complete (in->buffer, &start, &end, in->completion_flags);
    }

    if (in->completions != NULL)
    {
        if (what_to_do & DO_INSERTION || ((what_to_do & DO_QUERY) && !in->completions[1]))
        {
            char *lc_complete = in->completions[0];
            if (insert_text (in, lc_complete, strlen (lc_complete)))
            {
                if (in->completions[1])
                    tty_beep ();
                else
                    input_free_completions (in);
            }
            else
                tty_beep ();
        }
        if ((what_to_do & DO_QUERY) && in->completions && in->completions[1])
        {
            int maxlen = 0, i, count = 0;
            int x, y, w, h;
            int start_x, start_y;
            char **p, *q;
            Dlg_head *query_dlg;
            WListbox *query_list;

            for (p = in->completions + 1; *p != NULL; count++, p++)
            {
                i = str_term_width1 (*p);
                if (i > maxlen)
                    maxlen = i;
            }
            start_x = in->widget.x;
            start_y = in->widget.y;
            if (start_y - 2 >= count)
            {
                y = start_y - 2 - count;
                h = 2 + count;
            }
            else
            {
                if (start_y >= LINES - start_y - 1)
                {
                    y = 0;
                    h = start_y;
                }
                else
                {
                    y = start_y + 1;
                    h = LINES - start_y - 1;
                }
            }
            x = start - in->term_first_shown - 2 + start_x;
            w = maxlen + 4;
            if (x + w > COLS)
                x = COLS - w;
            if (x < 0)
                x = 0;
            if (x + w > COLS)
                w = COLS;
            input = in;
            min_end = end;
            query_height = h;
            query_width = w;
            query_dlg = create_dlg (TRUE, y, x, query_height, query_width,
                                    dialog_colors, query_callback, NULL,
                                    "[Completion]", NULL, DLG_COMPACT);
            query_list = listbox_new (1, 1, h - 2, w - 2, FALSE, NULL);
            add_widget (query_dlg, query_list);
            for (p = in->completions + 1; *p; p++)
                listbox_add_item (query_list, LISTBOX_APPEND_AT_END, 0, *p, NULL);
            run_dlg (query_dlg);
            q = NULL;
            if (query_dlg->ret_value == B_ENTER)
            {
                listbox_get_current (query_list, &q, NULL);
                if (q)
                    insert_text (in, q, strlen (q));
            }
            if (q || end != min_end)
                input_free_completions (in);
            i = query_dlg->ret_value;   /* B_USER if user wants to start over again */
            destroy_dlg (query_dlg);
            if (i == B_USER)
                return 1;
        }
    }
    else
        tty_beep ();
    return 0;
}
Esempio n. 11
0
File: history.c Progetto: BrEacK/mc
char *
history_show (GList ** history, Widget * widget, int current)
{
    GList *z, *hlist = NULL, *hi;
    size_t maxlen, i, count = 0;
    char *r = NULL;
    Dlg_head *query_dlg;
    WListbox *query_list;
    history_dlg_data hist_data;

    if (*history == NULL)
        return NULL;

    maxlen = str_term_width1 (_("History")) + 2;

    for (z = *history; z != NULL; z = g_list_previous (z))
    {
        WLEntry *entry;

        i = str_term_width1 ((char *) z->data);
        maxlen = max (maxlen, i);
        count++;

        entry = g_new0 (WLEntry, 1);
        /* history is being reverted here */
        entry->text = g_strdup ((char *) z->data);
        hlist = g_list_prepend (hlist, entry);
    }

    hist_data.widget = widget;
    hist_data.count = count;
    hist_data.maxlen = maxlen;

    query_dlg =
        create_dlg (TRUE, 0, 0, 4, 4, dialog_colors, history_dlg_callback, NULL,
                    "[History-query]", _("History"), DLG_COMPACT);
    query_dlg->data = &hist_data;

    query_list = listbox_new (1, 1, 2, 2, TRUE, NULL);

    /* this call makes list stick to all sides of dialog, effectively make
       it be resized with dialog */
    add_widget_autopos (query_dlg, query_list, WPOS_KEEP_ALL, NULL);

    /* to avoid diplicating of (calculating sizes in two places)
       code, call dlg_hist_callback function here, to set dialog and
       controls positions.
       The main idea - create 4x4 dialog and add 2x2 list in
       center of it, and let dialog function resize it to needed
       size. */
    history_dlg_callback (query_dlg, NULL, DLG_RESIZE, 0, NULL);

    if (query_dlg->y < widget->y)
    {
        /* draw list entries from bottom upto top */
        listbox_set_list (query_list, hlist);
        if (current < 0 || (size_t) current >= count)
            listbox_select_last (query_list);
        else
            listbox_select_entry (query_list, count - 1 - (size_t) current);
    }
    else
    {
        /* draw list entries from top downto bottom */
        /* revert history direction */
        hlist = g_list_reverse (hlist);
        listbox_set_list (query_list, hlist);
        if (current > 0)
            listbox_select_entry (query_list, current);
    }

    if (run_dlg (query_dlg) != B_CANCEL)
    {
        char *q;

        listbox_get_current (query_list, &q, NULL);
        r = g_strdup (q);
    }

    /* get modified history from dialog */
    z = NULL;
    for (hi = query_list->list; hi != NULL; hi = g_list_next (hi))
    {
        WLEntry *entry;

        entry = (WLEntry *) hi->data;
        /* history is being reverted here again */
        z = g_list_prepend (z, entry->text);
        entry->text = NULL;
    }

    /* restore history direction */
    if (query_dlg->y < widget->y)
        z = g_list_reverse (z);

    destroy_dlg (query_dlg);

    g_list_foreach (*history, (GFunc) g_free, NULL);
    g_list_free (*history);
    *history = g_list_last (z);

    return r;
}
Esempio n. 12
0
static void get_list_info (char **file, char **dir) {
    listbox_get_current (find_list, file, dir);
}
Esempio n. 13
0
/* let the user select its preferred completion */
void
editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
                                struct selection *compl, int num_compl)
{

    int start_x, start_y, offset, i;
    char *curr = NULL;
    Dlg_head *compl_dlg;
    WListbox *compl_list;
    int compl_dlg_h;            /* completion dialog height */
    int compl_dlg_w;            /* completion dialog width */

    /* calculate the dialog metrics */
    compl_dlg_h = num_compl + 2;
    compl_dlg_w = max_len + 4;
    start_x = edit->curs_col + edit->start_col - (compl_dlg_w / 2) +
              EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
    start_y = edit->curs_row + EDIT_TEXT_VERTICAL_OFFSET + 1;

    if (start_x < 0)
        start_x = 0;
    if (compl_dlg_w > COLS)
        compl_dlg_w = COLS;
    if (compl_dlg_h > LINES - 2)
        compl_dlg_h = LINES - 2;

    offset = start_x + compl_dlg_w - COLS;
    if (offset > 0)
        start_x -= offset;
    offset = start_y + compl_dlg_h - LINES;
    if (offset > 0)
        start_y -= (offset + 1);

    /* create the dialog */
    compl_dlg =
        create_dlg (start_y, start_x, compl_dlg_h, compl_dlg_w,
                    dialog_colors, NULL, "[Completion]", NULL, DLG_COMPACT);

    /* create the listbox */
    compl_list = listbox_new (1, 1, compl_dlg_h - 2, compl_dlg_w - 2, NULL);

    /* add the dialog */
    add_widget (compl_dlg, compl_list);

    /* fill the listbox with the completions */
    for (i = num_compl - 1; i >= 0; i--) /* reverse order */
        listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i].text, NULL);

    /* pop up the dialog and apply the choosen completion */
    if (run_dlg (compl_dlg) == B_ENTER) {
        listbox_get_current (compl_list, &curr, NULL);
        if (curr) {
#ifdef HAVE_CHARSET
	    GString *temp, *temp2;
	    temp = g_string_new("");
	    for (curr += word_len; *curr; curr++)
		g_string_append_c(temp, *curr);

	    temp2 = str_convert_to_input (temp->str);

	    if (temp2 && temp2->len){
		g_string_free(temp, TRUE);
		temp = temp2;
	    }
	    else
		g_string_free(temp2, TRUE);
	    for (curr = temp->str; *curr; curr++)
		edit_insert (edit, *curr);
	    g_string_free(temp, TRUE);
#else
            for (curr += word_len; *curr; curr++)
                edit_insert (edit, *curr);
#endif
        }
    }

    /* destroy dialog before return */
    destroy_dlg (compl_dlg);
}