Changes in uspace/app/nav/nav.c [b336bfd8:54ddb59] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nav/nav.c

    rb336bfd8 r54ddb59  
    11/*
    2  * Copyright (c) 2025 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939#include <stdlib.h>
    4040#include <str.h>
    41 #include <task.h>
    4241#include <ui/fixed.h>
    4342#include <ui/filelist.h>
     
    4948#include "panel.h"
    5049
    51 #define EDITOR_CMD "/app/edit"
    52 
    5350static void wnd_close(ui_window_t *, void *);
    5451static void wnd_kbd(ui_window_t *, void *, kbd_event_t *);
     
    6057
    6158static void navigator_file_open(void *);
    62 static void navigator_file_edit(void *);
    6359static void navigator_file_exit(void *);
    6460
    6561static nav_menu_cb_t navigator_menu_cb = {
    6662        .file_open = navigator_file_open,
    67         .file_edit = navigator_file_edit,
    6863        .file_exit = navigator_file_exit
    6964};
    7065
    7166static void navigator_panel_activate_req(void *, panel_t *);
    72 static void navigator_panel_file_open(void *, panel_t *, const char *);
    7367
    7468static 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
    7770};
    7871
     
    10497            (event->mods & KM_CTRL) != 0) {
    10598                switch (event->key) {
    106                 case KC_E:
    107                         navigator_file_edit((void *)navigator);
    108                         break;
    10999                case KC_Q:
    110100                        ui_quit(navigator->ui);
     
    328318}
    329319
    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 
    449320/** File / Exit menu entry selected */
    450321static void navigator_file_exit(void *arg)
     
    468339}
    469340
    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 
    484341/** @}
    485342 */
Note: See TracChangeset for help on using the changeset viewer.