Changeset e63e74a in mainline
- Timestamp:
- 2024-02-21T20:26:35Z (11 months ago)
- Branches:
- master
- Children:
- 95e2967
- Parents:
- 5f3188b8
- Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar-cfg/startmenu.c
r5f3188b8 re63e74a 54 54 static void startmenu_delete_entry_clicked(ui_pbutton_t *, void *); 55 55 static void startmenu_edit_entry_clicked(ui_pbutton_t *, void *); 56 static void startmenu_sep_entry_clicked(ui_pbutton_t *, void *); 56 57 static void startmenu_up_entry_clicked(ui_pbutton_t *, void *); 57 58 static void startmenu_down_entry_clicked(ui_pbutton_t *, void *); … … 75 76 ui_pbutton_cb_t startmenu_edit_entry_button_cb = { 76 77 .clicked = startmenu_edit_entry_clicked 78 }; 79 80 /** Separator entry button callbacks */ 81 ui_pbutton_cb_t startmenu_sep_entry_button_cb = { 82 .clicked = startmenu_sep_entry_clicked 77 83 }; 78 84 … … 275 281 &startmenu_edit_entry_button_cb, (void *)smenu); 276 282 277 /* Move entry upbutton */278 279 rc = ui_pbutton_create(ui_res, " Up", &smenu->up_entry);283 /* Separator entry button */ 284 285 rc = ui_pbutton_create(ui_res, "Separator", &smenu->sep_entry); 280 286 if (rc != EOK) { 281 287 printf("Error creating button.\n"); … … 285 291 if (ui_resource_is_textmode(ui_res)) { 286 292 rect.p0.x = 58; 287 rect.p0.y = 1 2;293 rect.p0.y = 11; 288 294 rect.p1.x = 68; 289 rect.p1.y = 1 3;295 rect.p1.y = 12; 290 296 } else { 291 297 rect.p0.x = 370; 292 rect.p0.y = 1 90;298 rect.p0.y = 170; 293 299 rect.p1.x = 450; 294 rect.p1.y = 215;295 } 296 297 ui_pbutton_set_rect(smenu-> up_entry, &rect);298 299 rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu-> up_entry));300 rect.p1.y = 195; 301 } 302 303 ui_pbutton_set_rect(smenu->sep_entry, &rect); 304 305 rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu->sep_entry)); 300 306 if (rc != EOK) { 301 307 printf("Error adding control to layout.\n"); … … 303 309 } 304 310 305 ui_pbutton_set_cb(smenu-> up_entry,306 &startmenu_ up_entry_button_cb, (void *)smenu);307 308 /* Move entry downbutton */309 310 rc = ui_pbutton_create(ui_res, " Down", &smenu->down_entry);311 ui_pbutton_set_cb(smenu->sep_entry, 312 &startmenu_sep_entry_button_cb, (void *)smenu); 313 314 /* Move entry up button */ 315 316 rc = ui_pbutton_create(ui_res, "Up", &smenu->up_entry); 311 317 if (rc != EOK) { 312 318 printf("Error creating button.\n"); … … 316 322 if (ui_resource_is_textmode(ui_res)) { 317 323 rect.p0.x = 58; 318 rect.p0.y = 1 4;324 rect.p0.y = 13; 319 325 rect.p1.x = 68; 320 rect.p1.y = 1 5;326 rect.p1.y = 14; 321 327 } else { 322 328 rect.p0.x = 370; … … 324 330 rect.p1.x = 450; 325 331 rect.p1.y = 245; 332 } 333 334 ui_pbutton_set_rect(smenu->up_entry, &rect); 335 336 rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu->up_entry)); 337 if (rc != EOK) { 338 printf("Error adding control to layout.\n"); 339 goto error; 340 } 341 342 ui_pbutton_set_cb(smenu->up_entry, 343 &startmenu_up_entry_button_cb, (void *)smenu); 344 345 /* Move entry down button */ 346 347 rc = ui_pbutton_create(ui_res, "Down", &smenu->down_entry); 348 if (rc != EOK) { 349 printf("Error creating button.\n"); 350 goto error; 351 } 352 353 if (ui_resource_is_textmode(ui_res)) { 354 rect.p0.x = 58; 355 rect.p0.y = 15; 356 rect.p1.x = 68; 357 rect.p1.y = 16; 358 } else { 359 rect.p0.x = 370; 360 rect.p0.y = 250; 361 rect.p1.x = 450; 362 rect.p1.y = 275; 326 363 } 327 364 … … 418 455 startmenu_entry_t *smentry; 419 456 ui_list_entry_attr_t attr; 457 bool separator; 420 458 errno_t rc; 421 459 … … 428 466 429 467 ui_list_entry_attr_init(&attr); 430 attr.caption = smenu_entry_get_caption(entry); 468 separator = smenu_entry_get_separator(entry); 469 if (separator) 470 attr.caption = "-- Separator --"; 471 else 472 attr.caption = smenu_entry_get_caption(entry); 473 431 474 attr.arg = (void *)smentry; 475 432 476 rc = ui_list_entry_append(smenu->entries_list, &attr, &smentry->lentry); 433 477 if (rc != EOK) { … … 473 517 } 474 518 519 /** Create new separator menu entry. 520 * 521 * @param smenu Start menu 522 */ 523 void startmenu_sep_entry(startmenu_t *smenu) 524 { 525 startmenu_entry_t *smentry = NULL; 526 smenu_entry_t *entry; 527 errno_t rc; 528 529 rc = smenu_entry_sep_create(smenu->tbarcfg->tbarcfg, &entry); 530 if (rc != EOK) 531 return; 532 533 (void)startmenu_insert(smenu, entry, &smentry); 534 (void)ui_control_paint(ui_list_ctl(smenu->entries_list)); 535 } 536 475 537 /** Edit selected menu entry. 476 538 * … … 485 547 smentry = startmenu_get_selected(smenu); 486 548 if (smentry == NULL) 549 return; 550 551 /* Do not edit separator entries */ 552 if (smenu_entry_get_separator(smentry->entry)) 487 553 return; 488 554 … … 582 648 } 583 649 584 /** Upentry button clicked.650 /** Separator entry button clicked. 585 651 * 586 652 * @param pbutton Push button 587 653 * @param arg Argument (startmenu_t *) 588 654 */ 655 static void startmenu_sep_entry_clicked(ui_pbutton_t *pbutton, void *arg) 656 { 657 startmenu_t *smenu = (startmenu_t *)arg; 658 659 (void)pbutton; 660 startmenu_sep_entry(smenu); 661 } 662 663 /** Up entry button clicked. 664 * 665 * @param pbutton Push button 666 * @param arg Argument (startmenu_t *) 667 */ 589 668 static void startmenu_up_entry_clicked(ui_pbutton_t *pbutton, void *arg) 590 669 { -
uspace/app/taskbar-cfg/startmenu.h
r5f3188b8 re63e74a 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 48 48 extern startmenu_entry_t *startmenu_get_selected(startmenu_t *); 49 49 extern void startmenu_new_entry(startmenu_t *); 50 extern void startmenu_sep_entry(startmenu_t *); 50 51 extern void startmenu_edit(startmenu_t *); 51 52 extern errno_t startmenu_entry_update(startmenu_entry_t *); -
uspace/app/taskbar-cfg/types/startmenu.h
r5f3188b8 re63e74a 62 62 /** Edit entry button */ 63 63 ui_pbutton_t *edit_entry; 64 /** Separator entry button */ 65 ui_pbutton_t *sep_entry; 64 66 /** Move entry up button */ 65 67 ui_pbutton_t *up_entry; -
uspace/app/taskbar/tbsmenu.c
r5f3188b8 re63e74a 129 129 tbarcfg_t *tbcfg = NULL; 130 130 smenu_entry_t *sme; 131 bool separator; 131 132 const char *caption; 132 133 const char *cmd; … … 140 141 sme = tbarcfg_smenu_first(tbcfg); 141 142 while (sme != NULL) { 142 caption = smenu_entry_get_caption(sme); 143 cmd = smenu_entry_get_cmd(sme); 144 terminal = smenu_entry_get_terminal(sme); 145 146 rc = tbsmenu_add(tbsmenu, caption, cmd, terminal, &tentry); 147 if (rc != EOK) 148 goto error; 143 separator = smenu_entry_get_separator(sme); 144 if (separator == false) { 145 caption = smenu_entry_get_caption(sme); 146 cmd = smenu_entry_get_cmd(sme); 147 terminal = smenu_entry_get_terminal(sme); 148 149 rc = tbsmenu_add(tbsmenu, caption, cmd, terminal, 150 &tentry); 151 if (rc != EOK) 152 goto error; 153 } else { 154 rc = tbsmenu_add_sep(tbsmenu, &tentry); 155 if (rc != EOK) 156 goto error; 157 } 149 158 150 159 (void)tentry; … … 272 281 if (entry->cmd != NULL) 273 282 free(entry->cmd); 283 free(entry); 284 return rc; 285 } 286 287 /** Add separator entry to start menu. 288 * 289 * @param tbsmenu Start menu 290 * @param entry Start menu entry 291 * @return @c EOK on success or an error code 292 */ 293 errno_t tbsmenu_add_sep(tbsmenu_t *tbsmenu, tbsmenu_entry_t **rentry) 294 { 295 errno_t rc; 296 tbsmenu_entry_t *entry; 297 298 entry = calloc(1, sizeof(tbsmenu_entry_t)); 299 if (entry == NULL) 300 return ENOMEM; 301 302 rc = ui_menu_entry_sep_create(tbsmenu->smenu, &entry->mentry); 303 if (rc != EOK) 304 goto error; 305 306 ui_menu_entry_set_cb(entry->mentry, tbsmenu_smenu_entry_cb, 307 (void *)entry); 308 309 entry->tbsmenu = tbsmenu; 310 list_append(&entry->lentries, &tbsmenu->entries); 311 *rentry = entry; 312 return EOK; 313 error: 274 314 free(entry); 275 315 return rc; -
uspace/app/taskbar/tbsmenu.h
r5f3188b8 re63e74a 55 55 extern errno_t tbsmenu_add(tbsmenu_t *, const char *, const char *, bool, 56 56 tbsmenu_entry_t **); 57 extern errno_t tbsmenu_add_sep(tbsmenu_t *, tbsmenu_entry_t **); 57 58 extern void tbsmenu_remove(tbsmenu_t *, tbsmenu_entry_t *, bool); 58 59 extern tbsmenu_entry_t *tbsmenu_first(tbsmenu_t *); -
uspace/lib/tbarcfg/include/tbarcfg/tbarcfg.h
r5f3188b8 re63e74a 52 52 extern const char *smenu_entry_get_cmd(smenu_entry_t *); 53 53 extern bool smenu_entry_get_terminal(smenu_entry_t *); 54 extern bool smenu_entry_get_separator(smenu_entry_t *); 54 55 extern errno_t smenu_entry_set_caption(smenu_entry_t *, const char *); 55 56 extern errno_t smenu_entry_set_cmd(smenu_entry_t *, const char *); … … 58 59 extern errno_t smenu_entry_create(tbarcfg_t *, const char *, const char *, 59 60 bool, smenu_entry_t **); 61 extern errno_t smenu_entry_sep_create(tbarcfg_t *, smenu_entry_t **); 60 62 extern errno_t smenu_entry_destroy(smenu_entry_t *); 61 63 extern errno_t smenu_entry_move_up(smenu_entry_t *); -
uspace/lib/tbarcfg/private/tbarcfg.h
r5f3188b8 re63e74a 61 61 /** SIF node (persistent storage) */ 62 62 sif_node_t *nentry; 63 /** Is this a separator entry */ 64 bool separator; 63 65 /** Entry caption (with accelerator markup) */ 64 66 char *caption; … … 71 73 extern errno_t smenu_entry_new(tbarcfg_t *, sif_node_t *, const char *, 72 74 const char *, bool, smenu_entry_t **); 75 extern errno_t smenu_entry_sep_new(tbarcfg_t *, sif_node_t *, smenu_entry_t **); 73 76 extern void smenu_entry_delete(smenu_entry_t *); 74 77 -
uspace/lib/tbarcfg/src/tbarcfg.c
r5f3188b8 re63e74a 108 108 sif_node_t *nentry; 109 109 const char *ntype; 110 const char *separator; 110 111 const char *caption; 111 112 const char *cmd; … … 143 144 } 144 145 145 caption = sif_node_get_attr(nentry, "caption");146 if ( caption == NULL) {146 separator = sif_node_get_attr(nentry, "separator"); 147 if (separator != NULL && str_cmp(separator, "y") != 0) { 147 148 rc = EIO; 148 149 goto error; 149 150 } 150 151 151 cmd = sif_node_get_attr(nentry, "cmd"); 152 if (cmd == NULL) { 153 rc = EIO; 154 goto error; 152 if (separator == NULL) { 153 caption = sif_node_get_attr(nentry, "caption"); 154 if (caption == NULL) { 155 rc = EIO; 156 goto error; 157 } 158 159 cmd = sif_node_get_attr(nentry, "cmd"); 160 if (cmd == NULL) { 161 rc = EIO; 162 goto error; 163 } 164 165 terminal = sif_node_get_attr(nentry, "terminal"); 166 if (terminal == NULL) 167 terminal = "n"; 168 169 rc = smenu_entry_new(tbcfg, nentry, caption, cmd, 170 str_cmp(terminal, "y") == 0, NULL); 171 if (rc != EOK) 172 goto error; 173 } else { 174 rc = smenu_entry_sep_new(tbcfg, nentry, NULL); 175 if (rc != EOK) 176 goto error; 155 177 } 156 157 terminal = sif_node_get_attr(nentry, "terminal");158 if (terminal == NULL)159 terminal = "n";160 161 rc = smenu_entry_new(tbcfg, nentry, caption, cmd,162 str_cmp(terminal, "y") == 0, NULL);163 if (rc != EOK)164 goto error;165 178 166 179 nentry = sif_node_next_child(nentry); … … 266 279 const char *smenu_entry_get_caption(smenu_entry_t *entry) 267 280 { 281 assert(!entry->separator); 268 282 return entry->caption; 269 283 } … … 276 290 const char *smenu_entry_get_cmd(smenu_entry_t *entry) 277 291 { 292 assert(!entry->separator); 278 293 return entry->cmd; 279 294 } 280 295 281 /** Get start menu start in terminal flag.296 /** Get start menu entry start in terminal flag. 282 297 * 283 298 * @param entry Start menu entry … … 286 301 bool smenu_entry_get_terminal(smenu_entry_t *entry) 287 302 { 303 assert(!entry->separator); 288 304 return entry->terminal; 305 } 306 307 /** Get start menu entry separator flag. 308 * 309 * @param entry Start menu entry 310 * @return Separator flag 311 */ 312 bool smenu_entry_get_separator(smenu_entry_t *entry) 313 { 314 return entry->separator; 289 315 } 290 316 … … 301 327 { 302 328 char *dcap; 329 330 assert(!entry->separator); 303 331 304 332 dcap = str_dup(caption); … … 324 352 char *dcmd; 325 353 354 assert(!entry->separator); 355 326 356 dcmd = str_dup(cmd); 327 357 if (dcmd == NULL) … … 343 373 void smenu_entry_set_terminal(smenu_entry_t *entry, bool terminal) 344 374 { 375 assert(!entry->separator); 345 376 entry->terminal = terminal; 346 377 } … … 355 386 errno_t rc; 356 387 357 rc = sif_node_set_attr(trans, entry->nentry, "cmd", entry->cmd); 358 if (rc != EOK) 359 goto error; 360 361 rc = sif_node_set_attr(trans, entry->nentry, "caption", entry->caption); 362 if (rc != EOK) 363 goto error; 364 365 rc = sif_node_set_attr(trans, entry->nentry, "terminal", 366 entry->terminal ? "y" : "n"); 367 if (rc != EOK) 368 goto error; 388 if (entry->separator) { 389 rc = sif_node_set_attr(trans, entry->nentry, "separator", "y"); 390 if (rc != EOK) 391 goto error; 392 } else { 393 sif_node_unset_attr(trans, entry->nentry, "separator"); 394 395 rc = sif_node_set_attr(trans, entry->nentry, "cmd", entry->cmd); 396 if (rc != EOK) 397 goto error; 398 399 rc = sif_node_set_attr(trans, entry->nentry, "caption", 400 entry->caption); 401 if (rc != EOK) 402 goto error; 403 404 rc = sif_node_set_attr(trans, entry->nentry, "terminal", 405 entry->terminal ? "y" : "n"); 406 if (rc != EOK) 407 goto error; 408 } 369 409 370 410 return EOK; … … 457 497 } 458 498 499 /** Allocate a start menu separator entry and append it to the start menu 500 * (internal). 501 * 502 * This only creates the entry in memory, but does not update the repository. 503 * 504 * @param smenu Start menu 505 * @param nentry Backing SIF node 506 * @param rentry Place to store pointer to new entry or @c NULL 507 */ 508 errno_t smenu_entry_sep_new(tbarcfg_t *smenu, sif_node_t *nentry, 509 smenu_entry_t **rentry) 510 { 511 smenu_entry_t *entry; 512 errno_t rc; 513 514 entry = calloc(1, sizeof(smenu_entry_t)); 515 if (entry == NULL) { 516 rc = ENOMEM; 517 goto error; 518 } 519 520 entry->nentry = nentry; 521 entry->separator = true; 522 523 entry->smenu = smenu; 524 list_append(&entry->lentries, &smenu->entries); 525 if (rentry != NULL) 526 *rentry = entry; 527 528 return EOK; 529 error: 530 return rc; 531 } 532 459 533 /** Delete start menu entry. 460 534 * … … 467 541 { 468 542 list_remove(&entry->lentries); 469 free(entry->caption); 470 free(entry->cmd); 543 if (entry->caption != NULL) 544 free(entry->caption); 545 if (entry->cmd != NULL) 546 free(entry->cmd); 471 547 free(entry); 472 548 } … … 527 603 } 528 604 605 /** Create new start menu separator entry. 606 * 607 * @param smenu Start menu 608 * @param nentry Backing SIF node 609 * @param rentry Place to store pointer to new entry or @c NULL 610 */ 611 errno_t smenu_entry_sep_create(tbarcfg_t *smenu, smenu_entry_t **rentry) 612 { 613 sif_node_t *nentry; 614 smenu_entry_t *entry; 615 errno_t rc; 616 sif_trans_t *trans = NULL; 617 618 rc = sif_trans_begin(smenu->repo, &trans); 619 if (rc != EOK) 620 goto error; 621 622 rc = sif_node_append_child(trans, smenu->nentries, "entry", 623 &nentry); 624 if (rc != EOK) 625 goto error; 626 627 rc = sif_node_set_attr(trans, nentry, "separator", "y"); 628 if (rc != EOK) 629 goto error; 630 631 rc = smenu_entry_sep_new(smenu, nentry, &entry); 632 if (rc != EOK) 633 goto error; 634 635 rc = sif_trans_end(trans); 636 if (rc != EOK) 637 goto error; 638 639 if (rentry != NULL) 640 *rentry = entry; 641 return EOK; 642 error: 643 if (trans != NULL) 644 sif_trans_abort(trans); 645 return rc; 646 } 647 529 648 /** Destroy start menu entry. 530 649 * -
uspace/lib/tbarcfg/test/tbarcfg.c
r5f3188b8 re63e74a 135 135 } 136 136 137 /** Separator entry */ 138 PCUT_TEST(separator) 139 { 140 errno_t rc; 141 tbarcfg_t *tbcfg; 142 char fname[L_tmpnam], *p; 143 const char *caption; 144 const char *cmd; 145 smenu_entry_t *e1 = NULL, *e2 = NULL; 146 smenu_entry_t *e; 147 148 p = tmpnam(fname); 149 PCUT_ASSERT_NOT_NULL(p); 150 151 rc = tbarcfg_create(fname, &tbcfg); 152 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 153 154 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 155 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 156 PCUT_ASSERT_NOT_NULL(e1); 157 158 rc = smenu_entry_sep_create(tbcfg, &e2); 159 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 160 PCUT_ASSERT_NOT_NULL(e2); 161 162 PCUT_ASSERT_FALSE(smenu_entry_get_separator(e1)); 163 PCUT_ASSERT_TRUE(smenu_entry_get_separator(e2)); 164 165 tbarcfg_close(tbcfg); 166 167 /* Re-open repository */ 168 169 rc = tbarcfg_open(fname, &tbcfg); 170 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 171 172 e = tbarcfg_smenu_first(tbcfg); 173 PCUT_ASSERT_NOT_NULL(e); 174 175 /* Check that new values of properties have persisted */ 176 PCUT_ASSERT_FALSE(smenu_entry_get_separator(e)); 177 caption = smenu_entry_get_caption(e); 178 PCUT_ASSERT_STR_EQUALS("A", caption); 179 cmd = smenu_entry_get_cmd(e); 180 PCUT_ASSERT_STR_EQUALS("a", cmd); 181 182 e = tbarcfg_smenu_next(e); 183 184 /* Check that entry is still a separator */ 185 PCUT_ASSERT_TRUE(smenu_entry_get_separator(e)); 186 187 tbarcfg_close(tbcfg); 188 remove(fname); 189 } 190 137 191 /** Getting menu entry properties */ 138 192 PCUT_TEST(get_caption_cmd_term)
Note:
See TracChangeset
for help on using the changeset viewer.