Changeset b1397ab in mainline for uspace/lib/tbarcfg/src/tbarcfg.c


Ignore:
Timestamp:
2023-11-09T13:02:16Z (21 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, topic/msim-upgrade, topic/simplify-dev-export
Children:
e0d874b7
Parents:
40eab9f
git-author:
Jiri Svoboda <jiri@…> (2023-11-08 18:01:53)
git-committer:
Jiri Svoboda <jiri@…> (2023-11-09 13:02:16)
Message:

Start menu editor is editing

You can change an entry and it will be saved to the configuration repo.
(Cannot create/delete yet). To see the change in the editor, you need
to restart it. To see the change in the taskbar, you need to restart it.

File:
1 edited

Legend:

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

    r40eab9f rb1397ab  
    7171                goto error;
    7272
     73        tbcfg->repo = repo;
     74
    7375        rnode = sif_get_root(repo);
    7476        nentries = sif_node_first_child(rnode);
     
    99101                }
    100102
    101                 rc = smenu_entry_create(tbcfg, caption, cmd);
     103                rc = smenu_entry_create(tbcfg, nentry, caption, cmd);
    102104                if (rc != EOK)
    103105                        goto error;
     
    122124void tbarcfg_close(tbarcfg_t *tbcfg)
    123125{
     126        (void)sif_close(tbcfg->repo);
    124127}
    125128
     
    176179}
    177180
     181/** Set start menu entry caption.
     182 *
     183 * Note: To make the change visible to others and persistent,
     184 * you must call @c smenu_entry_save()
     185 *
     186 * @param entry Start menu entry
     187 * @param caption New caption
     188 * @return EOK on success, ENOMEM if out of memory
     189 */
     190errno_t smenu_entry_set_caption(smenu_entry_t *entry, const char *caption)
     191{
     192        char *dcap;
     193
     194        dcap = str_dup(caption);
     195        if (dcap == NULL)
     196                return ENOMEM;
     197
     198        free(entry->caption);
     199        entry->caption = dcap;
     200        return EOK;
     201}
     202
     203/** Set start menu entry command.
     204 *
     205 * Note: To make the change visible to others and persistent,
     206 * you must call @c smenu_entry_save()
     207 *
     208 * @param entry Start menu entry
     209 * @param cmd New command
     210 * @return EOK on success, ENOMEM if out of memory
     211 */
     212errno_t smenu_entry_set_cmd(smenu_entry_t *entry, const char *cmd)
     213{
     214        char *dcmd;
     215
     216        dcmd = str_dup(cmd);
     217        if (dcmd == NULL)
     218                return ENOMEM;
     219
     220        free(entry->cmd);
     221        entry->cmd = dcmd;
     222        return EOK;
     223}
     224
     225/** Save any changes to start menu entry.
     226 *
     227 * @param entry Start menu entry
     228 */
     229errno_t smenu_entry_save(smenu_entry_t *entry)
     230{
     231        sif_trans_t *trans;
     232        errno_t rc;
     233
     234        rc = sif_trans_begin(entry->smenu->repo, &trans);
     235        if (rc != EOK)
     236                goto error;
     237
     238        rc = sif_node_set_attr(trans, entry->nentry, "cmd", entry->cmd);
     239        if (rc != EOK)
     240                goto error;
     241
     242        rc = sif_node_set_attr(trans, entry->nentry, "caption", entry->caption);
     243        if (rc != EOK)
     244                goto error;
     245
     246        rc = sif_trans_end(trans);
     247        if (rc != EOK)
     248                goto error;
     249
     250        return EOK;
     251error:
     252        if (trans != NULL)
     253                sif_trans_abort(trans);
     254        return rc;
     255}
     256
    178257/** Create a start menu entry and append it to the start menu (internal).
    179258 *
     
    181260 *
    182261 * @param smenu Start menu
     262 * @param nentry Backing SIF node
    183263 * @param caption Caption
    184264 * @param cmd Command to run
    185265 */
    186 errno_t smenu_entry_create(tbarcfg_t *smenu, const char *caption,
    187     const char *cmd)
     266errno_t smenu_entry_create(tbarcfg_t *smenu, sif_node_t *nentry,
     267    const char *caption, const char *cmd)
    188268{
    189269        smenu_entry_t *entry;
     
    195275                goto error;
    196276        }
     277
     278        entry->nentry = nentry;
    197279
    198280        entry->caption = str_dup(caption);
Note: See TracChangeset for help on using the changeset viewer.