summaryrefslogtreecommitdiff
path: root/src/ui/sidebarwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/sidebarwidget.c')
-rw-r--r--src/ui/sidebarwidget.c68
1 files changed, 42 insertions, 26 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 7fd0d7f1..19886964 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -482,7 +482,7 @@ static const iGmIdentity *constHoverIdentity_SidebarWidget_(const iSidebarWidget
482 if (d->mode == identities_SidebarMode) { 482 if (d->mode == identities_SidebarMode) {
483 const iSidebarItem *hoverItem = constHoverItem_SidebarWidget_(d); 483 const iSidebarItem *hoverItem = constHoverItem_SidebarWidget_(d);
484 if (hoverItem) { 484 if (hoverItem) {
485 return constAt_PtrArray(identities_GmCerts(certs_App()), hoverItem->id); 485 return identity_GmCerts(certs_App(), hoverItem->id);
486 } 486 }
487 } 487 }
488 return NULL; 488 return NULL;
@@ -492,6 +492,13 @@ static iGmIdentity *hoverIdentity_SidebarWidget_(const iSidebarWidget *d) {
492 return iConstCast(iGmIdentity *, constHoverIdentity_SidebarWidget_(d)); 492 return iConstCast(iGmIdentity *, constHoverIdentity_SidebarWidget_(d));
493} 493}
494 494
495static void setHoverItem_SidebarWidget_(iSidebarWidget *d, size_t index) {
496 if (d->hoverItem != index) {
497 d->hoverItem = index;
498 invalidate_SidebarWidget_(d);
499 }
500}
501
495static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) { 502static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) {
496 iWidget *w = as_Widget(d); 503 iWidget *w = as_Widget(d);
497 /* Handle commands. */ 504 /* Handle commands. */
@@ -630,7 +637,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
630 else if (isCommand_Widget(w, ev, "ident.reveal")) { 637 else if (isCommand_Widget(w, ev, "ident.reveal")) {
631 return iTrue; 638 return iTrue;
632 } 639 }
633 else if (isCommand_Widget(w, ev, "ident.delete")) { 640 else if (equal_Command(cmd, "ident.delete")) {
634 iSidebarItem *item = hoverItem_SidebarWidget_(d); 641 iSidebarItem *item = hoverItem_SidebarWidget_(d);
635 if (argLabel_Command(cmd, "confirm")) { 642 if (argLabel_Command(cmd, "confirm")) {
636 makeQuestion_Widget(uiTextCaution_ColorEscape "DELETE IDENTITY", 643 makeQuestion_Widget(uiTextCaution_ColorEscape "DELETE IDENTITY",
@@ -646,6 +653,8 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
646 2); 653 2);
647 return iTrue; 654 return iTrue;
648 } 655 }
656 deleteIdentity_GmCerts(certs_App(), hoverIdentity_SidebarWidget_(d));
657 updateItems_SidebarWidget_(d);
649 return iTrue; 658 return iTrue;
650 } 659 }
651 else if (equal_Command(cmd, "history.delete")) { 660 else if (equal_Command(cmd, "history.delete")) {
@@ -708,10 +717,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
708 setCursor_Window(get_Window(), SDL_SYSTEM_CURSOR_ARROW); 717 setCursor_Window(get_Window(), SDL_SYSTEM_CURSOR_ARROW);
709 } 718 }
710 } 719 }
711 if (hover != d->hoverItem) { 720 setHoverItem_SidebarWidget_(d, hover);
712 d->hoverItem = hover;
713 invalidate_SidebarWidget_(d);
714 }
715 } 721 }
716 if (ev->type == SDL_MOUSEWHEEL && isHover_Widget(w)) { 722 if (ev->type == SDL_MOUSEWHEEL && isHover_Widget(w)) {
717#if defined (iPlatformApple) 723#if defined (iPlatformApple)
@@ -723,32 +729,42 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
723 return iTrue; 729 return iTrue;
724 } 730 }
725 if (d->menu && ev->type == SDL_MOUSEBUTTONDOWN) { 731 if (d->menu && ev->type == SDL_MOUSEBUTTONDOWN) {
726 if (d->hoverItem != iInvalidPos || isVisible_Widget(d->menu)) { 732 if (ev->button.button == SDL_BUTTON_RIGHT) {
727 /* Update menu items. */ 733 if (!isVisible_Widget(d->menu)) {
728 if (d->mode == identities_SidebarMode) { 734 setHoverItem_SidebarWidget_(
729 const iGmIdentity *ident = constHoverIdentity_SidebarWidget_(d); 735 d, itemIndex_SidebarWidget_(d, init_I2(ev->button.x, ev->button.y)));
730 const iString * docUrl = url_DocumentWidget(document_App()); 736 }
731 iForEach(ObjectList, i, children_Widget(d->menu)) { 737 if (d->hoverItem != iInvalidPos || isVisible_Widget(d->menu)) {
732 if (isInstance_Object(i.object, &Class_LabelWidget)) { 738 /* Update menu items. */
733 iLabelWidget *menuItem = i.object; 739 if (d->mode == identities_SidebarMode) {
734 const char * itemCmd = cstr_String(command_LabelWidget(menuItem)); 740 const iGmIdentity *ident = constHoverIdentity_SidebarWidget_(d);
735 if (equal_Command(itemCmd, "ident.use")) { 741 const iString * docUrl = url_DocumentWidget(document_App());
736 setFlags_Widget(as_Widget(menuItem), 742 iForEach(ObjectList, i, children_Widget(d->menu)) {
737 disabled_WidgetFlag, 743 if (isInstance_Object(i.object, &Class_LabelWidget)) {
738 (arg_Command(itemCmd) != 0) ^ 744 iLabelWidget *menuItem = i.object;
739 (!isUsed_GmIdentity(ident))); 745 const char * cmdItem = cstr_String(command_LabelWidget(menuItem));
740 } 746 if (equal_Command(cmdItem, "ident.use")) {
741 else if (equal_Command(itemCmd, "ident.showuse")) { 747 const iBool cmdUse = arg_Command(cmdItem) != 0;
742 setFlags_Widget(as_Widget(menuItem), 748 const iBool cmdClear = argLabel_Command(cmdItem, "clear") != 0;
743 disabled_WidgetFlag, 749 setFlags_Widget(
744 !isUsed_GmIdentity(ident)); 750 as_Widget(menuItem),
751 disabled_WidgetFlag,
752 (cmdClear && !isUsed_GmIdentity(ident)) ||
753 (!cmdClear && cmdUse && isUsedOn_GmIdentity(ident, docUrl)) ||
754 (!cmdClear && !cmdUse && !isUsedOn_GmIdentity(ident, docUrl)));
755 }
756 else if (equal_Command(cmdItem, "ident.showuse")) {
757 setFlags_Widget(as_Widget(menuItem),
758 disabled_WidgetFlag,
759 !isUsed_GmIdentity(ident));
760 }
745 } 761 }
746 } 762 }
747 } 763 }
748 } 764 }
749 processContextMenuEvent_Widget(d->menu, ev, {});
750 } 765 }
751 } 766 }
767 processContextMenuEvent_Widget(d->menu, ev, {});
752 switch (processEvent_Click(&d->click, ev)) { 768 switch (processEvent_Click(&d->click, ev)) {
753 case started_ClickResult: 769 case started_ClickResult:
754 invalidate_SidebarWidget_(d); 770 invalidate_SidebarWidget_(d);