Changeset f9c4c433 in mainline
- Timestamp:
- 2025-09-16T13:02:37Z (5 months ago)
- Branches:
- master
- Children:
- 283bb9f
- Parents:
- 113fb4f
- Location:
- uspace
- Files:
-
- 5 added
- 16 edited
-
app/nav/dlg/newfiledlg.c (added)
-
app/nav/dlg/newfiledlg.h (added)
-
app/nav/menu.c (modified) (3 diffs)
-
app/nav/menu.h (modified) (1 diff)
-
app/nav/meson.build (modified) (2 diffs)
-
app/nav/nav.c (modified) (5 diffs)
-
app/nav/nav.h (modified) (2 diffs)
-
app/nav/newfile.c (added)
-
app/nav/newfile.h (added)
-
app/nav/panel.c (modified) (1 diff)
-
app/nav/panel.h (modified) (2 diffs)
-
app/nav/types/dlg/newfiledlg.h (added)
-
app/nav/types/menu.h (modified) (1 diff)
-
lib/ui/include/types/ui/list.h (modified) (3 diffs)
-
lib/ui/include/ui/filelist.h (modified) (1 diff)
-
lib/ui/include/ui/list.h (modified) (2 diffs)
-
lib/ui/src/filelist.c (modified) (3 diffs)
-
lib/ui/src/list.c (modified) (2 diffs)
-
lib/ui/src/msgdialog.c (modified) (4 diffs)
-
lib/ui/test/filelist.c (modified) (2 diffs)
-
lib/ui/test/list.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/menu.c
r113fb4f rf9c4c433 54 54 nav_menu_t *menu; 55 55 ui_menu_t *mfile; 56 ui_menu_entry_t *mnew; 56 57 ui_menu_entry_t *mopen; 57 58 ui_menu_entry_t *medit; … … 78 79 goto error; 79 80 81 rc = ui_menu_entry_create(mfile, "~N~ew File", "Ctrl-M", &mnew); 82 if (rc != EOK) 83 goto error; 84 85 ui_menu_entry_set_cb(mnew, nav_menu_file_new_file, (void *) menu); 86 80 87 rc = ui_menu_entry_create(mfile, "~O~pen", "Enter", &mopen); 81 88 if (rc != EOK) … … 148 155 } 149 156 157 /** File / New File menu entry selected. 158 * 159 * @param mentry Menu entry 160 * @param arg Argument (navigator_t *) 161 */ 162 void nav_menu_file_new_file(ui_menu_entry_t *mentry, void *arg) 163 { 164 nav_menu_t *menu = (nav_menu_t *)arg; 165 166 if (menu->cb != NULL && menu->cb->file_new_file != NULL) 167 menu->cb->file_new_file(menu->cb_arg); 168 } 169 150 170 /** File / Open menu entry selected. 151 171 * -
uspace/app/nav/menu.h
r113fb4f rf9c4c433 46 46 extern void nav_menu_destroy(nav_menu_t *); 47 47 extern ui_control_t *nav_menu_ctl(nav_menu_t *); 48 extern void nav_menu_file_new_file(ui_menu_entry_t *, void *); 48 49 extern void nav_menu_file_open(ui_menu_entry_t *, void *); 49 50 extern void nav_menu_file_edit(ui_menu_entry_t *, void *); -
uspace/app/nav/meson.build
r113fb4f rf9c4c433 1 1 # 2 # Copyright (c) 202 1Jiri Svoboda2 # Copyright (c) 2025 Jiri Svoboda 3 3 # All rights reserved. 4 4 # … … 29 29 deps = [ 'ui' ] 30 30 src = files( 31 'dlg/newfiledlg.c', 31 32 'main.c', 32 33 'menu.c', 33 34 'nav.c', 35 'newfile.c', 34 36 'panel.c', 35 37 ) 36 38 37 39 test_src = files( 40 'dlg/newfiledlg.c', 38 41 'menu.c', 39 42 'nav.c', 43 'newfile.c', 40 44 'panel.c', 41 45 'test/main.c', -
uspace/app/nav/nav.c
r113fb4f rf9c4c433 46 46 #include <ui/window.h> 47 47 #include "menu.h" 48 #include "newfile.h" 48 49 #include "nav.h" 49 50 #include "panel.h" … … 59 60 }; 60 61 62 static void navigator_file_new_file(void *); 61 63 static void navigator_file_open(void *); 62 64 static void navigator_file_edit(void *); … … 64 66 65 67 static nav_menu_cb_t navigator_menu_cb = { 68 .file_new_file = navigator_file_new_file, 66 69 .file_open = navigator_file_open, 67 70 .file_edit = navigator_file_edit, … … 104 107 (event->mods & KM_CTRL) != 0) { 105 108 switch (event->key) { 109 case KC_M: 110 navigator_new_file_dlg(navigator); 111 break; 106 112 case KC_E: 107 113 navigator_file_edit((void *)navigator); … … 318 324 } 319 325 326 /** Refresh navigator panels. 327 * 328 * This needs to be called when the disk/directory contents might have 329 * changed. 330 * 331 * @param navigator Navigator 332 */ 333 void navigator_refresh_panels(navigator_t *navigator) 334 { 335 errno_t rc; 336 unsigned i; 337 338 /* First refresh inactive panel. */ 339 340 for (i = 0; i < 2; i++) { 341 if (!panel_is_active(navigator->panel[i])) { 342 rc = panel_refresh(navigator->panel[i]); 343 if (rc != EOK) 344 return; 345 } 346 } 347 348 /* 349 * Refresh active panel last so that working directory is left 350 * to that of the active panel. 351 */ 352 353 for (i = 0; i < 2; i++) { 354 if (panel_is_active(navigator->panel[i])) { 355 rc = panel_refresh(navigator->panel[i]); 356 if (rc != EOK) 357 return; 358 } 359 } 360 } 361 362 /** File / New File menu entry selected */ 363 static void navigator_file_new_file(void *arg) 364 { 365 navigator_t *navigator = (navigator_t *)arg; 366 367 navigator_new_file_dlg(navigator); 368 } 369 320 370 /** File / Open menu entry selected */ 321 371 static void navigator_file_open(void *arg) -
uspace/app/nav/nav.h
r113fb4f rf9c4c433 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 46 46 extern panel_t *navigator_get_active_panel(navigator_t *); 47 47 extern void navigator_switch_panel(navigator_t *); 48 extern void navigator_refresh_panels(navigator_t *); 48 49 49 50 #endif -
uspace/app/nav/panel.c
r113fb4f rf9c4c433 365 365 } 366 366 367 /** Refresh panel contents. 368 * 369 * @param panel Panel 370 * @return EOK on success or an error code 371 */ 372 errno_t panel_refresh(panel_t *panel) 373 { 374 errno_t rc; 375 376 rc = ui_file_list_refresh(panel->flist); 377 if (rc != EOK) 378 return rc; 379 380 return panel_paint(panel); 381 } 382 367 383 /** Request panel activation. 368 384 * -
uspace/app/nav/panel.h
r113fb4f rf9c4c433 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 58 58 extern void panel_deactivate(panel_t *); 59 59 extern errno_t panel_read_dir(panel_t *, const char *); 60 extern errno_t panel_refresh(panel_t *); 60 61 extern void panel_activate_req(panel_t *); 61 62 -
uspace/app/nav/types/menu.h
r113fb4f rf9c4c433 43 43 /** Navigator menu callbacks */ 44 44 typedef struct nav_menu_cb { 45 /** File / New File */ 46 void (*file_new_file)(void *); 45 47 /** File / Open */ 46 48 void (*file_open)(void *); -
uspace/lib/ui/include/types/ui/list.h
r113fb4f rf9c4c433 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 38 38 39 39 #include <gfx/color.h> 40 #include <stddef.h> 40 41 41 42 struct ui_list; … … 67 68 } ui_list_cb_t; 68 69 70 /** Saved list position. */ 71 typedef struct { 72 /** Page index */ 73 size_t page_idx; 74 /** Cursor index */ 75 size_t cursor_idx; 76 } ui_list_pos_t; 77 69 78 #endif 70 79 -
uspace/lib/ui/include/ui/filelist.h
r113fb4f rf9c4c433 51 51 extern errno_t ui_file_list_read_dir(ui_file_list_t *, const char *); 52 52 extern errno_t ui_file_list_activate(ui_file_list_t *); 53 extern errno_t ui_file_list_refresh(ui_file_list_t *); 53 54 extern void ui_file_list_deactivate(ui_file_list_t *); 54 55 extern errno_t ui_file_list_open(ui_file_list_t *, ui_file_list_entry_t *); -
uspace/lib/ui/include/ui/list.h
r113fb4f rf9c4c433 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 71 71 extern ui_list_entry_t *ui_list_prev(ui_list_entry_t *); 72 72 extern bool ui_list_is_active(ui_list_t *); 73 extern void ui_list_save_pos(ui_list_t *, ui_list_pos_t *); 74 extern void ui_list_restore_pos(ui_list_t *, ui_list_pos_t *); 73 75 74 76 #endif -
uspace/lib/ui/src/filelist.c
r113fb4f rf9c4c433 349 349 goto error; 350 350 } 351 352 ui_file_list_clear_entries(flist); 351 353 352 354 if (str_cmp(ndir, "/") != 0) { … … 422 424 } 423 425 426 /** Re-read file list from directory. 427 * 428 * @param flist File list 429 * @return EOK on success or an error code 430 */ 431 errno_t ui_file_list_refresh(ui_file_list_t *flist) 432 { 433 errno_t rc; 434 ui_list_pos_t pos; 435 436 ui_list_save_pos(flist->list, &pos); 437 rc = ui_file_list_read_dir(flist, flist->dir); 438 if (rc != EOK) 439 return rc; 440 ui_list_restore_pos(flist->list, &pos); 441 return EOK; 442 } 443 424 444 /** Sort file list entries. 425 445 * … … 593 613 return ENOMEM; 594 614 595 ui_file_list_clear_entries(flist);596 597 615 rc = ui_file_list_read_dir(flist, dirname); 598 616 if (rc != EOK) { -
uspace/lib/ui/src/list.c
r113fb4f rf9c4c433 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 1652 1652 } 1653 1653 1654 /** Save list position for later. 1655 * 1656 * The position will be valid even if the list is cleaned and re-populated 1657 * (it just counts position from the top.) 1658 * 1659 * @param list UI list 1660 * @param pos Place to store position 1661 */ 1662 void ui_list_save_pos(ui_list_t *list, ui_list_pos_t *pos) 1663 { 1664 pos->page_idx = list->page_idx; 1665 pos->cursor_idx = list->cursor_idx; 1666 } 1667 1668 /** Restore saved list position. 1669 * 1670 * The position will be valid even if the list is cleaned and re-populated 1671 * (it just counts position from the top.) 1672 * 1673 * @param list UI list 1674 * @param pos Saved list position 1675 */ 1676 void ui_list_restore_pos(ui_list_t *list, ui_list_pos_t *pos) 1677 { 1678 size_t idx, i; 1679 ui_list_entry_t *entry, *next; 1680 1681 idx = 0; 1682 entry = ui_list_first(list); 1683 1684 for (i = 0; i < pos->cursor_idx; i++) { 1685 next = ui_list_next(entry); 1686 if (next != NULL) { 1687 entry = next; 1688 ++idx; 1689 } 1690 } 1691 1692 list->cursor = entry; 1693 list->cursor_idx = idx; 1694 1695 idx = 0; 1696 entry = ui_list_first(list); 1697 1698 for (i = 0; i < pos->page_idx; i++) { 1699 next = ui_list_next(entry); 1700 if (next != NULL) { 1701 entry = next; 1702 ++idx; 1703 } 1704 } 1705 1706 list->page = entry; 1707 list->page_idx = idx; 1708 } 1709 1654 1710 /** @} 1655 1711 */ -
uspace/lib/ui/src/msgdialog.c
r113fb4f rf9c4c433 285 285 if (dialog->cb != NULL && dialog->cb->close != NULL) 286 286 dialog->cb->close(dialog, dialog->arg); 287 else 288 ui_msg_dialog_destroy(dialog); 287 289 } 288 290 … … 310 312 dialog->cb->button(dialog, dialog->arg, 0); 311 313 return; 314 } else { 315 ui_msg_dialog_destroy(dialog); 312 316 } 313 317 } else if (event->key == KC_ESCAPE) { … … 316 320 dialog->cb->close(dialog, dialog->arg); 317 321 return; 322 } else { 323 ui_msg_dialog_destroy(dialog); 318 324 } 319 325 } … … 337 343 dialog->cb->button(dialog, dialog->arg, i); 338 344 } 345 } else { 346 ui_msg_dialog_destroy(dialog); 339 347 } 340 348 } -
uspace/lib/ui/test/filelist.c
r113fb4f rf9c4c433 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 665 665 } 666 666 667 /** ui_file_list_refresh() */ 668 PCUT_TEST(refresh) 669 { 670 ui_t *ui; 671 ui_window_t *window; 672 ui_wnd_params_t params; 673 ui_file_list_t *flist; 674 ui_file_list_entry_t *entry; 675 char buf[L_tmpnam]; 676 char *fname; 677 char *p; 678 errno_t rc; 679 FILE *f; 680 int rv; 681 682 /* Create name for temporary directory */ 683 p = tmpnam(buf); 684 PCUT_ASSERT_NOT_NULL(p); 685 686 /* Create temporary directory */ 687 rc = vfs_link_path(p, KIND_DIRECTORY, NULL); 688 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 689 690 rv = asprintf(&fname, "%s/%s", p, "a"); 691 PCUT_ASSERT_TRUE(rv >= 0); 692 693 f = fopen(fname, "wb"); 694 PCUT_ASSERT_NOT_NULL(f); 695 696 rv = fprintf(f, "X"); 697 PCUT_ASSERT_TRUE(rv >= 0); 698 699 rv = fclose(f); 700 PCUT_ASSERT_INT_EQUALS(0, rv); 701 702 rc = ui_create_disp(NULL, &ui); 703 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 704 705 ui_wnd_params_init(¶ms); 706 params.caption = "Test"; 707 708 rc = ui_window_create(ui, ¶ms, &window); 709 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 710 711 rc = ui_file_list_create(window, true, &flist); 712 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 713 714 rc = ui_file_list_read_dir(flist, p); 715 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 716 717 PCUT_ASSERT_INT_EQUALS(2, ui_list_entries_cnt(flist->list)); 718 719 entry = ui_file_list_first(flist); 720 PCUT_ASSERT_NOT_NULL(entry); 721 PCUT_ASSERT_STR_EQUALS("..", entry->name); 722 723 entry = ui_file_list_next(entry); 724 PCUT_ASSERT_NOT_NULL(entry); 725 PCUT_ASSERT_STR_EQUALS("a", entry->name); 726 PCUT_ASSERT_INT_EQUALS(1, entry->size); 727 728 rv = remove(fname); 729 PCUT_ASSERT_INT_EQUALS(0, rv); 730 free(fname); 731 732 rv = asprintf(&fname, "%s/%s", p, "b"); 733 PCUT_ASSERT_TRUE(rv >= 0); 734 735 f = fopen(fname, "wb"); 736 PCUT_ASSERT_NOT_NULL(f); 737 738 rv = fprintf(f, "X"); 739 PCUT_ASSERT_TRUE(rv >= 0); 740 741 rv = fclose(f); 742 PCUT_ASSERT_INT_EQUALS(0, rv); 743 744 rc = ui_file_list_refresh(flist); 745 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 746 747 entry = ui_file_list_first(flist); 748 PCUT_ASSERT_NOT_NULL(entry); 749 PCUT_ASSERT_STR_EQUALS("..", entry->name); 750 751 entry = ui_file_list_next(entry); 752 PCUT_ASSERT_NOT_NULL(entry); 753 PCUT_ASSERT_STR_EQUALS("b", entry->name); 754 PCUT_ASSERT_INT_EQUALS(1, entry->size); 755 756 rv = remove(fname); 757 PCUT_ASSERT_INT_EQUALS(0, rv); 758 free(fname); 759 760 rv = remove(p); 761 PCUT_ASSERT_INT_EQUALS(0, rv); 762 763 ui_file_list_destroy(flist); 764 765 ui_window_destroy(window); 766 ui_destroy(ui); 767 } 768 667 769 /** ui_file_list_list_compare compares two file list entries */ 668 770 PCUT_TEST(list_compare) -
uspace/lib/ui/test/list.c
r113fb4f rf9c4c433 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 3064 3064 } 3065 3065 3066 /** ui_list_save_pos() / ui_list_restore_pos() saves/restores position */ 3067 PCUT_TEST(save_pos_restore_pos) 3068 { 3069 ui_t *ui; 3070 ui_window_t *window; 3071 ui_wnd_params_t params; 3072 ui_list_t *list; 3073 ui_list_entry_t *a, *b; 3074 ui_list_entry_attr_t attr; 3075 ui_list_pos_t pos; 3076 test_resp_t resp; 3077 errno_t rc; 3078 3079 rc = ui_create_disp(NULL, &ui); 3080 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3081 3082 ui_wnd_params_init(¶ms); 3083 params.caption = "Test"; 3084 3085 rc = ui_window_create(ui, ¶ms, &window); 3086 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3087 3088 rc = ui_list_create(window, true, &list); 3089 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3090 3091 ui_list_set_cb(list, &test_cb, &resp); 3092 3093 ui_list_entry_attr_init(&attr); 3094 3095 attr.caption = "a"; 3096 attr.arg = (void *)2; 3097 rc = ui_list_entry_append(list, &attr, &a); 3098 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3099 3100 attr.caption = "b"; 3101 attr.arg = (void *)1; 3102 rc = ui_list_entry_append(list, &attr, &b); 3103 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3104 3105 ui_list_set_cursor(list, b); 3106 3107 ui_list_save_pos(list, &pos); 3108 3109 /* Empty and re-build list. */ 3110 3111 ui_list_entry_destroy(a); 3112 ui_list_entry_destroy(b); 3113 3114 ui_list_entry_attr_init(&attr); 3115 3116 attr.caption = "a"; 3117 attr.arg = (void *)2; 3118 rc = ui_list_entry_append(list, &attr, &a); 3119 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3120 3121 attr.caption = "b"; 3122 attr.arg = (void *)1; 3123 rc = ui_list_entry_append(list, &attr, &b); 3124 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 3125 3126 ui_list_restore_pos(list, &pos); 3127 3128 PCUT_ASSERT_STR_EQUALS("b", list->cursor->caption); 3129 3130 ui_list_destroy(list); 3131 ui_window_destroy(window); 3132 ui_destroy(ui); 3133 } 3134 3066 3135 static void test_list_activate_req(ui_list_t *list, void *arg) 3067 3136 {
Note:
See TracChangeset
for help on using the changeset viewer.
