303
297
tui_set_attr(MENU_FORE, MENU_BACK, 0);
305
for (i = strlen(path) - 1, xx = MIN(x + width - 1, x + i);
299
for (i = strlen(path) - 1, xx = MIN(x + width - 1, x + i); i >= 0 && xx >= x; i--, xx--) {
310
302
/* Display ellipsis on the left if longer than the line. */
311
if (xx <= x + 1 && i > 1)
303
if (xx <= x + 1 && i > 1) {
314
306
c = path[i] == '/' ? '\\' : path[i];
315
308
tui_put_char(xx, y, c);
319
static void file_selector_display_item(struct file_list *fl, int num,
320
int first_item_num, int x, int y,
321
int width, int height, int num_cols)
312
static void file_selector_display_item(struct file_list *fl, int num, int first_item_num, int x, int y, int width, int height, int num_cols)
323
314
y += (num - first_item_num) % height;
324
315
x += ((num - first_item_num) / height) * width;
343
334
name[width - 2] = '\0';
344
335
tui_display(x, y, width, " %s ", name);
346
if (fl->items[num].type == FT_DIR)
347
/* tui_display(x, y, width, " %s\\ ", fl->items[num].name); */
337
if (fl->items[num].type == FT_DIR) {
348
338
tui_display(x, y, width, " %s/ ", fl->items[num].name);
350
340
tui_display(x, y, width, " %s ", fl->items[num].name);
355
static void file_selector_update(struct file_list *fl,
356
int first_item_num, int x, int y,
357
int width, int height, int num_cols)
346
static void file_selector_update(struct file_list *fl, int first_item_num, int x, int y, int width, int height, int num_cols)
361
for (i = 0; i < num_cols * height; i++)
362
file_selector_display_item(fl, first_item_num + i, first_item_num,
363
x, y, width, height, num_cols);
350
for (i = 0; i < num_cols * height; i++) {
351
file_selector_display_item(fl, first_item_num + i, first_item_num, x, y, width, height, num_cols);
366
355
/* ------------------------------------------------------------------------- */
494
486
tui_area_get(&backing_store, x, y, width + 2, height + 1);
496
tui_display_window(x, y, width, height, MENU_BORDER, MENU_BACK,
488
tui_display_window(x, y, width, height, MENU_BORDER, MENU_BACK, title, NULL);
502
493
tui_set_attr(MENU_FORE, MENU_BACK, 0);
503
494
if (need_update) {
504
file_selector_display_path(return_path, x + 1, y + height - 1,
506
file_selector_update(fl, first_item, x + 2, y + 1,
507
field_width, num_lines, num_cols);
495
file_selector_display_path(return_path, x + 1, y + height - 1, width - 2);
496
file_selector_update(fl, first_item, x + 2, y + 1, field_width, num_lines, num_cols);
508
497
tui_set_attr(FIRST_LINE_FORE, FIRST_LINE_BACK, 0);
509
tui_display(0, tui_num_lines() - 1, tui_num_cols(),
510
"\030\031\033\032: Move <Enter>: Select %s<Alt>-<letter>: Change drive",
511
contents_func != NULL ? "<Space>: Preview " : "");
498
tui_display(0, tui_num_lines() - 1, tui_num_cols(), "\030\031\033\032: Move <Enter>: Select %s<Alt>-<letter>: Change drive", contents_func != NULL ? "<Space>: Preview " : "");
514
501
tui_set_attr(MENU_FORE, MENU_HIGHLIGHT, 0);
515
file_selector_display_item(fl, curr_item, first_item, x + 2, y + 1,
516
field_width, num_lines, num_cols);
502
file_selector_display_item(fl, curr_item, first_item, x + 2, y + 1, field_width, num_lines, num_cols);
518
504
tui_set_attr(MENU_FORE, MENU_BACK, 0);
519
file_selector_display_item(fl, curr_item, first_item, x + 2, y + 1,
520
field_width, num_lines, num_cols);
505
file_selector_display_item(fl, curr_item, first_item, x + 2, y + 1, field_width, num_lines, num_cols);
524
tui_area_put(backing_store, x, y);
525
tui_area_free(backing_store);
529
if (curr_item - num_lines >= 0) {
530
curr_item -= num_lines;
531
if (curr_item < first_item) {
532
if (first_item >= num_lines) {
533
first_item -= num_lines;
536
curr_item += num_lines;
544
if (curr_item < first_item) {
545
first_item = curr_item;
552
if (curr_item + num_lines < fl->num_used_items) {
553
curr_item += num_lines;
554
if (curr_item - first_item >= num_files) {
555
first_item += num_lines;
562
if (curr_item < fl->num_used_items - 1) {
564
if (curr_item == first_item + num_files) {
572
if (curr_item + num_files < fl->num_used_items) {
573
curr_item += num_files;
574
first_item += num_files;
580
if (curr_item - num_files >= 0) {
581
curr_item -= num_files;
582
first_item -= num_files;
591
if (first_item != 0) {
598
curr_item = fl->num_used_items - 1;
599
first_item = curr_item - num_files + 1;
606
if (fl->items[curr_item].type == FT_DIR) {
607
struct file_list *new_fl;
610
new_path = change_path(fl, return_path, curr_item);
612
new_fl = file_list_read(new_path, pattern);
614
if (new_fl != NULL) {
617
first_item = curr_item = 0;
618
lib_free(return_path);
619
return_path = new_path;
621
ioutil_chdir(return_path);
626
char *p = util_concat(return_path, fl->items[curr_item].name,
629
lib_free(return_path);
631
509
tui_area_put(backing_store, x, y);
632
510
tui_area_free(backing_store);
640
n = file_list_find(fl, str, str_len);
514
if (curr_item - num_lines >= 0) {
515
curr_item -= num_lines;
516
if (curr_item < first_item) {
517
if (first_item >= num_lines) {
518
first_item -= num_lines;
521
curr_item += num_lines;
643
530
if (curr_item < first_item) {
644
531
first_item = curr_item;
646
} else if (first_item + num_files <= curr_item) {
647
first_item = curr_item - num_files + 1;
538
if (curr_item + num_lines < fl->num_used_items) {
539
curr_item += num_lines;
540
if (curr_item - first_item >= num_files) {
541
first_item += num_lines;
548
if (curr_item < fl->num_used_items - 1) {
550
if (curr_item == first_item + num_files) {
558
if (curr_item + num_files < fl->num_used_items) {
559
curr_item += num_files;
560
first_item += num_files;
566
if (curr_item - num_files >= 0) {
567
curr_item -= num_files;
568
first_item -= num_files;
569
if (first_item < 0) {
654
578
if (first_item != 0) {
661
if (contents_func != NULL
662
&& fl->items[curr_item].type != FT_DIR
663
&& browse_file_return != NULL) {
664
tui_display(0, tui_num_lines() - 1, tui_num_cols(), "");
665
*browse_file_return = tui_image_browser(type,
666
fl->items[curr_item].name,
668
browse_file_number_return);
669
if (*browse_file_return != NULL) {
670
char *p = util_concat(return_path,
671
fl->items[curr_item].name, NULL);
585
curr_item = fl->num_used_items - 1;
586
first_item = curr_item - num_files + 1;
587
if (first_item < 0) {
594
if (fl->items[curr_item].type == FT_DIR) {
595
struct file_list *new_fl;
598
new_path = change_path(fl, return_path, curr_item);
600
new_fl = file_list_read(new_path, pattern);
602
if (new_fl != NULL) {
605
first_item = curr_item = 0;
606
lib_free(return_path);
607
return_path = new_path;
609
ioutil_chdir(return_path);
614
char *p = util_concat(return_path, fl->items[curr_item].name, NULL);
673
616
lib_free(return_path);
676
619
tui_area_free(backing_store);
677
620
return return_path;
688
drive_num = alt_key_to_drive_num(key);
691
/* `A-a' ... `A-z' change the current drive. */
692
int num_available_drives;
695
_dos_getdrive(¤t_drive);
696
_dos_setdrive(current_drive, &num_available_drives);
697
if (drive_num <= num_available_drives) {
700
/* FIXME: This is a hack... Maybe there is a cleaner
701
way to do it, but for now I just don't know. */
702
_dos_setdrive(drive_num, &num_available_drives);
703
new_path = ioutil_current_dir();
704
if (new_path != NULL) {
705
slashize_path(&new_path);
706
_dos_setdrive(current_drive, &num_available_drives);
707
if (new_path != NULL) {
708
struct file_list *new_fl;
710
new_fl = file_list_read(new_path, pattern);
711
if (new_fl != NULL) {
714
first_item = curr_item = 0;
715
lib_free(return_path);
716
return_path = new_path;
718
ioutil_chdir(return_path);
724
_dos_setdrive(current_drive, &num_available_drives); tui_beep();
729
} else if (isprint(key) && str_len < 0x100) {
732
n = file_list_find(fl, str, str_len + 1);
627
n = file_list_find(fl, str, str_len);
738
630
if (curr_item < first_item) {
739
631
first_item = curr_item;
641
if (first_item != 0) {
648
if (contents_func != NULL && fl->items[curr_item].type != FT_DIR && browse_file_return != NULL) {
649
tui_display(0, tui_num_lines() - 1, tui_num_cols(), "");
650
*browse_file_return = tui_image_browser(fl->items[curr_item].name, contents_func, browse_file_number_return);
651
if (*browse_file_return != NULL) {
652
char *p = util_concat(return_path, fl->items[curr_item].name, NULL);
654
lib_free(return_path);
656
tui_area_put(backing_store, x, y);
657
tui_area_free(backing_store);
669
drive_num = alt_key_to_drive_num(key);
672
/* `A-a' ... `A-z' change the current drive. */
673
int num_available_drives;
676
_dos_getdrive(¤t_drive);
677
_dos_setdrive(current_drive, &num_available_drives);
678
if (drive_num <= num_available_drives) {
681
/* FIXME: This is a hack... Maybe there is a cleaner
682
way to do it, but for now I just don't know. */
683
_dos_setdrive(drive_num, &num_available_drives);
684
new_path = ioutil_current_dir();
685
if (new_path != NULL) {
686
slashize_path(&new_path);
687
_dos_setdrive(current_drive, &num_available_drives);
688
if (new_path != NULL) {
689
struct file_list *new_fl;
691
new_fl = file_list_read(new_path, pattern);
692
if (new_fl != NULL) {
695
first_item = curr_item = 0;
696
lib_free(return_path);
697
return_path = new_path;
699
ioutil_chdir(return_path);
705
_dos_setdrive(current_drive, &num_available_drives);
711
} else if (isprint(key) && str_len < 0x100) {
715
n = file_list_find(fl, str, str_len + 1);
721
if (curr_item < first_item) {
722
first_item = curr_item;
724
} else if (first_item + num_files <= curr_item) {
725
first_item = curr_item - num_files + 1;