Changeset 9bed565 in mainline
- Timestamp:
- 2021-10-15T16:58:28Z (3 years ago)
- Children:
- 0e125698
- Parents:
- 03c4b23
- Location:
- uspace/app/nav
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/panel.c
r03c4b23 r9bed565 44 44 #include <ui/paint.h> 45 45 #include <ui/resource.h> 46 #include <vfs/vfs.h> 46 47 #include <qsort.h> 47 48 #include "panel.h" … … 93 94 94 95 rc = gfx_color_new_ega(0x0f, &panel->act_border_color); 96 if (rc != EOK) 97 goto error; 98 99 rc = gfx_color_new_ega(0x0f, &panel->dir_color); 95 100 if (rc != EOK) 96 101 goto error; … … 107 112 if (panel->curs_color != NULL) 108 113 gfx_color_delete(panel->curs_color); 114 if (panel->act_border_color != NULL) 115 gfx_color_delete(panel->act_border_color); 116 if (panel->dir_color != NULL) 117 gfx_color_delete(panel->dir_color); 109 118 ui_control_delete(panel->control); 110 119 free(panel); … … 121 130 gfx_color_delete(panel->curs_color); 122 131 gfx_color_delete(panel->act_border_color); 132 gfx_color_delete(panel->dir_color); 123 133 panel_clear_entries(panel); 124 134 ui_control_delete(panel->control); … … 157 167 if (entry == panel->cursor && panel->active) 158 168 fmt.color = panel->curs_color; 169 else if (entry->isdir) 170 fmt.color = panel->dir_color; 159 171 else 160 172 fmt.color = panel->color; … … 402 414 * @param panel Panel 403 415 * @param name File name 404 * @param size File size; 416 * @param size File size 417 * @param isdir @c true iff the entry is a directory 405 418 * @return EOK on success or an error code 406 419 */ 407 errno_t panel_entry_append(panel_t *panel, const char *name, uint64_t size) 420 errno_t panel_entry_append(panel_t *panel, const char *name, uint64_t size, 421 bool isdir) 408 422 { 409 423 panel_entry_t *entry; … … 421 435 422 436 entry->size = size; 437 entry->isdir = isdir; 423 438 link_initialize(&entry->lentries); 424 439 list_append(&entry->lentries, &panel->entries); … … 469 484 DIR *dir; 470 485 struct dirent *dirent; 486 vfs_stat_t finfo; 471 487 errno_t rc; 472 488 … … 477 493 dirent = readdir(dir); 478 494 while (dirent != NULL) { 479 rc = panel_entry_append(panel, dirent->d_name, 1);495 rc = vfs_stat_path(dirent->d_name, &finfo); 480 496 if (rc != EOK) 481 497 goto error; 498 499 rc = panel_entry_append(panel, dirent->d_name, 1, 500 finfo.is_directory); 501 if (rc != EOK) 502 goto error; 503 482 504 dirent = readdir(dir); 483 505 } … … 553 575 panel_entry_t *a = *(panel_entry_t **)pa; 554 576 panel_entry_t *b = *(panel_entry_t **)pb; 577 int dcmp; 578 579 /* Sort directories first */ 580 dcmp = b->isdir - a->isdir; 581 if (dcmp != 0) 582 return dcmp; 555 583 556 584 return str_cmp(a->name, b->name); -
uspace/app/nav/panel.h
r03c4b23 r9bed565 58 58 extern void panel_activate(panel_t *); 59 59 extern void panel_deactivate(panel_t *); 60 extern errno_t panel_entry_append(panel_t *, const char *, uint64_t );60 extern errno_t panel_entry_append(panel_t *, const char *, uint64_t, bool); 61 61 extern void panel_entry_delete(panel_entry_t *); 62 62 extern void panel_clear_entries(panel_t *); -
uspace/app/nav/test/panel.c
r03c4b23 r9bed565 73 73 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 74 74 75 rc = panel_entry_append(panel, "a", 1 );75 rc = panel_entry_append(panel, "a", 1, false); 76 76 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 77 77 … … 324 324 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 325 325 326 rc = panel_entry_append(panel, "a", 1 );326 rc = panel_entry_append(panel, "a", 1, false); 327 327 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 328 328 329 329 PCUT_ASSERT_INT_EQUALS(1, list_count(&panel->entries)); 330 330 331 rc = panel_entry_append(panel, "b", 2 );331 rc = panel_entry_append(panel, "b", 2, false); 332 332 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 333 333 … … 347 347 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 348 348 349 rc = panel_entry_append(panel, "a", 1 );350 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 351 352 rc = panel_entry_append(panel, "b", 2 );349 rc = panel_entry_append(panel, "a", 1, false); 350 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 351 352 rc = panel_entry_append(panel, "b", 2, false); 353 353 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 354 354 … … 377 377 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 378 378 379 rc = panel_entry_append(panel, "a", 1 );380 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 381 382 rc = panel_entry_append(panel, "b", 2 );379 rc = panel_entry_append(panel, "a", 1, false); 380 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 381 382 rc = panel_entry_append(panel, "b", 2, false); 383 383 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 384 384 … … 456 456 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 457 457 458 rc = panel_entry_append(panel, "b", 1 );459 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 460 461 rc = panel_entry_append(panel, "c", 3 );462 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 463 464 rc = panel_entry_append(panel, "a", 2 );458 rc = panel_entry_append(panel, "b", 1, false); 459 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 460 461 rc = panel_entry_append(panel, "c", 3, false); 462 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 463 464 rc = panel_entry_append(panel, "a", 2, false); 465 465 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 466 466 … … 494 494 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 495 495 496 rc = panel_entry_append(panel, "a", 2 );497 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 498 499 rc = panel_entry_append(panel, "b", 1 );496 rc = panel_entry_append(panel, "a", 2, false); 497 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 498 499 rc = panel_entry_append(panel, "b", 1, false); 500 500 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 501 501 … … 534 534 535 535 /* Add one entry */ 536 rc = panel_entry_append(panel, "a", 1 );536 rc = panel_entry_append(panel, "a", 1, false); 537 537 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 538 538 … … 544 544 545 545 /* Add another entry */ 546 rc = panel_entry_append(panel, "b", 2 );546 rc = panel_entry_append(panel, "b", 2, false); 547 547 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 548 548 … … 570 570 571 571 /* Add one entry */ 572 rc = panel_entry_append(panel, "a", 1 );572 rc = panel_entry_append(panel, "a", 1, false); 573 573 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 574 574 … … 580 580 581 581 /* Add another entry */ 582 rc = panel_entry_append(panel, "b", 2 );582 rc = panel_entry_append(panel, "b", 2, false); 583 583 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 584 584 … … 603 603 604 604 /* Add one entry */ 605 rc = panel_entry_append(panel, "a", 1 );605 rc = panel_entry_append(panel, "a", 1, false); 606 606 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 607 607 … … 614 614 615 615 /* Add another entry */ 616 rc = panel_entry_append(panel, "b", 2 );616 rc = panel_entry_append(panel, "b", 2, false); 617 617 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 618 618 … … 640 640 641 641 /* Add one entry */ 642 rc = panel_entry_append(panel, "a", 1 );642 rc = panel_entry_append(panel, "a", 1, false); 643 643 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 644 644 … … 651 651 652 652 /* Add another entry */ 653 rc = panel_entry_append(panel, "b", 2 );653 rc = panel_entry_append(panel, "b", 2, false); 654 654 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 655 655 … … 702 702 703 703 /* Add tree entries (more than page size, which is 2) */ 704 rc = panel_entry_append(panel, "a", 1 );705 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 706 707 rc = panel_entry_append(panel, "b", 2 );708 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 709 710 rc = panel_entry_append(panel, "c", 3 );704 rc = panel_entry_append(panel, "a", 1, false); 705 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 706 707 rc = panel_entry_append(panel, "b", 2, false); 708 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 709 710 rc = panel_entry_append(panel, "c", 3, false); 711 711 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 712 712 … … 783 783 784 784 /* Add tree entries (more than page size, which is 2) */ 785 rc = panel_entry_append(panel, "a", 1 );786 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 787 788 rc = panel_entry_append(panel, "b", 2 );789 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 790 791 rc = panel_entry_append(panel, "c", 3 );785 rc = panel_entry_append(panel, "a", 1, false); 786 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 787 788 rc = panel_entry_append(panel, "b", 2, false); 789 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 790 791 rc = panel_entry_append(panel, "c", 3, false); 792 792 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 793 793 … … 866 866 867 867 /* Add tree entries (more than page size, which is 2) */ 868 rc = panel_entry_append(panel, "a", 1 );869 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 870 871 rc = panel_entry_append(panel, "b", 2 );872 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 873 874 rc = panel_entry_append(panel, "c", 3 );868 rc = panel_entry_append(panel, "a", 1, false); 869 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 870 871 rc = panel_entry_append(panel, "b", 2, false); 872 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 873 874 rc = panel_entry_append(panel, "c", 3, false); 875 875 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 876 876 … … 927 927 928 928 /* Add tree entries (more than page size, which is 2) */ 929 rc = panel_entry_append(panel, "a", 1 );930 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 931 932 rc = panel_entry_append(panel, "b", 2 );933 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 934 935 rc = panel_entry_append(panel, "c", 3 );929 rc = panel_entry_append(panel, "a", 1, false); 930 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 931 932 rc = panel_entry_append(panel, "b", 2, false); 933 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 934 935 rc = panel_entry_append(panel, "c", 3, false); 936 936 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 937 937 … … 989 989 990 990 /* Add five entries (2 full pages, one partial) */ 991 rc = panel_entry_append(panel, "a", 1 );992 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 993 994 rc = panel_entry_append(panel, "b", 2 );995 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 996 997 rc = panel_entry_append(panel, "c", 3 );998 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 999 1000 rc = panel_entry_append(panel, "d", 4 );1001 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1002 1003 rc = panel_entry_append(panel, "e", 5 );991 rc = panel_entry_append(panel, "a", 1, false); 992 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 993 994 rc = panel_entry_append(panel, "b", 2, false); 995 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 996 997 rc = panel_entry_append(panel, "c", 3, false); 998 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 999 1000 rc = panel_entry_append(panel, "d", 4, false); 1001 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1002 1003 rc = panel_entry_append(panel, "e", 5, false); 1004 1004 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1005 1005 … … 1077 1077 1078 1078 /* Add five entries (2 full pages, one partial) */ 1079 rc = panel_entry_append(panel, "a", 1 );1080 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1081 1082 rc = panel_entry_append(panel, "b", 2 );1083 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1084 1085 rc = panel_entry_append(panel, "c", 3 );1086 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1087 1088 rc = panel_entry_append(panel, "d", 4 );1089 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1090 1091 rc = panel_entry_append(panel, "e", 5 );1079 rc = panel_entry_append(panel, "a", 1, false); 1080 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1081 1082 rc = panel_entry_append(panel, "b", 2, false); 1083 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1084 1085 rc = panel_entry_append(panel, "c", 3, false); 1086 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1087 1088 rc = panel_entry_append(panel, "d", 4, false); 1089 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1090 1091 rc = panel_entry_append(panel, "e", 5, false); 1092 1092 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1093 1093 -
uspace/app/nav/types/panel.h
r03c4b23 r9bed565 53 53 /** File size */ 54 54 uint64_t size; 55 /** @c true iff entry is a directory */ 56 bool isdir; 55 57 } panel_entry_t; 56 58 … … 77 79 /** Active border color */ 78 80 gfx_color_t *act_border_color; 81 82 /** Directory-type entry color */ 83 gfx_color_t *dir_color; 79 84 80 85 /** Panel entries (list of panel_entry_t) */
Note:
See TracChangeset
for help on using the changeset viewer.