diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-05 17:35:32 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-05 17:35:50 +0300 |
commit | 3282d252439d4166ed8f95ce42c82f0d21582e17 (patch) | |
tree | 0e44503c5337e1e79fd7e22dac0835ac6402b411 | |
parent | b557188c664184a4adb34d81d69d02384747f64d (diff) |
SidebarWidget: List item for the context menu
-rw-r--r-- | src/ui/listwidget.h | 2 | ||||
-rw-r--r-- | src/ui/sidebarwidget.c | 44 | ||||
-rw-r--r-- | src/ui/util.c | 24 |
3 files changed, 45 insertions, 25 deletions
diff --git a/src/ui/listwidget.h b/src/ui/listwidget.h index 37afe895..71635eaf 100644 --- a/src/ui/listwidget.h +++ b/src/ui/listwidget.h | |||
@@ -62,7 +62,7 @@ void updateVisible_ListWidget (iListWidget *); | |||
62 | void updateMouseHover_ListWidget (iListWidget *); | 62 | void updateMouseHover_ListWidget (iListWidget *); |
63 | 63 | ||
64 | size_t numItems_ListWidget (const iListWidget *); | 64 | size_t numItems_ListWidget (const iListWidget *); |
65 | size_t itemIndex_ListWidget(const iListWidget *, iInt2 pos); | 65 | size_t itemIndex_ListWidget(const iListWidget *, iInt2 pos); |
66 | const iAnyObject *constHoverItem_ListWidget(const iListWidget *); | 66 | const iAnyObject *constHoverItem_ListWidget(const iListWidget *); |
67 | iAnyObject *hoverItem_ListWidget(iListWidget *); | 67 | iAnyObject *hoverItem_ListWidget(iListWidget *); |
68 | 68 | ||
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 8d7b47b7..4cedd731 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c | |||
@@ -92,6 +92,7 @@ struct Impl_SidebarWidget { | |||
92 | iWidget *resizer; | 92 | iWidget *resizer; |
93 | SDL_Cursor *resizeCursor; | 93 | SDL_Cursor *resizeCursor; |
94 | iWidget *menu; | 94 | iWidget *menu; |
95 | iSidebarItem *menuItem; /* list item accessed in the context menu */ | ||
95 | }; | 96 | }; |
96 | 97 | ||
97 | iDefineObjectConstruction(SidebarWidget) | 98 | iDefineObjectConstruction(SidebarWidget) |
@@ -347,6 +348,15 @@ static const iGmIdentity *constHoverIdentity_SidebarWidget_(const iSidebarWidget | |||
347 | return NULL; | 348 | return NULL; |
348 | } | 349 | } |
349 | 350 | ||
351 | static iGmIdentity *menuIdentity_SidebarWidget_(const iSidebarWidget *d) { | ||
352 | if (d->mode == identities_SidebarMode) { | ||
353 | if (d->menuItem) { | ||
354 | return identity_GmCerts(certs_App(), d->menuItem->id); | ||
355 | } | ||
356 | } | ||
357 | return NULL; | ||
358 | } | ||
359 | |||
350 | static iGmIdentity *hoverIdentity_SidebarWidget_(const iSidebarWidget *d) { | 360 | static iGmIdentity *hoverIdentity_SidebarWidget_(const iSidebarWidget *d) { |
351 | return iConstCast(iGmIdentity *, constHoverIdentity_SidebarWidget_(d)); | 361 | return iConstCast(iGmIdentity *, constHoverIdentity_SidebarWidget_(d)); |
352 | } | 362 | } |
@@ -477,6 +487,12 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
477 | itemClicked_SidebarWidget_(d, pointerLabel_Command(cmd, "item")); | 487 | itemClicked_SidebarWidget_(d, pointerLabel_Command(cmd, "item")); |
478 | return iTrue; | 488 | return iTrue; |
479 | } | 489 | } |
490 | else if (isCommand_Widget(w, ev, "menu.opened")) { | ||
491 | setFlags_Widget(as_Widget(d->list), disabled_WidgetFlag, iTrue); | ||
492 | } | ||
493 | else if (isCommand_Widget(w, ev, "menu.closed")) { | ||
494 | setFlags_Widget(as_Widget(d->list), disabled_WidgetFlag, iFalse); | ||
495 | } | ||
480 | else if (equal_Command(cmd, "sidebar.width")) { | 496 | else if (equal_Command(cmd, "sidebar.width")) { |
481 | setWidth_SidebarWidget(d, arg_Command(cmd)); | 497 | setWidth_SidebarWidget(d, arg_Command(cmd)); |
482 | return iTrue; | 498 | return iTrue; |
@@ -508,14 +524,14 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
508 | updateItems_SidebarWidget_(d); | 524 | updateItems_SidebarWidget_(d); |
509 | } | 525 | } |
510 | else if (equal_Command(cmd, "bookmark.copy")) { | 526 | else if (equal_Command(cmd, "bookmark.copy")) { |
511 | const iSidebarItem *item = hoverItem_ListWidget(d->list); | 527 | const iSidebarItem *item = d->menuItem; //hoverItem_ListWidget(d->list); |
512 | if (d->mode == bookmarks_SidebarMode && item) { | 528 | if (d->mode == bookmarks_SidebarMode && item) { |
513 | SDL_SetClipboardText(cstr_String(&item->url)); | 529 | SDL_SetClipboardText(cstr_String(&item->url)); |
514 | } | 530 | } |
515 | return iTrue; | 531 | return iTrue; |
516 | } | 532 | } |
517 | else if (equal_Command(cmd, "bookmark.edit")) { | 533 | else if (equal_Command(cmd, "bookmark.edit")) { |
518 | const iSidebarItem *item = hoverItem_ListWidget(d->list); | 534 | const iSidebarItem *item = d->menuItem; //hoverItem_ListWidget(d->list); |
519 | if (d->mode == bookmarks_SidebarMode && item) { | 535 | if (d->mode == bookmarks_SidebarMode && item) { |
520 | setFlags_Widget(w, disabled_WidgetFlag, iTrue); | 536 | setFlags_Widget(w, disabled_WidgetFlag, iTrue); |
521 | iWidget *dlg = makeBookmarkEditor_Widget(); | 537 | iWidget *dlg = makeBookmarkEditor_Widget(); |
@@ -529,7 +545,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
529 | return iTrue; | 545 | return iTrue; |
530 | } | 546 | } |
531 | else if (equal_Command(cmd, "bookmark.delete")) { | 547 | else if (equal_Command(cmd, "bookmark.delete")) { |
532 | const iSidebarItem *item = hoverItem_ListWidget(d->list); | 548 | const iSidebarItem *item = d->menuItem; |
533 | if (d->mode == bookmarks_SidebarMode && item && remove_Bookmarks(bookmarks_App(), item->id)) { | 549 | if (d->mode == bookmarks_SidebarMode && item && remove_Bookmarks(bookmarks_App(), item->id)) { |
534 | postCommand_App("bookmarks.changed"); | 550 | postCommand_App("bookmarks.changed"); |
535 | } | 551 | } |
@@ -542,7 +558,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
542 | updateItems_SidebarWidget_(d); | 558 | updateItems_SidebarWidget_(d); |
543 | } | 559 | } |
544 | else if (isCommand_Widget(w, ev, "ident.use")) { | 560 | else if (isCommand_Widget(w, ev, "ident.use")) { |
545 | iGmIdentity * ident = hoverIdentity_SidebarWidget_(d); | 561 | iGmIdentity * ident = menuIdentity_SidebarWidget_(d); |
546 | const iString *tabUrl = url_DocumentWidget(document_App()); | 562 | const iString *tabUrl = url_DocumentWidget(document_App()); |
547 | if (ident) { | 563 | if (ident) { |
548 | if (argLabel_Command(cmd, "clear")) { | 564 | if (argLabel_Command(cmd, "clear")) { |
@@ -559,7 +575,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
559 | return iTrue; | 575 | return iTrue; |
560 | } | 576 | } |
561 | else if (isCommand_Widget(w, ev, "ident.showuse")) { | 577 | else if (isCommand_Widget(w, ev, "ident.showuse")) { |
562 | const iGmIdentity *ident = constHoverIdentity_SidebarWidget_(d); | 578 | const iGmIdentity *ident = menuIdentity_SidebarWidget_(d); |
563 | if (ident) { | 579 | if (ident) { |
564 | makeMessage_Widget(uiHeading_ColorEscape "IDENTITY USAGE", | 580 | makeMessage_Widget(uiHeading_ColorEscape "IDENTITY USAGE", |
565 | cstrCollect_String(joinCStr_StringSet(ident->useUrls, "\n"))); | 581 | cstrCollect_String(joinCStr_StringSet(ident->useUrls, "\n"))); |
@@ -567,7 +583,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
567 | return iTrue; | 583 | return iTrue; |
568 | } | 584 | } |
569 | else if (isCommand_Widget(w, ev, "ident.edit")) { | 585 | else if (isCommand_Widget(w, ev, "ident.edit")) { |
570 | const iGmIdentity *ident = constHoverIdentity_SidebarWidget_(d); | 586 | const iGmIdentity *ident = menuIdentity_SidebarWidget_(d); |
571 | if (ident) { | 587 | if (ident) { |
572 | makeValueInput_Widget(get_Window()->root, | 588 | makeValueInput_Widget(get_Window()->root, |
573 | &ident->notes, | 589 | &ident->notes, |
@@ -590,7 +606,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
590 | return iTrue; | 606 | return iTrue; |
591 | } | 607 | } |
592 | else if (isCommand_Widget(w, ev, "ident.reveal")) { | 608 | else if (isCommand_Widget(w, ev, "ident.reveal")) { |
593 | const iGmIdentity *ident = constHoverIdentity_SidebarWidget_(d); | 609 | const iGmIdentity *ident = menuIdentity_SidebarWidget_(d); |
594 | if (ident) { | 610 | if (ident) { |
595 | const iString *crtPath = certificatePath_GmCerts(certs_App(), ident); | 611 | const iString *crtPath = certificatePath_GmCerts(certs_App(), ident); |
596 | if (crtPath) { | 612 | if (crtPath) { |
@@ -600,7 +616,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
600 | return iTrue; | 616 | return iTrue; |
601 | } | 617 | } |
602 | else if (equal_Command(cmd, "ident.delete")) { | 618 | else if (equal_Command(cmd, "ident.delete")) { |
603 | iSidebarItem *item = hoverItem_ListWidget(d->list); | 619 | iSidebarItem *item = d->menuItem; |
604 | if (argLabel_Command(cmd, "confirm")) { | 620 | if (argLabel_Command(cmd, "confirm")) { |
605 | makeQuestion_Widget(uiTextCaution_ColorEscape "DELETE IDENTITY", | 621 | makeQuestion_Widget(uiTextCaution_ColorEscape "DELETE IDENTITY", |
606 | format_CStr("Do you really want to delete the identity\n" | 622 | format_CStr("Do you really want to delete the identity\n" |
@@ -620,23 +636,22 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
620 | return iTrue; | 636 | return iTrue; |
621 | } | 637 | } |
622 | else if (equal_Command(cmd, "history.delete")) { | 638 | else if (equal_Command(cmd, "history.delete")) { |
623 | const iSidebarItem *item = hoverItem_ListWidget(d->list); | 639 | if (d->menuItem && !isEmpty_String(&d->menuItem->url)) { |
624 | if (item && !isEmpty_String(&item->url)) { | 640 | removeUrl_Visited(visited_App(), &d->menuItem->url); |
625 | removeUrl_Visited(visited_App(), &item->url); | ||
626 | updateItems_SidebarWidget_(d); | 641 | updateItems_SidebarWidget_(d); |
627 | scrollOffset_ListWidget(d->list, 0); | 642 | scrollOffset_ListWidget(d->list, 0); |
628 | } | 643 | } |
629 | return iTrue; | 644 | return iTrue; |
630 | } | 645 | } |
631 | else if (equal_Command(cmd, "history.copy")) { | 646 | else if (equal_Command(cmd, "history.copy")) { |
632 | const iSidebarItem *item = hoverItem_ListWidget(d->list); | 647 | const iSidebarItem *item = d->menuItem; |
633 | if (item && !isEmpty_String(&item->url)) { | 648 | if (item && !isEmpty_String(&item->url)) { |
634 | SDL_SetClipboardText(cstr_String(&item->url)); | 649 | SDL_SetClipboardText(cstr_String(&item->url)); |
635 | } | 650 | } |
636 | return iTrue; | 651 | return iTrue; |
637 | } | 652 | } |
638 | else if (equal_Command(cmd, "history.addbookmark")) { | 653 | else if (equal_Command(cmd, "history.addbookmark")) { |
639 | const iSidebarItem *item = hoverItem_ListWidget(d->list); | 654 | const iSidebarItem *item = d->menuItem; |
640 | if (!isEmpty_String(&item->url)) { | 655 | if (!isEmpty_String(&item->url)) { |
641 | makeBookmarkCreation_Widget( | 656 | makeBookmarkCreation_Widget( |
642 | &item->url, | 657 | &item->url, |
@@ -660,7 +675,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
660 | } | 675 | } |
661 | return iTrue; | 676 | return iTrue; |
662 | } | 677 | } |
663 | } | 678 | } |
664 | if (ev->type == SDL_MOUSEMOTION && !isVisible_Widget(d->menu)) { | 679 | if (ev->type == SDL_MOUSEMOTION && !isVisible_Widget(d->menu)) { |
665 | const iInt2 mouse = init_I2(ev->motion.x, ev->motion.y); | 680 | const iInt2 mouse = init_I2(ev->motion.x, ev->motion.y); |
666 | if (contains_Widget(d->resizer, mouse)) { | 681 | if (contains_Widget(d->resizer, mouse)) { |
@@ -685,6 +700,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
685 | updateMouseHover_ListWidget(d->list); | 700 | updateMouseHover_ListWidget(d->list); |
686 | } | 701 | } |
687 | if (constHoverItem_ListWidget(d->list) || isVisible_Widget(d->menu)) { | 702 | if (constHoverItem_ListWidget(d->list) || isVisible_Widget(d->menu)) { |
703 | d->menuItem = hoverItem_ListWidget(d->list); | ||
688 | /* Update menu items. */ | 704 | /* Update menu items. */ |
689 | if (d->mode == identities_SidebarMode) { | 705 | if (d->mode == identities_SidebarMode) { |
690 | const iGmIdentity *ident = constHoverIdentity_SidebarWidget_(d); | 706 | const iGmIdentity *ident = constHoverIdentity_SidebarWidget_(d); |
diff --git a/src/ui/util.c b/src/ui/util.c index 120be3be..50aabf88 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -181,6 +181,9 @@ iWidget *addAction_Widget(iWidget *parent, int key, int kmods, const char *comma | |||
181 | 181 | ||
182 | static iBool menuHandler_(iWidget *menu, const char *cmd) { | 182 | static iBool menuHandler_(iWidget *menu, const char *cmd) { |
183 | if (isVisible_Widget(menu)) { | 183 | if (isVisible_Widget(menu)) { |
184 | if (equalWidget_Command(cmd, menu, "menu.opened")) { | ||
185 | return iFalse; | ||
186 | } | ||
184 | if (equal_Command(cmd, "menu.open") && pointer_Command(cmd) == menu->parent) { | 187 | if (equal_Command(cmd, "menu.open") && pointer_Command(cmd) == menu->parent) { |
185 | /* Don't reopen self; instead, root will close the menu. */ | 188 | /* Don't reopen self; instead, root will close the menu. */ |
186 | return iFalse; | 189 | return iFalse; |
@@ -259,12 +262,14 @@ void openMenu_Widget(iWidget *d, iInt2 coord) { | |||
259 | d->rect.pos.x += leftExcess; | 262 | d->rect.pos.x += leftExcess; |
260 | } | 263 | } |
261 | refresh_App(); | 264 | refresh_App(); |
265 | postCommand_Widget(d, "menu.opened"); | ||
262 | } | 266 | } |
263 | 267 | ||
264 | void closeMenu_Widget(iWidget *d) { | 268 | void closeMenu_Widget(iWidget *d) { |
265 | setFlags_Widget(d, hidden_WidgetFlag, iTrue); | 269 | setFlags_Widget(d, hidden_WidgetFlag, iTrue); |
266 | setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iTrue); | 270 | setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iTrue); |
267 | refresh_App(); | 271 | refresh_App(); |
272 | postCommand_Widget(d, "menu.closed"); | ||
268 | } | 273 | } |
269 | 274 | ||
270 | int checkContextMenu_Widget(iWidget *menu, const SDL_Event *ev) { | 275 | int checkContextMenu_Widget(iWidget *menu, const SDL_Event *ev) { |
@@ -663,8 +668,10 @@ void updateValueInput_Widget(iWidget *d, const char *title, const char *prompt) | |||
663 | } | 668 | } |
664 | 669 | ||
665 | static iBool messageHandler_(iWidget *msg, const char *cmd) { | 670 | static iBool messageHandler_(iWidget *msg, const char *cmd) { |
666 | /* Any command dismisses the sheet. */ | 671 | /* Almost any command dismisses the sheet. */ |
667 | iUnused(cmd); | 672 | // if (equal_Command(cmd, "menu.closed")) { |
673 | // return iFalse; | ||
674 | // } | ||
668 | destroy_Widget(msg); | 675 | destroy_Widget(msg); |
669 | return iFalse; | 676 | return iFalse; |
670 | } | 677 | } |
@@ -677,12 +684,9 @@ iWidget *makeMessage_Widget(const char *title, const char *msg) { | |||
677 | return dlg; | 684 | return dlg; |
678 | } | 685 | } |
679 | 686 | ||
680 | iWidget *makeQuestion_Widget(const char *title, | 687 | iWidget *makeQuestion_Widget(const char *title, const char *msg, const char *labels[], |
681 | const char *msg, | 688 | const char *commands[], size_t count) { |
682 | const char *labels[], | 689 | processEvents_App(postedEventsOnly_AppEventMode); |
683 | const char *commands[], | ||
684 | size_t count) { | ||
685 | // processEvents_App(postedEventsOnly_AppEventMode); | ||
686 | iWidget *dlg = makeSheet_Widget(""); | 690 | iWidget *dlg = makeSheet_Widget(""); |
687 | setCommandHandler_Widget(dlg, messageHandler_); | 691 | setCommandHandler_Widget(dlg, messageHandler_); |
688 | addChildFlags_Widget(dlg, iClob(new_LabelWidget(title, 0, 0, NULL)), frameless_WidgetFlag); | 692 | addChildFlags_Widget(dlg, iClob(new_LabelWidget(title, 0, 0, NULL)), frameless_WidgetFlag); |
@@ -715,8 +719,8 @@ static iBool toggleHandler_(iWidget *d, const char *cmd) { | |||
715 | setToggle_Widget(d, (flags_Widget(d) & selected_WidgetFlag) == 0); | 719 | setToggle_Widget(d, (flags_Widget(d) & selected_WidgetFlag) == 0); |
716 | postCommand_Widget(d, | 720 | postCommand_Widget(d, |
717 | format_CStr("%s.changed arg:%d", | 721 | format_CStr("%s.changed arg:%d", |
718 | cstr_String(id_Widget(d)), | 722 | cstr_String(id_Widget(d)), |
719 | isSelected_Widget(d) ? 1 : 0)); | 723 | isSelected_Widget(d) ? 1 : 0)); |
720 | return iTrue; | 724 | return iTrue; |
721 | } | 725 | } |
722 | return iFalse; | 726 | return iFalse; |