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


Ignore:
File:
1 edited

Legend:

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

    r54ddb59 raccdf882  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939#include <stdlib.h>
    4040#include <str.h>
     41#include <task.h>
    4142#include <ui/fixed.h>
    4243#include <ui/filelist.h>
     
    4849#include "panel.h"
    4950
     51#define EDITOR_CMD "/app/edit"
     52
    5053static void wnd_close(ui_window_t *, void *);
    5154static void wnd_kbd(ui_window_t *, void *, kbd_event_t *);
     
    5760
    5861static void navigator_file_open(void *);
     62static void navigator_file_edit(void *);
    5963static void navigator_file_exit(void *);
    6064
    6165static nav_menu_cb_t navigator_menu_cb = {
    6266        .file_open = navigator_file_open,
     67        .file_edit = navigator_file_edit,
    6368        .file_exit = navigator_file_exit
    6469};
     
    97102            (event->mods & KM_CTRL) != 0) {
    98103                switch (event->key) {
     104                case KC_E:
     105                        navigator_file_edit((void *)navigator);
     106                        break;
    99107                case KC_Q:
    100108                        ui_quit(navigator->ui);
     
    318326}
    319327
     328/** Open file in text editor.
     329 *
     330 * @param panel Panel
     331 * @param fname File name
     332 *
     333 * @return EOK on success or an error code
     334 */
     335static errno_t navigator_edit_file(navigator_t *navigator, const char *fname)
     336{
     337        task_id_t id;
     338        task_wait_t wait;
     339        task_exit_t texit;
     340        int retval;
     341        errno_t rc;
     342
     343        /* Free up and clean console for the child task. */
     344        rc = ui_suspend(navigator->ui);
     345        if (rc != EOK)
     346                return rc;
     347
     348        rc = task_spawnl(&id, &wait, EDITOR_CMD, EDITOR_CMD, fname, NULL);
     349        if (rc != EOK)
     350                goto error;
     351
     352        rc = task_wait(&wait, &texit, &retval);
     353        if ((rc != EOK) || (texit != TASK_EXIT_NORMAL))
     354                goto error;
     355
     356        /* Resume UI operation */
     357        rc = ui_resume(navigator->ui);
     358        if (rc != EOK)
     359                return rc;
     360
     361        (void) ui_paint(navigator->ui);
     362        return EOK;
     363error:
     364        (void) ui_resume(navigator->ui);
     365        (void) ui_paint(navigator->ui);
     366        return rc;
     367}
     368
     369/** File / Edit menu entry selected */
     370static void navigator_file_edit(void *arg)
     371{
     372        navigator_t *navigator = (navigator_t *)arg;
     373        ui_file_list_entry_t *entry;
     374        ui_file_list_entry_attr_t attr;
     375        panel_t *panel;
     376
     377        panel = navigator_get_active_panel(navigator);
     378        entry = ui_file_list_get_cursor(panel->flist);
     379        ui_file_list_entry_get_attr(entry, &attr);
     380
     381        (void)navigator_edit_file(navigator, attr.name);
     382}
     383
    320384/** File / Exit menu entry selected */
    321385static void navigator_file_exit(void *arg)
Note: See TracChangeset for help on using the changeset viewer.