Changeset 550ed86 in mainline


Ignore:
Timestamp:
2023-12-19T17:25:58Z (4 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, topic/simplify-dev-export
Children:
7130754
Parents:
f87ff8e
git-author:
Jiri Svoboda <jiri@…> (2023-12-19 17:19:18)
git-committer:
Jiri Svoboda <jiri@…> (2023-12-19 17:25:58)
Message:

Need to add new start menu entry to editor's list

Location:
uspace
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/taskbar-cfg/smeedit.c

    rf87ff8e r550ed86  
    116116
    117117        ui_wnd_params_init(&params);
    118         params.caption = smentry != NULL ? "Edit Start Menu Entry"
    119             : "Create Start Menu Entry";
     118        params.caption = smentry != NULL ? "Edit Start Menu Entry" :
     119            "Create Start Menu Entry";
    120120        if (ui_is_textmode(ui)) {
    121121                params.rect.p0.x = 0;
     
    345345{
    346346        smeedit_t *smee;
     347        smenu_entry_t *entry;
     348        startmenu_entry_t *smentry;
    347349        const char *cmd;
    348350        const char *caption;
     
    358360                /* Create new entry */
    359361                rc = smenu_entry_create(smee->startmenu->tbarcfg->tbarcfg,
    360                     caption, cmd);
     362                    caption, cmd, &entry);
    361363                if (rc != EOK)
    362364                        return;
     365
     366                rc = startmenu_insert(smee->startmenu, entry, &smentry);
     367                if (rc != EOK)
     368                        return;
     369
     370                startmenu_repaint(smee->startmenu);
    363371        } else {
    364372                /* Edit existing entry */
    365 
    366 
    367373                rc = smenu_entry_set_cmd(smee->smentry->entry, cmd);
    368374                if (rc != EOK)
  • uspace/app/taskbar-cfg/startmenu.c

    rf87ff8e r550ed86  
    429429}
    430430
     431/** Repaint start menu entry list.
     432 *
     433 * When editing an entry the entry's label might change. We need
     434 * to update the list entry caption to reflect that.
     435 *
     436 * @param smenu Start menu
     437 */
     438void startmenu_repaint(startmenu_t *smenu)
     439{
     440        (void) ui_control_paint(ui_list_ctl(smenu->entries_list));
     441}
     442
    431443/** Entry in entry list is selected.
    432444 *
  • uspace/app/taskbar-cfg/startmenu.h

    rf87ff8e r550ed86  
    5050extern void startmenu_edit(startmenu_t *);
    5151extern errno_t startmenu_entry_update(startmenu_entry_t *);
     52extern void startmenu_repaint(startmenu_t *);
    5253
    5354#endif
  • uspace/lib/tbarcfg/include/tbarcfg/tbarcfg.h

    rf87ff8e r550ed86  
    5151extern errno_t smenu_entry_set_cmd(smenu_entry_t *, const char *);
    5252extern errno_t smenu_entry_save(smenu_entry_t *);
    53 extern errno_t smenu_entry_create(tbarcfg_t *, const char *, const char *);
     53extern errno_t smenu_entry_create(tbarcfg_t *, const char *, const char *,
     54    smenu_entry_t **);
    5455extern errno_t smenu_entry_destroy(smenu_entry_t *);
    5556
  • uspace/lib/tbarcfg/private/tbarcfg.h

    rf87ff8e r550ed86  
    6767
    6868extern errno_t smenu_entry_new(tbarcfg_t *, sif_node_t *, const char *,
    69     const char *);
     69    const char *, smenu_entry_t **);
    7070extern void smenu_entry_delete(smenu_entry_t *);
    7171
  • uspace/lib/tbarcfg/src/tbarcfg.c

    rf87ff8e r550ed86  
    154154                }
    155155
    156                 rc = smenu_entry_new(tbcfg, nentry, caption, cmd);
     156                rc = smenu_entry_new(tbcfg, nentry, caption, cmd, NULL);
    157157                if (rc != EOK)
    158158                        goto error;
     
    325325 * @param caption Caption
    326326 * @param cmd Command to run
     327 * @param rentry Place to store pointer to new entry or @c NULL
    327328 */
    328329errno_t smenu_entry_new(tbarcfg_t *smenu, sif_node_t *nentry,
    329     const char *caption, const char *cmd)
     330    const char *caption, const char *cmd, smenu_entry_t **rentry)
    330331{
    331332        smenu_entry_t *entry;
     
    354355        entry->smenu = smenu;
    355356        list_append(&entry->lentries, &smenu->entries);
     357        if (rentry != NULL)
     358                *rentry = entry;
    356359        return EOK;
    357360error:
     
    388391 * @param caption Caption
    389392 * @param cmd Command to run
     393 * @param rentry Place to store pointer to new entry or @c NULL
    390394 */
    391395errno_t smenu_entry_create(tbarcfg_t *smenu, const char *caption,
    392     const char *cmd)
     396    const char *cmd, smenu_entry_t **rentry)
    393397{
    394398        sif_node_t *nentry;
     399        smenu_entry_t *entry;
    395400        errno_t rc;
    396401        sif_trans_t *trans = NULL;
     
    413418                goto error;
    414419
    415         rc = smenu_entry_new(smenu, nentry, caption, cmd);
     420        rc = smenu_entry_new(smenu, nentry, caption, cmd, &entry);
    416421        if (rc != EOK)
    417422                goto error;
     
    421426                goto error;
    422427
     428        if (rentry != NULL)
     429                *rentry = entry;
    423430        return EOK;
    424431error:
  • uspace/lib/tbarcfg/test/tbarcfg.c

    rf87ff8e r550ed86  
    6767        tbarcfg_t *tbcfg;
    6868        char fname[L_tmpnam], *p;
    69         smenu_entry_t *e;
    70 
    71         p = tmpnam(fname);
    72         PCUT_ASSERT_NOT_NULL(p);
    73 
    74         rc = tbarcfg_create(fname, &tbcfg);
    75         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    76 
    77         rc = smenu_entry_create(tbcfg, "A", "a");
    78         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    79 
    80         rc = smenu_entry_create(tbcfg, "B", "b");
     69        smenu_entry_t *e1 = NULL, *e2 = NULL;
     70        smenu_entry_t *e;
     71
     72        p = tmpnam(fname);
     73        PCUT_ASSERT_NOT_NULL(p);
     74
     75        rc = tbarcfg_create(fname, &tbcfg);
     76        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     77
     78        rc = smenu_entry_create(tbcfg, "A", "a", &e1);
     79        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     80        PCUT_ASSERT_NOT_NULL(e1);
     81
     82        rc = smenu_entry_create(tbcfg, "B", "b", &e2);
     83        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     84        PCUT_ASSERT_NOT_NULL(e2);
     85
     86        /* Create entry without getting a pointer to it */
     87        rc = smenu_entry_create(tbcfg, "C", "c", NULL);
    8188        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    8289
    8390        e = tbarcfg_smenu_first(tbcfg);
    84         PCUT_ASSERT_NOT_NULL(e);
     91        PCUT_ASSERT_EQUALS(e1, e);
     92        e = tbarcfg_smenu_next(e);
     93        PCUT_ASSERT_EQUALS(e2, e);
    8594        e = tbarcfg_smenu_next(e);
    8695        PCUT_ASSERT_NOT_NULL(e);
     
    108117        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    109118
    110         rc = smenu_entry_create(tbcfg, "A", "a");
     119        rc = smenu_entry_create(tbcfg, "A", "a", &e);
     120        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     121
     122        caption = smenu_entry_get_caption(e);
     123        PCUT_ASSERT_STR_EQUALS("A", caption);
     124        cmd = smenu_entry_get_cmd(e);
     125        PCUT_ASSERT_STR_EQUALS("a", cmd);
     126
     127        tbarcfg_close(tbcfg);
     128        remove(fname);
     129}
     130
     131/** Setting menu entry properties */
     132PCUT_TEST(set_caption_cmd)
     133{
     134        errno_t rc;
     135        tbarcfg_t *tbcfg;
     136        char fname[L_tmpnam], *p;
     137        smenu_entry_t *e;
     138        const char *caption;
     139        const char *cmd;
     140
     141        p = tmpnam(fname);
     142        PCUT_ASSERT_NOT_NULL(p);
     143
     144        rc = tbarcfg_create(fname, &tbcfg);
     145        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     146
     147        rc = smenu_entry_create(tbcfg, "A", "a", &e);
     148        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     149
     150        caption = smenu_entry_get_caption(e);
     151        PCUT_ASSERT_STR_EQUALS("A", caption);
     152        cmd = smenu_entry_get_cmd(e);
     153        PCUT_ASSERT_STR_EQUALS("a", cmd);
     154
     155        /* Set properties */
     156        rc = smenu_entry_set_caption(e, "B");
     157        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     158        rc = smenu_entry_set_cmd(e, "b");
     159        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     160
     161        rc = smenu_entry_save(e);
     162        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     163
     164        /* Check that properties have been set */
     165        caption = smenu_entry_get_caption(e);
     166        PCUT_ASSERT_STR_EQUALS("B", caption);
     167        cmd = smenu_entry_get_cmd(e);
     168        PCUT_ASSERT_STR_EQUALS("b", cmd);
     169
     170        tbarcfg_close(tbcfg);
     171
     172        /* Re-open repository */
     173
     174        rc = tbarcfg_open(fname, &tbcfg);
    111175        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    112176
     
    114178        PCUT_ASSERT_NOT_NULL(e);
    115179
    116         caption = smenu_entry_get_caption(e);
    117         PCUT_ASSERT_STR_EQUALS("A", caption);
    118         cmd = smenu_entry_get_cmd(e);
    119         PCUT_ASSERT_STR_EQUALS("a", cmd);
    120 
    121         tbarcfg_close(tbcfg);
    122         remove(fname);
    123 }
    124 
    125 /** Setting menu entry properties */
    126 PCUT_TEST(set_caption_cmd)
     180        /* Check that new values of properties have persisted */
     181        caption = smenu_entry_get_caption(e);
     182        PCUT_ASSERT_STR_EQUALS("B", caption);
     183        cmd = smenu_entry_get_cmd(e);
     184        PCUT_ASSERT_STR_EQUALS("b", cmd);
     185
     186        tbarcfg_close(tbcfg);
     187        remove(fname);
     188}
     189
     190/** Create start menu entry */
     191PCUT_TEST(entry_create)
    127192{
    128193        errno_t rc;
     
    139204        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    140205
    141         rc = smenu_entry_create(tbcfg, "A", "a");
    142         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    143 
    144         e = tbarcfg_smenu_first(tbcfg);
    145         PCUT_ASSERT_NOT_NULL(e);
    146 
    147         caption = smenu_entry_get_caption(e);
    148         PCUT_ASSERT_STR_EQUALS("A", caption);
    149         cmd = smenu_entry_get_cmd(e);
    150         PCUT_ASSERT_STR_EQUALS("a", cmd);
    151 
    152         /* Set properties */
    153         rc = smenu_entry_set_caption(e, "B");
    154         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    155         rc = smenu_entry_set_cmd(e, "b");
    156         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    157 
    158         rc = smenu_entry_save(e);
    159         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    160 
    161         /* Check that properties have been set */
    162         caption = smenu_entry_get_caption(e);
    163         PCUT_ASSERT_STR_EQUALS("B", caption);
    164         cmd = smenu_entry_get_cmd(e);
    165         PCUT_ASSERT_STR_EQUALS("b", cmd);
    166 
    167         tbarcfg_close(tbcfg);
    168 
    169         /* Re-open repository */
    170 
    171         rc = tbarcfg_open(fname, &tbcfg);
    172         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    173 
    174         e = tbarcfg_smenu_first(tbcfg);
    175         PCUT_ASSERT_NOT_NULL(e);
    176 
    177         /* Check that new values of properties have persisted */
    178         caption = smenu_entry_get_caption(e);
    179         PCUT_ASSERT_STR_EQUALS("B", caption);
    180         cmd = smenu_entry_get_cmd(e);
    181         PCUT_ASSERT_STR_EQUALS("b", cmd);
    182 
    183         tbarcfg_close(tbcfg);
    184         remove(fname);
    185 }
    186 
    187 /** Create start menu entry */
    188 PCUT_TEST(entry_create)
    189 {
    190         errno_t rc;
    191         tbarcfg_t *tbcfg;
    192         char fname[L_tmpnam], *p;
    193         smenu_entry_t *e;
    194         const char *caption;
    195         const char *cmd;
    196 
    197         p = tmpnam(fname);
    198         PCUT_ASSERT_NOT_NULL(p);
    199 
    200         rc = tbarcfg_create(fname, &tbcfg);
    201         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    202 
    203         rc = smenu_entry_create(tbcfg, "A", "a");
    204         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    205 
    206         e = tbarcfg_smenu_first(tbcfg);
     206        rc = smenu_entry_create(tbcfg, "A", "a", &e);
     207        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    207208        PCUT_ASSERT_NOT_NULL(e);
    208209
     
    222223        tbarcfg_t *tbcfg;
    223224        char fname[L_tmpnam], *p;
    224         smenu_entry_t *e;
    225 
    226         p = tmpnam(fname);
    227         PCUT_ASSERT_NOT_NULL(p);
    228 
    229         rc = tbarcfg_create(fname, &tbcfg);
    230         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    231 
    232         rc = smenu_entry_create(tbcfg, "A", "a");
    233         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    234 
    235         e = tbarcfg_smenu_first(tbcfg);
    236         PCUT_ASSERT_NOT_NULL(e);
     225        smenu_entry_t *e, *f;
     226
     227        p = tmpnam(fname);
     228        PCUT_ASSERT_NOT_NULL(p);
     229
     230        rc = tbarcfg_create(fname, &tbcfg);
     231        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     232
     233        rc = smenu_entry_create(tbcfg, "A", "a", &e);
     234        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     235
     236        f = tbarcfg_smenu_first(tbcfg);
     237        PCUT_ASSERT_EQUALS(e, f);
    237238
    238239        rc = smenu_entry_destroy(e);
    239240        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    240241
    241         e = tbarcfg_smenu_first(tbcfg);
    242         PCUT_ASSERT_NULL(e);
     242        f = tbarcfg_smenu_first(tbcfg);
     243        PCUT_ASSERT_NULL(f);
    243244
    244245        tbarcfg_close(tbcfg);
Note: See TracChangeset for help on using the changeset viewer.