Changeset 9468680 in mainline
- Timestamp:
- 2021-10-19T19:48:40Z (3 years ago)
- Children:
- bdb2a72f
- Parents:
- 516c160
- Location:
- uspace/app/nav
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/panel.c
r516c160 r9468680 519 519 char *ndir = NULL; 520 520 panel_entry_attr_t attr; 521 panel_entry_t *next; 522 panel_entry_t *prev; 523 char *olddn; 524 size_t pg_size; 525 size_t i; 521 526 errno_t rc; 522 527 … … 582 587 panel->page = panel_first(panel); 583 588 panel->page_idx = 0; 589 590 /* Moving up? */ 591 if (str_cmp(dirname, "..") == 0) { 592 /* Get the last component of old path */ 593 olddn = str_rchr(panel->dir, '/'); 594 if (olddn != NULL && *olddn != '\0') { 595 /* Find corresponding entry */ 596 ++olddn; 597 next = panel_next(panel->cursor); 598 while (next != NULL && str_cmp(next->name, olddn) <= 0 && 599 next->isdir) { 600 panel->cursor = next; 601 ++panel->cursor_idx; 602 next = panel_next(panel->cursor); 603 } 604 605 /* Move page so that cursor is in the center */ 606 panel->page = panel->cursor; 607 panel->page_idx = panel->cursor_idx; 608 609 pg_size = panel_page_size(panel); 610 611 for (i = 0; i < pg_size / 2; i++) { 612 prev = panel_prev(panel->page); 613 if (prev == NULL) 614 break; 615 616 panel->page = prev; 617 --panel->page_idx; 618 } 619 } 620 } 621 584 622 free(panel->dir); 585 623 panel->dir = ndir; 624 586 625 return EOK; 587 626 error: … … 974 1013 { 975 1014 gfx_context_t *gc = ui_window_get_gc(panel->window); 1015 char *dirname; 976 1016 errno_t rc; 977 1017 978 1018 assert(entry->isdir); 979 1019 1020 /* 1021 * Need to copy out name before we free the entry below 1022 * via panel_clear_entries(). 1023 */ 1024 dirname = str_dup(entry->name); 1025 if (dirname == NULL) 1026 return ENOMEM; 1027 980 1028 panel_clear_entries(panel); 981 1029 982 rc = panel_read_dir(panel, entry->name); 983 if (rc != EOK) 984 return rc; 1030 rc = panel_read_dir(panel, dirname); 1031 if (rc != EOK) { 1032 free(dirname); 1033 return rc; 1034 } 1035 1036 free(dirname); 985 1037 986 1038 rc = panel_paint(panel); -
uspace/app/nav/test/panel.c
r516c160 r9468680 471 471 rv = remove(p); 472 472 PCUT_ASSERT_INT_EQUALS(0, rv); 473 473 474 free(fname); 475 } 476 477 /** When moving to parent directory from a subdir, we seek to the 478 * coresponding entry 479 */ 480 PCUT_TEST(read_dir_up) 481 { 482 panel_t *panel; 483 char buf[L_tmpnam]; 484 char *subdir_a; 485 char *subdir_b; 486 char *subdir_c; 487 char *p; 488 errno_t rc; 489 int rv; 490 491 /* Create name for temporary directory */ 492 p = tmpnam(buf); 493 PCUT_ASSERT_NOT_NULL(p); 494 495 /* Create temporary directory */ 496 rc = vfs_link_path(p, KIND_DIRECTORY, NULL); 497 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 498 499 /* Create some subdirectories */ 500 501 rv = asprintf(&subdir_a, "%s/%s", p, "a"); 502 PCUT_ASSERT_TRUE(rv >= 0); 503 rc = vfs_link_path(subdir_a, KIND_DIRECTORY, NULL); 504 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 505 506 rv = asprintf(&subdir_b, "%s/%s", p, "b"); 507 PCUT_ASSERT_TRUE(rv >= 0); 508 rc = vfs_link_path(subdir_b, KIND_DIRECTORY, NULL); 509 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 510 511 rv = asprintf(&subdir_c, "%s/%s", p, "c"); 512 PCUT_ASSERT_TRUE(rv >= 0); 513 rc = vfs_link_path(subdir_c, KIND_DIRECTORY, NULL); 514 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 515 516 rc = panel_create(NULL, true, &panel); 517 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 518 519 /* Start in subdirectory "b" */ 520 rc = panel_read_dir(panel, subdir_b); 521 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 522 523 /* Now go up (into p) */ 524 525 rc = panel_read_dir(panel, ".."); 526 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 527 528 PCUT_ASSERT_NOT_NULL(panel->cursor); 529 PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name); 530 531 panel_destroy(panel); 532 533 rv = remove(subdir_a); 534 PCUT_ASSERT_INT_EQUALS(0, rv); 535 536 rv = remove(subdir_b); 537 PCUT_ASSERT_INT_EQUALS(0, rv); 538 539 rv = remove(subdir_c); 540 PCUT_ASSERT_INT_EQUALS(0, rv); 541 542 rv = remove(p); 543 PCUT_ASSERT_INT_EQUALS(0, rv); 544 545 free(subdir_a); 546 free(subdir_b); 547 free(subdir_c); 474 548 } 475 549 … … 594 668 /* Add another entry */ 595 669 attr.name = "b"; 596 attr.size = 2;670 attr.size = 2; 597 671 rc = panel_entry_append(panel, &attr); 598 672 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
Note:
See TracChangeset
for help on using the changeset viewer.