Changeset 806d761 in mainline for uspace/lib/tbarcfg/src/tbarcfg.c


Ignore:
Timestamp:
2024-02-07T23:44:59Z (11 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
242e3c3
Parents:
74cb6610
Message:

Start menu should have 'open in terminal' functionality

Makes it easier for the user and if we are running in console mode,
we correctly start the application, instead of failing to start a
terminal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/tbarcfg/src/tbarcfg.c

    r74cb6610 r806d761  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    101101 * @return EOK on success or an error code
    102102 */
     103#include <stdio.h>
    103104errno_t tbarcfg_open(const char *repopath, tbarcfg_t **rtbcfg)
    104105{
     
    110111        const char *caption;
    111112        const char *cmd;
     113        const char *terminal = NULL;
    112114        errno_t rc;
    113115
     
    154156                }
    155157
    156                 rc = smenu_entry_new(tbcfg, nentry, caption, cmd, NULL);
     158                terminal = sif_node_get_attr(nentry, "terminal");
     159                if (terminal == NULL)
     160                        terminal = "n";
     161
     162                printf("terminal=%s\n", terminal);
     163
     164                rc = smenu_entry_new(tbcfg, nentry, caption, cmd,
     165                    str_cmp(terminal, "y") == 0, NULL);
    157166                if (rc != EOK)
    158167                        goto error;
     
    233242/** Get start menu entry command.
    234243 *
    235  * @param entr Start menu entry
     244 * @param entry Start menu entry
    236245 * @return Command to run
    237246 */
     
    239248{
    240249        return entry->cmd;
     250}
     251
     252/** Get start menu start in terminal flag.
     253 *
     254 * @param entry Start menu entry
     255 * @return Start in terminal flag
     256 */
     257bool smenu_entry_get_terminal(smenu_entry_t *entry)
     258{
     259        return entry->terminal;
    241260}
    242261
     
    285304}
    286305
     306/** Set start menu entry start in terminal flag.
     307 *
     308 * Note: To make the change visible to others and persistent,
     309 * you must call @c smenu_entry_save()
     310 *
     311 * @param entry Start menu entry
     312 * @param terminal Start in terminal flag
     313 */
     314void smenu_entry_set_terminal(smenu_entry_t *entry, bool terminal)
     315{
     316        entry->terminal = terminal;
     317}
     318
    287319/** Save any changes to start menu entry.
    288320 *
     
    303335
    304336        rc = sif_node_set_attr(trans, entry->nentry, "caption", entry->caption);
     337        if (rc != EOK)
     338                goto error;
     339
     340        rc = sif_node_set_attr(trans, entry->nentry, "terminal",
     341            entry->terminal ? "y" : "n");
    305342        if (rc != EOK)
    306343                goto error;
     
    325362 * @param caption Caption
    326363 * @param cmd Command to run
     364 * @param terminal Start in terminal
    327365 * @param rentry Place to store pointer to new entry or @c NULL
    328366 */
    329367errno_t smenu_entry_new(tbarcfg_t *smenu, sif_node_t *nentry,
    330     const char *caption, const char *cmd, smenu_entry_t **rentry)
     368    const char *caption, const char *cmd, bool terminal, smenu_entry_t **rentry)
    331369{
    332370        smenu_entry_t *entry;
     
    352390                goto error;
    353391        }
     392
     393        entry->terminal = terminal;
    354394
    355395        entry->smenu = smenu;
     
    391431 * @param caption Caption
    392432 * @param cmd Command to run
     433 * @param terminal Start in terminal
    393434 * @param rentry Place to store pointer to new entry or @c NULL
    394435 */
    395436errno_t smenu_entry_create(tbarcfg_t *smenu, const char *caption,
    396     const char *cmd, smenu_entry_t **rentry)
     437    const char *cmd, bool terminal, smenu_entry_t **rentry)
    397438{
    398439        sif_node_t *nentry;
     
    418459                goto error;
    419460
    420         rc = smenu_entry_new(smenu, nentry, caption, cmd, &entry);
     461        rc = sif_node_set_attr(trans, nentry, "terminal", terminal ? "y" : "n");
     462        if (rc != EOK)
     463                goto error;
     464
     465        rc = smenu_entry_new(smenu, nentry, caption, cmd, terminal ? "y" : "n",
     466            &entry);
    421467        if (rc != EOK)
    422468                goto error;
Note: See TracChangeset for help on using the changeset viewer.