summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gmcerts.c4
-rw-r--r--src/gmcerts.h2
-rw-r--r--src/ui/sidebarwidget.c59
-rw-r--r--src/ui/window.c8
4 files changed, 66 insertions, 7 deletions
diff --git a/src/gmcerts.c b/src/gmcerts.c
index 2624eb4d..0c6d709c 100644
--- a/src/gmcerts.c
+++ b/src/gmcerts.c
@@ -148,6 +148,10 @@ static iBool writeTextFile_(const iString *path, const iString *content) {
148 return iFalse; 148 return iFalse;
149} 149}
150 150
151iBool isUsed_GmIdentity(const iGmIdentity *d) {
152 return d && !isEmpty_SortedArray(&d->useUrls);
153}
154
151iDefineTypeConstruction(GmIdentity) 155iDefineTypeConstruction(GmIdentity)
152 156
153/*-----------------------------------------------------------------------------------------------*/ 157/*-----------------------------------------------------------------------------------------------*/
diff --git a/src/gmcerts.h b/src/gmcerts.h
index 32a383be..35beca7c 100644
--- a/src/gmcerts.h
+++ b/src/gmcerts.h
@@ -43,6 +43,8 @@ struct Impl_GmIdentity {
43 int flags; 43 int flags;
44}; 44};
45 45
46iBool isUsed_GmIdentity (const iGmIdentity *);
47
46iDeclareType(GmCerts) 48iDeclareType(GmCerts)
47iDeclareTypeConstructionArgs(GmCerts, const char *saveDir) 49iDeclareTypeConstructionArgs(GmCerts, const char *saveDir)
48 50
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 3e97437e..3f9f8503 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -223,6 +223,7 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
223 /* icon, common name, used URLs, expiration, isTemp, free-form notes */ 223 /* icon, common name, used URLs, expiration, isTemp, free-form notes */
224 iSidebarItem item; 224 iSidebarItem item;
225 init_SidebarItem(&item); 225 init_SidebarItem(&item);
226 item.id = index_PtrArrayConstIterator(&i);
226 item.icon = ident->icon; 227 item.icon = ident->icon;
227 set_String(&item.label, collect_String(subject_TlsCertificate(ident->cert))); 228 set_String(&item.label, collect_String(subject_TlsCertificate(ident->cert)));
228 iDate until; 229 iDate until;
@@ -240,8 +241,6 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
240 cstr_String(&ident->notes))); 241 cstr_String(&ident->notes)));
241 pushBack_Array(&d->items, &item); 242 pushBack_Array(&d->items, &item);
242 } 243 }
243 /* menu: set icon, edit notes, view urls, reveal files, delete, activate on this page,
244 * deactivate on this page, deactivate everywhere */
245 const iMenuItem menuItems[] = { 244 const iMenuItem menuItems[] = {
246 { "Use on This Page", 0, 0, "ident.use arg:1" }, 245 { "Use on This Page", 0, 0, "ident.use arg:1" },
247 { "Stop Using This Page", 0, 0, "ident.use arg:0" }, 246 { "Stop Using This Page", 0, 0, "ident.use arg:0" },
@@ -428,6 +427,13 @@ static void checkModeButtonLayout_SidebarWidget_(iSidebarWidget *d) {
428 } 427 }
429} 428}
430 429
430static const iSidebarItem *constHoverItem_SidebarWidget_(const iSidebarWidget *d) {
431 if (d->hoverItem < size_Array(&d->items)) {
432 return constAt_Array(&d->items, d->hoverItem);
433 }
434 return NULL;
435}
436
431static iSidebarItem *hoverItem_SidebarWidget_(iSidebarWidget *d) { 437static iSidebarItem *hoverItem_SidebarWidget_(iSidebarWidget *d) {
432 if (d->hoverItem < size_Array(&d->items)) { 438 if (d->hoverItem < size_Array(&d->items)) {
433 return at_Array(&d->items, d->hoverItem); 439 return at_Array(&d->items, d->hoverItem);
@@ -472,6 +478,20 @@ iBool handleBookmarkEditorCommands_SidebarWidget_(iWidget *editor, const char *c
472 return iFalse; 478 return iFalse;
473} 479}
474 480
481static const iGmIdentity *constHoverIdentity_SidebarWidget_(const iSidebarWidget *d) {
482 if (d->mode == identities_SidebarMode) {
483 const iSidebarItem *hoverItem = constHoverItem_SidebarWidget_(d);
484 if (hoverItem) {
485 return constAt_PtrArray(identities_GmCerts(certs_App()), hoverItem->id);
486 }
487 }
488 return NULL;
489}
490
491static iGmIdentity *hoverIdentity_SidebarWidget_(const iSidebarWidget *d) {
492 return iConstCast(iGmIdentity *, constHoverIdentity_SidebarWidget_(d));
493}
494
475static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) { 495static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) {
476 iWidget *w = as_Widget(d); 496 iWidget *w = as_Widget(d);
477 /* Handle commands. */ 497 /* Handle commands. */
@@ -514,12 +534,15 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
514 setMode_SidebarWidget(d, arg_Command(cmd)); 534 setMode_SidebarWidget(d, arg_Command(cmd));
515 updateItems_SidebarWidget_(d); 535 updateItems_SidebarWidget_(d);
516 if (argLabel_Command(cmd, "show") && !isVisible_Widget(w)) { 536 if (argLabel_Command(cmd, "show") && !isVisible_Widget(w)) {
517 postCommand_App("sidebar.toggle"); 537 postCommand_App("sidebar.toggle arg:1");
518 } 538 }
519 scroll_SidebarWidget_(d, 0); 539 scroll_SidebarWidget_(d, 0);
520 return iTrue; 540 return iTrue;
521 } 541 }
522 else if (equal_Command(cmd, "sidebar.toggle")) { 542 else if (equal_Command(cmd, "sidebar.toggle")) {
543 if (arg_Command(cmd) && isVisible_Widget(w)) {
544 return iTrue;
545 }
523 setFlags_Widget(w, hidden_WidgetFlag, isVisible_Widget(w)); 546 setFlags_Widget(w, hidden_WidgetFlag, isVisible_Widget(w));
524 if (isVisible_Widget(w)) { 547 if (isVisible_Widget(w)) {
525 w->rect.size.x = d->width; 548 w->rect.size.x = d->width;
@@ -577,6 +600,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
577 updateItems_SidebarWidget_(d); 600 updateItems_SidebarWidget_(d);
578 } 601 }
579 else if (isCommand_Widget(w, ev, "ident.use")) { 602 else if (isCommand_Widget(w, ev, "ident.use")) {
603
580 return iTrue; 604 return iTrue;
581 } 605 }
582 else if (isCommand_Widget(w, ev, "ident.showuse")) { 606 else if (isCommand_Widget(w, ev, "ident.showuse")) {
@@ -685,6 +709,29 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
685 } 709 }
686 if (d->menu && ev->type == SDL_MOUSEBUTTONDOWN) { 710 if (d->menu && ev->type == SDL_MOUSEBUTTONDOWN) {
687 if (d->hoverItem != iInvalidPos || isVisible_Widget(d->menu)) { 711 if (d->hoverItem != iInvalidPos || isVisible_Widget(d->menu)) {
712 /* Update menu items. */
713 if (d->mode == identities_SidebarMode) {
714 const iGmIdentity *ident = constHoverIdentity_SidebarWidget_(d);
715 const iString * docUrl = url_DocumentWidget(document_App());
716 iForEach(ObjectList, i, children_Widget(d->menu)) {
717 if (isInstance_Object(i.object, &Class_LabelWidget)) {
718 iLabelWidget *menuItem = i.object;
719 const char * itemCmd = cstr_String(command_LabelWidget(menuItem));
720 if (equal_Command(itemCmd, "ident.use")) {
721 if (!arg_Command(itemCmd)) {
722 setFlags_Widget(as_Widget(menuItem),
723 disabled_WidgetFlag,
724 !isUsed_GmIdentity(ident));
725 }
726 }
727 else if (equal_Command(itemCmd, "ident.showuse")) {
728 setFlags_Widget(as_Widget(menuItem),
729 disabled_WidgetFlag,
730 !isUsed_GmIdentity(ident));
731 }
732 }
733 }
734 }
688 processContextMenuEvent_Widget(d->menu, ev, {}); 735 processContextMenuEvent_Widget(d->menu, ev, {});
689 } 736 }
690 } 737 }
@@ -722,8 +769,8 @@ static void allocVisBuffer_SidebarWidget_(iSidebarWidget *d) {
722} 769}
723 770
724static void draw_SidebarWidget_(const iSidebarWidget *d) { 771static void draw_SidebarWidget_(const iSidebarWidget *d) {
725 const iWidget *w = constAs_Widget(d); 772 const iWidget *w = constAs_Widget(d);
726 const iRect bounds = contentBounds_SidebarWidget_(d); 773 const iRect bounds = contentBounds_SidebarWidget_(d);
727 const iBool isPressing = d->click.isActive && contains_Rect(bounds, pos_Click(&d->click)); 774 const iBool isPressing = d->click.isActive && contains_Rect(bounds, pos_Click(&d->click));
728 iPaint p; 775 iPaint p;
729 init_Paint(&p); 776 init_Paint(&p);
@@ -743,7 +790,7 @@ static void draw_SidebarWidget_(const iSidebarWidget *d) {
743 for (size_t i = visRange.start; i < visRange.end; i++) { 790 for (size_t i = visRange.start; i < visRange.end; i++) {
744 const iSidebarItem *item = constAt_Array(&d->items, i); 791 const iSidebarItem *item = constAt_Array(&d->items, i);
745 const iRect itemRect = { pos, init_I2(width_Rect(bufBounds), d->itemHeight) }; 792 const iRect itemRect = { pos, init_I2(width_Rect(bufBounds), d->itemHeight) };
746 const iBool isHover = (d->hoverItem == i); 793 const iBool isHover = isHover_Widget(w) && (d->hoverItem == i);
747 const int iconColor = 794 const int iconColor =
748 isHover ? (isPressing ? uiTextPressed_ColorId : uiIconHover_ColorId) 795 isHover ? (isPressing ? uiTextPressed_ColorId : uiIconHover_ColorId)
749 : uiIcon_ColorId; 796 : uiIcon_ColorId;
diff --git a/src/ui/window.c b/src/ui/window.c
index b5961f77..4cddff5b 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -150,11 +150,17 @@ static const iMenuItem helpMenuItems[] = {
150#endif 150#endif
151 151
152static const iMenuItem identityButtonMenuItems[] = { 152static const iMenuItem identityButtonMenuItems[] = {
153 { "No Active Identity", 0, 0, NULL },
154 { "---", 0, 0, NULL },
153#if !defined (iHaveNativeMenus) 155#if !defined (iHaveNativeMenus)
154 { "New Identity...", SDLK_n, KMOD_PRIMARY | KMOD_SHIFT, "ident.new" }, 156 { "New Identity...", SDLK_n, KMOD_PRIMARY | KMOD_SHIFT, "ident.new" },
155 { "---", 0, 0, NULL }, 157 { "---", 0, 0, NULL },
156#endif
157 { "Show Identities", '3', KMOD_PRIMARY, "sidebar.mode arg:2 show:1" }, 158 { "Show Identities", '3', KMOD_PRIMARY, "sidebar.mode arg:2 show:1" },
159#else
160 { "New Identity...", 0, 0, "ident.new" },
161 { "---", 0, 0, NULL },
162 { "Show Identities", 0, 0, "sidebar.mode arg:2 show:1" },
163#endif
158}; 164};
159 165
160static const char *reloadCStr_ = "\U0001f503"; 166static const char *reloadCStr_ = "\U0001f503";