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.c94
1 files changed, 74 insertions, 20 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index ac2d147e..55c74774 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -148,6 +148,64 @@ static iLabelWidget *addActionButton_SidebarWidget_(iSidebarWidget *d, const cha
148 return btn; 148 return btn;
149} 149}
150 150
151static iGmIdentity *menuIdentity_SidebarWidget_(const iSidebarWidget *d) {
152 if (d->mode == identities_SidebarMode) {
153 if (d->contextItem) {
154 return identity_GmCerts(certs_App(), d->contextItem->id);
155 }
156 }
157 return NULL;
158}
159
160static void updateContextMenu_SidebarWidget_(iSidebarWidget *d) {
161 if (d->mode != identities_SidebarMode) {
162 return;
163 }
164 iArray *items = collectNew_Array(sizeof(iMenuItem));
165 pushBackN_Array(items, (iMenuItem[]){
166 { person_Icon " ${ident.use}", 0, 0, "ident.use arg:1" },
167 { close_Icon " ${ident.stopuse}", 0, 0, "ident.use arg:0" },
168 { close_Icon " ${ident.stopuse.all}", 0, 0, "ident.use arg:0 clear:1" },
169 { "---", 0, 0, NULL },
170 { edit_Icon " ${menu.edit.notes}", 0, 0, "ident.edit" },
171 { "${ident.fingerprint}", 0, 0, "ident.fingerprint" },
172 { "---", 0, 0, NULL },
173 { delete_Icon " " uiTextCaution_ColorEscape "${ident.delete}", 0, 0, "ident.delete confirm:1" },
174 }, 8);
175 /* Used URLs. */
176 const iGmIdentity *ident = menuIdentity_SidebarWidget_(d);
177 if (ident) {
178 size_t insertPos = 3;
179 if (!isEmpty_StringSet(ident->useUrls)) {
180 insert_Array(items, insertPos++, &(iMenuItem){ "---", 0, 0, NULL });
181 }
182 const iString *docUrl = url_DocumentWidget(document_App());
183 iBool usedOnCurrentPage = iFalse;
184 iConstForEach(StringSet, i, ident->useUrls) {
185 const iString *url = i.value;
186 usedOnCurrentPage |= equalCase_String(docUrl, url);
187 iRangecc urlStr = range_String(url);
188 if (startsWith_Rangecc(urlStr, "gemini://")) {
189 urlStr.start += 9; /* omit the default scheme */
190 }
191 if (endsWith_Rangecc(urlStr, "/")) {
192 urlStr.end--; /* looks cleaner */
193 }
194 insert_Array(items,
195 insertPos++,
196 &(iMenuItem){ format_CStr(globe_Icon " %s", cstr_Rangecc(urlStr)),
197 0,
198 0,
199 format_CStr("!open url:%s", cstr_String(url)) });
200 }
201 if (!usedOnCurrentPage) {
202 remove_Array(items, 1);
203 }
204 }
205 destroy_Widget(d->menu);
206 d->menu = makeMenu_Widget(as_Widget(d), data_Array(items), size_Array(items));
207}
208
151static void updateItems_SidebarWidget_(iSidebarWidget *d) { 209static void updateItems_SidebarWidget_(iSidebarWidget *d) {
152 clear_ListWidget(d->list); 210 clear_ListWidget(d->list);
153 releaseChildren_Widget(d->blank); 211 releaseChildren_Widget(d->blank);
@@ -380,8 +438,11 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
380 const iGmIdentity *ident = i.ptr; 438 const iGmIdentity *ident = i.ptr;
381 iSidebarItem *item = new_SidebarItem(); 439 iSidebarItem *item = new_SidebarItem();
382 item->id = (uint32_t) index_PtrArrayConstIterator(&i); 440 item->id = (uint32_t) index_PtrArrayConstIterator(&i);
383 item->icon = ident->icon; 441 item->icon = 0x1f464; /* person */
384 set_String(&item->label, collect_String(subject_TlsCertificate(ident->cert))); 442 set_String(&item->label, collect_String(subject_TlsCertificate(ident->cert)));
443 if (startsWith_String(&item->label, "CN = ")) {
444 remove_Block(&item->label.chars, 0, 5);
445 }
385 iDate until; 446 iDate until;
386 validUntil_TlsCertificate(ident->cert, &until); 447 validUntil_TlsCertificate(ident->cert, &until);
387 const iBool isActive = isUsedOn_GmIdentity(ident, tabUrl); 448 const iBool isActive = isUsedOn_GmIdentity(ident, tabUrl);
@@ -697,15 +758,6 @@ static const iGmIdentity *constHoverIdentity_SidebarWidget_(const iSidebarWidget
697 return NULL; 758 return NULL;
698} 759}
699 760
700static iGmIdentity *menuIdentity_SidebarWidget_(const iSidebarWidget *d) {
701 if (d->mode == identities_SidebarMode) {
702 if (d->contextItem) {
703 return identity_GmCerts(certs_App(), d->contextItem->id);
704 }
705 }
706 return NULL;
707}
708
709static iGmIdentity *hoverIdentity_SidebarWidget_(const iSidebarWidget *d) { 761static iGmIdentity *hoverIdentity_SidebarWidget_(const iSidebarWidget *d) {
710 return iConstCast(iGmIdentity *, constHoverIdentity_SidebarWidget_(d)); 762 return iConstCast(iGmIdentity *, constHoverIdentity_SidebarWidget_(d));
711} 763}
@@ -848,6 +900,7 @@ iBool handleBookmarkEditorCommands_SidebarWidget_(iWidget *editor, const char *c
848 isSelected_Widget(findChild_Widget(editor, "bmed.tag.linksplit"))); 900 isSelected_Widget(findChild_Widget(editor, "bmed.tag.linksplit")));
849 postCommand_App("bookmarks.changed"); 901 postCommand_App("bookmarks.changed");
850 } 902 }
903 setupSheetTransition_Mobile(editor, iFalse);
851 destroy_Widget(editor); 904 destroy_Widget(editor);
852 return iTrue; 905 return iTrue;
853 } 906 }
@@ -1199,14 +1252,6 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1199 } 1252 }
1200 return iTrue; 1253 return iTrue;
1201 } 1254 }
1202 else if (isCommand_Widget(w, ev, "ident.showuse")) {
1203 const iGmIdentity *ident = menuIdentity_SidebarWidget_(d);
1204 if (ident) {
1205 makeSimpleMessage_Widget(uiHeading_ColorEscape "${heading.ident.use}",
1206 cstrCollect_String(joinCStr_StringSet(ident->useUrls, "\n")));
1207 }
1208 return iTrue;
1209 }
1210 else if (isCommand_Widget(w, ev, "ident.edit")) { 1255 else if (isCommand_Widget(w, ev, "ident.edit")) {
1211 const iGmIdentity *ident = menuIdentity_SidebarWidget_(d); 1256 const iGmIdentity *ident = menuIdentity_SidebarWidget_(d);
1212 if (ident) { 1257 if (ident) {
@@ -1343,13 +1388,14 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1343 updateMouseHover_ListWidget(d->list); 1388 updateMouseHover_ListWidget(d->list);
1344 } 1389 }
1345 if (constHoverItem_ListWidget(d->list) || isVisible_Widget(d->menu)) { 1390 if (constHoverItem_ListWidget(d->list) || isVisible_Widget(d->menu)) {
1346 d->contextItem = hoverItem_ListWidget(d->list); 1391 d->contextItem = hoverItem_ListWidget(d->list);
1347 /* Context is drawn in hover state. */ 1392 /* Context is drawn in hover state. */
1348 if (d->contextIndex != iInvalidPos) { 1393 if (d->contextIndex != iInvalidPos) {
1349 invalidateItem_ListWidget(d->list, d->contextIndex); 1394 invalidateItem_ListWidget(d->list, d->contextIndex);
1350 } 1395 }
1351 d->contextIndex = hoverItemIndex_ListWidget(d->list); 1396 d->contextIndex = hoverItemIndex_ListWidget(d->list);
1352 /* Update menu items. */ 1397 /* Update menu items. */
1398 updateContextMenu_SidebarWidget_(d);
1353 /* TODO: Some callback-based mechanism would be nice for updating menus right 1399 /* TODO: Some callback-based mechanism would be nice for updating menus right
1354 before they open? */ 1400 before they open? */
1355 if (d->mode == bookmarks_SidebarMode && d->contextItem) { 1401 if (d->mode == bookmarks_SidebarMode && d->contextItem) {
@@ -1695,8 +1741,16 @@ static void draw_SidebarItem_(const iSidebarItem *d, iPaint *p, iRect itemRect,
1695 const int metaFg = isHover ? permanent_ColorId | (isPressing ? uiTextPressed_ColorId 1741 const int metaFg = isHover ? permanent_ColorId | (isPressing ? uiTextPressed_ColorId
1696 : uiTextFramelessHover_ColorId) 1742 : uiTextFramelessHover_ColorId)
1697 : uiTextDim_ColorId; 1743 : uiTextDim_ColorId;
1744 if (!d->listItem.isSelected) {
1745 for (int off = 0; off < 4; ++off) {
1746 drawRange_Text(font,
1747 add_I2(cPos, init_I2(off % 2 == 0 ? -1 : 1, off / 2 == 0 ? -1 : 1)),
1748 metaFg,
1749 range_String(&icon));
1750 }
1751 }
1698 drawRange_Text( 1752 drawRange_Text(
1699 font, cPos, d->listItem.isSelected ? iconColor : metaFg, range_String(&icon)); 1753 font, cPos, d->listItem.isSelected ? iconColor : uiBackgroundSidebar_ColorId /*metaFg*/, range_String(&icon));
1700 deinit_String(&icon); 1754 deinit_String(&icon);
1701 drawRange_Text(d->listItem.isSelected ? sidebar->itemFonts[1] : font, 1755 drawRange_Text(d->listItem.isSelected ? sidebar->itemFonts[1] : font,
1702 add_I2(cPos, init_I2(indent, 0)), 1756 add_I2(cPos, init_I2(indent, 0)),