Changes in uspace/app/nav/nav.c [b336bfd8:54ddb59] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/nav.c
rb336bfd8 r54ddb59 1 1 /* 2 * Copyright (c) 202 5Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 #include <stdlib.h> 40 40 #include <str.h> 41 #include <task.h>42 41 #include <ui/fixed.h> 43 42 #include <ui/filelist.h> … … 49 48 #include "panel.h" 50 49 51 #define EDITOR_CMD "/app/edit"52 53 50 static void wnd_close(ui_window_t *, void *); 54 51 static void wnd_kbd(ui_window_t *, void *, kbd_event_t *); … … 60 57 61 58 static void navigator_file_open(void *); 62 static void navigator_file_edit(void *);63 59 static void navigator_file_exit(void *); 64 60 65 61 static nav_menu_cb_t navigator_menu_cb = { 66 62 .file_open = navigator_file_open, 67 .file_edit = navigator_file_edit,68 63 .file_exit = navigator_file_exit 69 64 }; 70 65 71 66 static void navigator_panel_activate_req(void *, panel_t *); 72 static void navigator_panel_file_open(void *, panel_t *, const char *);73 67 74 68 static panel_cb_t navigator_panel_cb = { 75 .activate_req = navigator_panel_activate_req, 76 .file_open = navigator_panel_file_open 69 .activate_req = navigator_panel_activate_req 77 70 }; 78 71 … … 104 97 (event->mods & KM_CTRL) != 0) { 105 98 switch (event->key) { 106 case KC_E:107 navigator_file_edit((void *)navigator);108 break;109 99 case KC_Q: 110 100 ui_quit(navigator->ui); … … 328 318 } 329 319 330 /** Open file in text editor.331 *332 * @param navigator Navigator333 * @param fname File name334 *335 * @return EOK on success or an error code336 */337 static errno_t navigator_edit_file(navigator_t *navigator, const char *fname)338 {339 task_id_t id;340 task_wait_t wait;341 task_exit_t texit;342 int retval;343 errno_t rc;344 345 /* Free up and clean console for the child task. */346 rc = ui_suspend(navigator->ui);347 if (rc != EOK)348 return rc;349 350 rc = task_spawnl(&id, &wait, EDITOR_CMD, EDITOR_CMD, fname, NULL);351 if (rc != EOK)352 goto error;353 354 rc = task_wait(&wait, &texit, &retval);355 if ((rc != EOK) || (texit != TASK_EXIT_NORMAL))356 goto error;357 358 /* Resume UI operation */359 rc = ui_resume(navigator->ui);360 if (rc != EOK)361 return rc;362 363 (void) ui_paint(navigator->ui);364 return EOK;365 error:366 (void) ui_resume(navigator->ui);367 (void) ui_paint(navigator->ui);368 return rc;369 }370 371 /** Execute file entry.372 *373 * @param navigator Navigator374 * @param fname File name375 *376 * @return EOK on success or an error code377 */378 static errno_t navigator_exec_file(navigator_t *navigator, const char *fname)379 {380 task_id_t id;381 task_wait_t wait;382 task_exit_t texit;383 int retval;384 errno_t rc;385 386 /* Free up and clean console for the child task. */387 rc = ui_suspend(navigator->ui);388 if (rc != EOK)389 return rc;390 391 rc = task_spawnl(&id, &wait, fname, fname, NULL);392 if (rc != EOK)393 goto error;394 395 rc = task_wait(&wait, &texit, &retval);396 if ((rc != EOK) || (texit != TASK_EXIT_NORMAL))397 goto error;398 399 /* Resume UI operation */400 rc = ui_resume(navigator->ui);401 if (rc != EOK)402 return rc;403 404 (void) ui_paint(navigator->ui);405 return EOK;406 error:407 (void) ui_resume(navigator->ui);408 (void) ui_paint(navigator->ui);409 return rc;410 }411 412 /** Open panel file entry.413 *414 * Perform Open action on a file entry (based on extension).415 *416 * @param navigator Navigator417 * @param fname File name418 *419 * @return EOK on success or an error code420 */421 static errno_t navigator_open_file(navigator_t *navigator, const char *fname)422 {423 const char *ext;424 425 ext = str_rchr(fname, '.');426 if (ext != NULL) {427 if (str_casecmp(ext, ".txt") == 0)428 return navigator_edit_file(navigator, fname);429 }430 431 return navigator_exec_file(navigator, fname);432 }433 434 /** File / Edit menu entry selected */435 static void navigator_file_edit(void *arg)436 {437 navigator_t *navigator = (navigator_t *)arg;438 ui_file_list_entry_t *entry;439 ui_file_list_entry_attr_t attr;440 panel_t *panel;441 442 panel = navigator_get_active_panel(navigator);443 entry = ui_file_list_get_cursor(panel->flist);444 ui_file_list_entry_get_attr(entry, &attr);445 446 (void)navigator_edit_file(navigator, attr.name);447 }448 449 320 /** File / Exit menu entry selected */ 450 321 static void navigator_file_exit(void *arg) … … 468 339 } 469 340 470 /** Panel callback requesting file open.471 *472 * @param arg Argument (navigator_t *)473 * @param panel Panel474 * @param fname File name475 */476 void navigator_panel_file_open(void *arg, panel_t *panel, const char *fname)477 {478 navigator_t *navigator = (navigator_t *)arg;479 480 (void)panel;481 navigator_open_file(navigator, fname);482 }483 484 341 /** @} 485 342 */
Note:
See TracChangeset
for help on using the changeset viewer.