diff options
author | nwhitehorn <nwhitehorn@FreeBSD.org> | 2012-10-21 18:18:09 +0000 |
---|---|---|
committer | nwhitehorn <nwhitehorn@FreeBSD.org> | 2012-10-21 18:18:09 +0000 |
commit | a94245b3d36b447d1f761028da7e072210e64b43 (patch) | |
tree | 7533a68fe403654b5f1626734c2336dc7128d3bb /fselect.c | |
parent | 94f19e002939203294adf4d18b410183682bd2de (diff) | |
download | FreeBSD-src-a94245b3d36b447d1f761028da7e072210e64b43.zip FreeBSD-src-a94245b3d36b447d1f761028da7e072210e64b43.tar.gz |
Import dialog-1.1-20120706
Diffstat (limited to 'fselect.c')
-rw-r--r-- | fselect.c | 136 |
1 files changed, 78 insertions, 58 deletions
@@ -1,9 +1,9 @@ /* - * $Id: fselect.c,v 1.78 2011/06/29 09:48:21 tom Exp $ + * $Id: fselect.c,v 1.87 2012/07/01 18:14:09 Zoltan.Kelemen Exp $ * * fselect.c -- implements the file-selector box * - * Copyright 2000-2010,2011 Thomas E. Dickey + * Copyright 2000-2011,2012 Thomas E. Dickey * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License, version 2.1 @@ -230,11 +230,11 @@ display_list(LIST * list) break; (void) wmove(list->win, y, 0); if (n == list->choice) - wattrset(list->win, item_selected_attr); + (void) wattrset(list->win, item_selected_attr); (void) waddstr(list->win, list->data[n]); - wattrset(list->win, item_attr); + (void) wattrset(list->win, item_attr); } - wattrset(list->win, item_attr); + (void) wattrset(list->win, item_attr); getparyx(list->win, y, x); @@ -249,7 +249,7 @@ display_list(LIST * list) x + getmaxx(list->win), top, bottom, - menubox_attr, + menubox_border2_attr, menubox_border_attr); (void) wmove(list->win, list->choice - list->offset, 0); @@ -270,18 +270,20 @@ fix_arrows(LIST * list) int x; int y; int top; + int right; int bottom; if (list->win != 0) { getparyx(list->win, y, x); top = y - 1; + right = getmaxx(list->win); bottom = y + getmaxy(list->win); - mouse_mkbutton(top, x, 6, + mouse_mkbutton(top, x, right, ((list->mousex == MOUSE_D) ? KEY_PREVIOUS : KEY_PPAGE)); - mouse_mkbutton(bottom, x, 6, + mouse_mkbutton(bottom, x, right, ((list->mousex == MOUSE_D) ? KEY_NEXT : KEY_NPAGE)); @@ -429,6 +431,8 @@ complete(char *name, LIST * d_list, LIST * f_list, char **buff_ptr) static bool fill_lists(char *current, char *input, LIST * d_list, LIST * f_list, int keep) { + bool result = TRUE; + bool rescan = FALSE; DIR *dp; DIRENT *de; struct stat sb; @@ -441,51 +445,60 @@ fill_lists(char *current, char *input, LIST * d_list, LIST * f_list, int keep) if (current[n] != input[n]) break; } - if (current[n] == input[n]) - return FALSE; - if (strchr(current + n, '/') == 0 - && strchr(input + n, '/') == 0) { - return show_both_lists(input, d_list, f_list, keep); - } - - strcpy(current, input); - /* refill the lists */ - free_list(d_list, TRUE); - free_list(f_list, TRUE); - strcpy(path, current); - if ((leaf = strrchr(path, '/')) != 0) { - *++leaf = 0; + if (current[n] == input[n]) { + result = FALSE; + rescan = (n == 0 && d_list->length == 0); + } else if (strchr(current + n, '/') == 0 + && strchr(input + n, '/') == 0) { + result = show_both_lists(input, d_list, f_list, keep); } else { - strcpy(path, "./"); - leaf = path + strlen(path); + rescan = TRUE; } - if ((dp = opendir(path)) != 0) { - while ((de = readdir(dp)) != 0) { - strncpy(leaf, de->d_name, NAMLEN(de))[NAMLEN(de)] = 0; - if (stat(path, &sb) == 0) { - if ((sb.st_mode & S_IFMT) == S_IFDIR) - add_to_list(d_list, leaf); - else if (f_list->win) - add_to_list(f_list, leaf); + + if (rescan) { + + strcpy(current, input); + + /* refill the lists */ + free_list(d_list, TRUE); + free_list(f_list, TRUE); + strcpy(path, current); + if ((leaf = strrchr(path, '/')) != 0) { + *++leaf = 0; + } else { + strcpy(path, "./"); + leaf = path + strlen(path); + } + dlg_trace_msg("opendir '%s'\n", path); + if ((dp = opendir(path)) != 0) { + while ((de = readdir(dp)) != 0) { + strncpy(leaf, de->d_name, NAMLEN(de))[NAMLEN(de)] = 0; + if (stat(path, &sb) == 0) { + if ((sb.st_mode & S_IFMT) == S_IFDIR) + add_to_list(d_list, leaf); + else if (f_list->win) + add_to_list(f_list, leaf); + } } + (void) closedir(dp); + /* sort the lists */ + qsort(d_list->data, + (size_t) d_list->length, + sizeof(d_list->data[0]), + compar); + qsort(f_list->data, + (size_t) f_list->length, + sizeof(f_list->data[0]), + compar); } - (void) closedir(dp); - /* sort the lists */ - qsort(d_list->data, - (size_t) d_list->length, - sizeof(d_list->data[0]), - compar); - qsort(f_list->data, - (size_t) f_list->length, - sizeof(f_list->data[0]), - compar); - } - (void) show_both_lists(input, d_list, f_list, FALSE); - d_list->offset = d_list->choice; - f_list->offset = f_list->choice; - return TRUE; + (void) show_both_lists(input, d_list, f_list, FALSE); + d_list->offset = d_list->choice; + f_list->offset = f_list->choice; + result = TRUE; + } + return result; } static bool @@ -560,9 +573,10 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel int fkey = FALSE; int code; int result = DLG_EXIT_UNKNOWN; - int state = dialog_vars.defaultno ? dlg_defaultno_button() : sTEXT; - int button = state; + int state = dialog_vars.default_button >=0 ? dlg_default_button() : sTEXT; + int button; int first = (state == sTEXT); + int first_trace = TRUE; char *input; char *completed; char current[MAX_LEN + 1]; @@ -604,11 +618,11 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel dlg_mouse_setbase(0, 0); - dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); - dlg_draw_bottom_box(dialog); + dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr); + dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr); dlg_draw_title(dialog, title); - wattrset(dialog, dialog_attr); + (void) wattrset(dialog, dialog_attr); /* Draw the input field box */ tbox_height = 1; @@ -623,14 +637,14 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel (void) keypad(w_text, TRUE); dlg_draw_box(dialog, tbox_y - MARGIN, tbox_x - MARGIN, (2 * MARGIN + 1), tbox_width + (MARGIN + EXT_WIDE), - menubox_border_attr, menubox_attr); + menubox_border_attr, menubox_border2_attr); dlg_mouse_mkbigregion(getbegy(dialog) + tbox_y - MARGIN, getbegx(dialog) + tbox_x - MARGIN, 1 + (2 * MARGIN), tbox_width + (MARGIN + EXT_WIDE), MOUSE_T, 1, 1, 3 /* doesn't matter */ ); - dlg_register_window(w_text, "fselect", binding2); + dlg_register_window(w_text, "fselect2", binding2); /* Draw the directory listing box */ if (dselect) @@ -646,11 +660,11 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel return DLG_EXIT_ERROR; (void) keypad(w_work, TRUE); - (void) mvwprintw(dialog, dbox_y - (MARGIN + 1), dbox_x - MARGIN, d_label); + (void) mvwaddstr(dialog, dbox_y - (MARGIN + 1), dbox_x - MARGIN, d_label); dlg_draw_box(dialog, dbox_y - MARGIN, dbox_x - MARGIN, dbox_height + (MARGIN + 1), dbox_width + (MARGIN + 1), - menubox_border_attr, menubox_attr); + menubox_border_attr, menubox_border2_attr); init_list(&d_list, dialog, w_work, MOUSE_D); if (!dselect) { @@ -665,11 +679,11 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel return DLG_EXIT_ERROR; (void) keypad(w_work, TRUE); - (void) mvwprintw(dialog, fbox_y - (MARGIN + 1), fbox_x - MARGIN, f_label); + (void) mvwaddstr(dialog, fbox_y - (MARGIN + 1), fbox_x - MARGIN, f_label); dlg_draw_box(dialog, fbox_y - MARGIN, fbox_x - MARGIN, fbox_height + (MARGIN + 1), fbox_width + (MARGIN + 1), - menubox_border_attr, menubox_attr); + menubox_border_attr, menubox_border2_attr); init_list(&f_list, dialog, w_work, MOUSE_F); } else { memset(&f_list, 0, sizeof(f_list)); @@ -696,6 +710,12 @@ dlg_fselect(const char *title, const char *path, int height, int width, int dsel button = (state < 0) ? 0 : state; dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); } + + if (first_trace) { + first_trace = FALSE; + dlg_trace_win(dialog); + } + if (state < 0) { switch (state) { case sTEXT: |