Changes in uspace/app/nav/nav.c [54ddb59:b336bfd8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/nav.c
r54ddb59 rb336bfd8 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 #include <stdlib.h> 40 40 #include <str.h> 41 #include <task.h> 41 42 #include <ui/fixed.h> 42 43 #include <ui/filelist.h> … … 48 49 #include "panel.h" 49 50 51 #define EDITOR_CMD "/app/edit" 52 50 53 static void wnd_close(ui_window_t *, void *); 51 54 static void wnd_kbd(ui_window_t *, void *, kbd_event_t *); … … 57 60 58 61 static void navigator_file_open(void *); 62 static void navigator_file_edit(void *); 59 63 static void navigator_file_exit(void *); 60 64 61 65 static nav_menu_cb_t navigator_menu_cb = { 62 66 .file_open = navigator_file_open, 67 .file_edit = navigator_file_edit, 63 68 .file_exit = navigator_file_exit 64 69 }; 65 70 66 71 static void navigator_panel_activate_req(void *, panel_t *); 72 static void navigator_panel_file_open(void *, panel_t *, const char *); 67 73 68 74 static panel_cb_t navigator_panel_cb = { 69 .activate_req = navigator_panel_activate_req 75 .activate_req = navigator_panel_activate_req, 76 .file_open = navigator_panel_file_open 70 77 }; 71 78 … … 97 104 (event->mods & KM_CTRL) != 0) { 98 105 switch (event->key) { 106 case KC_E: 107 navigator_file_edit((void *)navigator); 108 break; 99 109 case KC_Q: 100 110 ui_quit(navigator->ui); … … 318 328 } 319 329 330 /** Open file in text editor. 331 * 332 * @param navigator Navigator 333 * @param fname File name 334 * 335 * @return EOK on success or an error code 336 */ 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 Navigator 374 * @param fname File name 375 * 376 * @return EOK on success or an error code 377 */ 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 Navigator 417 * @param fname File name 418 * 419 * @return EOK on success or an error code 420 */ 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 320 449 /** File / Exit menu entry selected */ 321 450 static void navigator_file_exit(void *arg) … … 339 468 } 340 469 470 /** Panel callback requesting file open. 471 * 472 * @param arg Argument (navigator_t *) 473 * @param panel Panel 474 * @param fname File name 475 */ 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 341 484 /** @} 342 485 */
Note:
See TracChangeset
for help on using the changeset viewer.