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.c187
1 files changed, 116 insertions, 71 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index da377ac2..8a96961a 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -412,19 +412,25 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct
412 setOutline_LabelWidget(child_Widget(d->actions, 1), d->feedsMode != all_FeedsMode); 412 setOutline_LabelWidget(child_Widget(d->actions, 1), d->feedsMode != all_FeedsMode);
413 setOutline_LabelWidget(child_Widget(d->actions, 2), d->feedsMode != unread_FeedsMode); 413 setOutline_LabelWidget(child_Widget(d->actions, 2), d->feedsMode != unread_FeedsMode);
414 } 414 }
415 d->menu = makeMenu_Widget( 415 const iMenuItem menuItems[] = {
416 as_Widget(d), 416 { openTab_Icon " ${menu.opentab}", 0, 0, "feed.entry.open newtab:1" },
417 (iMenuItem[]){ { openTab_Icon " ${feeds.entry.newtab}", 0, 0, "feed.entry.opentab" }, 417 { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "feed.entry.open newtab:2" },
418 { circle_Icon " ${feeds.entry.markread}", 0, 0, "feed.entry.toggleread" }, 418#if defined (iPlatformDesktop)
419 { bookmark_Icon " ${feeds.entry.bookmark}", 0, 0, "feed.entry.bookmark" }, 419 { openWindow_Icon " ${menu.openwindow}", 0, 0, "feed.entry.open newwindow:1" },
420 { "---", 0, 0, NULL }, 420#endif
421 { page_Icon " ${feeds.entry.openfeed}", 0, 0, "feed.entry.openfeed" }, 421 { "---", 0, 0, NULL },
422 { edit_Icon " ${feeds.edit}", 0, 0, "feed.entry.edit" }, 422 { circle_Icon " ${feeds.entry.markread}", 0, 0, "feed.entry.toggleread" },
423 { whiteStar_Icon " " uiTextCaution_ColorEscape "${feeds.unsubscribe}", 0, 0, "feed.entry.unsubscribe" }, 423 { bookmark_Icon " ${feeds.entry.bookmark}", 0, 0, "feed.entry.bookmark" },
424 { "---", 0, 0, NULL }, 424 { "${menu.copyurl}", 0, 0, "feed.entry.copy" },
425 { check_Icon " ${feeds.markallread}", SDLK_a, KMOD_SHIFT, "feeds.markallread" }, 425 { "---", 0, 0, NULL },
426 { reload_Icon " ${feeds.refresh}", SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh" } }, 426 { page_Icon " ${feeds.entry.openfeed}", 0, 0, "feed.entry.openfeed" },
427 10); 427 { edit_Icon " ${feeds.edit}", 0, 0, "feed.entry.edit" },
428 { whiteStar_Icon " " uiTextCaution_ColorEscape "${feeds.unsubscribe}", 0, 0, "feed.entry.unsubscribe" },
429 { "---", 0, 0, NULL },
430 { check_Icon " ${feeds.markallread}", SDLK_a, KMOD_SHIFT, "feeds.markallread" },
431 { reload_Icon " ${feeds.refresh}", SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh" }
432 };
433 d->menu = makeMenu_Widget(as_Widget(d), menuItems, iElemCount(menuItems));
428 d->modeMenu = makeMenu_Widget( 434 d->modeMenu = makeMenu_Widget(
429 as_Widget(d), 435 as_Widget(d),
430 (iMenuItem[]){ 436 (iMenuItem[]){
@@ -487,26 +493,29 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct
487 addItem_ListWidget(d->list, item); 493 addItem_ListWidget(d->list, item);
488 iRelease(item); 494 iRelease(item);
489 } 495 }
490 d->menu = makeMenu_Widget( 496 const iMenuItem menuItems[] = {
491 as_Widget(d), 497 { openTab_Icon " ${menu.opentab}", 0, 0, "bookmark.open newtab:1" },
492 (iMenuItem[]){ { openTab_Icon " ${menu.opentab}", 0, 0, "bookmark.open newtab:1" }, 498 { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "bookmark.open newtab:2" },
493 { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "bookmark.open newtab:2" }, 499#if defined (iPlatformDesktop)
494 { "---", 0, 0, NULL }, 500 { openWindow_Icon " ${menu.openwindow}", 0, 0, "bookmark.open newwindow:1" },
495 { edit_Icon " ${menu.edit}", 0, 0, "bookmark.edit" }, 501#endif
496 { copy_Icon " ${menu.dup}", 0, 0, "bookmark.dup" }, 502 { "---", 0, 0, NULL },
497 { "${menu.copyurl}", 0, 0, "bookmark.copy" }, 503 { edit_Icon " ${menu.edit}", 0, 0, "bookmark.edit" },
498 { "---", 0, 0, NULL }, 504 { copy_Icon " ${menu.dup}", 0, 0, "bookmark.dup" },
499 { "", 0, 0, "bookmark.tag tag:subscribed" }, 505 { "${menu.copyurl}", 0, 0, "bookmark.copy" },
500 { "", 0, 0, "bookmark.tag tag:homepage" }, 506 { "---", 0, 0, NULL },
501 { "", 0, 0, "bookmark.tag tag:remotesource" }, 507 { "", 0, 0, "bookmark.tag tag:subscribed" },
502 { "---", 0, 0, NULL }, 508 { "", 0, 0, "bookmark.tag tag:homepage" },
503 { delete_Icon " " uiTextCaution_ColorEscape "${bookmark.delete}", 0, 0, "bookmark.delete" }, 509 { "", 0, 0, "bookmark.tag tag:remotesource" },
504 { "---", 0, 0, NULL }, 510 { "---", 0, 0, NULL },
505 { add_Icon " ${menu.newfolder}", 0, 0, "bookmark.addfolder" }, 511 { delete_Icon " " uiTextCaution_ColorEscape "${bookmark.delete}", 0, 0, "bookmark.delete" },
506 { upDownArrow_Icon " ${menu.sort.alpha}", 0, 0, "bookmark.sortfolder" }, 512 { "---", 0, 0, NULL },
507 { "---", 0, 0, NULL }, 513 { folder_Icon " ${menu.newfolder}", 0, 0, "bookmark.addfolder" },
508 { reload_Icon " ${bookmarks.reload}", 0, 0, "bookmarks.reload.remote" } }, 514 { upDownArrow_Icon " ${menu.sort.alpha}", 0, 0, "bookmark.sortfolder" },
509 17); 515 { "---", 0, 0, NULL },
516 { reload_Icon " ${bookmarks.reload}", 0, 0, "bookmarks.reload.remote" }
517 };
518 d->menu = makeMenu_Widget(as_Widget(d), menuItems, iElemCount(menuItems));
510 d->modeMenu = makeMenu_Widget( 519 d->modeMenu = makeMenu_Widget(
511 as_Widget(d), 520 as_Widget(d),
512 (iMenuItem[]){ { bookmark_Icon " ${menu.page.bookmark}", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, 521 (iMenuItem[]){ { bookmark_Icon " ${menu.page.bookmark}", SDLK_d, KMOD_PRIMARY, "bookmark.add" },
@@ -520,7 +529,7 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct
520 addActionButton_SidebarWidget_(d, "${sidebar.action.bookmarks.newfolder}", 529 addActionButton_SidebarWidget_(d, "${sidebar.action.bookmarks.newfolder}",
521 "bookmarks.addfolder", !d->isEditing ? hidden_WidgetFlag : 0); 530 "bookmarks.addfolder", !d->isEditing ? hidden_WidgetFlag : 0);
522 addChildFlags_Widget(d->actions, iClob(new_Widget()), expand_WidgetFlag); 531 addChildFlags_Widget(d->actions, iClob(new_Widget()), expand_WidgetFlag);
523 iLabelWidget *btn = addActionButton_SidebarWidget_(d, 532 addActionButton_SidebarWidget_(d,
524 d->isEditing ? "${sidebar.close}" : "${sidebar.action.bookmarks.edit}", 533 d->isEditing ? "${sidebar.close}" : "${sidebar.action.bookmarks.edit}",
525 "sidebar.bookmarks.edit", 0); 534 "sidebar.bookmarks.edit", 0);
526 } 535 }
@@ -568,16 +577,21 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct
568 addItem_ListWidget(d->list, item); 577 addItem_ListWidget(d->list, item);
569 iRelease(item); 578 iRelease(item);
570 } 579 }
571 d->menu = makeMenu_Widget( 580 const iMenuItem menuItems[] = {
572 as_Widget(d), 581 { openTab_Icon " ${menu.opentab}", 0, 0, "history.open newtab:1" },
573 (iMenuItem[]){ 582 { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "history.open newtab:2" },
574 { "${menu.copyurl}", 0, 0, "history.copy" }, 583#if defined (iPlatformDesktop)
575 { bookmark_Icon " ${sidebar.entry.bookmark}", 0, 0, "history.addbookmark" }, 584 { openWindow_Icon " ${menu.openwindow}", 0, 0, "history.open newwindow:1" },
576 { "---", 0, 0, NULL }, 585#endif
577 { close_Icon " ${menu.forgeturl}", 0, 0, "history.delete" }, 586 { "---" },
578 { "---", 0, 0, NULL }, 587 { bookmark_Icon " ${sidebar.entry.bookmark}", 0, 0, "history.addbookmark" },
579 { delete_Icon " " uiTextCaution_ColorEscape "${history.clear}", 0, 0, "history.clear confirm:1" }, 588 { "${menu.copyurl}", 0, 0, "history.copy" },
580 }, 6); 589 { "---", 0, 0, NULL },
590 { close_Icon " ${menu.forgeturl}", 0, 0, "history.delete" },
591 { "---", 0, 0, NULL },
592 { delete_Icon " " uiTextCaution_ColorEscape "${history.clear}", 0, 0, "history.clear confirm:1" },
593 };
594 d->menu = makeMenu_Widget(as_Widget(d), menuItems, iElemCount(menuItems));
581 d->modeMenu = makeMenu_Widget( 595 d->modeMenu = makeMenu_Widget(
582 as_Widget(d), 596 as_Widget(d),
583 (iMenuItem[]){ 597 (iMenuItem[]){
@@ -981,7 +995,7 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, iSidebarItem *item, si
981 } 995 }
982 case feeds_SidebarMode: { 996 case feeds_SidebarMode: {
983 postCommandString_Root(get_Root(), 997 postCommandString_Root(get_Root(),
984 feedEntryOpenCommand_String(&item->url, openTabMode_Sym(modState_Keys()))); 998 feedEntryOpenCommand_String(&item->url, openTabMode_Sym(modState_Keys()), 0));
985 break; 999 break;
986 } 1000 }
987 case bookmarks_SidebarMode: 1001 case bookmarks_SidebarMode:
@@ -1641,11 +1655,20 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1641 else if (startsWith_CStr(cmd, "feed.entry.") && d->mode == feeds_SidebarMode) { 1655 else if (startsWith_CStr(cmd, "feed.entry.") && d->mode == feeds_SidebarMode) {
1642 const iSidebarItem *item = d->contextItem; 1656 const iSidebarItem *item = d->contextItem;
1643 if (item) { 1657 if (item) {
1644 if (isCommand_Widget(w, ev, "feed.entry.opentab")) { 1658 if (isCommand_Widget(w, ev, "feed.entry.open")) {
1645 postCommandString_Root(get_Root(), feedEntryOpenCommand_String(&item->url, 1)); 1659 const char *cmd = command_UserEvent(ev);
1660 postCommandString_Root(
1661 get_Root(),
1662 feedEntryOpenCommand_String(&item->url,
1663 argLabel_Command(cmd, "newtab"),
1664 argLabel_Command(cmd, "newwindow")));
1646 return iTrue; 1665 return iTrue;
1647 } 1666 }
1648 if (isCommand_Widget(w, ev, "feed.entry.toggleread")) { 1667 else if (isCommand_Widget(w, ev, "feed.entry.copy")) {
1668 SDL_SetClipboardText(cstr_String(&item->url));
1669 return iTrue;
1670 }
1671 else if (isCommand_Widget(w, ev, "feed.entry.toggleread")) {
1649 iVisited *vis = visited_App(); 1672 iVisited *vis = visited_App();
1650 const iString *url = urlFragmentStripped_String(&item->url); 1673 const iString *url = urlFragmentStripped_String(&item->url);
1651 if (containsUrl_Visited(vis, url)) { 1674 if (containsUrl_Visited(vis, url)) {
@@ -1657,7 +1680,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1657 postCommand_App("visited.changed"); 1680 postCommand_App("visited.changed");
1658 return iTrue; 1681 return iTrue;
1659 } 1682 }
1660 if (isCommand_Widget(w, ev, "feed.entry.bookmark")) { 1683 else if (isCommand_Widget(w, ev, "feed.entry.bookmark")) {
1661 makeBookmarkCreation_Widget(&item->url, &item->label, item->icon); 1684 makeBookmarkCreation_Widget(&item->url, &item->label, item->icon);
1662 if (deviceType_App() == desktop_AppDeviceType) { 1685 if (deviceType_App() == desktop_AppDeviceType) {
1663 postCommand_App("focus.set id:bmed.title"); 1686 postCommand_App("focus.set id:bmed.title");
@@ -1706,6 +1729,18 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1706 } 1729 }
1707 return iTrue; 1730 return iTrue;
1708 } 1731 }
1732 else if (isCommand_Widget(w, ev, "history.open")) {
1733 const iSidebarItem *item = d->contextItem;
1734 if (item && !isEmpty_String(&item->url)) {
1735 const char *cmd = command_UserEvent(ev);
1736 postCommand_Widget(d,
1737 "!open newtab:%d newwindow:%d url:%s",
1738 argLabel_Command(cmd, "newtab"),
1739 argLabel_Command(cmd, "newwindow"),
1740 cstr_String(&item->url));
1741 }
1742 return iTrue;
1743 }
1709 else if (isCommand_Widget(w, ev, "history.copy")) { 1744 else if (isCommand_Widget(w, ev, "history.copy")) {
1710 const iSidebarItem *item = d->contextItem; 1745 const iSidebarItem *item = d->contextItem;
1711 if (item && !isEmpty_String(&item->url)) { 1746 if (item && !isEmpty_String(&item->url)) {
@@ -2156,28 +2191,38 @@ static void draw_SidebarItem_(const iSidebarItem *d, iPaint *p, iRect itemRect,
2156 : uiTextDim_ColorId; 2191 : uiTextDim_ColorId;
2157 iUrl parts; 2192 iUrl parts;
2158 init_Url(&parts, &d->label); 2193 init_Url(&parts, &d->label);
2159 const iBool isAbout = equalCase_Rangecc(parts.scheme, "about"); 2194 const iBool isAbout = equalCase_Rangecc(parts.scheme, "about");
2160 const iBool isGemini = equalCase_Rangecc(parts.scheme, "gemini"); 2195 const iBool isGemini = equalCase_Rangecc(parts.scheme, "gemini");
2161 draw_Text(font, 2196 const iBool isData = equalCase_Rangecc(parts.scheme, "data");
2162 add_I2(topLeft_Rect(itemRect), 2197 const int queryColor = isPressing ? uiTextPressed_ColorId
2163 init_I2(3 * gap_UI, (itemHeight - lineHeight_Text(font)) / 2)), 2198 : isHover ? uiText_ColorId
2164 fg, 2199 : uiAnnotation_ColorId;
2165 "%s%s%s%s%s%s%s%s", 2200 const iInt2 textPos =
2166 isGemini ? "" : cstr_Rangecc(parts.scheme), 2201 add_I2(topLeft_Rect(itemRect),
2167 isGemini ? "" 2202 init_I2(3 * gap_UI, (itemHeight - lineHeight_Text(font)) / 2));
2168 : isAbout ? ":" 2203 if (isData) {
2169 : "://", 2204 drawRange_Text(
2170 escape_Color(isHover ? (isPressing ? uiTextPressed_ColorId 2205 font, textPos, fg, range_String(prettyDataUrl_String(&d->label, queryColor)));
2171 : uiTextFramelessHover_ColorId) 2206 }
2172 : uiTextStrong_ColorId), 2207 else {
2173 cstr_Rangecc(parts.host), 2208 draw_Text(
2174 escape_Color(fg), 2209 font,
2175 cstr_Rangecc(parts.path), 2210 textPos,
2176 !isEmpty_Range(&parts.query) ? escape_Color(isPressing ? uiTextPressed_ColorId 2211 fg,
2177 : isHover ? uiText_ColorId 2212 "%s%s%s%s%s%s%s%s",
2178 : uiAnnotation_ColorId) 2213 isGemini ? "" : cstr_Rangecc(parts.scheme),
2179 : "", 2214 isGemini ? ""
2180 !isEmpty_Range(&parts.query) ? cstr_Rangecc(parts.query) : ""); 2215 : isAbout ? ":"
2216 : "://",
2217 escape_Color(isHover ? (isPressing ? uiTextPressed_ColorId
2218 : uiTextFramelessHover_ColorId)
2219 : uiTextStrong_ColorId),
2220 cstr_Rangecc(parts.host),
2221 escape_Color(fg),
2222 cstr_Rangecc(parts.path),
2223 !isEmpty_Range(&parts.query) ? escape_Color(queryColor) : "",
2224 !isEmpty_Range(&parts.query) ? cstr_Rangecc(parts.query) : "");
2225 }
2181 } 2226 }
2182 iEndCollect(); 2227 iEndCollect();
2183 } 2228 }