Changeset b336bfd8 in mainline
- Timestamp:
- 2025-02-06T20:42:14Z (6 days ago)
- Branches:
- master
- Children:
- a7a16a2f
- Parents:
- accdf882
- Location:
- uspace/app/nav
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/nav.c
raccdf882 rb336bfd8 70 70 71 71 static void navigator_panel_activate_req(void *, panel_t *); 72 static void navigator_panel_file_open(void *, panel_t *, const char *); 72 73 73 74 static panel_cb_t navigator_panel_cb = { 74 .activate_req = navigator_panel_activate_req 75 .activate_req = navigator_panel_activate_req, 76 .file_open = navigator_panel_file_open 75 77 }; 76 78 … … 328 330 /** Open file in text editor. 329 331 * 330 * @param panel Panel332 * @param navigator Navigator 331 333 * @param fname File name 332 334 * … … 367 369 } 368 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 369 434 /** File / Edit menu entry selected */ 370 435 static void navigator_file_edit(void *arg) … … 403 468 } 404 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 405 484 /** @} 406 485 */ -
uspace/app/nav/panel.c
raccdf882 rb336bfd8 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 377 377 } 378 378 379 /** Open panel file entry.380 *381 * Perform Open action on a file entry (i.e. try running it).382 *383 * @param panel Panel384 * @param fname File name385 *386 * @return EOK on success or an error code387 */388 static errno_t panel_open_file(panel_t *panel, const char *fname)389 {390 task_id_t id;391 task_wait_t wait;392 task_exit_t texit;393 int retval;394 errno_t rc;395 ui_t *ui;396 397 ui = ui_window_get_ui(panel->window);398 399 /* Free up and clean console for the child task. */400 rc = ui_suspend(ui);401 if (rc != EOK)402 return rc;403 404 rc = task_spawnl(&id, &wait, fname, fname, NULL);405 if (rc != EOK)406 goto error;407 408 rc = task_wait(&wait, &texit, &retval);409 if ((rc != EOK) || (texit != TASK_EXIT_NORMAL))410 goto error;411 412 /* Resume UI operation */413 rc = ui_resume(ui);414 if (rc != EOK)415 return rc;416 417 (void) ui_paint(ui_window_get_ui(panel->window));418 return EOK;419 error:420 (void) ui_resume(ui);421 (void) ui_paint(ui_window_get_ui(panel->window));422 return rc;423 }424 425 379 /** File list in panel requests activation. 426 380 * … … 446 400 panel_t *panel = (panel_t *)arg; 447 401 448 (void) panel_open_file(panel, fname); 402 if (panel->cb != NULL && panel->cb->file_open != NULL) 403 panel->cb->file_open(panel->cb_arg, panel, fname); 449 404 } 450 405 -
uspace/app/nav/types/panel.h
raccdf882 rb336bfd8 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 80 80 /** Request panel activation */ 81 81 void (*activate_req)(void *, panel_t *); 82 /** Open file */ 83 void (*file_open)(void *, panel_t *, const char *); 82 84 } panel_cb_t; 83 85
Note:
See TracChangeset
for help on using the changeset viewer.