⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fselect.c

📁 This version of dialog, formerly known as cdialog is based on the Debian package for dialog 0.9a (se
💻 C
📖 第 1 页 / 共 2 页
字号:
    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);    }    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		    add_to_list(f_list, leaf);	    }	}	(void) closedir(dp);	/* sort the lists */	qsort(d_list->data, d_list->length, sizeof(d_list->data[0]), compar);	qsort(f_list->data, 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;}static boolusable_state(STATES state, LIST * dirs, LIST * files){    bool result;    switch (state) {    case sDIRS:	result = (data_of(dirs) != 0);	break;    case sFILES:	result = (data_of(files) != 0);	break;    default:	result = TRUE;	break;    }    return result;}#define which_list() ((state == sFILES) \			? &f_list \			: ((state == sDIRS) \			  ? &d_list \			  : 0))/* * Display a dialog box for entering a filename */intdialog_fselect(const char *title, const char *path, int height, int width){    int tbox_y, tbox_x, tbox_width, tbox_height;    int dbox_y, dbox_x, dbox_width, dbox_height;    int fbox_y, fbox_x, fbox_width, fbox_height;    int show_buttons = TRUE;    int offset = 0;    int key = 0;    int fkey = FALSE;    int code;    int result = DLG_EXIT_UNKNOWN;    int state = dialog_vars.defaultno ? dlg_defaultno_button() : sTEXT;    int button = state;    int first = (state == sTEXT);    char *input = dialog_vars.input_result;    char *completed;    char current[MAX_LEN + 1];    WINDOW *dialog, *w_text, *w_dir, *w_file;    const char **buttons = dlg_ok_labels();    char *d_label = _("Directories");    char *f_label = _("Files");    int min_wide = MIN_WIDE;    int min_items = height ? 0 : 4;    LIST d_list, f_list;    dlg_does_output();    dlg_auto_size(title, (char *) 0, &height, &width, 6, 25);    height += MIN_HIGH + min_items;    if (width < min_wide)	width = min_wide;    dlg_print_size(height, width);    dlg_ctl_size(height, width);    dialog = dlg_new_window(height, width,			    dlg_box_y_ordinate(height),			    dlg_box_x_ordinate(width));    dlg_mouse_setbase(0, 0);    dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);    dlg_draw_bottom_box(dialog);    dlg_draw_title(dialog, title);    wattrset(dialog, dialog_attr);    /* Draw the input field box */    tbox_height = 1;    tbox_width = width - (4 * MARGIN + 2);    tbox_y = height - (BTN_HIGH * 2) + MARGIN;    tbox_x = (width - tbox_width) / 2;    w_text = derwin(dialog, tbox_height, tbox_width, tbox_y, tbox_x);    if (w_text == 0)	return DLG_EXIT_ERROR;    (void) keypad(w_text, TRUE);    dlg_draw_box(dialog, tbox_y - MARGIN, tbox_x - MARGIN,		 (2 * MARGIN + 1), tbox_width + (MARGIN + EXT_WIDE),		 border_attr, dialog_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 */ );    /* Draw the directory listing box */    dbox_height = height - MIN_HIGH;    dbox_width = (width - (6 * MARGIN + 2 * EXT_WIDE)) / 2;    dbox_y = (2 * MARGIN + 1);    dbox_x = tbox_x;    w_dir = derwin(dialog, dbox_height, dbox_width, dbox_y, dbox_x);    if (w_dir == 0)	return DLG_EXIT_ERROR;    (void) keypad(w_dir, TRUE);    (void) mvwprintw(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),		 border_attr, dialog_attr);    init_list(&d_list, dialog, w_dir, MOUSE_D);    /* Draw the filename listing box */    fbox_height = dbox_height;    fbox_width = dbox_width;    fbox_y = dbox_y;    fbox_x = tbox_x + dbox_width + (2 * MARGIN);    w_file = derwin(dialog, fbox_height, fbox_width, fbox_y, fbox_x);    if (w_file == 0)	return DLG_EXIT_ERROR;    (void) keypad(w_file, TRUE);    (void) mvwprintw(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),		 border_attr, dialog_attr);    init_list(&f_list, dialog, w_file, MOUSE_F);    /* Set up the initial value */    strcpy(input, path);    offset = strlen(input);    *current = 0;    while (result == DLG_EXIT_UNKNOWN) {	int edit = 0;	if (fill_lists(current, input, &d_list, &f_list, state < sTEXT))	    show_buttons = TRUE;	/*	 * The last field drawn determines where the cursor is shown:	 */	if (show_buttons) {	    show_buttons = FALSE;	    button = (state < 0) ? 0 : state;	    dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);	}	if (state < 0) {	    switch (state) {	    case sTEXT:		dlg_set_focus(dialog, w_text);		break;	    case sFILES:		dlg_set_focus(dialog, w_file);		break;	    case sDIRS:		dlg_set_focus(dialog, w_dir);		break;	    }	}	if (first) {	    (void) wrefresh(dialog);	} else {	    fix_arrows(&d_list);	    fix_arrows(&f_list);	    key = dlg_mouse_wgetch(dialog, &fkey);	}	if (!fkey) {	    fkey = TRUE;	    switch (key) {	    case ESC:		result = DLG_EXIT_ESC;		fkey = FALSE;		break;	    case '\n':	    case '\r':		key = KEY_ENTER;		break;	    case ' ':		key = KEY_SELECT;		break;	    case TAB:		key = KEY_RIGHT;		break;	    case 0:		break;	    default:		fkey = FALSE;		break;	    }	}	if (fkey) {	    switch (key) {	    case M_EVENT + KEY_PREVIOUS:		state = sDIRS;		scroll_list(-1, which_list());		continue;	    case M_EVENT + KEY_NEXT:		state = sDIRS;		scroll_list(1, which_list());		continue;	    case M_EVENT + KEY_PPAGE:		state = sFILES;		scroll_list(-1, which_list());		continue;	    case M_EVENT + KEY_NPAGE:		state = sFILES;		scroll_list(1, which_list());		continue;	    case KEY_PPAGE:		scroll_list(-1, which_list());		continue;	    case KEY_NPAGE:		scroll_list(1, which_list());		continue;	    case KEY_UP:		if (change_list(-1, which_list()))		    continue;		/* FALLTHRU */	    case KEY_LEFT:	    case KEY_BTAB:		show_buttons = TRUE;		do {		    state = dlg_prev_ok_buttonindex(state, sDIRS);		} while (!usable_state(state, &d_list, &f_list));		continue;	    case KEY_DOWN:		if (change_list(1, which_list()))		    continue;		/* FALLTHRU */	    case KEY_RIGHT:		show_buttons = TRUE;		do {		    state = dlg_next_ok_buttonindex(state, sDIRS);		} while (!usable_state(state, &d_list, &f_list));		continue;	    case KEY_SELECT:		completed = 0;		if (state == sFILES) {		    completed = data_of(&f_list);		} else if (state == sDIRS) {		    completed = data_of(&d_list);		}		if (completed != 0) {		    state = sTEXT;		    show_buttons = TRUE;		    strcpy(leaf_of(input), completed);		    offset = strlen(input);		    dlg_show_string(w_text, input, offset, inputbox_attr,				    0, 0, tbox_width, 0, first);		    continue;		} else if (state < sTEXT) {		    (void) beep();		    continue;		}		/* FALLTHRU */	    case KEY_ENTER:		result = (state > 0) ? dlg_ok_buttoncode(state) : DLG_EXIT_OK;		continue;	    default:		if (key >= M_EVENT + MOUSE_T) {		    state = sTEXT;		    continue;		} else if (key >= M_EVENT + MOUSE_F) {		    state = sFILES;		    f_list.choice = (key - (M_EVENT + MOUSE_F)) + f_list.offset;		    display_list(&f_list);		    continue;		} else if (key >= M_EVENT + MOUSE_D) {		    state = sDIRS;		    d_list.choice = (key - (M_EVENT + MOUSE_D)) + d_list.offset;		    display_list(&d_list);		    continue;		} else if (key >= M_EVENT			   && (code = dlg_ok_buttoncode(key - M_EVENT)) >= 0) {		    result = code;		    continue;		}		break;	    }	}	if (state < 0) {	/* Input box selected if we're editing */	    edit = dlg_edit_string(input, &offset, key, fkey, first);	    if (edit) {		dlg_show_string(w_text, input, offset, inputbox_attr,				0, 0, tbox_width, 0, first);		first = FALSE;		state = sTEXT;	    }	} else if (state >= 0 &&		   (code = dlg_char_to_button(key, buttons)) >= 0) {	    result = code;	    break;	}    }    dlg_del_window(dialog);    dlg_mouse_free_regions();    free_list(&d_list, FALSE);    free_list(&f_list, FALSE);    return result;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -