Changeset 0e125698 in mainline
- Timestamp:
- 2021-10-16T20:41:33Z (3 years ago)
- Children:
- fd6dc08
- Parents:
- 9bed565
- Location:
- uspace/app/nav
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/nav.c
r9bed565 r0e125698 263 263 void navigator_switch_panel(navigator_t *navigator) 264 264 { 265 errno_t rc; 266 265 267 if (panel_is_active(navigator->panel[0])) { 268 rc = panel_activate(navigator->panel[1]); 269 if (rc != EOK) 270 return; 266 271 panel_deactivate(navigator->panel[0]); 267 panel_activate(navigator->panel[1]);268 272 } else { 273 rc = panel_activate(navigator->panel[0]); 274 if (rc != EOK) 275 return; 269 276 panel_deactivate(navigator->panel[1]); 270 panel_activate(navigator->panel[0]);271 277 } 272 278 } -
uspace/app/nav/panel.c
r9bed565 r0e125698 281 281 panel_page_down(panel); 282 282 break; 283 case KC_ENTER: 284 panel_open(panel, panel->cursor); 285 break; 283 286 default: 284 287 break; … … 344 347 * 345 348 * @param panel Panel 346 */ 347 void panel_activate(panel_t *panel) 348 { 349 * 350 * @return EOK on success or an error code 351 */ 352 errno_t panel_activate(panel_t *panel) 353 { 354 errno_t rc; 355 356 if (panel->dir != NULL) { 357 rc = vfs_cwd_set(panel->dir); 358 if (rc != EOK) 359 return rc; 360 } 361 349 362 panel->active = true; 350 363 (void) panel_paint(panel); 364 return EOK; 351 365 } 352 366 … … 485 499 struct dirent *dirent; 486 500 vfs_stat_t finfo; 501 char newdir[256]; 502 char *ndir = NULL; 487 503 errno_t rc; 488 504 489 dir = opendir(dirname); 490 if (dir == NULL) 491 return errno; 505 rc = vfs_cwd_set(dirname); 506 if (rc != EOK) 507 return rc; 508 509 rc = vfs_cwd_get(newdir, sizeof(newdir)); 510 if (rc != EOK) 511 return rc; 512 513 ndir = str_dup(newdir); 514 if (ndir == NULL) 515 return ENOMEM; 516 517 dir = opendir("."); 518 if (dir == NULL) { 519 rc = errno; 520 goto error; 521 } 522 523 if (str_cmp(ndir, "/") != 0) { 524 /* Need to add a synthetic up-dir entry */ 525 rc = panel_entry_append(panel, "..", 0, true); 526 if (rc != EOK) 527 goto error; 528 } 492 529 493 530 dirent = readdir(dir); 494 531 while (dirent != NULL) { 495 532 rc = vfs_stat_path(dirent->d_name, &finfo); 496 if (rc != EOK) 497 goto error; 498 499 rc = panel_entry_append(panel, dirent->d_name, 1, 533 if (rc != EOK) { 534 /* Possibly a stale entry */ 535 dirent = readdir(dir); 536 continue; 537 } 538 539 rc = panel_entry_append(panel, dirent->d_name, finfo.size, 500 540 finfo.is_directory); 501 541 if (rc != EOK) … … 515 555 panel->page = panel_first(panel); 516 556 panel->page_idx = 0; 557 free(panel->dir); 558 panel->dir = ndir; 517 559 return EOK; 518 560 error: 519 closedir(dir); 561 (void) vfs_cwd_set(panel->dir); 562 if (ndir != NULL) 563 free(ndir); 564 if (dir != NULL) 565 closedir(dir); 520 566 return rc; 521 567 } … … 870 916 } 871 917 918 /** Open panel entry. 919 * 920 * Perform Open action on a panel entry (e.g. switch to a subdirectory). 921 * 922 * @param panel Panel 923 * @param entry Panel entry 924 * 925 * @return EOK on success or an error code 926 */ 927 errno_t panel_open(panel_t *panel, panel_entry_t *entry) 928 { 929 gfx_context_t *gc = ui_window_get_gc(panel->window); 930 char *dirname; 931 errno_t rc; 932 933 if (!entry->isdir) 934 return EOK; 935 936 dirname = str_dup(entry->name); 937 panel_clear_entries(panel); 938 939 rc = panel_read_dir(panel, dirname); 940 if (rc != EOK) { 941 free(dirname); 942 return rc; 943 } 944 945 rc = panel_paint(panel); 946 if (rc != EOK) { 947 free(dirname); 948 return rc; 949 } 950 951 free(dirname); 952 return gfx_update(gc); 953 } 954 872 955 /** @} 873 956 */ -
uspace/app/nav/panel.h
r9bed565 r0e125698 56 56 extern unsigned panel_page_size(panel_t *); 57 57 extern bool panel_is_active(panel_t *); 58 extern voidpanel_activate(panel_t *);58 extern errno_t panel_activate(panel_t *); 59 59 extern void panel_deactivate(panel_t *); 60 60 extern errno_t panel_entry_append(panel_t *, const char *, uint64_t, bool); … … 75 75 extern void panel_page_up(panel_t *); 76 76 extern void panel_page_down(panel_t *); 77 extern errno_t panel_open(panel_t *, panel_entry_t *); 77 78 78 79 #endif -
uspace/app/nav/test/panel.c
r9bed565 r0e125698 143 143 144 144 event.type = KEY_PRESS; 145 event.key = KC_E NTER;145 event.key = KC_ESCAPE; 146 146 event.mods = 0; 147 147 event.c = '\0'; … … 158 158 159 159 event.type = KEY_PRESS; 160 event.key = KC_E NTER;160 event.key = KC_ESCAPE; 161 161 event.mods = 0; 162 162 event.c = '\0'; … … 277 277 278 278 PCUT_ASSERT_FALSE(panel_is_active(panel)); 279 panel_activate(panel); 279 rc = panel_activate(panel); 280 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 280 281 PCUT_ASSERT_TRUE(panel_is_active(panel)); 281 282 … … 429 430 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 430 431 431 PCUT_ASSERT_INT_EQUALS( 1, list_count(&panel->entries));432 PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries)); 432 433 433 434 entry = panel_first(panel); 434 435 PCUT_ASSERT_NOT_NULL(entry); 436 PCUT_ASSERT_STR_EQUALS("..", entry->name); 437 438 entry = panel_next(entry); 439 PCUT_ASSERT_NOT_NULL(entry); 435 440 PCUT_ASSERT_STR_EQUALS("a", entry->name); 436 //PCUT_ASSERT_INT_EQUALS(1, entry->size);441 PCUT_ASSERT_INT_EQUALS(1, entry->size); 437 442 438 443 panel_destroy(panel); … … 1136 1141 } 1137 1142 1143 /** panel_open() opens a directory entry */ 1144 PCUT_TEST(open) 1145 { 1146 ui_t *ui; 1147 ui_window_t *window; 1148 ui_wnd_params_t params; 1149 panel_t *panel; 1150 panel_entry_t *entry; 1151 char buf[L_tmpnam]; 1152 char *sdname; 1153 char *p; 1154 errno_t rc; 1155 int rv; 1156 1157 rc = ui_create_disp(NULL, &ui); 1158 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1159 1160 ui_wnd_params_init(¶ms); 1161 params.caption = "Test"; 1162 1163 rc = ui_window_create(ui, ¶ms, &window); 1164 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1165 1166 /* Create name for temporary directory */ 1167 p = tmpnam(buf); 1168 PCUT_ASSERT_NOT_NULL(p); 1169 1170 /* Create temporary directory */ 1171 rc = vfs_link_path(p, KIND_DIRECTORY, NULL); 1172 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1173 1174 rv = asprintf(&sdname, "%s/%s", p, "a"); 1175 PCUT_ASSERT_TRUE(rv >= 0); 1176 1177 /* Create sub-directory */ 1178 rc = vfs_link_path(sdname, KIND_DIRECTORY, NULL); 1179 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1180 1181 rc = panel_create(window, true, &panel); 1182 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1183 1184 rc = panel_read_dir(panel, p); 1185 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1186 PCUT_ASSERT_STR_EQUALS(p, panel->dir); 1187 1188 PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries)); 1189 1190 entry = panel_first(panel); 1191 PCUT_ASSERT_NOT_NULL(entry); 1192 PCUT_ASSERT_STR_EQUALS("..", entry->name); 1193 1194 entry = panel_next(entry); 1195 PCUT_ASSERT_NOT_NULL(entry); 1196 PCUT_ASSERT_STR_EQUALS("a", entry->name); 1197 PCUT_ASSERT_TRUE(entry->isdir); 1198 1199 rc = panel_open(panel, entry); 1200 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1201 1202 PCUT_ASSERT_STR_EQUALS(sdname, panel->dir); 1203 1204 panel_destroy(panel); 1205 ui_window_destroy(window); 1206 ui_destroy(ui); 1207 1208 rv = remove(sdname); 1209 PCUT_ASSERT_INT_EQUALS(0, rv); 1210 1211 rv = remove(p); 1212 PCUT_ASSERT_INT_EQUALS(0, rv); 1213 1214 free(sdname); 1215 } 1216 1138 1217 PCUT_EXPORT(panel); -
uspace/app/nav/types/panel.h
r9bed565 r0e125698 103 103 /** @c true iff the panel is active */ 104 104 bool active; 105 106 /** Directory */ 107 char *dir; 105 108 } panel_t; 106 109
Note:
See TracChangeset
for help on using the changeset viewer.