Deleted Added
full compact
fselect.c (224014) fselect.c (241818)
1/*
1/*
2 * $Id: fselect.c,v 1.78 2011/06/29 09:48:21 tom Exp $
2 * $Id: fselect.c,v 1.87 2012/07/01 18:14:09 Zoltan.Kelemen Exp $
3 *
4 * fselect.c -- implements the file-selector box
5 *
3 *
4 * fselect.c -- implements the file-selector box
5 *
6 * Copyright 2000-2010,2011 Thomas E. Dickey
6 * Copyright 2000-2011,2012 Thomas E. Dickey
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License, version 2.1
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

--- 210 unchanged lines hidden (view full) ---

225 if (list->win != 0) {
226 dlg_attr_clear(list->win, getmaxy(list->win), getmaxx(list->win), item_attr);
227 for (n = list->offset; n < list->length && list->data[n]; n++) {
228 y = n - list->offset;
229 if (y >= getmaxy(list->win))
230 break;
231 (void) wmove(list->win, y, 0);
232 if (n == list->choice)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License, version 2.1
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

--- 210 unchanged lines hidden (view full) ---

225 if (list->win != 0) {
226 dlg_attr_clear(list->win, getmaxy(list->win), getmaxx(list->win), item_attr);
227 for (n = list->offset; n < list->length && list->data[n]; n++) {
228 y = n - list->offset;
229 if (y >= getmaxy(list->win))
230 break;
231 (void) wmove(list->win, y, 0);
232 if (n == list->choice)
233 wattrset(list->win, item_selected_attr);
233 (void) wattrset(list->win, item_selected_attr);
234 (void) waddstr(list->win, list->data[n]);
234 (void) waddstr(list->win, list->data[n]);
235 wattrset(list->win, item_attr);
235 (void) wattrset(list->win, item_attr);
236 }
236 }
237 wattrset(list->win, item_attr);
237 (void) wattrset(list->win, item_attr);
238
239 getparyx(list->win, y, x);
240
241 top = y - 1;
242 bottom = y + getmaxy(list->win);
243 dlg_draw_scrollbar(list->par,
244 (long) list->offset,
245 (long) list->offset,
246 (long) (list->offset + getmaxy(list->win)),
247 (long) (list->length),
248 x + 1,
249 x + getmaxx(list->win),
250 top,
251 bottom,
238
239 getparyx(list->win, y, x);
240
241 top = y - 1;
242 bottom = y + getmaxy(list->win);
243 dlg_draw_scrollbar(list->par,
244 (long) list->offset,
245 (long) list->offset,
246 (long) (list->offset + getmaxy(list->win)),
247 (long) (list->length),
248 x + 1,
249 x + getmaxx(list->win),
250 top,
251 bottom,
252 menubox_attr,
252 menubox_border2_attr,
253 menubox_border_attr);
254
255 (void) wmove(list->win, list->choice - list->offset, 0);
256 (void) wnoutrefresh(list->win);
257 }
258}
259
260/* FIXME: see arrows.c

--- 4 unchanged lines hidden (view full) ---

265 * switch statement.
266 */
267static void
268fix_arrows(LIST * list)
269{
270 int x;
271 int y;
272 int top;
253 menubox_border_attr);
254
255 (void) wmove(list->win, list->choice - list->offset, 0);
256 (void) wnoutrefresh(list->win);
257 }
258}
259
260/* FIXME: see arrows.c

--- 4 unchanged lines hidden (view full) ---

265 * switch statement.
266 */
267static void
268fix_arrows(LIST * list)
269{
270 int x;
271 int y;
272 int top;
273 int right;
273 int bottom;
274
275 if (list->win != 0) {
276 getparyx(list->win, y, x);
277 top = y - 1;
274 int bottom;
275
276 if (list->win != 0) {
277 getparyx(list->win, y, x);
278 top = y - 1;
279 right = getmaxx(list->win);
278 bottom = y + getmaxy(list->win);
279
280 bottom = y + getmaxy(list->win);
281
280 mouse_mkbutton(top, x, 6,
282 mouse_mkbutton(top, x, right,
281 ((list->mousex == MOUSE_D)
282 ? KEY_PREVIOUS
283 : KEY_PPAGE));
283 ((list->mousex == MOUSE_D)
284 ? KEY_PREVIOUS
285 : KEY_PPAGE));
284 mouse_mkbutton(bottom, x, 6,
286 mouse_mkbutton(bottom, x, right,
285 ((list->mousex == MOUSE_D)
286 ? KEY_NEXT
287 : KEY_NPAGE));
288 }
289}
290
291static int
292show_list(char *target, LIST * list, int keep)

--- 131 unchanged lines hidden (view full) ---

424 buff[i] = '\0';
425 *buff_ptr = buff;
426 return (i != 0);
427}
428
429static bool
430fill_lists(char *current, char *input, LIST * d_list, LIST * f_list, int keep)
431{
287 ((list->mousex == MOUSE_D)
288 ? KEY_NEXT
289 : KEY_NPAGE));
290 }
291}
292
293static int
294show_list(char *target, LIST * list, int keep)

--- 131 unchanged lines hidden (view full) ---

426 buff[i] = '\0';
427 *buff_ptr = buff;
428 return (i != 0);
429}
430
431static bool
432fill_lists(char *current, char *input, LIST * d_list, LIST * f_list, int keep)
433{
434 bool result = TRUE;
435 bool rescan = FALSE;
432 DIR *dp;
433 DIRENT *de;
434 struct stat sb;
435 int n;
436 char path[MAX_LEN + 1];
437 char *leaf;
438
439 /* check if we've updated the lists */
440 for (n = 0; current[n] && input[n]; n++) {
441 if (current[n] != input[n])
442 break;
443 }
436 DIR *dp;
437 DIRENT *de;
438 struct stat sb;
439 int n;
440 char path[MAX_LEN + 1];
441 char *leaf;
442
443 /* check if we've updated the lists */
444 for (n = 0; current[n] && input[n]; n++) {
445 if (current[n] != input[n])
446 break;
447 }
444 if (current[n] == input[n])
445 return FALSE;
446 if (strchr(current + n, '/') == 0
447 && strchr(input + n, '/') == 0) {
448 return show_both_lists(input, d_list, f_list, keep);
449 }
450
448
451 strcpy(current, input);
452
453 /* refill the lists */
454 free_list(d_list, TRUE);
455 free_list(f_list, TRUE);
456 strcpy(path, current);
457 if ((leaf = strrchr(path, '/')) != 0) {
458 *++leaf = 0;
449 if (current[n] == input[n]) {
450 result = FALSE;
451 rescan = (n == 0 && d_list->length == 0);
452 } else if (strchr(current + n, '/') == 0
453 && strchr(input + n, '/') == 0) {
454 result = show_both_lists(input, d_list, f_list, keep);
459 } else {
455 } else {
460 strcpy(path, "./");
461 leaf = path + strlen(path);
456 rescan = TRUE;
462 }
457 }
463 if ((dp = opendir(path)) != 0) {
464 while ((de = readdir(dp)) != 0) {
465 strncpy(leaf, de->d_name, NAMLEN(de))[NAMLEN(de)] = 0;
466 if (stat(path, &sb) == 0) {
467 if ((sb.st_mode & S_IFMT) == S_IFDIR)
468 add_to_list(d_list, leaf);
469 else if (f_list->win)
470 add_to_list(f_list, leaf);
458
459 if (rescan) {
460
461 strcpy(current, input);
462
463 /* refill the lists */
464 free_list(d_list, TRUE);
465 free_list(f_list, TRUE);
466 strcpy(path, current);
467 if ((leaf = strrchr(path, '/')) != 0) {
468 *++leaf = 0;
469 } else {
470 strcpy(path, "./");
471 leaf = path + strlen(path);
472 }
473 dlg_trace_msg("opendir '%s'\n", path);
474 if ((dp = opendir(path)) != 0) {
475 while ((de = readdir(dp)) != 0) {
476 strncpy(leaf, de->d_name, NAMLEN(de))[NAMLEN(de)] = 0;
477 if (stat(path, &sb) == 0) {
478 if ((sb.st_mode & S_IFMT) == S_IFDIR)
479 add_to_list(d_list, leaf);
480 else if (f_list->win)
481 add_to_list(f_list, leaf);
482 }
471 }
483 }
484 (void) closedir(dp);
485 /* sort the lists */
486 qsort(d_list->data,
487 (size_t) d_list->length,
488 sizeof(d_list->data[0]),
489 compar);
490 qsort(f_list->data,
491 (size_t) f_list->length,
492 sizeof(f_list->data[0]),
493 compar);
472 }
494 }
473 (void) closedir(dp);
474 /* sort the lists */
475 qsort(d_list->data,
476 (size_t) d_list->length,
477 sizeof(d_list->data[0]),
478 compar);
479 qsort(f_list->data,
480 (size_t) f_list->length,
481 sizeof(f_list->data[0]),
482 compar);
483 }
484
495
485 (void) show_both_lists(input, d_list, f_list, FALSE);
486 d_list->offset = d_list->choice;
487 f_list->offset = f_list->choice;
488 return TRUE;
496 (void) show_both_lists(input, d_list, f_list, FALSE);
497 d_list->offset = d_list->choice;
498 f_list->offset = f_list->choice;
499 result = TRUE;
500 }
501 return result;
489}
490
491static bool
492usable_state(int state, LIST * dirs, LIST * files)
493{
494 bool result;
495
496 switch (state) {

--- 58 unchanged lines hidden (view full) ---

555 int dbox_y, dbox_x, dbox_width, dbox_height;
556 int fbox_y, fbox_x, fbox_width, fbox_height;
557 int show_buttons = TRUE;
558 int offset = 0;
559 int key = 0;
560 int fkey = FALSE;
561 int code;
562 int result = DLG_EXIT_UNKNOWN;
502}
503
504static bool
505usable_state(int state, LIST * dirs, LIST * files)
506{
507 bool result;
508
509 switch (state) {

--- 58 unchanged lines hidden (view full) ---

568 int dbox_y, dbox_x, dbox_width, dbox_height;
569 int fbox_y, fbox_x, fbox_width, fbox_height;
570 int show_buttons = TRUE;
571 int offset = 0;
572 int key = 0;
573 int fkey = FALSE;
574 int code;
575 int result = DLG_EXIT_UNKNOWN;
563 int state = dialog_vars.defaultno ? dlg_defaultno_button() : sTEXT;
564 int button = state;
576 int state = dialog_vars.default_button >=0 ? dlg_default_button() : sTEXT;
577 int button;
565 int first = (state == sTEXT);
578 int first = (state == sTEXT);
579 int first_trace = TRUE;
566 char *input;
567 char *completed;
568 char current[MAX_LEN + 1];
569 WINDOW *dialog = 0;
570 WINDOW *w_text = 0;
571 WINDOW *w_work = 0;
572 const char **buttons = dlg_ok_labels();
573 const char *d_label = _("Directories");

--- 25 unchanged lines hidden (view full) ---

599 dialog = dlg_new_window(height, width,
600 dlg_box_y_ordinate(height),
601 dlg_box_x_ordinate(width));
602 dlg_register_window(dialog, "fselect", binding);
603 dlg_register_buttons(dialog, "fselect", buttons);
604
605 dlg_mouse_setbase(0, 0);
606
580 char *input;
581 char *completed;
582 char current[MAX_LEN + 1];
583 WINDOW *dialog = 0;
584 WINDOW *w_text = 0;
585 WINDOW *w_work = 0;
586 const char **buttons = dlg_ok_labels();
587 const char *d_label = _("Directories");

--- 25 unchanged lines hidden (view full) ---

613 dialog = dlg_new_window(height, width,
614 dlg_box_y_ordinate(height),
615 dlg_box_x_ordinate(width));
616 dlg_register_window(dialog, "fselect", binding);
617 dlg_register_buttons(dialog, "fselect", buttons);
618
619 dlg_mouse_setbase(0, 0);
620
607 dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
608 dlg_draw_bottom_box(dialog);
621 dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr);
622 dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr);
609 dlg_draw_title(dialog, title);
610
623 dlg_draw_title(dialog, title);
624
611 wattrset(dialog, dialog_attr);
625 (void) wattrset(dialog, dialog_attr);
612
613 /* Draw the input field box */
614 tbox_height = 1;
615 tbox_width = width - (4 * MARGIN + 2);
616 tbox_y = height - (BTN_HIGH * 2) + MARGIN;
617 tbox_x = (width - tbox_width) / 2;
618
619 w_text = derwin(dialog, tbox_height, tbox_width, tbox_y, tbox_x);
620 if (w_text == 0)
621 return DLG_EXIT_ERROR;
622
623 (void) keypad(w_text, TRUE);
624 dlg_draw_box(dialog, tbox_y - MARGIN, tbox_x - MARGIN,
625 (2 * MARGIN + 1), tbox_width + (MARGIN + EXT_WIDE),
626
627 /* Draw the input field box */
628 tbox_height = 1;
629 tbox_width = width - (4 * MARGIN + 2);
630 tbox_y = height - (BTN_HIGH * 2) + MARGIN;
631 tbox_x = (width - tbox_width) / 2;
632
633 w_text = derwin(dialog, tbox_height, tbox_width, tbox_y, tbox_x);
634 if (w_text == 0)
635 return DLG_EXIT_ERROR;
636
637 (void) keypad(w_text, TRUE);
638 dlg_draw_box(dialog, tbox_y - MARGIN, tbox_x - MARGIN,
639 (2 * MARGIN + 1), tbox_width + (MARGIN + EXT_WIDE),
626 menubox_border_attr, menubox_attr);
640 menubox_border_attr, menubox_border2_attr);
627 dlg_mouse_mkbigregion(getbegy(dialog) + tbox_y - MARGIN,
628 getbegx(dialog) + tbox_x - MARGIN,
629 1 + (2 * MARGIN),
630 tbox_width + (MARGIN + EXT_WIDE),
631 MOUSE_T, 1, 1, 3 /* doesn't matter */ );
632
641 dlg_mouse_mkbigregion(getbegy(dialog) + tbox_y - MARGIN,
642 getbegx(dialog) + tbox_x - MARGIN,
643 1 + (2 * MARGIN),
644 tbox_width + (MARGIN + EXT_WIDE),
645 MOUSE_T, 1, 1, 3 /* doesn't matter */ );
646
633 dlg_register_window(w_text, "fselect", binding2);
647 dlg_register_window(w_text, "fselect2", binding2);
634
635 /* Draw the directory listing box */
636 if (dselect)
637 dbox_width = (width - (6 * MARGIN));
638 else
639 dbox_width = (width - (6 * MARGIN + 2 * EXT_WIDE)) / 2;
640 dbox_height = height - MIN_HIGH;
641 dbox_y = (2 * MARGIN + 1);
642 dbox_x = tbox_x;
643
644 w_work = derwin(dialog, dbox_height, dbox_width, dbox_y, dbox_x);
645 if (w_work == 0)
646 return DLG_EXIT_ERROR;
647
648 (void) keypad(w_work, TRUE);
648
649 /* Draw the directory listing box */
650 if (dselect)
651 dbox_width = (width - (6 * MARGIN));
652 else
653 dbox_width = (width - (6 * MARGIN + 2 * EXT_WIDE)) / 2;
654 dbox_height = height - MIN_HIGH;
655 dbox_y = (2 * MARGIN + 1);
656 dbox_x = tbox_x;
657
658 w_work = derwin(dialog, dbox_height, dbox_width, dbox_y, dbox_x);
659 if (w_work == 0)
660 return DLG_EXIT_ERROR;
661
662 (void) keypad(w_work, TRUE);
649 (void) mvwprintw(dialog, dbox_y - (MARGIN + 1), dbox_x - MARGIN, d_label);
663 (void) mvwaddstr(dialog, dbox_y - (MARGIN + 1), dbox_x - MARGIN, d_label);
650 dlg_draw_box(dialog,
651 dbox_y - MARGIN, dbox_x - MARGIN,
652 dbox_height + (MARGIN + 1), dbox_width + (MARGIN + 1),
664 dlg_draw_box(dialog,
665 dbox_y - MARGIN, dbox_x - MARGIN,
666 dbox_height + (MARGIN + 1), dbox_width + (MARGIN + 1),
653 menubox_border_attr, menubox_attr);
667 menubox_border_attr, menubox_border2_attr);
654 init_list(&d_list, dialog, w_work, MOUSE_D);
655
656 if (!dselect) {
657 /* Draw the filename listing box */
658 fbox_height = dbox_height;
659 fbox_width = dbox_width;
660 fbox_y = dbox_y;
661 fbox_x = tbox_x + dbox_width + (2 * MARGIN);
662
663 w_work = derwin(dialog, fbox_height, fbox_width, fbox_y, fbox_x);
664 if (w_work == 0)
665 return DLG_EXIT_ERROR;
666
667 (void) keypad(w_work, TRUE);
668 init_list(&d_list, dialog, w_work, MOUSE_D);
669
670 if (!dselect) {
671 /* Draw the filename listing box */
672 fbox_height = dbox_height;
673 fbox_width = dbox_width;
674 fbox_y = dbox_y;
675 fbox_x = tbox_x + dbox_width + (2 * MARGIN);
676
677 w_work = derwin(dialog, fbox_height, fbox_width, fbox_y, fbox_x);
678 if (w_work == 0)
679 return DLG_EXIT_ERROR;
680
681 (void) keypad(w_work, TRUE);
668 (void) mvwprintw(dialog, fbox_y - (MARGIN + 1), fbox_x - MARGIN, f_label);
682 (void) mvwaddstr(dialog, fbox_y - (MARGIN + 1), fbox_x - MARGIN, f_label);
669 dlg_draw_box(dialog,
670 fbox_y - MARGIN, fbox_x - MARGIN,
671 fbox_height + (MARGIN + 1), fbox_width + (MARGIN + 1),
683 dlg_draw_box(dialog,
684 fbox_y - MARGIN, fbox_x - MARGIN,
685 fbox_height + (MARGIN + 1), fbox_width + (MARGIN + 1),
672 menubox_border_attr, menubox_attr);
686 menubox_border_attr, menubox_border2_attr);
673 init_list(&f_list, dialog, w_work, MOUSE_F);
674 } else {
675 memset(&f_list, 0, sizeof(f_list));
676 }
677
678 while (result == DLG_EXIT_UNKNOWN) {
679
680 if (fill_lists(current, input, &d_list, &f_list, state < sTEXT))

--- 10 unchanged lines hidden (view full) ---

691 /*
692 * The last field drawn determines where the cursor is shown:
693 */
694 if (show_buttons) {
695 show_buttons = FALSE;
696 button = (state < 0) ? 0 : state;
697 dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
698 }
687 init_list(&f_list, dialog, w_work, MOUSE_F);
688 } else {
689 memset(&f_list, 0, sizeof(f_list));
690 }
691
692 while (result == DLG_EXIT_UNKNOWN) {
693
694 if (fill_lists(current, input, &d_list, &f_list, state < sTEXT))

--- 10 unchanged lines hidden (view full) ---

705 /*
706 * The last field drawn determines where the cursor is shown:
707 */
708 if (show_buttons) {
709 show_buttons = FALSE;
710 button = (state < 0) ? 0 : state;
711 dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
712 }
713
714 if (first_trace) {
715 first_trace = FALSE;
716 dlg_trace_win(dialog);
717 }
718
699 if (state < 0) {
700 switch (state) {
701 case sTEXT:
702 dlg_set_focus(dialog, w_text);
703 break;
704 case sFILES:
705 dlg_set_focus(dialog, f_list.win);
706 break;

--- 178 unchanged lines hidden ---
719 if (state < 0) {
720 switch (state) {
721 case sTEXT:
722 dlg_set_focus(dialog, w_text);
723 break;
724 case sFILES:
725 dlg_set_focus(dialog, f_list.win);
726 break;

--- 178 unchanged lines hidden ---