Changeset b1397ab in mainline
- Timestamp:
- 2023-11-09T13:02:16Z (13 months ago)
- 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)
- Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar-cfg/smeedit.c
r40eab9f rb1397ab 48 48 }; 49 49 50 static void smeedit_ok_clicked(ui_pbutton_t *, void *); 51 static void smeedit_cancel_clicked(ui_pbutton_t *, void *); 52 53 /** OK button callbacks */ 54 ui_pbutton_cb_t smeedit_ok_button_cb = { 55 .clicked = smeedit_ok_clicked 56 }; 57 58 /** Cancel button callbacks */ 59 ui_pbutton_cb_t smeedit_cancel_button_cb = { 60 .clicked = smeedit_cancel_clicked 61 }; 62 50 63 /** Window close button was clicked. 51 64 * … … 64 77 * 65 78 * @param smenu Start menu 79 * @param smentry Start menu entry to edit or @c NULL if creating 80 * a new entry 66 81 * @param rsmee Place to store pointer to new start menu entry edit window 67 82 * @return EOK on success or an error code 68 83 */ 69 errno_t smeedit_create(startmenu_t *smenu, smeedit_t **rsmee) 84 errno_t smeedit_create(startmenu_t *smenu, startmenu_entry_t *smentry, 85 smeedit_t **rsmee) 70 86 { 71 87 ui_wnd_params_t params; … … 75 91 gfx_rect_t rect; 76 92 ui_resource_t *res; 93 const char *cmd; 94 const char *caption; 77 95 errno_t rc; 78 96 79 97 ui = smenu->tbarcfg->ui; 98 99 if (smentry != NULL) { 100 cmd = smenu_entry_get_cmd(smentry->entry); 101 caption = smenu_entry_get_caption(smentry->entry); 102 } else { 103 cmd = ""; 104 caption = ""; 105 } 80 106 81 107 smee = calloc(1, sizeof(smeedit_t)); … … 85 111 } 86 112 113 smee->smentry = smentry; 114 87 115 ui_wnd_params_init(¶ms); 88 116 params.caption = "Edit Start Menu Entry"; … … 145 173 /* Command entry */ 146 174 147 rc = ui_entry_create(window, "foo", &smee->ecmd);175 rc = ui_entry_create(window, cmd, &smee->ecmd); 148 176 if (rc != EOK) 149 177 goto error; … … 199 227 /* Caption entry */ 200 228 201 rc = ui_entry_create(window, "bar", &smee->ecaption);229 rc = ui_entry_create(window, caption, &smee->ecaption); 202 230 if (rc != EOK) 203 231 goto error; … … 243 271 } 244 272 273 ui_pbutton_set_cb(smee->bok, &smeedit_ok_button_cb, (void *)smee); 245 274 ui_pbutton_set_rect(smee->bok, &rect); 246 275 ui_pbutton_set_default(smee->bok, true); … … 271 300 } 272 301 302 ui_pbutton_set_cb(smee->bcancel, &smeedit_cancel_button_cb, 303 (void *)smee); 273 304 ui_pbutton_set_rect(smee->bcancel, &rect); 274 305 … … 303 334 } 304 335 336 /** OK button clicked. 337 * 338 * @params bok OK button 339 * @params arg Argument (smeedit_t *) 340 */ 341 static void smeedit_ok_clicked(ui_pbutton_t *bok, void *arg) 342 { 343 smeedit_t *smee; 344 const char *cmd; 345 const char *caption; 346 errno_t rc; 347 348 (void)bok; 349 smee = (smeedit_t *)arg; 350 351 cmd = ui_entry_get_text(smee->ecmd); 352 caption = ui_entry_get_text(smee->ecaption); 353 354 rc = smenu_entry_set_cmd(smee->smentry->entry, cmd); 355 if (rc != EOK) 356 return; 357 358 smenu_entry_set_caption(smee->smentry->entry, caption); 359 if (rc != EOK) 360 return; 361 362 (void)smenu_entry_save(smee->smentry->entry); 363 364 smeedit_destroy(smee); 365 } 366 367 /** Cancel button clicked. 368 * 369 * @params bok OK button 370 * @params arg Argument (smeedit_t *) 371 */ 372 static void smeedit_cancel_clicked(ui_pbutton_t *bcancel, void *arg) 373 { 374 smeedit_t *smee; 375 376 (void)bcancel; 377 smee = (smeedit_t *)arg; 378 smeedit_destroy(smee); 379 } 380 305 381 /** @} 306 382 */ -
uspace/app/taskbar-cfg/smeedit.h
r40eab9f rb1397ab 40 40 #include "types/startmenu.h" 41 41 42 extern errno_t smeedit_create(startmenu_t *, s meedit_t **);42 extern errno_t smeedit_create(startmenu_t *, startmenu_entry_t *, smeedit_t **); 43 43 extern void smeedit_destroy(smeedit_t *); 44 44 -
uspace/app/taskbar-cfg/startmenu.c
r40eab9f rb1397ab 292 292 smenu_entry_t *entry; 293 293 startmenu_entry_t *smentry; 294 const char *caption;295 const char *cmd;296 294 errno_t rc; 297 295 298 296 entry = tbarcfg_smenu_first(tbarcfg); 299 297 while (entry != NULL) { 300 caption = smenu_entry_get_caption(entry); 301 cmd = smenu_entry_get_cmd(entry); 302 303 rc = startmenu_insert(smenu, caption, cmd, &smentry); 298 rc = startmenu_insert(smenu, entry, &smentry); 304 299 if (rc != EOK) 305 300 return rc; … … 323 318 while (lentry != NULL) { 324 319 entry = (startmenu_entry_t *)ui_list_entry_get_arg(lentry); 325 free(entry->caption);326 free(entry->cmd);327 320 free(entry); 328 321 ui_list_entry_delete(lentry); … … 338 331 * 339 332 * @param smenu Start menu configuration tab 340 * @param caption Entry caption 341 * @param cmd Command to run 342 * @param rentry Place to store pointer to new entry or NULL 333 * @param entry Backing entry 334 * @param rsmentry Place to store pointer to new entry or NULL 343 335 * @return EOK on success or an error code 344 336 */ 345 errno_t startmenu_insert(startmenu_t *smenu, const char *caption,346 const char *cmd, startmenu_entry_t **rentry)347 { 348 startmenu_entry_t * entry;337 errno_t startmenu_insert(startmenu_t *smenu, smenu_entry_t *entry, 338 startmenu_entry_t **rsmentry) 339 { 340 startmenu_entry_t *smentry; 349 341 ui_list_entry_attr_t attr; 350 342 errno_t rc; 351 343 352 entry = calloc(1, sizeof(startmenu_entry_t));353 if ( entry == NULL)344 smentry = calloc(1, sizeof(startmenu_entry_t)); 345 if (smentry == NULL) 354 346 return ENOMEM; 355 347 356 entry->startmenu = smenu; 357 entry->caption = str_dup(caption); 358 if (entry->caption == NULL) { 359 free(entry); 360 return ENOMEM; 361 } 362 363 entry->cmd = str_dup(cmd); 364 if (entry->caption == NULL) { 365 free(entry->caption); 366 free(entry); 367 return ENOMEM; 368 } 369 348 smentry->startmenu = smenu; 349 smentry->entry = entry; 350 351 printf("startmenu_insert: smentry=%p entry=%p\n", 352 smentry, entry); 370 353 ui_list_entry_attr_init(&attr); 371 attr.caption = caption; 372 attr.arg = (void *)entry; 373 rc = ui_list_entry_append(smenu->entries_list, &attr, &entry->lentry); 374 if (rc != EOK) { 375 free(entry->caption); 376 free(entry->cmd); 377 free(entry); 354 attr.caption = smenu_entry_get_caption(entry); 355 attr.arg = (void *)smentry; 356 rc = ui_list_entry_append(smenu->entries_list, &attr, &smentry->lentry); 357 if (rc != EOK) { 358 free(smentry); 378 359 return rc; 379 360 } 380 361 381 if (r entry != NULL)382 *r entry =entry;362 if (rsmentry != NULL) 363 *rsmentry = smentry; 383 364 return EOK; 384 365 } 385 366 367 /** Get selected start menu entry. 368 * 369 * @param smenu Start menu 370 * @return Selected entry 371 */ 372 startmenu_entry_t *startmenu_get_selected(startmenu_t *smenu) 373 { 374 ui_list_entry_t *entry; 375 376 entry = ui_list_get_cursor(smenu->entries_list); 377 return (startmenu_entry_t *)ui_list_entry_get_arg(entry); 378 } 379 386 380 /** Edit selected menu entry. 387 381 * … … 391 385 { 392 386 smeedit_t *smee; 387 startmenu_entry_t *smentry; 393 388 errno_t rc; 394 389 395 rc = smeedit_create(smenu, &smee); 390 smentry = startmenu_get_selected(smenu); 391 392 printf("smeedit_create:entry=%p\n", smentry); 393 rc = smeedit_create(smenu, smentry, &smee); 396 394 if (rc != EOK) 397 395 return; -
uspace/app/taskbar-cfg/startmenu.h
r40eab9f rb1397ab 44 44 extern errno_t startmenu_populate(startmenu_t *, tbarcfg_t *); 45 45 extern void startmenu_destroy(startmenu_t *); 46 extern errno_t startmenu_insert(startmenu_t *, const char *, const char*,46 extern errno_t startmenu_insert(startmenu_t *, smenu_entry_t *, 47 47 startmenu_entry_t **); 48 extern startmenu_entry_t *startmenu_get_selected(startmenu_t *); 48 49 extern void startmenu_edit(startmenu_t *); 49 50 -
uspace/app/taskbar-cfg/types/smeedit.h
r40eab9f rb1397ab 47 47 /** Containing start menu configuration tab */ 48 48 struct startmenu *startmenu; 49 /** Start menu entry or @c NULL if creating a new entry */ 50 struct startmenu_entry *smentry; 49 51 /** Window */ 50 52 ui_window_t *window; -
uspace/app/taskbar-cfg/types/startmenu.h
r40eab9f rb1397ab 37 37 #define TYPES_STARTMENU_H 38 38 39 #include <tbarcfg/tbarcfg.h> 39 40 #include <ui/fixed.h> 40 41 #include <ui/label.h> … … 64 65 65 66 /** Start menu entry */ 66 typedef struct {67 typedef struct startmenu_entry { 67 68 /** Containing start menu configuration tab */ 68 69 struct startmenu *startmenu; 70 /** Backing entry */ 71 smenu_entry_t *entry; 69 72 /** List entry */ 70 73 ui_list_entry_t *lentry; 71 /** Caption */72 char *caption;73 /** Command */74 char *cmd;75 74 } startmenu_entry_t; 76 75 -
uspace/lib/tbarcfg/include/tbarcfg/tbarcfg.h
r40eab9f rb1397ab 46 46 extern const char *smenu_entry_get_caption(smenu_entry_t *); 47 47 extern const char *smenu_entry_get_cmd(smenu_entry_t *); 48 extern errno_t smenu_entry_set_caption(smenu_entry_t *, const char *); 49 extern errno_t smenu_entry_set_cmd(smenu_entry_t *, const char *); 50 extern errno_t smenu_entry_save(smenu_entry_t *); 48 51 49 52 #endif -
uspace/lib/tbarcfg/private/tbarcfg.h
r40eab9f rb1397ab 44 44 /** Taskbar configuration */ 45 45 struct tbarcfg { 46 /** Repository session */ 47 sif_sess_t *repo; 46 48 /** List of start menu entries (smenu_entry_t) */ 47 49 list_t entries; … … 54 56 /** Link to @c smenu->entries */ 55 57 link_t lentries; 58 /** SIF node (persistent storage) */ 59 sif_node_t *nentry; 56 60 /** Entry caption (with accelerator markup) */ 57 61 char *caption; … … 60 64 }; 61 65 62 extern errno_t smenu_entry_create(tbarcfg_t *, const char *,66 extern errno_t smenu_entry_create(tbarcfg_t *, sif_node_t *, const char *, 63 67 const char *); 64 68 -
uspace/lib/tbarcfg/src/tbarcfg.c
r40eab9f rb1397ab 71 71 goto error; 72 72 73 tbcfg->repo = repo; 74 73 75 rnode = sif_get_root(repo); 74 76 nentries = sif_node_first_child(rnode); … … 99 101 } 100 102 101 rc = smenu_entry_create(tbcfg, caption, cmd);103 rc = smenu_entry_create(tbcfg, nentry, caption, cmd); 102 104 if (rc != EOK) 103 105 goto error; … … 122 124 void tbarcfg_close(tbarcfg_t *tbcfg) 123 125 { 126 (void)sif_close(tbcfg->repo); 124 127 } 125 128 … … 176 179 } 177 180 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 */ 190 errno_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 */ 212 errno_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 */ 229 errno_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; 251 error: 252 if (trans != NULL) 253 sif_trans_abort(trans); 254 return rc; 255 } 256 178 257 /** Create a start menu entry and append it to the start menu (internal). 179 258 * … … 181 260 * 182 261 * @param smenu Start menu 262 * @param nentry Backing SIF node 183 263 * @param caption Caption 184 264 * @param cmd Command to run 185 265 */ 186 errno_t smenu_entry_create(tbarcfg_t *smenu, const char *caption,187 const char *c md)266 errno_t smenu_entry_create(tbarcfg_t *smenu, sif_node_t *nentry, 267 const char *caption, const char *cmd) 188 268 { 189 269 smenu_entry_t *entry; … … 195 275 goto error; 196 276 } 277 278 entry->nentry = nentry; 197 279 198 280 entry->caption = str_dup(caption);
Note:
See TracChangeset
for help on using the changeset viewer.